Class: FlickrOfflineGallery::TemplateRenderer

Inherits:
Object
  • Object
show all
Includes:
VerbosePuts
Defined in:
lib/flickr_offline_gallery/template_renderer.rb

Direct Known Subclasses

PhotoPage, PhotosetIndexPage

Instance Method Summary collapse

Methods included from VerbosePuts

#verbose_puts

Constructor Details

#initialize(template) ⇒ TemplateRenderer

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

#renderObject



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_contentsObject



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_directoryObject



14
15
16
# File 'lib/flickr_offline_gallery/template_renderer.rb', line 14

def template_directory
  File.expand_path("../../../erb/", __FILE__)
end

#template_pathObject



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

#writeObject



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