Class: Maglev::Section

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ContentConcern

#build_block_content_for, #build_default_content

Instance Attribute Details

#blocksObject

attributes ##



15
16
17
# File 'app/models/maglev/section.rb', line 15

def blocks
  @blocks
end

#blocks_labelObject

attributes ##



15
16
17
# File 'app/models/maglev/section.rb', line 15

def blocks_label
  @blocks_label
end

#blocks_presentationObject

attributes ##



15
16
17
# File 'app/models/maglev/section.rb', line 15

def blocks_presentation
  @blocks_presentation
end

#categoryObject

attributes ##



15
16
17
# File 'app/models/maglev/section.rb', line 15

def category
  @category
end

#idObject

validations ##



15
16
17
# File 'app/models/maglev/section.rb', line 15

def id
  @id
end

#insert_atObject

attributes ##



15
16
17
# File 'app/models/maglev/section.rb', line 15

def insert_at
  @insert_at
end

#insert_buttonObject

attributes ##



15
16
17
# File 'app/models/maglev/section.rb', line 15

def insert_button
  @insert_button
end

#max_width_paneObject

attributes ##



15
16
17
# File 'app/models/maglev/section.rb', line 15

def max_width_pane
  @max_width_pane
end

#nameObject

attributes ##



15
16
17
# File 'app/models/maglev/section.rb', line 15

def name
  @name
end

#sampleObject

attributes ##



15
16
17
# File 'app/models/maglev/section.rb', line 15

def sample
  @sample
end

#screenshot_timestampObject

attributes ##



15
16
17
# File 'app/models/maglev/section.rb', line 15

def screenshot_timestamp
  @screenshot_timestamp
end

#settingsObject

attributes ##



15
16
17
# File 'app/models/maglev/section.rb', line 15

def settings
  @settings
end

#singletonObject

attributes ##



15
16
17
# File 'app/models/maglev/section.rb', line 15

def singleton
  @singleton
end

#site_scopedObject

attributes ##



15
16
17
# File 'app/models/maglev/section.rb', line 15

def site_scoped
  @site_scoped
end

#themeObject

attributes ##



15
16
17
# File 'app/models/maglev/section.rb', line 15

def theme
  @theme
end

#viewport_fixed_positionObject

attributes ##



15
16
17
# File 'app/models/maglev/section.rb', line 15

def viewport_fixed_position
  @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

Returns:

  • (Boolean)


52
53
54
# File 'app/models/maglev/section.rb', line 52

def accepts_blocks?
  blocks.any? { |block| block.accept.present? }
end

#advanced_settingsObject



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

Returns:

  • (Boolean)


48
49
50
# File 'app/models/maglev/section.rb', line 48

def blocks_tree?
  blocks_presentation == 'tree'
end

#empty?Boolean

Returns:

  • (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_nameObject

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_scopeObject



77
78
79
# File 'app/models/maglev/section.rb', line 77

def i18n_scope
  "maglev.themes.#{theme.id}.sections.#{id}"
end

#local_screenshot?Boolean

Returns:

  • (Boolean)


85
86
87
# File 'app/models/maglev/section.rb', line 85

def local_screenshot?
  screenshot_timestamp.present?
end

#main_settingsObject



60
61
62
# File 'app/models/maglev/section.rb', line 60

def main_settings
  settings.reject(&:advanced?)
end

#root_blocksObject



44
45
46
# File 'app/models/maglev/section.rb', line 44

def root_blocks
  blocks.select(&:root?)
end

#singleton?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'app/models/maglev/section.rb', line 40

def singleton?
  !!singleton
end

#site_scoped?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'app/models/maglev/section.rb', line 36

def site_scoped?
  !!site_scoped
end

#viewport_fixed_position?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'app/models/maglev/section.rb', line 56

def viewport_fixed_position?
  !!viewport_fixed_position
end