-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Eric Wollesen
committed
Nov 8, 2011
1 parent
eb84d42
commit 5e53ede
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |