Class: Theme

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, path) ⇒ Theme

Returns a new instance of Theme.



6
7
8
9
# File 'lib/theme.rb', line 6

def initialize(name, path)
  @name = name
  @path = path
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

Class Method Details

.find(name) ⇒ Object

Find a theme, given the theme name



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

def self.find(name)
  registered_themes[name]
end

.find_allObject

List all themes



48
49
50
# File 'lib/theme.rb', line 48

def self.find_all
  registered_themes.values
end

.register_theme(path) ⇒ Object



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

def self.register_theme(path)
  theme = theme_from_path(path)
  registered_themes[theme.name] = theme
end

.register_themes(themes_root) ⇒ Object



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

def self.register_themes(themes_root)
  search_theme_directory(themes_root).each do |path|
    register_theme path
  end
end

Instance Method Details

#descriptionObject



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/theme.rb', line 18

def description
  @description ||=
    begin
      about_file = theme_file("about.markdown")
      if File.exist? about_file
        File.read about_file
      else
        "### #{name}"
      end
    end
end

#description_htmlObject



30
31
32
# File 'lib/theme.rb', line 30

def description_html
  TextFilter.markdown.filter_text(description)
end

#layout(action = :default) ⇒ Object



11
12
13
14
15
16
# File 'lib/theme.rb', line 11

def layout(action = :default)
  if action.to_s == "view_page"
    return "layouts/pages" if File.exist? "#{view_path}/layouts/pages.html.erb"
  end
  "layouts/default"
end

#theme_file(filename) ⇒ Object



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

def theme_file(filename)
  File.join(path, filename)
end

#view_pathObject



34
35
36
# File 'lib/theme.rb', line 34

def view_path
  "#{path}/views"
end