Class: Editmode::ChunkValue
- Inherits:
-
Object
- Object
- Editmode::ChunkValue
- Includes:
- ActionViewExtensions::EditmodeHelper
- Defined in:
- lib/editmode/chunk_value.rb
Instance Attribute Summary collapse
-
#branch_id ⇒ Object
Returns the value of attribute branch_id.
-
#chunk_type ⇒ Object
Returns the value of attribute chunk_type.
- #content ⇒ Object
-
#identifier ⇒ Object
Returns the value of attribute identifier.
-
#project_id ⇒ Object
Returns the value of attribute project_id.
-
#response ⇒ Object
Returns the value of attribute response.
-
#variable_fallbacks ⇒ Object
Returns the value of attribute variable_fallbacks.
-
#variable_values ⇒ Object
Returns the value of attribute variable_values.
Instance Method Summary collapse
- #field(field = nil) ⇒ Object
-
#initialize(identifier, **options) ⇒ ChunkValue
constructor
A new instance of ChunkValue.
Methods included from ActionViewExtensions::EditmodeHelper
#api_root_url, #api_version, #chunk_collection, #chunk_display, #chunk_field_value, #no_response_received, #render_chunk, #render_chunk_content, #render_custom_field, #require_field_id, #variable_parse!
Methods included from Helper
#e, #parse_arguments, #render_custom_field_raw
Constructor Details
#initialize(identifier, **options) ⇒ ChunkValue
Returns a new instance of ChunkValue.
11 12 13 14 15 16 |
# File 'lib/editmode/chunk_value.rb', line 11 def initialize(identifier, **) @identifier = identifier @branch_id = [:branch_id].presence @variable_values = [:variables].presence || {} get_content end |
Instance Attribute Details
#branch_id ⇒ Object
Returns the value of attribute branch_id.
5 6 7 |
# File 'lib/editmode/chunk_value.rb', line 5 def branch_id @branch_id end |
#chunk_type ⇒ Object
Returns the value of attribute chunk_type.
5 6 7 |
# File 'lib/editmode/chunk_value.rb', line 5 def chunk_type @chunk_type end |
#content ⇒ Object
40 41 42 43 44 45 |
# File 'lib/editmode/chunk_value.rb', line 40 def content raise "undefined method 'content` for chunk_type: collection_item \nDid you mean? field" if chunk_type == 'collection_item' result = variable_parse!(@content, variable_fallbacks, variable_values, true) result.try(:html_safe) end |
#identifier ⇒ Object
Returns the value of attribute identifier.
5 6 7 |
# File 'lib/editmode/chunk_value.rb', line 5 def identifier @identifier end |
#project_id ⇒ Object
Returns the value of attribute project_id.
5 6 7 |
# File 'lib/editmode/chunk_value.rb', line 5 def project_id @project_id end |
#response ⇒ Object
Returns the value of attribute response.
5 6 7 |
# File 'lib/editmode/chunk_value.rb', line 5 def response @response end |
#variable_fallbacks ⇒ Object
Returns the value of attribute variable_fallbacks.
5 6 7 |
# File 'lib/editmode/chunk_value.rb', line 5 def variable_fallbacks @variable_fallbacks end |
#variable_values ⇒ Object
Returns the value of attribute variable_values.
5 6 7 |
# File 'lib/editmode/chunk_value.rb', line 5 def variable_values @variable_values end |
Instance Method Details
#field(field = nil) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/editmode/chunk_value.rb', line 18 def field(field = nil) # Field ID can be a slug or field_name if chunk_type == 'collection_item' if field.present? field.downcase! field_content = @content.detect {|f| f["custom_field_identifier"].downcase == field || f["custom_field_name"].downcase == field } if field_content.present? result = field_content['content'] result = variable_parse!(result, variable_fallbacks, variable_values, true) else raise no_response_received(field) end else raise require_field_id end else raise "undefined method 'field` for chunk_type: #{chunk_type} \n" end result ||= @content result.try(:html_safe) end |