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 176
176:       def initialize(args)
177:         super
178:         @options[:for_engine] = {}
179:       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 250
250:       def process_result
251:         super
252:         @options[:for_engine][:filename] = @options[:filename] if @options[:filename]
253:         require File.dirname(__FILE__) + "/../#{@name.downcase}"
254:       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 190
190:       def set_opts(opts)
191:         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"
192: 
193:         opts.on('--rails RAILS_DIR', "Install Haml and Sass from the Gem to a Rails project") do |dir|
194:           original_dir = dir
195: 
196:           dir = File.join(dir, 'vendor', 'plugins')
197: 
198:           unless File.exists?(dir)
199:             puts "Directory #{dir} doesn't exist"
200:             exit
201:           end
202: 
203:           dir = File.join(dir, 'haml')
204: 
205:           if File.exists?(dir)
206:             print "Directory #{dir} already exists, overwrite [y/N]? "
207:             exit if gets !~ /y/i
208:             FileUtils.rm_rf(dir)
209:           end
210: 
211:           begin
212:             Dir.mkdir(dir)
213:           rescue SystemCallError
214:             puts "Cannot create #{dir}"
215:             exit
216:           end
217: 
218:           File.open(File.join(dir, 'init.rb'), 'w') do |file|
219:             file << File.read(File.dirname(__FILE__) + "/../../init.rb")
220:           end
221: 
222:           puts "Haml plugin added to #{original_dir}"
223:           exit
224:         end
225: 
226:         opts.on('-c', '--check', "Just check syntax, don't evaluate.") do
227:           require 'stringio'
228:           @options[:check_syntax] = true
229:           @options[:output] = StringIO.new
230:         end
231: 
232:         super
233:       end

[Validate]