Class: Renderer
- Inherits:
-
Object
- Object
- Renderer
- Defined in:
- lib/Renderer.rb
Instance Method Summary collapse
-
#initialize(path, output_path) ⇒ Renderer
constructor
A new instance of Renderer.
-
#render ⇒ Object
Render results.
Constructor Details
#initialize(path, output_path) ⇒ Renderer
Returns a new instance of Renderer.
3 4 5 6 |
# File 'lib/Renderer.rb', line 3 def initialize(path, output_path) @path = path @output_path = output_path end |
Instance Method Details
#render ⇒ Object
Render results.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/Renderer.rb', line 11 def render() # Get JSON. json = File.read("#{@output_path}/db.json") # Save HTML. template = File.read("#{@path}/web/template.html.erb") rendered = ERB.new(template).result(binding) File.open("#{@output_path}/index.html", 'w+') do |f| f.write rendered end # Add JS. javascript = File.read("#{@path}/web/script.js") File.open("#{@output_path}/script.js", 'w+') do |f| f.write javascript end # Add CSS. stylesheet = File.read("#{@path}/web/style.css") File.open("#{@output_path}/style.css", 'w+') do |f| f.write stylesheet end end |