# File lib/less/command.rb, line 5
5: def initialize options
6: $verbose = options[:debug]
7: @source = options[:source]
8: @destination = (options[:destination] || options[:source]).gsub /\.(less|lss)/, '.css'
9: @options = options
10: @mutter = Mutter.new.clear
11: end
# File lib/less/command.rb, line 14
14: def compress?() @options[:compress] end
# File lib/less/command.rb, line 15
15: def debug?() @options[:debug] end
# File lib/less/command.rb, line 92
92: def err s = '', type = ''
93: type = type.strip + ' ' unless type.empty?
94: $stderr.print "#{o("! #{type}Error", :red)}: #{s}"
95: if @options[:growl]
96: growl = Growl.new
97: growl.title = "LESS"
98: growl.message = "#{type}Error in #@source!"
99: growl.run
100: false
101: end
102: end
Just a logging function to avoid typing ’*’
# File lib/less/command.rb, line 88
88: def log s = ''
89: print '* ' + s.to_s
90: end
# File lib/less/command.rb, line 55
55: def parse new = false
56: begin
57: # Create a new Less object with the contents of a file
58: css = Less::Engine.new(File.new(@source), @options).to_css
59: css = css.delete " \n" if compress?
60:
61: File.open( @destination, "w" ) do |file|
62: file.write css
63: end
64:
65: act, file = (new ? 'Created' : 'Updated'), @destination.split('/').last
66: print "#{o("* #{act}", :green)} #{file}\n: " if watch?
67: Growl.notify "#{act} #{file}", :title => 'LESS' if @options[:growl] && @options[:verbose]
68: rescue Errno::ENOENT => e
69: abort "#{e}"
70: rescue SyntaxError => e
71: err "#{e}\n", "Syntax"
72: rescue CompileError => e
73: err "#{e}\n", "Compile"
74: rescue MixedUnitsError => e
75: err "`#{e}` you're mixing units together! What do you expect?\n", "Mixed Units"
76: rescue PathError => e
77: err "`#{e}` was not found.\n", "Path"
78: rescue VariableNameError => e
79: err "#{o(e, :yellow)} is undefined.\n", "Variable Name"
80: rescue MixinNameError => e
81: err "#{o(e, :yellow)} is undefined.\n", "Mixin Name"
82: else
83: true
84: end
85: end
# File lib/less/command.rb, line 28
28: def run!
29: if watch?
30: parse(true) unless File.exist? @destination
31:
32: log "Watching for changes in #@source... Ctrl-C to abort.\n: "
33:
34: # Main watch loop
35: loop do
36: watch { sleep 1 }
37:
38: # File has changed
39: if File.stat( @source ).mtime > File.stat( @destination ).mtime
40: print Time.now.strftime("%H:%M:%S -- ") if @options[:timestamps]
41: print "Change detected... "
42:
43: # Loop until error is fixed
44: until parse
45: log "Press [return] to continue..."
46: watch { $stdin.gets }
47: end
48: end
49: end
50: else
51: parse
52: end
53: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.