Class: Contentful::Bootstrap::Templates::JsonTemplate
- Defined in:
- lib/contentful/bootstrap/templates/json_template.rb
Constant Summary collapse
- CONTENT_TYPES_KEY =
'contentTypes'
- ENTRIES_KEY =
'entries'
- ASSETS_KEY =
'assets'
- BOOTSTRAP_PROCCESSED_KEY =
'bootstrapProcessed'
- DISPLAY_FIELD_KEY =
'displayField'
- ALTERNATE_DISPLAY_FIELD_KEY =
'display_field'
- SYS_KEY =
'sys'
Instance Attribute Summary collapse
-
#assets ⇒ Object
readonly
Returns the value of attribute assets.
-
#content_types ⇒ Object
readonly
Returns the value of attribute content_types.
-
#entries ⇒ Object
readonly
Returns the value of attribute entries.
Attributes inherited from Base
Instance Method Summary collapse
- #after_run ⇒ Object
-
#initialize(space, file, mark_processed = false, all = true, skip_content_types = false) ⇒ JsonTemplate
constructor
A new instance of JsonTemplate.
Methods inherited from Base
Constructor Details
#initialize(space, file, mark_processed = false, all = true, skip_content_types = false) ⇒ JsonTemplate
Returns a new instance of JsonTemplate.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/contentful/bootstrap/templates/json_template.rb', line 19 def initialize(space, file, mark_processed = false, all = true, skip_content_types = false) super(space, skip_content_types) @file = file @all = all @mark_processed = mark_processed json @assets = process_assets @entries = process_entries @content_types = process_content_types check_version end |
Instance Attribute Details
#assets ⇒ Object (readonly)
Returns the value of attribute assets.
17 18 19 |
# File 'lib/contentful/bootstrap/templates/json_template.rb', line 17 def assets @assets end |
#content_types ⇒ Object (readonly)
Returns the value of attribute content_types.
17 18 19 |
# File 'lib/contentful/bootstrap/templates/json_template.rb', line 17 def content_types @content_types end |
#entries ⇒ Object (readonly)
Returns the value of attribute entries.
17 18 19 |
# File 'lib/contentful/bootstrap/templates/json_template.rb', line 17 def entries @entries end |
Instance Method Details
#after_run ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/contentful/bootstrap/templates/json_template.rb', line 34 def after_run return unless mark_processed? @json.fetch(CONTENT_TYPES_KEY, []).each do |content_type| content_type[BOOTSTRAP_PROCCESSED_KEY] = true end @json.fetch(ASSETS_KEY, []).each do |asset| asset[BOOTSTRAP_PROCCESSED_KEY] = true end @json.fetch(ENTRIES_KEY, {}).each do |_content_type_name, entry_list| entry_list.each do |entry| if entry.key?(SYS_KEY) entry[SYS_KEY][BOOTSTRAP_PROCCESSED_KEY] = true else entry[SYS_KEY] = { BOOTSTRAP_PROCCESSED_KEY => true } end end end ::File.write(@file, JSON.pretty_generate(@json)) end |