Sha256: 066e543e627cd838ac4dc718b5473584c78c858642adabb2f43566a5149deeb9

Contents?: true

Size: 1.36 KB

Versions: 8

Compression:

Stored size: 1.36 KB

Contents

# frozen_string_literal: true

module Maglev
  class Theme
    ## concerns ##
    include ActiveModel::Model

    ## attributes ##
    attr_accessor :id, :name, :description, :section_categories, :sections, :style_settings, :pages, :icons

    ## validations ##
    validates :id, :name, presence: true

    ## methods ##

    def find_setting!(section_id, block_id, setting_id)
      setting = find_setting(section_id, block_id, setting_id)
      raise Maglev::Errors::UnknownSetting.new(section_id, block_id, setting_id) if setting.nil?

      setting
    end

    def find_setting(section_id, block_id, setting_id)
      key = [section_id, block_id, setting_id].compact.join('.')
      section_setting_types[key]
    end

    private

    def section_setting_types
      @section_setting_types ||= build_section_setting_types
    end

    def build_section_setting_types
      hash = {}
      sections.each do |section|
        build_section_setting_types_from_settings(hash, section.id, section.settings)
        section.blocks.each do |block|
          build_section_setting_types_from_settings(hash, "#{section.id}.#{block.type}", block.settings)
        end
      end
      hash
    end

    def build_section_setting_types_from_settings(hash, parent_key, settings)
      settings.each do |setting|
        hash["#{parent_key}.#{setting.id}"] = setting
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
maglevcms-1.7.3 app/models/maglev/theme.rb
maglevcms-1.7.2 app/models/maglev/theme.rb
maglevcms-1.7.1 app/models/maglev/theme.rb
maglevcms-1.7.0 app/models/maglev/theme.rb
maglevcms-1.6.1 app/models/maglev/theme.rb
maglevcms-1.6.0 app/models/maglev/theme.rb
maglevcms-1.5.1 app/models/maglev/theme.rb
maglevcms-1.4.0 app/models/maglev/theme.rb