Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add output option #1

Merged
merged 4 commits into from

2 participants

@Nemo157

Simply adds an option to the guard so you can use

guard 'haml', :output => 'public' do
  watch %r{^src/.+(\.html\.haml)}
end

to compile HAML files in src into HTML files in public.

@manufaktor manufaktor merged commit ca21c28 into from
@manufaktor
Collaborator

thank you, looks good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 29 additions and 3 deletions.
  1. +12 −1 README.md
  2. +17 −2 lib/guard/haml.rb
View
13 README.md
@@ -16,4 +16,15 @@ Add it to your Gemfile if you're using bundler (you should)
Add a basic guard setup:
- guard init haml
+ guard init haml
+
+## Options
+
+If you want to change the output directory use the `output` option in your
+Guardfile, e.g.:
+
+ guard 'haml', :output => 'public' do
+ watch %r{^src/.+(\.html\.haml)}
+ end
+
+This output is relative to the Guardfile.
View
19 lib/guard/haml.rb
@@ -17,6 +17,21 @@ def compile_haml file
engine = ::Haml::Engine.new(content, @haml_options)
engine.render
end
+
+ # Get the file path to output the html based on the file being
+ # built. The output path is relative to where guard is being run.
+ #
+ # @param file [String] path to file being built
+ # @return [String] path to file where output should be written
+ #
+ def get_output(file)
+ if @options[:output]
+ FileUtils.mkdir_p(@options[:output])
+ File.join(@options[:output], File.basename(file).split('.')[0..-2].join('.'))
+ else
+ file.split('.')[0..-2].join('.')
+ end
+ end
def run_all
patterns = @watchers.map { |w| w.pattern }
@@ -29,10 +44,10 @@ def run_all
def run_on_change(paths)
paths.each do |file|
- output_file = file.split('.')[0..-2].join('.')
+ output_file = get_output(file)
File.open(output_file, 'w') { |f| f.write(compile_haml(file)) }
puts "# compiled haml in '#{file}' to html in '#{output_file}'"
end
end
end
-end
+end
Something went wrong with that request. Please try again.