Class: Spina::Theme

Inherits:
Object
  • Object
show all
Defined in:
lib/spina/theme.rb

Defined Under Namespace

Classes: NewPageTemplate

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTheme

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

#configObject

Returns the value of attribute config.



3
4
5
# File 'lib/spina/theme.rb', line 3

def config
  @config
end

#custom_pagesObject

Returns the value of attribute custom_pages.



3
4
5
# File 'lib/spina/theme.rb', line 3

def custom_pages
  @custom_pages
end

#embedsObject

Returns the value of attribute embeds.



3
4
5
# File 'lib/spina/theme.rb', line 3

def embeds
  @embeds
end

#layout_partsObject

Returns the value of attribute layout_parts.



3
4
5
# File 'lib/spina/theme.rb', line 3

def layout_parts
  @layout_parts
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/spina/theme.rb', line 3

def name
  @name
end

Returns the value of attribute navigations.



3
4
5
# File 'lib/spina/theme.rb', line 3

def navigations
  @navigations
end

#page_partsObject

Returns the value of attribute page_parts.



3
4
5
# File 'lib/spina/theme.rb', line 3

def page_parts
  @page_parts
end

#partsObject

Returns the value of attribute parts.



3
4
5
# File 'lib/spina/theme.rb', line 3

def parts
  @parts
end

#pluginsObject

Returns the value of attribute plugins.



3
4
5
# File 'lib/spina/theme.rb', line 3

def plugins
  @plugins
end

#public_themeObject

Returns the value of attribute public_theme.



3
4
5
# File 'lib/spina/theme.rb', line 3

def public_theme
  @public_theme
end

#resourcesObject

Returns the value of attribute resources.



3
4
5
# File 'lib/spina/theme.rb', line 3

def resources
  @resources
end

#structuresObject

Returns the value of attribute structures.



3
4
5
# File 'lib/spina/theme.rb', line 3

def structures
  @structures
end

#titleObject

Returns the value of attribute title.



3
4
5
# File 'lib/spina/theme.rb', line 3

def title
  @title
end

#view_templatesObject

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

.allObject



8
9
10
# File 'lib/spina/theme.rb', line 8

def all
  ::Spina::THEMES
end

.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

Yields:

  • (theme)


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

#embeddablesObject



45
46
47
# File 'lib/spina/theme.rb', line 45

def embeddables
  embeds.map { |embed| Embeds.constantize(embed) }
end

#is_custom_undeletable_page?(view_template_name) ⇒ Boolean

Check if view_template is defined as a custom undeletable page

Returns:

  • (Boolean)


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