Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HAML plugin #28

Merged
merged 1 commit into from Nov 15, 2011
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 38 additions & 0 deletions lib/soca/plugins/haml.rb
@@ -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