Class: ThemeKit::Theme
- Inherits:
-
Object
- Object
- ThemeKit::Theme
- Defined in:
- lib/themekit/theme.rb
Instance Attribute Summary collapse
-
#example_path ⇒ Object
readonly
Returns the value of attribute example_path.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
- #create ⇒ Object
-
#initialize(name, path) ⇒ Theme
constructor
A new instance of Theme.
Constructor Details
#initialize(name, path) ⇒ Theme
Returns a new instance of Theme.
10 11 12 13 14 |
# File 'lib/themekit/theme.rb', line 10 def initialize(name, path) @name = name @path = path @example_path = File.join(File.dirname(__FILE__), '../../example_theme') end |
Instance Attribute Details
#example_path ⇒ Object (readonly)
Returns the value of attribute example_path.
8 9 10 |
# File 'lib/themekit/theme.rb', line 8 def example_path @example_path end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/themekit/theme.rb', line 8 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
8 9 10 |
# File 'lib/themekit/theme.rb', line 8 def path @path end |
Class Method Details
.render(html, options = {}) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/themekit/theme.rb', line 20 def self.render(html, ={}) data = { :variations => 'default', :title => "Welcome | CompuGlobal Exams", :meta_tags => ThemeKit::Data::META_TAGS, :main_nav => ThemeKit::Data::MAIN_NAV, :user_nav => ThemeKit::Data::USER_NAV, :page_title => "Welcome to my website", :page_content => "#{ThemeKit::Data::DUMMY_HTML}<p>Yardstick ThemeKit: <strong>#{Time.now}</strong></p>", :system_stylesheet_path => "system.css", :stylesheet_path => "styles.css", :media_path => "", :notice => "This is an example notice.", }.merge() html.gsub!(/\{\{\s*theme_variation\s*\}\}/, data[:variations]) # {{ theme_variation }} html.gsub!(/\{\{\s*title\s*\}\}/, data[:title]) # {{ title }} html.gsub!(/\{\{\s*page.title\s*\}\}/, data[:page_title]) # {{ page.title }} html.gsub!(/\{%\s*image \w.*, (\w.*)\s*%\}/, "<img src=\"#{data[:media_path]}\\1\" />") # {% image ... %} html.gsub!(/\{%\s*text \w.*, (\w.*)\s*%\}/, "\\1") # {% text ... %} html.gsub!(/\{%\s*page_meta\s*%\}/, data[:meta_tags]) # {% page_meta %} html.gsub!(/\{%\s*menu main\s*%\}/, data[:main_nav]) # {% menu main %} html.gsub!(/\{%\s*menu account\s*%\}/, data[:user_nav]) # {% menu account %} html.gsub!(/\{\{\s*page.content\s*\}\}/, data[:page_content]) # {{ page.content }} html.gsub!(/\{\{\s*system_stylesheet_tag\s*\}\}/, data[:system_stylesheet_tag]) # {{ system_stylesheet_tag }} html.gsub!(/\{\{\s*stylesheet_tag\s*\}\}/, data[:stylesheet_tag]) # {{ stylesheet_tag }} # Notices html.gsub!(/\{%\s*if notice\s*%\}/, '') html.gsub!(/\{%\s*endif\s*%\}/, '') html.gsub!(/\{\{\s*notice\s*\}\}/, data[:notice]) html end |
Instance Method Details
#create ⇒ Object
16 17 18 |
# File 'lib/themekit/theme.rb', line 16 def create FileUtils.cp_r @example_path, File.join(@path, @name) end |