class Shop::Template

Public Instance Methods

custom_template_path(name) click to toggle source

Returns the path to the custom template if it exists

# 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) click to toggle source

Replace the placeholders by the variables

name: template name datas: hash containing the values

Returns string

# 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) click to toggle source

Returns the path to the templates directory

Returns string

# 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.expand_path File.dirname(__FILE__)

    return "#{path}/../../templates/#{name}" if name

    "#{path}/../../templates"
  end
end