Class: Guard::Less

Inherits:
Plugin
  • Object
show all
Defined in:
lib/guard/less.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Less

Returns a new instance of Less.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/guard/less.rb', line 8

def initialize(options = {})
  defaults = {
    all_after_change: true,
    all_on_start: true,
    output: nil,
    import_paths: [],
    compress: false,
    patterns: [],
    yuicompress: false
  }
  super(defaults.merge(options))
end

Instance Method Details

#run(paths) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/guard/less.rb', line 40

def run(paths)
  directories = nested_directory_map(paths)

  directories.each do |destination, stylesheets|
    stylesheets.each do |lessfile|
      # Skip partials
      basename = File.basename(lessfile)
      next if basename[0, 1] == '_'

      cssfile = File.join(destination, basename.gsub(/\.less$/, '.css'))

      # Just in case
      if cssfile == lessfile
        Compat::UI.info "Guard::Less: Skipping #{lessfile} since output and source are the same"
      elsif mtime(cssfile) >= mtime_including_imports(lessfile)
        Compat::UI.info "Guard::Less: Skipping #{lessfile} because #{cssfile} is already up-to-date"
      else
        Compat::UI.info "Guard::Less: #{lessfile} -> #{cssfile}\n"
        FileUtils.mkdir_p(File.expand_path(destination))
        compile(lessfile, cssfile)
      end
    end
  end
end

#run_allObject

Call with Ctrl-/ signal This method should be principally used for long action like running all specs/tests/…



28
29
30
31
32
33
# File 'lib/guard/less.rb', line 28

def run_all
  Compat::UI.info 'Guard::Less: compiling all files'
  files = Dir.glob('**/*.*')
  paths = Compat.matching_files(self, files).uniq
  run(paths)
end

#run_on_changes(paths) ⇒ Object

Call on file(s) modifications



36
37
38
# File 'lib/guard/less.rb', line 36

def run_on_changes(paths)
  options[:all_after_change] ? run_all : run(paths)
end

#startObject



21
22
23
24
# File 'lib/guard/less.rb', line 21

def start
  Compat::UI.info "Guard::Less #{LessVersion::VERSION} is on the job!"
  run_all if options[:all_on_start]
end