Class: FlickrOfflineGallery::TemplateRenderer
- Inherits:
-
Object
- Object
- FlickrOfflineGallery::TemplateRenderer
show all
- Includes:
- VerbosePuts
- Defined in:
- lib/flickr_offline_gallery/template_renderer.rb
Instance Method Summary
collapse
#verbose_puts
Constructor Details
Returns a new instance of TemplateRenderer.
6
7
8
|
# File 'lib/flickr_offline_gallery/template_renderer.rb', line 6
def initialize(template)
@template = template
end
|
Instance Method Details
#render ⇒ Object
27
28
29
|
# File 'lib/flickr_offline_gallery/template_renderer.rb', line 27
def render
raise "not implemented"
end
|
#render_erb(locals) ⇒ Object
23
24
25
|
# File 'lib/flickr_offline_gallery/template_renderer.rb', line 23
def render_erb(locals)
ERB.new(template_contents).result(OpenStruct.new(locals).instance_eval { binding })
end
|
#template_contents ⇒ Object
18
19
20
21
|
# File 'lib/flickr_offline_gallery/template_renderer.rb', line 18
def template_contents
raise "Unknown template: #{template_path}" unless File.exist?(template_path)
@template_content ||= File.read(template_path)
end
|
#template_directory ⇒ Object
14
15
16
|
# File 'lib/flickr_offline_gallery/template_renderer.rb', line 14
def template_directory
File.expand_path("../../../erb/", __FILE__)
end
|
#template_path ⇒ Object
10
11
12
|
# File 'lib/flickr_offline_gallery/template_renderer.rb', line 10
def template_path
File.expand_path("../../../erb/#{@template}.html.erb",__FILE__)
end
|
#write ⇒ Object
31
32
33
|
# File 'lib/flickr_offline_gallery/template_renderer.rb', line 31
def write
raise "not implemented"
end
|
#write_file(filename) ⇒ Object
35
36
37
38
39
40
|
# File 'lib/flickr_offline_gallery/template_renderer.rb', line 35
def write_file(filename)
File.open(filename, 'w') do |file|
file.write render
end
verbose_puts "Wrote out #{filename}"
end
|