Class: Haml::Exec::HamlSass
Overview
An abstrac class that encapsulates the code
specific to the haml
and sass
executables.
Instance Method Summary collapse
-
#initialize(args) ⇒ HamlSass
constructor
A new instance of HamlSass.
-
#process_result ⇒ Object
protected
Processes the options set by the command-line arguments.
-
#set_opts(opts) ⇒ Object
protected
Tells optparse how to parse the arguments available for the
haml
andsass
executables.
Methods inherited from Generic
Constructor Details
#initialize(args) ⇒ HamlSass
Returns a new instance of HamlSass.
116 117 118 119 |
# File 'lib/haml/exec.rb', line 116
def initialize(args)
super
@options[:for_engine] = {}
end
|
Instance Method Details
#process_result ⇒ Object (protected)
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.
189 190 191 192 193 |
# File 'lib/haml/exec.rb', line 189
def process_result
super
@options[:for_engine][:filename] = @options[:filename] if @options[:filename]
require File.dirname(__FILE__) + "/../#{@name.downcase}"
end
|
#set_opts(opts) ⇒ Object (protected)
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.
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/haml/exec.rb', line 130
def set_opts(opts)
opts.banner = <<END
Usage: #{@name.downcase} [options] [INPUT] [OUTPUT]
Description:
Uses the #{@name} engine to parse the specified template
and outputs the result to the specified file.
Options:
END
opts.on('--rails RAILS_DIR', "Install Haml and Sass from the Gem to a Rails project") do |dir|
original_dir = dir
dir = File.join(dir, 'vendor', 'plugins')
unless File.exists?(dir)
puts "Directory #{dir} doesn't exist"
exit
end
dir = File.join(dir, 'haml')
if File.exists?(dir)
print "Directory #{dir} already exists, overwrite [y/N]? "
exit if gets !~ /y/i
FileUtils.rm_rf(dir)
end
begin
Dir.mkdir(dir)
rescue SystemCallError
puts "Cannot create #{dir}"
exit
end
File.open(File.join(dir, 'init.rb'), 'w') do |file|
file << File.read(File.dirname(__FILE__) + "/../../init.rb")
end
puts "Haml plugin added to #{original_dir}"
exit
end
opts.on('-c', '--check', "Just check syntax, don't evaluate.") do
require 'stringio'
@options[:check_syntax] = true
@options[:output] = StringIO.new
end
super
end
|