Class: Shop::Template
- Inherits:
-
Object
- Object
- Shop::Template
- Defined in:
- lib/shop/template.rb
Instance Method Summary collapse
-
#custom_template_path(name) ⇒ Object
Returns the path to the custom template if it exists.
-
#template(name, datas) ⇒ Object
Replace the placeholders by the variables.
-
#template_path(name = false) ⇒ Object
Returns the path to the templates directory.
Instance Method Details
#custom_template_path(name) ⇒ Object
Returns the path to the custom template if it exists
6 7 8 9 10 11 12 13 14 |
# File 'lib/shop/template.rb', line 6 def custom_template_path(name) config = ShopConfig.new custom_path = config.get('template', 'path') if File.exists?("#{custom_path}/#{name}") "#{custom_path}/#{name}" else false end end |
#template(name, datas) ⇒ Object
Replace the placeholders by the variables
name: template name datas: hash containing the values
Returns string
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/shop/template.rb', line 38 def template(name, datas) file = template_path(name) content = File.read(file) datas.each do |k, v| k = "<%= #{k} %>" content = content.gsub(k, v) end return content end |
#template_path(name = false) ⇒ Object
Returns the path to the templates directory
Returns string
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/shop/template.rb', line 19 def template_path(name=false) custom_path = custom_template_path(name) if custom_path custom_path else path = File. File.dirname(__FILE__) return "#{path}/../../templates/#{name}" if name "#{path}/../../templates" end end |