Class: ThemeKit::Theme

Inherits:
Object
  • Object
show all
Defined in:
lib/themekit/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.



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_pathObject (readonly)

Returns the value of attribute example_path.



8
9
10
# File 'lib/themekit/theme.rb', line 8

def example_path
  @example_path
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/themekit/theme.rb', line 8

def name
  @name
end

#pathObject (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
# File 'lib/themekit/theme.rb', line 20

def self.render(html, options={})
  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",
    :image_path_prefix => "",
  }.merge(options)
  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 image_data_id, (\w.*)\s*%\}/, "<img src=\"#{data[:image_path_prefix]}\\1\" />")              # {% image ... %}
  html.gsub!(/\{%\s*text text_data_id, (\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_path\s*\}\}/, data[:system_stylesheet_path])         # {{ system_stylesheet_path }}
  html.gsub!(/\{\{\s*stylesheet_path\s*\}\}/, data[:stylesheet_path])                       # {{ stylesheet_path }}
  html
end

Instance Method Details

#createObject



16
17
18
# File 'lib/themekit/theme.rb', line 16

def create
  FileUtils.cp_r @example_path, File.join(@path, @name)
end