mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
Get rid of Haml::Exec::Generic.
This commit is contained in:
parent
c3cdc567b1
commit
e16f5d7c38
1 changed files with 39 additions and 58 deletions
|
@ -168,64 +168,14 @@ MESSAGE
|
|||
end
|
||||
end
|
||||
|
||||
# An abstrac class that encapsulates the code
|
||||
# specific to the `haml` and `sass` executables.
|
||||
class HamlSass < Generic
|
||||
# @param args [Array<String>] The command-line arguments
|
||||
def initialize(args)
|
||||
super
|
||||
@options[:for_engine] = {}
|
||||
end
|
||||
|
||||
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.
|
||||
#
|
||||
# @param opts [OptionParser]
|
||||
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('-c', '--check', "Just check syntax, don't evaluate.") do
|
||||
require 'stringio'
|
||||
@options[:check_syntax] = true
|
||||
@options[:output] = StringIO.new
|
||||
end
|
||||
|
||||
super
|
||||
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.
|
||||
def process_result
|
||||
super
|
||||
@options[:for_engine][:filename] = @options[:filename] if @options[:filename]
|
||||
require File.dirname(__FILE__) + "/../#{@name.downcase}"
|
||||
end
|
||||
end
|
||||
|
||||
# The `sass` executable.
|
||||
class Sass < HamlSass
|
||||
class Sass < Generic
|
||||
# @param args [Array<String>] The command-line arguments
|
||||
def initialize(args)
|
||||
super
|
||||
@name = "Sass"
|
||||
@options[:for_engine][:load_paths] = ['.'] + (ENV['SASSPATH'] || '').split(File::PATH_SEPARATOR)
|
||||
@options[:for_engine] = {
|
||||
:load_paths => ['.'] + (ENV['SASSPATH'] || '').split(File::PATH_SEPARATOR)
|
||||
}
|
||||
end
|
||||
|
||||
protected
|
||||
|
@ -236,6 +186,15 @@ END
|
|||
def set_opts(opts)
|
||||
super
|
||||
|
||||
opts.banner = <<END
|
||||
Usage: sass [options] [INPUT] [OUTPUT]
|
||||
|
||||
Description:
|
||||
Converts SCSS or Sass files to CSS.
|
||||
|
||||
Options:
|
||||
END
|
||||
|
||||
opts.on('--scss',
|
||||
'Use the CSS-superset SCSS syntax.') do
|
||||
@options[:for_engine][:syntax] = :scss
|
||||
|
@ -254,6 +213,11 @@ END
|
|||
'Only meaningful for --watch and --update.') do
|
||||
@options[:stop_on_error] = true
|
||||
end
|
||||
opts.on('-c', '--check', "Just check syntax, don't evaluate.") do
|
||||
require 'stringio'
|
||||
@options[:check_syntax] = true
|
||||
@options[:output] = StringIO.new
|
||||
end
|
||||
opts.on('-t', '--style NAME',
|
||||
'Output style. Can be nested (default), compact, compressed, or expanded.') do |name|
|
||||
@options[:for_engine][:style] = name.to_sym
|
||||
|
@ -296,6 +260,8 @@ END
|
|||
# Processes the options set by the command-line arguments,
|
||||
# and runs the Sass compiler appropriately.
|
||||
def process_result
|
||||
require 'sass'
|
||||
|
||||
if !@options[:update] && !@options[:watch] &&
|
||||
@args.first && colon_path?(@args.first)
|
||||
if @args.size == 1
|
||||
|
@ -308,6 +274,7 @@ END
|
|||
return interactive if @options[:interactive]
|
||||
return watch_or_update if @options[:watch] || @options[:update]
|
||||
super
|
||||
@options[:for_engine][:filename] = @options[:filename]
|
||||
|
||||
begin
|
||||
input = @options[:input]
|
||||
|
@ -337,13 +304,11 @@ END
|
|||
private
|
||||
|
||||
def interactive
|
||||
require 'sass'
|
||||
require 'sass/repl'
|
||||
::Sass::Repl.new(@options).run
|
||||
end
|
||||
|
||||
def watch_or_update
|
||||
require 'sass'
|
||||
require 'sass/plugin'
|
||||
::Sass::Plugin.options.merge! @options[:for_engine]
|
||||
::Sass::Plugin.options[:unix_newlines] = @options[:unix_newlines]
|
||||
|
@ -432,11 +397,11 @@ MSG
|
|||
end
|
||||
|
||||
# The `haml` executable.
|
||||
class Haml < HamlSass
|
||||
class Haml < Generic
|
||||
# @param args [Array<String>] The command-line arguments
|
||||
def initialize(args)
|
||||
super
|
||||
@name = "Haml"
|
||||
@options[:for_engine] = {}
|
||||
@options[:requires] = []
|
||||
@options[:load_paths] = []
|
||||
end
|
||||
|
@ -447,6 +412,21 @@ MSG
|
|||
def set_opts(opts)
|
||||
super
|
||||
|
||||
opts.banner = <<END
|
||||
Usage: haml [options] [INPUT] [OUTPUT]
|
||||
|
||||
Description:
|
||||
Converts Haml files to HTML.
|
||||
|
||||
Options:
|
||||
END
|
||||
|
||||
opts.on('-c', '--check', "Just check syntax, don't evaluate.") do
|
||||
require 'stringio'
|
||||
@options[:check_syntax] = true
|
||||
@options[:output] = StringIO.new
|
||||
end
|
||||
|
||||
opts.on('-t', '--style NAME',
|
||||
'Output style. Can be indented (default) or ugly.') do |name|
|
||||
@options[:for_engine][:ugly] = true if name.to_sym == :ugly
|
||||
|
@ -492,6 +472,7 @@ MSG
|
|||
# and runs the Haml compiler appropriately.
|
||||
def process_result
|
||||
super
|
||||
@options[:for_engine][:filename] = @options[:filename]
|
||||
input = @options[:input]
|
||||
output = @options[:output]
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue