Class: Noumenon::Theme
- Inherits:
-
Object
- Object
- Noumenon::Theme
- Defined in:
- lib/noumenon/theme.rb
Overview
Provides access to a theme and it’s contents.
Defined Under Namespace
Classes: AssetsMiddleware, Drop, NotFoundError
Instance Attribute Summary collapse
-
#author ⇒ Object
The author of this theme.
-
#copyright ⇒ Object
The copyright line to attribute this theme to.
-
#email ⇒ Object
The email address to contact regarding this theme.
-
#license ⇒ Object
The license this theme is distributed under.
-
#name ⇒ Object
The name to refer to this theme by.
-
#path ⇒ Object
readonly
The path the theme was loaded from.
Class Method Summary collapse
-
.load(path) ⇒ Noumenon::Theme
Load a theme from the specified path.
-
.themes ⇒ Hash
A hash containing any loaded themes, keyed by their name.
Instance Method Summary collapse
-
#initialize(path, description = {}) ⇒ Theme
constructor
Create a new theme instance.
-
#layout(name) ⇒ Noumenon::Template
Load a template from the theme’s layouts directory.
-
#template(name) ⇒ Noumenon::Template
Load a template from the theme’s templates directory.
- #to_liquid ⇒ Object
Constructor Details
#initialize(path, description = {}) ⇒ Theme
Create a new theme instance.
78 79 80 81 82 83 84 85 86 |
# File 'lib/noumenon/theme.rb', line 78 def initialize(path, description = {}) @path = path description.each do |name, value| if respond_to? "#{name}=" send "#{name}=", value end end end |
Instance Attribute Details
#author ⇒ Object
The author of this theme. Loaded from theme.yml.
54 55 56 |
# File 'lib/noumenon/theme.rb', line 54 def @author end |
#copyright ⇒ Object
The copyright line to attribute this theme to. Loaded from theme.yml.
62 63 64 |
# File 'lib/noumenon/theme.rb', line 62 def copyright @copyright end |
#email ⇒ Object
The email address to contact regarding this theme. Loaded from theme.yml.
58 59 60 |
# File 'lib/noumenon/theme.rb', line 58 def email @email end |
#license ⇒ Object
The license this theme is distributed under. Loaded from theme.yml.
66 67 68 |
# File 'lib/noumenon/theme.rb', line 66 def license @license end |
#name ⇒ Object
The name to refer to this theme by. Loaded from theme.yml.
50 51 52 |
# File 'lib/noumenon/theme.rb', line 50 def name @name end |
#path ⇒ Object (readonly)
The path the theme was loaded from.
46 47 48 |
# File 'lib/noumenon/theme.rb', line 46 def path @path end |
Class Method Details
.load(path) ⇒ Noumenon::Theme
Load a theme from the specified path. Metadata about the theme will be laoded from “theme.yml”, which should have the format shown in the example.
If the theme is loaded succesfully it will also be registered in the theme list.
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/noumenon/theme.rb', line 26 def self.load(path) unless File.exist?("#{path}/theme.yml") raise NotFoundError.new("No theme was found at #{path}. Did you create a theme.yml file?") end description = YAML.load(File.read("#{path}/theme.yml")) theme = Noumenon::Theme.new(path, description) themes[theme.name] = theme theme end |
.themes ⇒ Hash
Returns A hash containing any loaded themes, keyed by their name.
40 41 42 |
# File 'lib/noumenon/theme.rb', line 40 def self.themes @themes ||= {} end |
Instance Method Details
#layout(name) ⇒ Noumenon::Template
Load a template from the theme’s layouts directory.
104 105 106 |
# File 'lib/noumenon/theme.rb', line 104 def layout(name) Noumenon::Template.from_file File.join(path, "layouts", name) end |
#template(name) ⇒ Noumenon::Template
Load a template from the theme’s templates directory.
94 95 96 |
# File 'lib/noumenon/theme.rb', line 94 def template(name) Noumenon::Template.from_file File.join(path, "templates", name) end |
#to_liquid ⇒ Object
115 116 117 |
# File 'lib/noumenon/theme.rb', line 115 def to_liquid { name: name, author: , email: email, copyright: copyright, license: license } end |