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