Permalink
Browse files

HAML plugin

  • Loading branch information...
1 parent eb84d42 commit 5e53edee2fda80e574aed3ebae3aa7ed6eff0cc1 Eric Wollesen committed Nov 8, 2011
Showing with 38 additions and 0 deletions.
  1. +38 −0 lib/soca/plugins/haml.rb
View
@@ -0,0 +1,38 @@
+require 'haml'
+
+module Soca
+ module Plugins
+ class Haml < Soca::Plugin
+
+ name 'haml'
+
+ def run(options={})
+ @options = options
+
+ Dir[File.join(haml_from, "**/*.haml")].each do |file|
+ Soca.logger.debug "Running #{file} through Haml."
+ basename = File.basename(file, ".haml")
+ dir = File.dirname(file).sub(/^#{haml_from}/,
+ haml_to)
+ new_file = basename + ".html"
+ FileUtils.mkdir_p(dir) unless File.exists?(dir)
+
+ File.open(File.join(dir, new_file), 'w') do |f|
+ f << ::Haml::Engine.new(File.read(file)).render
+ end
+ Soca.logger.debug "Wrote to #{File.join(dir, new_file)}"
+ end
+ end
+
+ private
+ def haml_from
+ @options.has_key?(:from) ? File.join(app_dir, @options[:from]) : File.join(app_dir, 'haml')
+ end
+
+ def haml_to
+ @options.has_key?(:to) ? File.join(app_dir, @options[:to]) : File.join(app_dir, '')
+ end
+
+ end
+ end
+end

0 comments on commit 5e53ede

Please sign in to comment.