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 116
116:       def initialize(args)
117:         super
118:         @options[:for_engine] = {}
119:       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 191
191:       def process_result
192:         super
193:         @options[:for_engine][:filename] = @options[:filename] if @options[:filename]
194:         require File.dirname(__FILE__) + "/../#{@name.downcase}"
195:       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 130
130:       def set_opts(opts)
131:         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"
132: 
133:         opts.on('--rails RAILS_DIR', "Install Haml and Sass from the Gem to a Rails project") do |dir|
134:           original_dir = dir
135: 
136:           dir = File.join(dir, 'vendor', 'plugins')
137: 
138:           unless File.exists?(dir)
139:             puts "Directory #{dir} doesn't exist"
140:             exit
141:           end
142: 
143:           dir = File.join(dir, 'haml')
144: 
145:           if File.exists?(dir)
146:             print "Directory #{dir} already exists, overwrite [y/N]? "
147:             exit if gets !~ /y/i
148:             FileUtils.rm_rf(dir)
149:           end
150: 
151:           begin
152:             Dir.mkdir(dir)
153:           rescue SystemCallError
154:             puts "Cannot create #{dir}"
155:             exit
156:           end
157: 
158:           File.open(File.join(dir, 'init.rb'), 'w') do |file|
159:             file.puts "require 'rubygems'"
160:             file << File.read(File.dirname(__FILE__) + "/../../init.rb")
161:           end
162: 
163:           puts "Haml plugin added to #{original_dir}"
164:           exit
165:         end
166: 
167:         opts.on('-c', '--check', "Just check syntax, don't evaluate.") do
168:           require 'stringio'
169:           @options[:check_syntax] = true
170:           @options[:output] = StringIO.new
171:         end
172: 
173:         super
174:       end

[Validate]