Class: Spina::Theme
- Inherits:
-
Object
- Object
- Spina::Theme
- Defined in:
- lib/spina/theme.rb
Defined Under Namespace
Classes: NewPageTemplate
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#custom_pages ⇒ Object
Returns the value of attribute custom_pages.
-
#embeds ⇒ Object
Returns the value of attribute embeds.
-
#layout_parts ⇒ Object
Returns the value of attribute layout_parts.
-
#name ⇒ Object
Returns the value of attribute name.
-
#navigations ⇒ Object
Returns the value of attribute navigations.
-
#page_parts ⇒ Object
Returns the value of attribute page_parts.
-
#parts ⇒ Object
Returns the value of attribute parts.
-
#plugins ⇒ Object
Returns the value of attribute plugins.
-
#public_theme ⇒ Object
Returns the value of attribute public_theme.
-
#resources ⇒ Object
Returns the value of attribute resources.
-
#structures ⇒ Object
Returns the value of attribute structures.
-
#title ⇒ Object
Returns the value of attribute title.
-
#view_templates ⇒ Object
Returns the value of attribute view_templates.
Class Method Summary collapse
- .all ⇒ Object
- .find_by_name(name) ⇒ Object
- .register {|theme| ... } ⇒ Object
- .unregister(name) ⇒ Object
Instance Method Summary collapse
- #embeddables ⇒ Object
-
#initialize ⇒ Theme
constructor
A new instance of Theme.
-
#is_custom_undeletable_page?(view_template_name) ⇒ Boolean
Check if view_template is defined as a custom undeletable page.
- #new_page_templates(resource: nil) ⇒ Object
Constructor Details
#initialize ⇒ Theme
Returns a new instance of Theme.
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/spina/theme.rb', line 33 def initialize @page_parts = [] @structures = [] @layout_parts = [] @view_templates = [] @custom_pages = [] @navigations = [] @resources = [] @embeds = [] @public_theme = false end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
3 4 5 |
# File 'lib/spina/theme.rb', line 3 def config @config end |
#custom_pages ⇒ Object
Returns the value of attribute custom_pages.
3 4 5 |
# File 'lib/spina/theme.rb', line 3 def custom_pages @custom_pages end |
#embeds ⇒ Object
Returns the value of attribute embeds.
3 4 5 |
# File 'lib/spina/theme.rb', line 3 def @embeds end |
#layout_parts ⇒ Object
Returns the value of attribute layout_parts.
3 4 5 |
# File 'lib/spina/theme.rb', line 3 def layout_parts @layout_parts end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/spina/theme.rb', line 3 def name @name end |
#navigations ⇒ Object
Returns the value of attribute navigations.
3 4 5 |
# File 'lib/spina/theme.rb', line 3 def @navigations end |
#page_parts ⇒ Object
Returns the value of attribute page_parts.
3 4 5 |
# File 'lib/spina/theme.rb', line 3 def page_parts @page_parts end |
#parts ⇒ Object
Returns the value of attribute parts.
3 4 5 |
# File 'lib/spina/theme.rb', line 3 def parts @parts end |
#plugins ⇒ Object
Returns the value of attribute plugins.
3 4 5 |
# File 'lib/spina/theme.rb', line 3 def plugins @plugins end |
#public_theme ⇒ Object
Returns the value of attribute public_theme.
3 4 5 |
# File 'lib/spina/theme.rb', line 3 def public_theme @public_theme end |
#resources ⇒ Object
Returns the value of attribute resources.
3 4 5 |
# File 'lib/spina/theme.rb', line 3 def resources @resources end |
#structures ⇒ Object
Returns the value of attribute structures.
3 4 5 |
# File 'lib/spina/theme.rb', line 3 def structures @structures end |
#title ⇒ Object
Returns the value of attribute title.
3 4 5 |
# File 'lib/spina/theme.rb', line 3 def title @title end |
#view_templates ⇒ Object
Returns the value of attribute view_templates.
3 4 5 |
# File 'lib/spina/theme.rb', line 3 def view_templates @view_templates end |
Class Method Details
.find_by_name(name) ⇒ Object
17 18 19 |
# File 'lib/spina/theme.rb', line 17 def find_by_name(name) all.find { |theme| theme.name == name } end |
.register {|theme| ... } ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/spina/theme.rb', line 21 def register theme = ::Spina::Theme.new yield theme raise "Missing theme name" if theme.name.nil? unregister(theme.name) if theme.plugins.nil? theme.plugins = ::Spina::Plugin.all.map { |plugin| plugin.name } end all << theme end |
.unregister(name) ⇒ Object
12 13 14 15 |
# File 'lib/spina/theme.rb', line 12 def unregister(name) theme = find_by_name(name) all.delete(theme) if theme end |
Instance Method Details
#embeddables ⇒ Object
45 46 47 |
# File 'lib/spina/theme.rb', line 45 def .map { || Embeds.constantize() } end |
#is_custom_undeletable_page?(view_template_name) ⇒ Boolean
Check if view_template is defined as a custom undeletable page
67 68 69 |
# File 'lib/spina/theme.rb', line 67 def is_custom_undeletable_page?(view_template_name) @custom_pages.any? { |page| page[:view_template] == view_template_name && !page[:deletable] } end |
#new_page_templates(resource: nil) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/spina/theme.rb', line 49 def new_page_templates(resource: nil) page_collection = resource&.name || "main" @view_templates.map do |view_template| next if is_custom_undeletable_page?(view_template[:name]) next if view_template[:exclude_from]&.include?(page_collection) NewPageTemplate.new( view_template[:name], view_template[:title], view_template[:description], view_template[:name] == resource&.view_template ) end.compact.sort_by do |page_template| [page_template.recommended ? 0 : 1] end end |