Class: Alula::Theme
- Inherits:
-
Object
- Object
- Alula::Theme
- Defined in:
- lib/alula/theme.rb,
lib/alula/theme/view.rb,
lib/alula/theme/layout.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#layouts ⇒ Object
readonly
Returns the value of attribute layouts.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#site ⇒ Object
readonly
Returns the value of attribute site.
-
#theme ⇒ Object
readonly
Returns the value of attribute theme.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
- .install(options) ⇒ Object
- .load(name, options) ⇒ Object
- .register(name, klass) ⇒ Object
- .themes ⇒ Object
Instance Method Summary collapse
-
#initialize(opts) ⇒ Theme
constructor
A new instance of Theme.
- #layout(name) ⇒ Object
- #name ⇒ Object
- #options(file) ⇒ Object
- #searchpath(type, name) ⇒ Object
- #themes ⇒ Object
- #view(name) ⇒ Object
Constructor Details
#initialize(opts) ⇒ Theme
Returns a new instance of Theme.
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/alula/theme.rb', line 25 def initialize(opts) @site = Site.instance # @theme = theme # @path = @@themes[theme] @context = @site.context @layouts = {} @views = {} # @version = @@theme_versions[theme] end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
23 24 25 |
# File 'lib/alula/theme.rb', line 23 def context @context end |
#layouts ⇒ Object (readonly)
Returns the value of attribute layouts.
22 23 24 |
# File 'lib/alula/theme.rb', line 22 def layouts @layouts end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
21 22 23 |
# File 'lib/alula/theme.rb', line 21 def path @path end |
#site ⇒ Object (readonly)
Returns the value of attribute site.
19 20 21 |
# File 'lib/alula/theme.rb', line 19 def site @site end |
#theme ⇒ Object (readonly)
Returns the value of attribute theme.
20 21 22 |
# File 'lib/alula/theme.rb', line 20 def theme @theme end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
18 19 20 |
# File 'lib/alula/theme.rb', line 18 def version @version end |
Class Method Details
.install(options) ⇒ Object
16 |
# File 'lib/alula/theme.rb', line 16 def self.install(); true; end |
.load(name, options) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/alula/theme.rb', line 9 def self.load(name, ) if themes[name] and !(!! == and !) theme = themes[name] return theme.new() if theme.install() end end |
.register(name, klass) ⇒ Object
5 |
# File 'lib/alula/theme.rb', line 5 def self.register(name, klass); themes[name.to_s] = klass; end |
.themes ⇒ Object
6 |
# File 'lib/alula/theme.rb', line 6 def self.themes; @@themes ||= {}; end |
Instance Method Details
#layout(name) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/alula/theme.rb', line 55 def layout(name) @layouts[name] ||= begin # Find our layout name file = Dir[*self.searchpath("layouts", name)].first if file Layout.new(theme: self, name: name, file: file) else raise "Cannot find layout #{name}" end end end |
#name ⇒ Object
38 39 40 |
# File 'lib/alula/theme.rb', line 38 def name themes.key(self.class) end |
#options(file) ⇒ Object
80 81 82 83 84 85 86 87 |
# File 'lib/alula/theme.rb', line 80 def (file) = case File.extname(file)[1..-1] when "haml" { :format => :html5, :ugly => @site.config.assets.compress } else {} end end |
#searchpath(type, name) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/alula/theme.rb', line 42 def searchpath(type, name) [ # Blog custom ::File.join(self.site.storage.path(:custom), type, "#{name}.*"), # Theme path ::File.join(self.path, type, "#{name}.*"), # Alula vendor path ::File.join(::File.dirname(__FILE__), "..", "..", "vendor", type, "#{name}.*") ] end |
#themes ⇒ Object
7 |
# File 'lib/alula/theme.rb', line 7 def themes; self.class.themes; end |
#view(name) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/alula/theme.rb', line 67 def view(name) @views[name] ||= begin # Find our layout name # file = Dir[::File.join(self.path, "views", "#{name}.*")].first file = Dir[*self.searchpath("views", name)].first if file View.new(theme: self, name: name, file: file) else raise "Cannot find view #{name}" end end end |