Class: Rubyception::Templating
- Inherits:
-
Object
- Object
- Rubyception::Templating
- Defined in:
- lib/rubyception/templating.rb
Overview
This compiles haml templates into a json object and writes it to the file app/javascripts/template.js. Its so we can render html via javascript.
Class Method Summary collapse
- .append_to_tree(template, current) ⇒ Object
- .compile ⇒ Object
- .process_tree(template, key = nil, current = '') ⇒ Object
- .r(partial) ⇒ Object
Class Method Details
.append_to_tree(template, current) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/rubyception/templating.rb', line 11 def self.append_to_tree template, current keys = current.split('/').collect{|k|"['#{k}']"}.join partials = {} template.each_index do |i| partials[template[i]] = self.r("#{current}/#{template[i]}") end eval "@@templates#{keys} = partials" end |
.compile ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/rubyception/templating.rb', line 38 def self.compile yml = File.join(File.dirname(__FILE__),'..','..','config','templating.yml') file = File.open yml templates = YAML::load file @@templates = templates self.process_tree templates js = "Template = #{@@templates.to_json}" path = File.join(File.dirname(__FILE__),'..','..','app','assets','javascripts','rubyception','template.js') File.open(path,'w'){|f|f.write(js)} end |
.process_tree(template, key = nil, current = '') ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/rubyception/templating.rb', line 20 def self.process_tree template, key=nil, current='' path = "#{current}/#{key}" path = key.to_s if current == '' kind = template.class.to_s case kind when 'Hash' template.each do |k,v| if v.nil? self.append_to_tree [k], path else self.process_tree v, k, path end end when 'Array' self.append_to_tree template, path end end |
.r(partial) ⇒ Object
6 7 8 9 |
# File 'lib/rubyception/templating.rb', line 6 def self.r partial t = Rubyception::TemplatingController.new t.r partial end |