This new class replaces all existing server side message rendering helpers and is the new global entry point for such needs. All models with relevant fields now expose an instance of MessageRenderer for those. MessageRenderer acts as gateway between the existing processing solutions for markdown, mentions and tags and provides a very flexible interface for all output needs. This makes the API to obtain a message in a certain format clear. As a result of centralizing the processing a lot of duplication is eliminated. Centralizing the message processing also makes it clear where to change its behaviour, add new representations and what options are already available.
47 lines
999 B
Ruby
47 lines
999 B
Ruby
class OEmbedPresenter
|
|
include PostsHelper
|
|
|
|
def initialize(post, opts = {})
|
|
@post = post
|
|
@opts = opts
|
|
end
|
|
|
|
def to_json(opts={})
|
|
as_json(opts).to_json
|
|
end
|
|
|
|
def as_json(opts={})
|
|
{
|
|
:provider_name => "Diaspora",
|
|
:provider_url => AppConfig.pod_uri.to_s,
|
|
:type => 'rich',
|
|
:version => '1.0',
|
|
:title => post_title,
|
|
:author_name => post_author,
|
|
:author_url => post_author_url,
|
|
:width => @opts.fetch(:maxwidth, 516),
|
|
:height => @opts.fetch(:maxheight, 320),
|
|
:html => iframe_html
|
|
}
|
|
end
|
|
|
|
def self.id_from_url(url)
|
|
URI.parse(url).path.gsub(%r{\/posts\/|\/p\/}, '')
|
|
end
|
|
|
|
def post_title
|
|
post_page_title(@post)
|
|
end
|
|
|
|
def post_author
|
|
@post.author_name
|
|
end
|
|
|
|
def post_author_url
|
|
Rails.application.routes.url_helpers.person_url(@post.author, :host => AppConfig.pod_uri.host)
|
|
end
|
|
|
|
def iframe_html
|
|
post_iframe_url(@post.id, :height => @opts[:maxheight], :width => @opts[:maxwidth])
|
|
end
|
|
end
|