Sha256: e7c294642b261a8cb91b547d57a3b7fb74ea71f1e9352da7c8defc51cb7a59fc

Contents?: true

Size: 1.18 KB

Versions: 18

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true

module Maglev
  class PageComponent < BaseComponent
    attr_reader :site, :theme, :page, :page_sections, :templates_root_path, :config

    # rubocop:disable Lint/MissingSuper, Metrics/ParameterLists
    def initialize(site:, theme:, page:, page_sections:, templates_root_path:, config:)
      @site = site
      @theme = theme
      @page = page
      @page_sections = page_sections
      @templates_root_path = templates_root_path
      @config = config
    end
    # rubocop:enable Lint/MissingSuper, Metrics/ParameterLists

    # Sections within a dropzone
    def sections
      @sections ||= page_sections.map do |attributes|
        definition = theme.sections.find(attributes['type'])
        next unless definition

        build_section(definition, attributes)
      end.compact
    end

    def render
      sections.collect(&:render).join
    end

    private

    def build_section(definition, attributes)
      build(
        SectionComponent,
        parent: self,
        definition: definition,
        attributes: attributes.deep_transform_keys! { |k| k.to_s.underscore.to_sym },
        templates_root_path: templates_root_path
      )
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
maglevcms-1.5.1 app/components/maglev/page_component.rb
maglevcms-1.4.0 app/components/maglev/page_component.rb
maglevcms-1.3.0 app/components/maglev/page_component.rb
maglevcms-1.2.2 app/components/maglev/page_component.rb
maglevcms-1.2.1 app/components/maglev/page_component.rb
maglevcms-1.2.0 app/components/maglev/page_component.rb
maglevcms-1.1.7 app/components/maglev/page_component.rb
maglevcms-1.1.6 app/components/maglev/page_component.rb
maglevcms-1.1.5 app/components/maglev/page_component.rb
maglevcms-1.1.4 app/components/maglev/page_component.rb
maglevcms-1.1.3 app/components/maglev/page_component.rb
maglevcms-1.1.2 app/components/maglev/page_component.rb
maglevcms-1.1.1 app/components/maglev/page_component.rb
maglevcms-1.1.0 app/components/maglev/page_component.rb
maglevcms-1.0.0 app/components/maglev/page_component.rb
maglevcms-1.0.0.rc3 app/components/maglev/page_component.rb
maglevcms-1.0.0.rc2 app/components/maglev/page_component.rb
maglevcms-1.0.0.rc1 app/components/maglev/page_component.rb