Module: Sidekick::Helpers::Compile
- Defined in:
- lib/sidekick/helpers/rake.rb,
lib/sidekick/helpers/compile.rb
Instance Method Summary collapse
-
#auto_compile(source, target) ⇒ Object
watches for changes matching the
sourceglob, and compiles totarget, replacing ‘:name’ intargetwith the basename of the changed file. -
#compile(source, target) ⇒ Object
Compiles one template using the
tiltgem. - #rake(task_name) ⇒ Object
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/helpers/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/helpers/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 |
#rake(task_name) ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/sidekick/helpers/rake.rb', line 4 def rake(task_name) needs 'rake', 'to invoke rake tasks' handling Exception, "rake #{task_name}" do load 'Rakefile' Rake::application[task_name].invoke end end |