| 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.
@param args [Array<String>] The command-line arguments
# File lib/haml/exec.rb, line 176
176: def initialize(args)
177: super
178: @options[:for_engine] = {}
179: end
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.
# File lib/haml/exec.rb, line 261
261: def process_result
262: super
263: @options[:for_engine][:filename] = @options[:filename] if @options[:filename]
264: require File.dirname(__FILE__) + "/../#{@name.downcase}"
265: 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]
# 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: env = File.join(dir, "config", "environment.rb")
197: if File.exists?(File.join(dir, "Gemfile"))
198: puts("haml --rails isn't needed for Rails 3 or greater.",
199: "Add 'gem \"haml\"' to your Gemfile instead.", "",
200: "haml --rails will no longer work in the next version of #{@name}.", "")
201: elsif File.exists?(env) && File.open(env) {|env| env.grep(/config\.gem/)}
202: puts("haml --rails isn't needed for Rails 2.1 or greater.",
203: "Add 'gem \"haml\"' to config/environment.rb instead.", "",
204: "haml --rails will no longer work in the next version of #{@name}.", "")
205: end
206:
207: dir = File.join(dir, 'vendor', 'plugins')
208:
209: unless File.exists?(dir)
210: puts "Directory #{dir} doesn't exist"
211: exit 1
212: end
213:
214: dir = File.join(dir, 'haml')
215:
216: if File.exists?(dir)
217: print "Directory #{dir} already exists, overwrite [y/N]? "
218: exit 2 if gets !~ /y/i
219: FileUtils.rm_rf(dir)
220: end
221:
222: begin
223: Dir.mkdir(dir)
224: rescue SystemCallError
225: puts "Cannot create #{dir}"
226: exit 1
227: end
228:
229: File.open(File.join(dir, 'init.rb'), 'w') do |file|
230: file << File.read(File.dirname(__FILE__) + "/../../init.rb")
231: end
232:
233: puts "Haml plugin added to #{original_dir}"
234: exit
235: end
236:
237: opts.on('-c', '--check', "Just check syntax, don't evaluate.") do
238: require 'stringio'
239: @options[:check_syntax] = true
240: @options[:output] = StringIO.new
241: end
242:
243: super
244: end