Class Haml::Exec::HamlSass
In: lib/haml/exec.rb
Parent: Generic

An abstrac class that encapsulates the code specific to the `haml` and `sass` executables.

Methods

Public Class methods

@param args [Array<String>] The command-line arguments

[Source]

     # File lib/haml/exec.rb, line 183
183:       def initialize(args)
184:         super
185:         @options[:for_engine] = {}
186:       end

Protected Instance methods

Processes the options set by the command-line arguments. In particular, sets `@options[:for_engine][:filename]` to the input filename and requires the appropriate file.

This is meant to be overridden by subclasses so they can run their respective programs.

[Source]

     # File lib/haml/exec.rb, line 268
268:       def process_result
269:         super
270:         @options[:for_engine][:filename] = @options[:filename] if @options[:filename]
271:         require File.dirname(__FILE__) + "/../#{@name.downcase}"
272:       end

Tells optparse how to parse the arguments available for the `haml` and `sass` executables.

This is meant to be overridden by subclasses so they can add their own options.

@param opts [OptionParser]

[Source]

     # File lib/haml/exec.rb, line 197
197:       def set_opts(opts)
198:         opts.banner = "Usage: \#{@name.downcase} [options] [INPUT] [OUTPUT]\n\nDescription:\n  Uses the \#{@name} engine to parse the specified template\n  and outputs the result to the specified file.\n\nOptions:\n"
199: 
200:         opts.on('--rails RAILS_DIR', "Install Haml and Sass from the Gem to a Rails project") do |dir|
201:           original_dir = dir
202: 
203:           env = File.join(dir, "config", "environment.rb")
204:           if File.exists?(File.join(dir, "Gemfile"))
205:             puts("haml --rails isn't needed for Rails 3 or greater.",
206:               "Add 'gem \"haml\"' to your Gemfile instead.", "",
207:               "haml --rails will no longer work in the next version of #{@name}.", "")
208:           elsif File.exists?(env) && File.open(env) {|env| env.grep(/config\.gem/)}
209:             puts("haml --rails isn't needed for Rails 2.1 or greater.",
210:               "Add 'config.gem \"haml\"' to config/environment.rb instead.", "",
211:               "haml --rails will no longer work in the next version of #{@name}.", "")
212:           end
213: 
214:           dir = File.join(dir, 'vendor', 'plugins')
215: 
216:           unless File.exists?(dir)
217:             puts "Directory #{dir} doesn't exist"
218:             exit 1
219:           end
220: 
221:           dir = File.join(dir, 'haml')
222: 
223:           if File.exists?(dir)
224:             print "Directory #{dir} already exists, overwrite [y/N]? "
225:             exit 2 if gets !~ /y/i
226:             FileUtils.rm_rf(dir)
227:           end
228: 
229:           begin
230:             Dir.mkdir(dir)
231:           rescue SystemCallError
232:             puts "Cannot create #{dir}"
233:             exit 1
234:           end
235: 
236:           File.open(File.join(dir, 'init.rb'), 'w') do |file|
237:             file << File.read(File.dirname(__FILE__) + "/../../init.rb")
238:           end
239: 
240:           puts "Haml plugin added to #{original_dir}"
241:           exit
242:         end
243: 
244:         opts.on('-c', '--check', "Just check syntax, don't evaluate.") do
245:           require 'stringio'
246:           @options[:check_syntax] = true
247:           @options[:output] = StringIO.new
248:         end
249: 
250:         super
251:       end

[Validate]