Class: RogerThemes::Theme

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, themes_path) ⇒ Theme

Returns a new instance of Theme.



31
32
33
34
35
36
# File 'lib/roger_themes/theme.rb', line 31

def initialize(name, themes_path)
  @name = name.to_s.sub(/\A\//, "")
  @themes_path = themes_path
  @path = themes_path + @name
  @manifest = Manifest.new(self)
end

Instance Attribute Details

#manifestObject (readonly)

Returns the value of attribute manifest.



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

def manifest
  @manifest
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

Class Method Details

.all(themes_path, refresh = false) ⇒ Object

Get all themes, will cache the results for a themesepath



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/roger_themes/theme.rb', line 6

def self.all(themes_path, refresh = false)
  @_themes ||= {}

  if @_themes[themes_path] && !refresh
    return @_themes[themes_path]
  end

  @_themes[themes_path] = Dir.glob(themes_path + "*").select{|d| File.directory?(d) }.map do |path|
    name = path.sub(/\A#{Regexp.escape(themes_path.to_s)}/, "")
    Theme.new(name, themes_path)
  end
end

.main_themes(themes_path) ⇒ Object



23
24
25
# File 'lib/roger_themes/theme.rb', line 23

def self.main_themes(themes_path)
  all(themes_path).select{|theme| theme.type == "main" }
end

.sub_themes(themes_path) ⇒ Object



27
28
29
# File 'lib/roger_themes/theme.rb', line 27

def self.sub_themes(themes_path)
  all(themes_path).select{|theme| theme.type == "sub" }
end

.sub_themes_for(main_theme_name, themes_path) ⇒ Object



19
20
21
# File 'lib/roger_themes/theme.rb', line 19

def self.sub_themes_for(main_theme_name, themes_path)
  all(themes_path).select{|theme| theme.type == "sub" && theme.compatible_with_main?(main_theme_name) }
end

Instance Method Details

#assetsObject



50
51
52
53
54
55
# File 'lib/roger_themes/theme.rb', line 50

def assets
  return [] unless manifest[:assets]
  return @assets if @assets

  @assets = manifest[:assets].map {|asset_data| Asset.new(asset_data, self) }
end

#compatible_with_main?(main_theme_name) ⇒ Boolean

Returns:

  • (Boolean)


90
91
92
93
94
# File 'lib/roger_themes/theme.rb', line 90

def compatible_with_main?(main_theme_name)
  return false unless self.mains.kind_of?(Array)

  mains.include?(main_theme_name)
end

#html_pathObject

The path where the templates for this theme will reside



78
79
80
# File 'lib/roger_themes/theme.rb', line 78

def html_path
  self.path + "theme"
end

#html_path_in_main(main_theme_name) ⇒ Object



82
83
84
# File 'lib/roger_themes/theme.rb', line 82

def html_path_in_main(main_theme_name)
  path_in_main(main_theme_name) + "theme"
end

#mainsObject



46
47
48
# File 'lib/roger_themes/theme.rb', line 46

def mains
  manifest[:mains]
end

#path_in_main(main_theme_name) ⇒ Object



86
87
88
# File 'lib/roger_themes/theme.rb', line 86

def path_in_main(main_theme_name)
  @themes_path + [main_theme_name, name].join(".")
end

#shared_foldersObject

Shared folders to use. Will default to the globally set shared folders if nil or false



65
66
67
# File 'lib/roger_themes/theme.rb', line 65

def shared_folders
  manifest[:shared_folders]
end

#shared_templatesObject

Wether or not we take the toplevel templates and render them as our own.



59
60
61
# File 'lib/roger_themes/theme.rb', line 59

def shared_templates
  manifest[:shared_templates]
end

#sub_themesObject



69
70
71
# File 'lib/roger_themes/theme.rb', line 69

def sub_themes
  self.class.sub_themes_for(name, @themes_path)
end

#titleObject



38
39
40
# File 'lib/roger_themes/theme.rb', line 38

def title
  manifest[:title]
end

#typeObject



42
43
44
# File 'lib/roger_themes/theme.rb', line 42

def type
  manifest[:type]
end

#urlObject



73
74
75
# File 'lib/roger_themes/theme.rb', line 73

def url
  "/" + RogerThemes.themes_path + "/" + name
end