Class: Scribo::ContentRenderService

Inherits:
ApplicationService show all
Defined in:
app/services/scribo/content_render_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationService

#call

Constructor Details

#initialize(content, context, options = {}) ⇒ ContentRenderService

Returns a new instance of ContentRenderService.



9
10
11
12
13
14
15
16
# File 'app/services/scribo/content_render_service.rb', line 9

def initialize(content, context, options = {})
  super()
  @content = content
  @context = context
  @options = options
  @assigns = nil
  @registers = nil
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



7
8
9
# File 'app/services/scribo/content_render_service.rb', line 7

def content
  @content
end

#contextObject (readonly)

Returns the value of attribute context.



7
8
9
# File 'app/services/scribo/content_render_service.rb', line 7

def context
  @context
end

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'app/services/scribo/content_render_service.rb', line 7

def options
  @options
end

Instance Method Details

#performObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/services/scribo/content_render_service.rb', line 18

def perform
  if content.kind == 'asset'
    render_asset
  else
    layout = options[:layout] == false ? nil : content.layout

    # FIXME: Though this works for layout, we need to be able to merge all properties with defaults
    # Luckily this is mostly used for layouts
    if options[:site]
      layout_name = options[:site].defaults_for(content)['layout']
      layout ||= options[:site].contents.layout(layout_name).first if layout_name
    end

    render_liquidum(options[:data] || content.data, layout)
  end
end