Module: Editmode::Helper

Included in:
Editmode, ActionViewExtensions::EditmodeHelper
Defined in:
lib/editmode/helper.rb

Instance Method Summary collapse

Instance Method Details

#e(identifier, *args) ⇒ Object

Render non-editable content



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/editmode/helper.rb', line 4

def e(identifier, *args)
  field, options = parse_arguments(args)
  begin
    chunk = Editmode::ChunkValue.new(identifier, **options.merge({raw: true}))
    
    if chunk.chunk_type == 'collection_item'
      chunk.field(field)
    else
      chunk.content
    end 
  rescue => er
    Rails.logger.info "#{er}: We can't render content for #{identifier}"
    return ""
  end
end

#parse_arguments(args) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/editmode/helper.rb', line 25

def parse_arguments(args)
  field = nil
  options = {}
  if args[0].class.name == 'String'
    field = args[0]
    options =  args[1] || {}
  elsif args[0].class.name == 'Hash'
    options =  args[0] || {}
  end
  return field, options
end

#render_custom_field_raw(label, options = {}) ⇒ Object Also known as: f



20
21
22
# File 'lib/editmode/helper.rb', line 20

def render_custom_field_raw(label, options={})
  e(@custom_field_chunk["identifier"], label, options.merge({response: @custom_field_chunk}))      
end