Module: Sidekick::Actions::Compile
- Defined in:
- lib/sidekick/actions/compile.rb
Instance Method Summary collapse
-
#auto_compile(source, target) ⇒ Object
watches for changes matching the ‘source` glob, and compiles to `target`, replacing ’:name’ in ‘target` with the basename of the changed file.
-
#compile(source, target) ⇒ Object
Compiles one template using the ‘tilt` gem.
Instance Method Details
#auto_compile(source, target) ⇒ Object
watches for changes matching the ‘source` glob, and compiles to `target`, replacing ’:name’ in ‘target` with the basename of the changed file.
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/sidekick/actions/compile.rb', line 18 def auto_compile(source, target) watch(source) do |files| files.each do |file| if File.exists?(file) t = target.gsub(':name', File.basename(file, '.*')) compile file, t log "render #{file} => #{t}" end end end end |
#compile(source, target) ⇒ Object
Compiles one template using the ‘tilt` gem.
7 8 9 10 11 12 13 14 |
# File 'lib/sidekick/actions/compile.rb', line 7 def compile(source, target) needs 'tilt', 'to compile templates' handling Exception, source do File.open(target, 'w') do |f| f.write(Tilt.new(source).render) end end end |