Class: RogerThemes::Theme
- Inherits:
-
Object
- Object
- RogerThemes::Theme
- Defined in:
- lib/roger_themes/theme.rb
Instance Attribute Summary collapse
-
#manifest ⇒ Object
readonly
Returns the value of attribute manifest.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
-
.all(themes_path, refresh = false) ⇒ Object
Get all themes, will cache the results for a themesepath.
- .main_themes(themes_path) ⇒ Object
- .sub_themes(themes_path) ⇒ Object
- .sub_themes_for(main_theme_name, themes_path) ⇒ Object
Instance Method Summary collapse
- #assets ⇒ Object
- #compatible_with_main?(main_theme_name) ⇒ Boolean
-
#html_path ⇒ Object
The path where the templates for this theme will reside.
- #html_path_in_main(main_theme_name) ⇒ Object
-
#initialize(name, themes_path) ⇒ Theme
constructor
A new instance of Theme.
- #mains ⇒ Object
- #path_in_main(main_theme_name) ⇒ Object
-
#shared_folders ⇒ Object
Shared folders to use.
-
#shared_templates ⇒ Object
Wether or not we take the toplevel templates and render them as our own.
- #sub_themes ⇒ Object
- #title ⇒ Object
- #type ⇒ Object
- #url ⇒ Object
Constructor Details
Instance Attribute Details
#manifest ⇒ Object (readonly)
Returns the value of attribute manifest.
3 4 5 |
# File 'lib/roger_themes/theme.rb', line 3 def manifest @manifest end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/roger_themes/theme.rb', line 3 def name @name end |
#path ⇒ Object (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
#assets ⇒ Object
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
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_path ⇒ Object
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 |
#mains ⇒ Object
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_folders ⇒ Object
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_templates ⇒ Object
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_themes ⇒ Object
69 70 71 |
# File 'lib/roger_themes/theme.rb', line 69 def sub_themes self.class.sub_themes_for(name, @themes_path) end |
#title ⇒ Object
38 39 40 |
# File 'lib/roger_themes/theme.rb', line 38 def title manifest[:title] end |
#type ⇒ Object
42 43 44 |
# File 'lib/roger_themes/theme.rb', line 42 def type manifest[:type] end |
#url ⇒ Object
73 74 75 |
# File 'lib/roger_themes/theme.rb', line 73 def url "/" + RogerThemes.themes_path + "/" + name end |