Class: Hassless::Compiler

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

Instance Method Summary collapse

Instance Method Details

#destination(path = "") ⇒ Object



10
11
12
13
# File 'lib/hassless/compiler.rb', line 10

def destination(path = "")
  @destination ||= File.join("tmp", "hassless", "stylesheets")
  File.join(@destination, path.sub(/(le?|c)ss$/, "css"))
end

#generate(template) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/hassless/compiler.rb', line 19

def generate(template)
  source = source(template)
  destination = destination(template)

  if mtime(destination) < mtime(source, :imports => true)
    FileUtils.mkdir_p File.dirname(destination)
    File.open(destination, "w"){|f| f.write compile(source) }
  end
end

#runObject



29
30
31
32
33
# File 'lib/hassless/compiler.rb', line 29

def run
  Dir[File.join(Rails.root, source, "**", "*.{css,less,lss}")].reject { |path| File.basename(path) =~ /^_/ }.each do |path|
    generate(path.sub(File.join(Rails.root, source), ""))
  end
end

#source(path = "") ⇒ Object



5
6
7
8
# File 'lib/hassless/compiler.rb', line 5

def source(path = "")
  @source ||= File.join("app", "stylesheets")
  File.join(@source, path)
end

#stylesheetsObject



15
16
17
# File 'lib/hassless/compiler.rb', line 15

def stylesheets
  Dir[File.join(destination, "**", "*.css")].map { |css| "/stylesheets/" + css.gsub(destination, "") }
end