Class: Alula::Theme

Inherits:
Object
  • Object
show all
Defined in:
lib/alula/theme.rb,
lib/alula/theme/view.rb,
lib/alula/theme/layout.rb

Defined Under Namespace

Classes: Layout, View

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#contextObject (readonly)

Returns the value of attribute context.



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

def context
  @context
end

#layoutsObject (readonly)

Returns the value of attribute layouts.



22
23
24
# File 'lib/alula/theme.rb', line 22

def layouts
  @layouts
end

#pathObject (readonly)

Returns the value of attribute path.



21
22
23
# File 'lib/alula/theme.rb', line 21

def path
  @path
end

#siteObject (readonly)

Returns the value of attribute site.



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

def site
  @site
end

#themeObject (readonly)

Returns the value of attribute theme.



20
21
22
# File 'lib/alula/theme.rb', line 20

def theme
  @theme
end

#versionObject (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(options); true; end

.load(name, options) ⇒ Object



9
10
11
12
13
14
# File 'lib/alula/theme.rb', line 9

def self.load(name, options)
  if themes[name] and !(!!options == options and !options)
    theme = themes[name]
    return theme.new(options) if theme.install(options)
  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

.themesObject



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

#nameObject



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 options(file)
  options = 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

#themesObject



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