Class: Maglev::Section
- Inherits:
-
Object
- Object
- Maglev::Section
- Includes:
- ActiveModel::Model, ActiveModel::Serializers::JSON, ContentConcern
- Defined in:
- app/models/maglev/section.rb
Defined Under Namespace
Modules: ContentConcern Classes: Block, Setting, Store
Constant Summary collapse
- HASH_ATTRIBUTES =
%w[id theme name site_scoped singleton viewport_fixed_position insert_button max_width_pane insert_at category blocks_label blocks_presentation sample screenshot_timestamp].freeze
Instance Attribute Summary collapse
-
#blocks ⇒ Object
attributes ##.
-
#blocks_label ⇒ Object
attributes ##.
-
#blocks_presentation ⇒ Object
attributes ##.
-
#category ⇒ Object
attributes ##.
-
#id ⇒ Object
validations ##.
-
#insert_at ⇒ Object
attributes ##.
-
#insert_button ⇒ Object
attributes ##.
-
#max_width_pane ⇒ Object
attributes ##.
-
#name ⇒ Object
attributes ##.
-
#sample ⇒ Object
attributes ##.
-
#screenshot_timestamp ⇒ Object
attributes ##.
-
#settings ⇒ Object
attributes ##.
-
#singleton ⇒ Object
attributes ##.
-
#site_scoped ⇒ Object
attributes ##.
-
#theme ⇒ Object
attributes ##.
-
#viewport_fixed_position ⇒ Object
attributes ##.
Class Method Summary collapse
-
.build(hash) ⇒ Object
class methods ##.
Instance Method Summary collapse
- #accepts_blocks? ⇒ Boolean
- #advanced_settings ⇒ Object
- #assign_attributes_from_yaml(hash) ⇒ Object
- #blocks_tree? ⇒ Boolean
- #empty? ⇒ Boolean
- #human_blocks_label(default = nil) ⇒ Object
-
#human_name ⇒ Object
methods ##.
- #i18n_scope ⇒ Object
- #local_screenshot? ⇒ Boolean
- #main_settings ⇒ Object
- #root_blocks ⇒ Object
- #singleton? ⇒ Boolean
- #site_scoped? ⇒ Boolean
- #viewport_fixed_position? ⇒ Boolean
Methods included from ContentConcern
#build_block_content_for, #build_default_content
Instance Attribute Details
#blocks ⇒ Object
attributes ##
15 16 17 |
# File 'app/models/maglev/section.rb', line 15 def blocks @blocks end |
#blocks_label ⇒ Object
attributes ##
15 16 17 |
# File 'app/models/maglev/section.rb', line 15 def blocks_label @blocks_label end |
#blocks_presentation ⇒ Object
attributes ##
15 16 17 |
# File 'app/models/maglev/section.rb', line 15 def blocks_presentation @blocks_presentation end |
#category ⇒ Object
attributes ##
15 16 17 |
# File 'app/models/maglev/section.rb', line 15 def category @category end |
#id ⇒ Object
validations ##
15 16 17 |
# File 'app/models/maglev/section.rb', line 15 def id @id end |
#insert_at ⇒ Object
attributes ##
15 16 17 |
# File 'app/models/maglev/section.rb', line 15 def insert_at @insert_at end |
#insert_button ⇒ Object
attributes ##
15 16 17 |
# File 'app/models/maglev/section.rb', line 15 def @insert_button end |
#max_width_pane ⇒ Object
attributes ##
15 16 17 |
# File 'app/models/maglev/section.rb', line 15 def max_width_pane @max_width_pane end |
#name ⇒ Object
attributes ##
15 16 17 |
# File 'app/models/maglev/section.rb', line 15 def name @name end |
#sample ⇒ Object
attributes ##
15 16 17 |
# File 'app/models/maglev/section.rb', line 15 def sample @sample end |
#screenshot_timestamp ⇒ Object
attributes ##
15 16 17 |
# File 'app/models/maglev/section.rb', line 15 def @screenshot_timestamp end |
#settings ⇒ Object
attributes ##
15 16 17 |
# File 'app/models/maglev/section.rb', line 15 def settings @settings end |
#singleton ⇒ Object
attributes ##
15 16 17 |
# File 'app/models/maglev/section.rb', line 15 def singleton @singleton end |
#site_scoped ⇒ Object
attributes ##
15 16 17 |
# File 'app/models/maglev/section.rb', line 15 def site_scoped @site_scoped end |
#theme ⇒ Object
attributes ##
15 16 17 |
# File 'app/models/maglev/section.rb', line 15 def theme @theme end |
#viewport_fixed_position ⇒ Object
attributes ##
15 16 17 |
# File 'app/models/maglev/section.rb', line 15 def @viewport_fixed_position end |
Class Method Details
.build(hash) ⇒ Object
class methods ##
91 92 93 94 95 |
# File 'app/models/maglev/section.rb', line 91 def self.build(hash) new.tap do |section| section.assign_attributes_from_yaml(hash) end end |
Instance Method Details
#accepts_blocks? ⇒ Boolean
52 53 54 |
# File 'app/models/maglev/section.rb', line 52 def accepts_blocks? blocks.any? { |block| block.accept.present? } end |
#advanced_settings ⇒ Object
64 65 66 |
# File 'app/models/maglev/section.rb', line 64 def advanced_settings settings.select(&:advanced?) end |
#assign_attributes_from_yaml(hash) ⇒ Object
68 69 70 71 72 73 74 75 |
# File 'app/models/maglev/section.rb', line 68 def assign_attributes_from_yaml(hash) attributes = prepare_default_attributes(hash).merge( settings: ::Maglev::Section::Setting.build_many(hash['settings']), blocks: ::Maglev::Section::Block::Store.new(hash['blocks'], section: self) ) assign_attributes(attributes) end |
#blocks_tree? ⇒ Boolean
48 49 50 |
# File 'app/models/maglev/section.rb', line 48 def blocks_tree? blocks_presentation == 'tree' end |
#empty? ⇒ Boolean
81 82 83 |
# File 'app/models/maglev/section.rb', line 81 def empty? settings.none? && blocks.none? end |
#human_blocks_label(default = nil) ⇒ Object
32 33 34 |
# File 'app/models/maglev/section.rb', line 32 def human_blocks_label(default = nil) ::I18n.t("#{i18n_scope}.blocks.label", default: blocks_label || default) end |
#human_name ⇒ Object
methods ##
28 29 30 |
# File 'app/models/maglev/section.rb', line 28 def human_name ::I18n.t("#{i18n_scope}.name", default: name.humanize) end |
#i18n_scope ⇒ Object
77 78 79 |
# File 'app/models/maglev/section.rb', line 77 def i18n_scope "maglev.themes.#{theme.id}.sections.#{id}" end |
#local_screenshot? ⇒ Boolean
85 86 87 |
# File 'app/models/maglev/section.rb', line 85 def local_screenshot? .present? end |
#main_settings ⇒ Object
60 61 62 |
# File 'app/models/maglev/section.rb', line 60 def main_settings settings.reject(&:advanced?) end |
#root_blocks ⇒ Object
44 45 46 |
# File 'app/models/maglev/section.rb', line 44 def root_blocks blocks.select(&:root?) end |
#singleton? ⇒ Boolean
40 41 42 |
# File 'app/models/maglev/section.rb', line 40 def singleton? !!singleton end |
#site_scoped? ⇒ Boolean
36 37 38 |
# File 'app/models/maglev/section.rb', line 36 def site_scoped? !!site_scoped end |
#viewport_fixed_position? ⇒ Boolean
56 57 58 |
# File 'app/models/maglev/section.rb', line 56 def !! end |