Skip to content

Commit

Permalink
HAML plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Wollesen committed Nov 8, 2011
1 parent eb84d42 commit 5e53ede
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions lib/soca/plugins/haml.rb
Original file line number Diff line number Diff line change
@@ -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.