Class: Haml::Exec::HamlSass
Overview
An abstrac class that encapsulates the code specific to the haml and sass executables.
Constant Summary
Instance Method Summary
- - (HamlSass) initialize(args) constructor A new instance of HamlSass.
- - process_result protected Processes the options set by the command-line arguments.
-
- set_opts(opts)
protected
Tells optparse how to parse the arguments available for the
hamlandsassexecutables.
Methods inherited from Generic
#color, #get_line, #parse, #parse!, #puts_action, #to_s
Constructor Details
- (HamlSass) initialize(args)
A new instance of HamlSass
176 177 178 179 |
# File '/var/www/sass-pages/.haml/lib/haml/exec.rb', line 176
def initialize(args)
super
@options[:for_engine] = {}
end
|
Instance Method Details
- process_result (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.
261 262 263 264 265 |
# File '/var/www/sass-pages/.haml/lib/haml/exec.rb', line 261
def process_result
super
@options[:for_engine][:filename] = @options[:filename] if @options[:filename]
require File.dirname(__FILE__) + "/../#{@name.downcase}"
end
|
- set_opts(opts) (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.
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File '/var/www/sass-pages/.haml/lib/haml/exec.rb', line 190
def set_opts(opts)
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"
opts.on('--rails RAILS_DIR', "Install Haml and Sass from the Gem to a Rails project") do |dir|
original_dir = dir
env = File.join(dir, "config", "environment.rb")
if File.exists?(File.join(dir, "Gemfile"))
puts("haml --rails isn't needed for Rails 3 or greater.",
"Add 'gem \"haml\"' to your Gemfile instead.", "",
"haml --rails will no longer work in the next version of #{@name}.", "")
elsif File.exists?(env) && File.open(env) {|env| env.grep(/config\.gem/)}
puts("haml --rails isn't needed for Rails 2.1 or greater.",
"Add 'gem \"haml\"' to config/environment.rb instead.", "",
"haml --rails will no longer work in the next version of #{@name}.", "")
end
dir = File.join(dir, 'vendor', 'plugins')
unless File.exists?(dir)
puts "Directory #{dir} doesn't exist"
exit 1
end
dir = File.join(dir, 'haml')
if File.exists?(dir)
print "Directory #{dir} already exists, overwrite [y/N]? "
exit 2 if gets !~ /y/i
FileUtils.rm_rf(dir)
end
begin
Dir.mkdir(dir)
rescue SystemCallError
puts "Cannot create #{dir}"
exit 1
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
|