Module: Hypermicrodata::Rails::HtmlBasedJsonRenderer

Defined in:
lib/hypermicrodata/rails/html_based_json_renderer.rb

Instance Method Summary collapse

Instance Method Details

#default_render(*args) ⇒ Object



30
31
32
# File 'lib/hypermicrodata/rails/html_based_json_renderer.rb', line 30

def default_render(*args)
  render_based_html(*args)
end

#initializeObject



4
5
6
7
# File 'lib/hypermicrodata/rails/html_based_json_renderer.rb', line 4

def initialize
  super
  @_render_based_html_options = {}
end

#render_based_html(*args) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/hypermicrodata/rails/html_based_json_renderer.rb', line 19

def render_based_html(*args)
   lookup_context.formats.first
  if m = lookup_context.formats.first.to_s.match(/json$/)
    json_format = m.pre_match.to_sym
    json = Hypermicrodata::Extract.new(render_to_string(formats: :html), @_render_based_html_options).to_json(json_format)
    render(json: json)
  else
    render(*args)
  end
end

#set_location(location) ⇒ Object



9
10
11
12
13
# File 'lib/hypermicrodata/rails/html_based_json_renderer.rb', line 9

def set_location(location)
  location_url = url_for(location)
  @_render_based_html_options[:location] = location_url
  response.headers['Content-Location'] = location_url
end

#set_profile_path(path) ⇒ Object



15
16
17
# File 'lib/hypermicrodata/rails/html_based_json_renderer.rb', line 15

def set_profile_path(path)
  @_render_based_html_options[:profile_path] = view_context.path_to_asset(path)
end