less-rails 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +46 -0
- data/Rakefile +19 -0
- data/VERSION +1 -0
- data/init.rb +1 -0
- data/less-rails.gemspec +44 -0
- data/lib/less-rails.rb +73 -0
- metadata +72 -0
data/README.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# less-rails
|
2
|
+
|
3
|
+
Plugin for Rails to automatically generate css templates out of less (http://www.lesscss.org) templates.
|
4
|
+
|
5
|
+
For this to work you need to have the less gem:
|
6
|
+
|
7
|
+
<pre><code>sudo gem install less</code></pre>
|
8
|
+
|
9
|
+
This plugin provides you with some configuration options that can be set in either an initializer or an environment file.
|
10
|
+
The options can be set like this:
|
11
|
+
|
12
|
+
<pre><code>Less::Plugin.options[:template_location] = "#{RAILS_ROOT}/app/stylesheets"
|
13
|
+
Less::Plugin.options[:css_location] = "#{RAILS_ROOT}/public/stylesheets"
|
14
|
+
Less::Plugin.options[:update] = :when_changed
|
15
|
+
Less::Plugin.options[:compress] = false</code></pre>
|
16
|
+
|
17
|
+
A quick description of the options:
|
18
|
+
|
19
|
+
* :template_location is the location where the *.less files are to be found.
|
20
|
+
* :css_location is the location where the generated *.css files are to be put.
|
21
|
+
* :update defines when to update the *.css files, you have three options:
|
22
|
+
* :never : never update the css files automatically.
|
23
|
+
* :when_changed : update the css files when the corresponding less file is newer than the generated css file.
|
24
|
+
* :always : update the css files on every request.
|
25
|
+
* :compress : turns less's built-in compress functionality on or off.
|
26
|
+
|
27
|
+
The options as listed in the example code are the defaults that less-rails uses.
|
28
|
+
|
29
|
+
# Contributors
|
30
|
+
|
31
|
+
* Karst Hammer
|
32
|
+
* Mathieu Fosse
|
33
|
+
* Nicolas Mérouze
|
34
|
+
* Tim Harvey
|
35
|
+
|
36
|
+
# License
|
37
|
+
|
38
|
+
Copyright (c) 2009, Karst Hammer <karst (at) motorzweefschool (dot) demon (dot) nl>
|
39
|
+
All rights reserved.
|
40
|
+
|
41
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
42
|
+
|
43
|
+
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
44
|
+
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
45
|
+
|
46
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require "rake"
|
2
|
+
|
3
|
+
begin
|
4
|
+
require "jeweler"
|
5
|
+
Jeweler::Tasks.new do |gem|
|
6
|
+
gem.name = "less-rails"
|
7
|
+
gem.summary = "Using Less CSS Framework with Rails"
|
8
|
+
gem.email = "nicolas.merouze@gmail.com"
|
9
|
+
gem.homepage = "http://github.com/yeastymobs/less-rails"
|
10
|
+
gem.authors = ["Karst Hammer", "Nicolas Mérouze", "Mathieu Fosse", "Tim Harvey"]
|
11
|
+
gem.files = Dir["*", "lib/**/*"]
|
12
|
+
|
13
|
+
gem.add_dependency("less", "~> 1.2.21")
|
14
|
+
end
|
15
|
+
|
16
|
+
Jeweler::GemcutterTasks.new
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
19
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.0
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "less-rails"
|
data/less-rails.gemspec
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{less-rails}
|
8
|
+
s.version = "1.0.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Karst Hammer", "Nicolas M\303\251rouze", "Mathieu Fosse", "Tim Harvey"]
|
12
|
+
s.date = %q{2010-02-03}
|
13
|
+
s.email = %q{nicolas.merouze@gmail.com}
|
14
|
+
s.extra_rdoc_files = [
|
15
|
+
"README.md"
|
16
|
+
]
|
17
|
+
s.files = [
|
18
|
+
"README.md",
|
19
|
+
"Rakefile",
|
20
|
+
"VERSION",
|
21
|
+
"init.rb",
|
22
|
+
"less-rails.gemspec",
|
23
|
+
"lib/less-rails.rb"
|
24
|
+
]
|
25
|
+
s.homepage = %q{http://github.com/yeastymobs/less-rails}
|
26
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
27
|
+
s.require_paths = ["lib"]
|
28
|
+
s.rubygems_version = %q{1.3.5}
|
29
|
+
s.summary = %q{Using Less CSS Framework with Rails}
|
30
|
+
|
31
|
+
if s.respond_to? :specification_version then
|
32
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
33
|
+
s.specification_version = 3
|
34
|
+
|
35
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
36
|
+
s.add_runtime_dependency(%q<less>, ["~> 1.2.21"])
|
37
|
+
else
|
38
|
+
s.add_dependency(%q<less>, ["~> 1.2.21"])
|
39
|
+
end
|
40
|
+
else
|
41
|
+
s.add_dependency(%q<less>, ["~> 1.2.21"])
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
data/lib/less-rails.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'less'
|
2
|
+
|
3
|
+
module Less
|
4
|
+
module Plugin
|
5
|
+
extend self
|
6
|
+
|
7
|
+
attr_reader :options
|
8
|
+
|
9
|
+
# Set default options
|
10
|
+
@options = {
|
11
|
+
:css_location => "#{RAILS_ROOT}/public/stylesheets",
|
12
|
+
:template_location => "#{RAILS_ROOT}/app/stylesheets",
|
13
|
+
:update => :when_changed, # Available are: :never, :when_changed and :always
|
14
|
+
:compress => false # Removes newlines from generated CSS
|
15
|
+
}
|
16
|
+
|
17
|
+
# Accessor for setting options from e.g. an initializer
|
18
|
+
def options=(opts)
|
19
|
+
@options.merge!(opts)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Updates all stylesheets in the template_location and
|
23
|
+
# create corresponding files in the css_location.
|
24
|
+
def update_stylesheets
|
25
|
+
return if options[:update] == :never
|
26
|
+
|
27
|
+
# Recursively loop through the directory specified in template_location.
|
28
|
+
Dir.glob(File.join(options[:template_location], '**', '*.less')).each do |stylesheet|
|
29
|
+
# Update the current stylesheet if update is not :when_changed OR when the
|
30
|
+
# less-file is newer than the css-file.
|
31
|
+
update_stylesheet(stylesheet) if options[:update] != :when_changed || stylesheet_needs_update?(stylesheet)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
# Update a single stylesheet.
|
38
|
+
def update_stylesheet(stylesheet)
|
39
|
+
relative_path = relative_path(stylesheet)
|
40
|
+
|
41
|
+
# Remove the old generated stylesheet
|
42
|
+
File.unlink(File.join(options[:css_location], relative_path + ".css")) if File.exist?(File.join(options[:css_location], relative_path + ".css"))
|
43
|
+
|
44
|
+
# Generate the new stylesheet
|
45
|
+
Less::Command.new({:source => stylesheet, :destination => File.join(options[:css_location], relative_path + ".css"), :compress => options[:compress]}).run!
|
46
|
+
end
|
47
|
+
|
48
|
+
# Check if the specified stylesheet is in need of an update.
|
49
|
+
def stylesheet_needs_update?(stylesheet)
|
50
|
+
relative_path = relative_path(stylesheet)
|
51
|
+
|
52
|
+
return true unless File.exist?(File.join(options[:css_location], relative_path + ".css"))
|
53
|
+
return File.ctime(stylesheet) > File.ctime(File.join(options[:css_location], relative_path + ".css"))
|
54
|
+
end
|
55
|
+
|
56
|
+
# Returns the relative path for the given stylesheet
|
57
|
+
def relative_path(stylesheet)
|
58
|
+
stylesheet.sub(options[:template_location] + '/', '').sub('.less', '')
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# Add a before_filter that triggers the update_stylesheets method
|
64
|
+
# before every call to a controller.
|
65
|
+
module ActionController
|
66
|
+
class Base
|
67
|
+
alias_method :less_old_process, :process
|
68
|
+
def process(*args)
|
69
|
+
Less::Plugin.update_stylesheets
|
70
|
+
less_old_process(*args)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: less-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Karst Hammer
|
8
|
+
- "Nicolas M\xC3\xA9rouze"
|
9
|
+
- Mathieu Fosse
|
10
|
+
- Tim Harvey
|
11
|
+
autorequire:
|
12
|
+
bindir: bin
|
13
|
+
cert_chain: []
|
14
|
+
|
15
|
+
date: 2010-02-03 00:00:00 +01:00
|
16
|
+
default_executable:
|
17
|
+
dependencies:
|
18
|
+
- !ruby/object:Gem::Dependency
|
19
|
+
name: less
|
20
|
+
type: :runtime
|
21
|
+
version_requirement:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.2.21
|
27
|
+
version:
|
28
|
+
description:
|
29
|
+
email: nicolas.merouze@gmail.com
|
30
|
+
executables: []
|
31
|
+
|
32
|
+
extensions: []
|
33
|
+
|
34
|
+
extra_rdoc_files:
|
35
|
+
- README.md
|
36
|
+
files:
|
37
|
+
- README.md
|
38
|
+
- Rakefile
|
39
|
+
- VERSION
|
40
|
+
- init.rb
|
41
|
+
- less-rails.gemspec
|
42
|
+
- lib/less-rails.rb
|
43
|
+
has_rdoc: true
|
44
|
+
homepage: http://github.com/yeastymobs/less-rails
|
45
|
+
licenses: []
|
46
|
+
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options:
|
49
|
+
- --charset=UTF-8
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: "0"
|
57
|
+
version:
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: "0"
|
63
|
+
version:
|
64
|
+
requirements: []
|
65
|
+
|
66
|
+
rubyforge_project:
|
67
|
+
rubygems_version: 1.3.5
|
68
|
+
signing_key:
|
69
|
+
specification_version: 3
|
70
|
+
summary: Using Less CSS Framework with Rails
|
71
|
+
test_files: []
|
72
|
+
|