class Theme

Attributes

description_html[RW]
name[RW]
path[RW]

Public Class Methods

find(name) click to toggle source

Find a theme, given the theme name

# File lib/theme.rb, line 32
def self.find(name)
  registered_themes[name]
end
find_all() click to toggle source

List all themes

# File lib/theme.rb, line 37
def self.find_all
  registered_themes.values
end
new(name, path) click to toggle source
# File lib/theme.rb, line 6
def initialize(name, path)
  @name = name
  @path = path
end
register_theme(path) click to toggle source
# File lib/theme.rb, line 41
def self.register_theme(path)
  theme = theme_from_path(path)
  registered_themes[theme.name] = theme
end
register_themes(themes_root) click to toggle source
# File lib/theme.rb, line 46
def self.register_themes(themes_root)
  search_theme_directory(themes_root).each do |path|
    register_theme path
  end
end

Private Class Methods

registered_themes() click to toggle source

Private

# File lib/theme.rb, line 54
def self.registered_themes
  @registered_themes ||= {}
end
search_theme_directory(themes_root) click to toggle source
# File lib/theme.rb, line 63
def self.search_theme_directory(themes_root)
  glob = "#{themes_root}/[a-zA-Z0-9]*"
  Dir.glob(glob).select do |file|
    File.readable?("#{file}/about.markdown")
  end.compact
end
theme_from_path(path) click to toggle source
# File lib/theme.rb, line 58
def self.theme_from_path(path)
  name = path.scan(/[-\w]+$/i).flatten.first
  new(name, path)
end

Public Instance Methods

description() click to toggle source
# File lib/theme.rb, line 18
def description
  about_file = "#{path}/about.markdown"
  if File.exist? about_file
    File.read about_file
  else
    "### #{name}"
  end
end
layout(action = :default) click to toggle source
# 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
view_path() click to toggle source
# File lib/theme.rb, line 27
def view_path
  "#{path}/views"
end