Sha256: 54b33021857c0a073b6af295dee4fbb51f4bfeffa85063a01b15d6da19533c16

Contents?: true

Size: 1008 Bytes

Versions: 7

Compression:

Stored size: 1008 Bytes

Contents

module Editmode
  module Helper
    # Render non-editable content
    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

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

    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
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
editmode-1.8.1 lib/editmode/helper.rb
editmode-1.8.0 lib/editmode/helper.rb
editmode-1.7.0.pre.4 lib/editmode/helper.rb
editmode-1.7.0.pre.3 lib/editmode/helper.rb
editmode-1.7.0.pre.2 lib/editmode/helper.rb
editmode-1.7.0.pre.1 lib/editmode/helper.rb
editmode-1.6.2 lib/editmode/helper.rb