Sha256: 3e87cfba04d065583041853f0d72b217fb690b36af3cc21e77c05f6a26d70019

Contents?: true

Size: 1.61 KB

Versions: 9

Compression:

Stored size: 1.61 KB

Contents

module Spina
  class Theme

    attr_accessor :name, :title, :parts, :page_parts, :structures, :view_templates, :layout_parts, :custom_pages, :plugins, :public_theme, :config, :navigations, :resources

    class << self

      def all
        ::Spina::THEMES
      end

      def find_by_name(name)
        all.find { |theme| theme.name == name }
      end

      def register
        theme = ::Spina::Theme.new
        yield theme
        raise 'Missing theme name' if theme.name.nil?
        if theme.plugins.nil?
          theme.plugins = ::Spina::Plugin.all.map { |plugin| plugin.name }
        end
        all << theme
      end

    end

    def initialize
      @page_parts       = []
      @structures       = []
      @layout_parts     = []
      @view_templates   = []
      @custom_pages     = []
      @navigations      = []
      @resources        = []
      @public_theme = false
    end

    def new_page_templates(recommended: "")
      @view_templates.map do |view_template|
        next if is_custom_undeletable_page?(view_template[:name])
        
        OpenStruct.new({
          name: view_template[:name],
          title: view_template[:title],
          description: view_template[:description],
          recommended: view_template[:name] == recommended
        })
      end.compact.sort_by do |page_template|
        [page_template.recommended ? 0 : 1]
      end
    end

    # Check if view_template is defined as a custom undeletable page
    def is_custom_undeletable_page?(view_template_name)
      @custom_pages.any? { |page| page[:view_template] == view_template_name && !page[:deletable] }
    end

  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
spina-2.3.5 lib/spina/theme.rb
spina-2.3.4 lib/spina/theme.rb
spina-2.3.3 lib/spina/theme.rb
spina-2.3.2 lib/spina/theme.rb
spina-2.3.1 lib/spina/theme.rb
spina-2.3.0 lib/spina/theme.rb
spina-2.2.0 lib/spina/theme.rb
spina-2.1.1 lib/spina/theme.rb
spina-2.1.0 lib/spina/theme.rb