less-rails 1.0.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ CHANGELOG
2
+ =========
3
+
4
+ 2.0.0 (Sept 25, 2011)
5
+ ---------------------
6
+
7
+ * Initial 2.0 release. Heavily inspired/copied code from sass-rails.
8
+
9
+
10
+ 1.0.0 (Feb 2, 2010)
11
+ -------------------
12
+
13
+ * Original project at http://github.com/yeastymobs/less-rails
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source :rubygems
2
+
3
+ gemspec
4
+
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Ken Collins
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,46 +1,26 @@
1
- # less-rails
1
+ # The dynamic stylesheet language for the Rails asset pipeline.
2
2
 
3
- Plugin for Rails to automatically generate css templates out of less (http://www.lesscss.org) templates.
3
+ This gem provides integration for Rails projects using the Less stylesheet language in the asset pipeline.
4
4
 
5
- For this to work you need to have the less gem:
6
5
 
7
- <pre><code>sudo gem install less</code></pre>
6
+ ## Installing
8
7
 
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:
8
+ Until we can publish this gem under an official less-rails name, please bundle to the git repo.
11
9
 
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>
10
+ gem 'less-rails', :git => 'git://github.com/metaskills/less-rails.git'
16
11
 
17
- A quick description of the options:
18
12
 
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.
13
+ ## Configuration
26
14
 
27
- The options as listed in the example code are the defaults that less-rails uses.
15
+ This gem was made for other gems to properly hook into one place to provide paths to the Less::Parser. For example, the less-rails-bootstrap project at http://github.com/metaskills/less-rails-bootstrap and each project should do the path configuration for you. If you need to, you can configure less-rails with additional paths. These paths have higher priority than those from your applications assets load paths.
28
16
 
29
- # Contributors
17
+ ```ruby
18
+ MyProject::Application.configure do
19
+ config.less.paths << "#{Rails.root}/lib/less/stylesheets"
20
+ end
21
+ ```
30
22
 
31
- * Karst Hammer
32
- * Mathieu Fosse
33
- * Nicolas Mérouze
34
- * Tim Harvey
23
+ ## License
35
24
 
36
- # License
25
+ Less::Rails is Copyright (c) 2011 Ken Collins, <ken@metaskills.net> and is distributed under the MIT license.
37
26
 
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 CHANGED
@@ -1,19 +1 @@
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
1
+ require "bundler/gem_tasks"
data/less-rails.gemspec CHANGED
@@ -1,44 +1,22 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
1
  # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "less/rails/version"
5
4
 
6
5
  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"]
6
+ s.name = "less-rails"
7
+ s.version = Less::Rails::VERSION
8
+ s.authors = ["Ken Collins"]
9
+ s.email = ["ken@metaskills.net"]
10
+ s.homepage = "http://github.com/metaskills/less-rails"
11
+ s.summary = %q{The dynamic stylesheet language for the Rails asset pipeline.}
12
+ s.description = %q{The dynamic stylesheet language for the Rails asset pipeline.}
13
+ s.files = `git ls-files`.split("\n")
14
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
27
16
  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
17
+ s.add_runtime_dependency 'less', '~> 2.0.7'
18
+ s.add_runtime_dependency 'railties', '~> 3.1.0'
19
+ s.add_runtime_dependency 'actionpack', '~> 3.1.0'
20
+ # s.add_development_dependency 'minitest'
21
+ # s.add_development_dependency 'combustion', '~> 0.3.1'
43
22
  end
44
-
data/lib/less-rails.rb CHANGED
@@ -1,73 +1,2 @@
1
- require 'less'
1
+ require "less/rails"
2
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
data/lib/less/rails.rb ADDED
@@ -0,0 +1,9 @@
1
+ module Less
2
+ module Rails
3
+ end
4
+ end
5
+
6
+ require 'less/rails/version'
7
+ require 'less/rails/railtie'
8
+ require 'less/rails/template_handlers'
9
+
@@ -0,0 +1,29 @@
1
+ module Less
2
+ module Rails
3
+ class Railtie < ::Rails::Railtie
4
+
5
+ module LessContext
6
+ attr_accessor :less_config
7
+ end
8
+
9
+ config.less = ActiveSupport::OrderedOptions.new
10
+
11
+ config.less.paths = []
12
+
13
+ config.before_initialize do |app|
14
+ unless app.config.assets && app.config.assets.enabled
15
+ raise "The less-rails plugin requires the asset pipeline to be enabled."
16
+ end
17
+ require 'less'
18
+ Sprockets::Engines #force autoloading
19
+ Sprockets.register_engine '.less', Less::Rails::LessTemplate
20
+ end
21
+
22
+ initializer 'less-rails.setup' do |app|
23
+ app.assets.context_class.extend(LessContext)
24
+ app.assets.context_class.less_config = app.config.less
25
+ end
26
+
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,35 @@
1
+ require 'tilt'
2
+ require 'sprockets'
3
+
4
+ module Less
5
+ module Rails
6
+
7
+ class LessTemplate < Tilt::LessTemplate
8
+
9
+ def prepare
10
+ end
11
+
12
+ def evaluate(scope, locals, &block)
13
+ @output ||= begin
14
+ parser = ::Less::Parser.new less_parser_options(scope)
15
+ engine = parser.parse(data)
16
+ engine.to_css
17
+ end
18
+ end
19
+
20
+ protected
21
+
22
+ def less_options_from_rails(scope)
23
+ scope.environment.context_class.less_config
24
+ end
25
+
26
+ def less_parser_options(scope)
27
+ less_options = less_options_from_rails(scope)
28
+ paths = less_options[:paths] + scope.environment.paths
29
+ {:filename => eval_file, :line => line, :paths => paths}
30
+ end
31
+
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,5 @@
1
+ module Less
2
+ module Rails
3
+ VERSION = "2.0.0"
4
+ end
5
+ end
metadata CHANGED
@@ -1,72 +1,126 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: less-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ hash: 15
5
+ prerelease:
6
+ segments:
7
+ - 2
8
+ - 0
9
+ - 0
10
+ version: 2.0.0
5
11
  platform: ruby
6
12
  authors:
7
- - Karst Hammer
8
- - "Nicolas M\xC3\xA9rouze"
9
- - Mathieu Fosse
10
- - Tim Harvey
13
+ - Ken Collins
11
14
  autorequire:
12
15
  bindir: bin
13
16
  cert_chain: []
14
17
 
15
- date: 2010-02-03 00:00:00 +01:00
18
+ date: 2011-09-26 00:00:00 -04:00
16
19
  default_executable:
17
20
  dependencies:
18
21
  - !ruby/object:Gem::Dependency
19
22
  name: less
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 1
30
+ segments:
31
+ - 2
32
+ - 0
33
+ - 7
34
+ version: 2.0.7
20
35
  type: :runtime
21
- version_requirement:
22
- version_requirements: !ruby/object:Gem::Requirement
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: railties
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
23
42
  requirements:
24
43
  - - ~>
25
44
  - !ruby/object:Gem::Version
26
- version: 1.2.21
27
- version:
28
- description:
29
- email: nicolas.merouze@gmail.com
45
+ hash: 3
46
+ segments:
47
+ - 3
48
+ - 1
49
+ - 0
50
+ version: 3.1.0
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: actionpack
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ hash: 3
62
+ segments:
63
+ - 3
64
+ - 1
65
+ - 0
66
+ version: 3.1.0
67
+ type: :runtime
68
+ version_requirements: *id003
69
+ description: The dynamic stylesheet language for the Rails asset pipeline.
70
+ email:
71
+ - ken@metaskills.net
30
72
  executables: []
31
73
 
32
74
  extensions: []
33
75
 
34
- extra_rdoc_files:
35
- - README.md
76
+ extra_rdoc_files: []
77
+
36
78
  files:
79
+ - .gitignore
80
+ - CHANGELOG.md
81
+ - Gemfile
82
+ - MIT-LICENSE
37
83
  - README.md
38
84
  - Rakefile
39
- - VERSION
40
- - init.rb
41
85
  - less-rails.gemspec
42
86
  - lib/less-rails.rb
87
+ - lib/less/rails.rb
88
+ - lib/less/rails/railtie.rb
89
+ - lib/less/rails/template_handlers.rb
90
+ - lib/less/rails/version.rb
43
91
  has_rdoc: true
44
- homepage: http://github.com/yeastymobs/less-rails
92
+ homepage: http://github.com/metaskills/less-rails
45
93
  licenses: []
46
94
 
47
95
  post_install_message:
48
- rdoc_options:
49
- - --charset=UTF-8
96
+ rdoc_options: []
97
+
50
98
  require_paths:
51
99
  - lib
52
100
  required_ruby_version: !ruby/object:Gem::Requirement
101
+ none: false
53
102
  requirements:
54
103
  - - ">="
55
104
  - !ruby/object:Gem::Version
105
+ hash: 3
106
+ segments:
107
+ - 0
56
108
  version: "0"
57
- version:
58
109
  required_rubygems_version: !ruby/object:Gem::Requirement
110
+ none: false
59
111
  requirements:
60
112
  - - ">="
61
113
  - !ruby/object:Gem::Version
114
+ hash: 3
115
+ segments:
116
+ - 0
62
117
  version: "0"
63
- version:
64
118
  requirements: []
65
119
 
66
120
  rubyforge_project:
67
- rubygems_version: 1.3.5
121
+ rubygems_version: 1.6.2
68
122
  signing_key:
69
123
  specification_version: 3
70
- summary: Using Less CSS Framework with Rails
124
+ summary: The dynamic stylesheet language for the Rails asset pipeline.
71
125
  test_files: []
72
126
 
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 1.0.0
data/init.rb DELETED
@@ -1 +0,0 @@
1
- require "less-rails"