class Locomotive::Steam::Liquid::Drops::SectionContentProxy

Represent the content of a section or a block This abstraction is required to handle content manipulation based on field setting type (url for instance).

Public Class Methods

new(content, settings) click to toggle source
# File lib/locomotive/steam/liquid/drops/section_content_proxy.rb, line 11
def initialize(content, settings)
  @content, @settings = content, settings
end

Public Instance Methods

liquid_method_missing(name) click to toggle source
# File lib/locomotive/steam/liquid/drops/section_content_proxy.rb, line 15
def liquid_method_missing(name)
  value = @content[name.to_s]

  return nil if value.blank?

  case type_of(name)
  when 'url'          then SectionUrlField.new(*url_finder.url_for(value))
  when 'image_picker' then SectionImagePickerField.new(value)
  when 'integer'      then value.to_i
  when 'text'         then url_finder.decode_urls_for(value)
  else value
  end
end

Private Instance Methods

setting_of(name) click to toggle source
# File lib/locomotive/steam/liquid/drops/section_content_proxy.rb, line 35
def setting_of(name)
  @settings.find { |setting| setting['id'] == name.to_s }
end
type_of(name) click to toggle source
# File lib/locomotive/steam/liquid/drops/section_content_proxy.rb, line 31
def type_of(name)
  setting_of(name).try(:[], 'type')
end
url_finder() click to toggle source
# File lib/locomotive/steam/liquid/drops/section_content_proxy.rb, line 39
def url_finder
  @context.registers[:services].url_finder
end