Parent

Files

Less::Command

Attributes

source[RW]
destination[RW]
options[RW]

Public Class Methods

new(options) click to toggle source
    # 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

Public Instance Methods

compress?() click to toggle source
    # File lib/less/command.rb, line 14
14:     def compress?() @options[:compress] end
debug?() click to toggle source
    # File lib/less/command.rb, line 15
15:     def debug?()    @options[:debug]    end
err(s = '', type = '') click to toggle source
     # 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
log(s = '') click to toggle source

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
parse(new = false) click to toggle source
    # 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
run!() click to toggle source
    # 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
watch() click to toggle source

little function which allows us to Ctrl-C exit inside the passed block

    # File lib/less/command.rb, line 19
19:     def watch
20:       begin
21:         yield
22:       rescue Interrupt
23:         puts
24:         exit 0
25:       end
26:     end
watch?() click to toggle source
    # File lib/less/command.rb, line 13
13:     def watch?()    @options[:watch]    end

Private Instance Methods

o(ex, *styles) click to toggle source
     # File lib/less/command.rb, line 106
106:     def o ex, *styles
107:       @mutter.process(ex.to_s, *(@options[:color] ? styles : []))
108:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.