Class: Hassle::Compiler

Inherits:
Object
  • Object
show all
Defined in:
lib/hassle.rb

Instance Method Summary collapse

Instance Method Details

#compileObject



63
64
65
66
67
# File 'lib/hassle.rb', line 63

def compile
  normalize
  prepare
  Sass::Plugin.update_stylesheets
end

#compile_location(*subdirs) ⇒ Object



31
32
33
# File 'lib/hassle.rb', line 31

def compile_location(*subdirs)
  File.join(Dir.pwd, "tmp", "hassle", subdirs)
end

#css_location(path) ⇒ Object



24
25
26
27
28
29
# File 'lib/hassle.rb', line 24

def css_location(path)
  expanded = File.expand_path(path)
  public_dir = File.join(File.expand_path(Dir.pwd), "public")

  File.expand_path(compile_location(expanded.gsub(public_dir, ''), '..'))
end

#normalizeObject



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/hassle.rb', line 35

def normalize
  template_location = options[:template_location]

  if template_location.is_a?(Hash) || template_location.is_a?(Array)
    options[:template_location] = template_location.to_a.map do |input, output|
      [input, css_location(input)]
    end
  else
    default_location = File.join(options[:css_location], "sass")
    options[:template_location] = {default_location => css_location(default_location)}
  end
end

#optionsObject



20
21
22
# File 'lib/hassle.rb', line 20

def options
  Sass::Plugin.options
end

#prepareObject



48
49
50
51
52
53
54
55
# File 'lib/hassle.rb', line 48

def prepare
  options.merge!(:cache        => false,
                 :never_update => false)

  options[:template_location].to_a.each do |location|
    FileUtils.mkdir_p(location.last)
  end
end

#stylesheetsObject



57
58
59
60
61
# File 'lib/hassle.rb', line 57

def stylesheets
  options[:template_location].to_a.map do |location|
    Dir[File.join(location.last, "**", "*.css")].map { |css| css.gsub(compile_location, "/") }
  end.flatten.sort
end