Module: Paste::ERBRenderer

Included in:
Glue
Defined in:
lib/paste/erb_renderer.rb

Instance Method Summary collapse

Instance Method Details

#render_all_erbObject



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/paste/erb_renderer.rb', line 6

def render_all_erb
  erb_sources.each { |s| render_erb s }

  Dir[erb_path + '/**/*.js'].each do |erb|
    erb_rel = erb.gsub erb_path + '/', ''

    begin
      find(erb_rel + '.erb')
    rescue ResolveError
      File.delete erb
    end
  end
end

#render_erb(source) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/paste/erb_renderer.rb', line 20

def render_erb source
  to_generate = erb_path source.sub(/\.erb$/, '')
  source      = find source

  if !File.exists?(to_generate) ||
      File.mtime(source) > File.mtime(to_generate)

    FileUtils.mkdir_p File.dirname(to_generate)
    contents = PasteERBHelper.new(File.read(source)).result
    File.open(to_generate, 'w') { |f| f << contents }
  end
end