Class: Staticise::Renderer
- Inherits:
-
Object
- Object
- Staticise::Renderer
- Defined in:
- lib/staticise/renderer.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
Returns the value of attribute file.
-
#layout ⇒ Object
Returns the value of attribute layout.
Class Method Summary collapse
Instance Method Summary collapse
- #export ⇒ Object
-
#initialize(file) ⇒ Renderer
constructor
A new instance of Renderer.
- #partial(file, locals = {}) ⇒ Object
- #render_page ⇒ Object
Constructor Details
#initialize(file) ⇒ Renderer
Returns a new instance of Renderer.
9 10 11 |
# File 'lib/staticise/renderer.rb', line 9 def initialize(file) extract(file) end |
Instance Attribute Details
#file ⇒ Object
Returns the value of attribute file.
7 8 9 |
# File 'lib/staticise/renderer.rb', line 7 def file @file end |
#layout ⇒ Object
Returns the value of attribute layout.
7 8 9 |
# File 'lib/staticise/renderer.rb', line 7 def layout @layout end |
Class Method Details
.compile_css(file) ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/staticise/renderer.rb', line 38 def self.compile_css(file) b = 'app/css/' out = File.join(APP_ROOT, 'public', 'css', file[(file.index(b) + b.length)..-1]) out = File.join(File.dirname(out), "#{ File.basename(out, File.extname(out)) }.css") puts " -- compiling #{ file } => #{ out }" FileUtils.mkdir_p(File.dirname(out)) unless File.exist?(File.dirname(out)) `lessc #{ file } #{ out }` true end |
.init ⇒ Object
60 61 62 63 64 65 |
# File 'lib/staticise/renderer.rb', line 60 def self.init puts "Creating default folder structure.." %w{app/pages app/layouts app/js app/css}.each do |f| FileUtils.mkdir_p(File.join(APP_ROOT, f)) unless File.exist?(File.join(APP_ROOT, f)) end end |
.pages ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/staticise/renderer.rb', line 49 def self.pages puts "Compiling pages.." files = Dir.glob(File.join(APP_ROOT, 'app/pages/**/*.haml')) files << Dir.glob(File.join(APP_ROOT, 'app/pages/**/*.html')) files.flatten.each do |f| self.new(f).export unless File.basename(f).start_with?("_") end return end |
Instance Method Details
#export ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/staticise/renderer.rb', line 28 def export b = 'app/pages/' out = File.join(APP_ROOT, 'public', @file[(@file.index(b) + b.length)..-1]) out = File.join(File.dirname(out), "#{ File.basename(out, File.extname(out)) }.html") puts " -- compiling #{ @file } => #{ out }" FileUtils.mkdir_p(File.dirname(out)) unless File.exist?(File.dirname(out)) File.open(out, 'w') {|f| f.puts render_page} end |
#partial(file, locals = {}) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/staticise/renderer.rb', line 19 def partial(file, locals = {}) if file.split("/").length > 1 path = File.join(APP_ROOT, 'app', 'pages', "_#{ file.to_s }") else path = File.join(File.dirname(@file), "_#{ file.to_s }") end Haml::Engine.new(read_template(path)).render(self, locals) end |
#render_page ⇒ Object
13 14 15 16 17 |
# File 'lib/staticise/renderer.rb', line 13 def render_page Haml::Engine.new(read_template(@layout)).render(self) do Haml::Engine.new(read_template(@file)).render(self) end end |