Permalink
Browse files

refactoring and cleanup

  • Loading branch information...
1 parent 54b229c commit 7817005e5a58cfc787fe8ebf92a6cb4f8b6edbca @grosser grosser committed Feb 13, 2010
Showing with 21 additions and 9 deletions.
  1. +21 −9 lib/less/more.rb
View
@@ -46,15 +46,15 @@ def compression
# Less::More.generate("screen.less")
# Less::More.generate("subdirectories/here/homepage.less")
def generate(source)
- generated = File.join(Rails.root, 'public', destination_path, source.sub(/\.le?ss$/, '.css'))
+ generated = to_dot_css(path_to_destination(source))
path_to_source = File.join(Rails.root, source_path, source)
# check if the destination file exists, and compare the modified times to see if it needs to be written
if File.exists?(generated) and File.mtime(generated) >= File.mtime(path_to_source)
# up to date, nothing to do!
else
# css file does not exist or is out of date
- css = if File.extname(source) == ".css"
+ css = if File.extname(path_to_source) == ".css"
# vanilla css nothing to do!
File.read(path_to_source)
else
@@ -73,28 +73,28 @@ def generate(source)
# Generates all the .css files
def generate_all
- Less::More.all_less_files.each do |path|
- relative_path = path.sub(File.join(Rails.root, source_path),'')[1..-1]
- Less::More.generate(relative_path)
+ all_less_files.each do |path|
+ generate(relative_to_source_path(path))
end
end
# Removes all generated css files.
def remove_all_generated
all_less_files.each do |path|
- relative_path = path.sub(File.join(Rails.root, source_path), '')
- css_path = relative_path.to_s.sub(/(le?|c)ss$/, "css")
- css_file = File.join(Rails.root, "public", destination_path, css_path)
+ css_path = to_dot_css(relative_to_source_path(path))
+ css_file = path_to_destination(css_path)
File.delete(css_file) if File.file?(css_file)
end
end
-
+
# Array of paths of less source files.
def all_less_files
all = Dir[File.join(Rails.root, source_path, "**", "*.{css,less,lss}")]
all.reject{|path| File.basename(path) =~ /^_/ }
end
+ private
+
def compile(file)
begin
engine = File.open(file){|f| Less::Engine.new(f) }
@@ -104,5 +104,17 @@ def compile(file)
raise e
end
end
+
+ def to_dot_css(path)
+ path.to_s.sub(/(le?|c)ss$/, "css")
+ end
+
+ def path_to_destination(path)
+ File.join(Rails.root, "public", destination_path, path)
+ end
+
+ def relative_to_source_path(path)
+ path.to_s.sub(File.join(Rails.root, source_path), '')[1..-1]
+ end
end
end

0 comments on commit 7817005

Please sign in to comment.