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