Class: HamlRenderer

Inherits:
Object
  • Object
show all
Defined in:
lib/gitstats/renderer/haml.rb

Defined Under Namespace

Classes: HamlHelper

Instance Method Summary collapse

Constructor Details

#initialize(templatedir, outdir, verbose) ⇒ HamlRenderer

Returns a new instance of HamlRenderer.



34
35
36
37
38
# File 'lib/gitstats/renderer/haml.rb', line 34

def initialize(templatedir, outdir, verbose)
  @templatedir = templatedir
  @outdir = outdir
  @verbose = verbose
end

Instance Method Details

#handle?(file) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/gitstats/renderer/haml.rb', line 44

def handle?(file)
  file =~ /\.haml$/
end

#nameObject



40
41
42
# File 'lib/gitstats/renderer/haml.rb', line 40

def name
  'haml'
end

#render(file, stats) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/gitstats/renderer/haml.rb', line 48

def render(file, stats)
  ifile = File.join(@templatedir, file)
  ofile = File.join(@outdir, File.basename(file, '.haml') + '.html')

  lines = IO::readlines(ifile).join('')

  helper = HamlHelper.new(@templatedir, stats, @verbose)

  engine = Haml::Engine.new(lines)
  lines = engine.render(helper)

  if !helper.get_layout.nil?
    puts "rendering layout '#{helper.get_layout}' ..." if @verbose
    layout = IO::readlines(File.join(@templatedir, 'layouts', helper.get_layout + '.haml')).join('')
    engine = Haml::Engine.new(layout)
    lines = engine.render(Object.new, :content => lines)
  end

  File.new(ofile, 'w').write(lines)
end