Sha256: 4a11af212520683a0f32fbafccd4cb7573f8190b6ad3a301e6d33c9472498356
Contents?: true
Size: 1.4 KB
Versions: 1
Compression:
Stored size: 1.4 KB
Contents
class Theme attr_accessor :name, :path, :description_html def initialize(name, path) @name = name @path = path end 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 def description about_file = "#{path}/about.markdown" if File.exist? about_file File.read about_file else "### #{name}" end end def view_path "#{path}/views" end # Find a theme, given the theme name def self.find(name) registered_themes[name] end # List all themes def self.find_all registered_themes.values end def self.register_theme(path) theme = theme_from_path(path) registered_themes[theme.name] = theme end def self.register_themes(themes_root) search_theme_directory(themes_root).each do |path| register_theme path end end # Private def self.registered_themes @registered_themes ||= {} end def self.theme_from_path(path) name = path.scan(/[-\w]+$/i).flatten.first new(name, path) end 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 private_class_method :search_theme_directory, :theme_from_path, :registered_themes end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
publify_core-9.1.0 | lib/theme.rb |