Class: Less::Command
Instance Attribute Summary collapse
-
#destination ⇒ Object
Returns the value of attribute destination.
-
#options ⇒ Object
Returns the value of attribute options.
-
#source ⇒ Object
Returns the value of attribute source.
Instance Method Summary collapse
- #compress? ⇒ Boolean
- #debug? ⇒ Boolean
- #err(s = '', type = '') ⇒ Object
-
#initialize(options) ⇒ Command
constructor
A new instance of Command.
-
#log(s = '') ⇒ Object
Just a logging function to avoid typing ‘*’.
- #parse(new = false) ⇒ Object
- #run! ⇒ Object
-
#watch ⇒ Object
little function which allows us to Ctrl-C exit inside the passed block.
- #watch? ⇒ Boolean
Constructor Details
#initialize(options) ⇒ Command
Returns a new instance of Command.
5 6 7 8 9 10 11 |
# File 'lib/less/command.rb', line 5 def initialize $verbose = [:debug] @source = [:source] @destination = ([:destination] || [:source]).gsub /\.(less|lss)/, '.css' @options = @mutter = Mutter.new.clear end |
Instance Attribute Details
#destination ⇒ Object
Returns the value of attribute destination.
3 4 5 |
# File 'lib/less/command.rb', line 3 def destination @destination end |
#options ⇒ Object
Returns the value of attribute options.
3 4 5 |
# File 'lib/less/command.rb', line 3 def @options end |
#source ⇒ Object
Returns the value of attribute source.
3 4 5 |
# File 'lib/less/command.rb', line 3 def source @source end |
Instance Method Details
#compress? ⇒ Boolean
14 |
# File 'lib/less/command.rb', line 14 def compress?() @options[:compress] end |
#debug? ⇒ Boolean
15 |
# File 'lib/less/command.rb', line 15 def debug?() @options[:debug] end |
#err(s = '', type = '') ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/less/command.rb', line 87 def err s = '', type = '' type = type.strip + ' ' unless type.empty? $stderr.print "#{o("! #{type}Error", :red)}: #{s}" if @options[:growl] growl = Growl.new growl.title = "LESS" growl. = "#{type}Error in #@source!" growl.run false end end |
#log(s = '') ⇒ Object
Just a logging function to avoid typing ‘*’
83 84 85 |
# File 'lib/less/command.rb', line 83 def log s = '' print '* ' + s.to_s end |
#parse(new = false) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/less/command.rb', line 54 def parse new = false begin # Create a new Less object with the contents of a file css = Less::Engine.new(File.new(@source), @options).to_css css = css.delete " \n" if compress? File.open( @destination, "w" ) do |file| file.write css end print "#{o('* ' + (new ? 'Created' : 'Updated'), :green)} " + "#{@destination.split('/').last}\n: " if watch? rescue Errno::ENOENT => e abort "#{e}" rescue SyntaxError => e err "#{e}\n", "Syntax" rescue MixedUnitsError => e err "`#{e}` you're mixing units together! What do you expect?\n", "Mixed Units" rescue PathError => e err "`#{e}` was not found.\n", "Path" rescue VariableNameError => e err "#{o(e, :yellow)} is undefined.\n", "Name" rescue MixinNameError => e err "#{o(e, :yellow)} is undefined.\n", "Name" else true end end |
#run! ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/less/command.rb', line 28 def run! if watch? parse(true) unless File.exist? @destination log "Watching for changes in #@source... Ctrl-C to abort.\n: " # Main watch loop loop do watch { sleep 1 } # File has changed if File.stat( @source ).mtime > File.stat( @destination ).mtime print "Change detected... " # Loop until error is fixed until parse log "Press [return] to continue..." watch { $stdin.gets } end end end else parse end end |
#watch ⇒ Object
little function which allows us to Ctrl-C exit inside the passed block
19 20 21 22 23 24 25 26 |
# File 'lib/less/command.rb', line 19 def watch begin yield rescue Interrupt puts exit 0 end end |
#watch? ⇒ Boolean
13 |
# File 'lib/less/command.rb', line 13 def watch?() @options[:watch] end |