more 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1 @@
1
- require File.join(File.dirname(__FILE__), '..', 'lib', 'controller_extension') if RAILS_ENV == 'development'
1
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'less', 'controller_extension') if RAILS_ENV == 'development'
@@ -0,0 +1,26 @@
1
+ require 'test_helper'
2
+
3
+ class ExampleController < ActionController::Base
4
+ def test
5
+ render :text => 'OK'
6
+ end
7
+ end
8
+
9
+ class ControllerTest < ActionController::TestCase
10
+ def setup
11
+ @controller = ExampleController.new
12
+ @request = ActionController::TestRequest.new
13
+ @response = ActionController::TestResponse.new
14
+ setup_for_generate_test
15
+ end
16
+
17
+ def teardown
18
+ teardown_for_generate_test
19
+ end
20
+
21
+ should "generate less files" do
22
+ write_less 'xxx.less', 'a{color:red}'
23
+ get :test
24
+ assert_equal 'a { color: red; }', read_css('xxx.css').strip
25
+ end
26
+ end
@@ -1,102 +1,213 @@
1
1
  require 'test_helper'
2
2
 
3
- class MoreTest < Test::Unit::TestCase
4
- def setup
3
+ class MoreTest < ActiveSupport::TestCase
4
+ setup do
5
5
  [:compression, :header, :destination_path, :source_path].each do |variable|
6
6
  Less::More.send("#{variable}=", nil)
7
7
  end
8
8
  end
9
9
 
10
- def prepare_for_generate
11
- Less::More.source_path = 'less_files'
12
- Less::More.destination_path = 'css'
10
+ context :header do
11
+ should "be true by default" do
12
+ assert_equal Less::More.header, true
13
+ end
13
14
 
14
- `rm -rf #{css_path}`
15
- `mkdir -p #{css_path}`
15
+ should "be overwriteable" do
16
+ Less::More.header = false
17
+ assert_equal false, Less::More.header
18
+ end
16
19
  end
17
20
 
18
- def css_path
19
- "#{Rails.root}/public/css"
20
- end
21
+ context :source_path do
22
+ should "be app/stylesheets by default" do
23
+ assert_equal 'app/stylesheets', Less::More.source_path
24
+ end
21
25
 
22
- def teardown
23
- `rm -rf #{css_path}`
26
+ should "be overwritteable" do
27
+ Less::More.source_path = 'xxx'
28
+ assert_equal 'xxx', Less::More.source_path
29
+ end
24
30
  end
25
31
 
26
- def test_default_for_header
27
- assert_equal Less::More.header, true
28
- end
32
+ context :destination_path do
33
+ should "be public/stylesheets by default" do
34
+ assert_equal 'stylesheets', Less::More.destination_path
35
+ end
29
36
 
30
- def test_header_can_be_overwritten
31
- Less::More.header = false
32
- assert_equal false, Less::More.header
37
+ should "be overwritteable" do
38
+ Less::More.destination_path = 'xxx'
39
+ assert_equal 'xxx', Less::More.destination_path
40
+ end
33
41
  end
34
42
 
35
- def test_default_for_source_path
36
- assert_equal 'app/stylesheets', Less::More.source_path
37
- end
43
+ context :compression do
44
+ should "be off by default" do
45
+ assert_equal nil, Less::More.compression
46
+ end
38
47
 
39
- def test_source_path_can_be_overwritten
40
- Less::More.source_path = 'xxx'
41
- assert_equal 'xxx', Less::More.source_path
48
+ should "be overwritteable" do
49
+ Less::More.compression = true
50
+ assert_equal true, Less::More.compression
51
+ end
42
52
  end
43
53
 
44
- def test_default_for_destination_path
45
- assert_equal 'stylesheets', Less::More.destination_path
46
- end
54
+ context :generate do
55
+ setup do
56
+ setup_for_generate_test
57
+ end
47
58
 
48
- def test_destination_path_can_be_overwritten
49
- Less::More.destination_path = 'xxx'
50
- assert_equal 'xxx', Less::More.destination_path
51
- end
59
+ teardown do
60
+ teardown_for_generate_test
61
+ end
52
62
 
53
- def test_default_for_compression
54
- assert_equal nil, Less::More.compression
55
- end
63
+ should 'generate css from .less files' do
64
+ write_less 'test.less', "a{color:red}"
65
+ Less::More.generate_all
66
+ assert_include 'a { color: red; }', read_css('test.css')
67
+ end
56
68
 
57
- def test_compression_can_be_overwritten
58
- Less::More.compression = true
59
- assert_equal true, Less::More.compression
60
- end
69
+ should 'generate css from .lss files' do
70
+ write_less 'test.lss', "a{color:red}"
71
+ Less::More.generate_all
72
+ assert_include 'a { color: red; }', read_css('test.css')
73
+ end
61
74
 
62
- def test_generate_with_partials
63
- prepare_for_generate
64
- Less::More.generate_all
65
- css = File.read(File.join(css_path, 'test.css'))
66
- assert css.include?(".allforms { font-size: 110%; }
67
- body { color: #222222; }
68
- form {
69
- font-size: 110%;
70
- color: #ffffff;
71
- }")
72
- end
75
+ should 'generate for files in subfolders' do
76
+ write_less 'xxx/test.less', "a{color:red}"
77
+ Less::More.generate_all
78
+ assert_include 'a { color: red; }', read_css('xxx/test.css')
79
+ end
73
80
 
74
- def test_generate_does_not_parse_css
75
- prepare_for_generate
76
- Less::More.generate_all
77
- original_css = File.read(File.join(css_path, 'plain.css'))
78
- assert_equal File.read(File.join(Rails.root,'less_files', 'plain.css')), original_css
79
- end
81
+ should "include imported partials" do
82
+ write_less 'test.less', "@import '_partial';\nb{color:blue}"
83
+ write_less '_partial.less', 'a{color:red}'
84
+ Less::More.generate_all
85
+ assert_include 'a { color: red; }', read_css('test.css')
86
+ end
80
87
 
81
- def test_generate_uses_header_when_set
82
- prepare_for_generate
83
- Less::More.header = true
84
- Less::More.generate_all
85
- css = File.read(File.join(css_path, 'test.css'))
86
- assert_match /^\/\*/, css # starts with comment -> header
87
- end
88
+ should "not generate css from partials" do
89
+ write_less '_partial.less', 'a{color:red}'
90
+ Less::More.generate_all
91
+ assert_equal '', `ls #{css_path}`.strip
92
+ end
88
93
 
89
- def test_generate_uses_no_header_when_not_set
90
- prepare_for_generate
91
- Less::More.header = false
92
- Less::More.generate_all
93
- css = File.read(File.join(css_path, 'test.css'))
94
- assert_match /^\.allforms/, css
94
+ should "not parse css" do
95
+ write_less 'test.css', 'a{color:red}'
96
+ Less::More.generate_all
97
+ assert_equal 'a{color:red}', read_css('test.css')
98
+ end
99
+
100
+ should "add disclaimer-header when active" do
101
+ write_less 'test.less', 'a{color:red}'
102
+ Less::More.header = true
103
+ Less::More.generate_all
104
+ assert_match /^\/\*/, read_css('test.css')
105
+ end
106
+
107
+ should "not include header when not set" do
108
+ write_less 'test.less', 'a{color:red}'
109
+ Less::More.header = false
110
+ Less::More.generate_all
111
+ assert_not_include '/*', read_css('test.css')
112
+ end
113
+
114
+ should "fail with current file when encountering an error" do
115
+ write_less 'test.less', 'import xxxx;;;;;'
116
+ content = begin
117
+ Less::More.generate_all
118
+ '!no exception!'
119
+ rescue Exception => e
120
+ e.message
121
+ end
122
+ assert_include '/test.less', content
123
+ end
124
+
125
+ context 'mtime' do
126
+ should "generate for outdated less files" do
127
+ write_less 'test.less', "a{color:red}"
128
+ Less::More.generate_all
129
+
130
+ write_css 'test.css', 'im updated!'
131
+ sleep 1 # or mtime will be still the same ...
132
+ write_less 'test.less', "a{color:blue}"
133
+ Less::More.generate_all
134
+
135
+ assert_equal 'a { color: blue; }', read_css('test.css').strip
136
+ end
137
+
138
+ should "not generate for up-to-date less files" do
139
+ write_less 'test.less', "a{color:red}"
140
+ Less::More.generate_all
141
+
142
+ write_css 'test.css', 'im updated!'
143
+ Less::More.generate_all
144
+
145
+ assert_equal 'im updated!', read_css('test.css')
146
+ end
147
+
148
+ should "not generate for files with up-to-date partials" do
149
+ write_less 'test.less', "@import 'xxx/_test.less';"
150
+ write_less 'xxx/_test.less', "a{color:red}"
151
+ Less::More.generate_all
152
+
153
+ write_css 'test.css', 'im updated!'
154
+ Less::More.generate_all
155
+
156
+ assert_equal 'im updated!', read_css('test.css')
157
+ end
158
+
159
+ should "generate for files with outdated partials" do
160
+ write_less 'test.less', "@import 'xxx/_test.less';"
161
+ write_less 'xxx/_test.less', "a{color:red}"
162
+ Less::More.generate_all
163
+
164
+ write_css 'test.css', 'im updated!'
165
+ sleep 1 # or mtime will be still the same ...
166
+ write_less 'xxx/_test.less', "a{color:blue}"
167
+ Less::More.generate_all
168
+
169
+ assert_equal 'a { color: blue; }', read_css('test.css').strip
170
+ end
171
+
172
+ should "generate for files with outdated partials that are not named .less" do
173
+ write_less 'test.less', "@import 'xxx/_test';"
174
+ write_less 'xxx/_test.less', "a{color:red}"
175
+ Less::More.generate_all
176
+
177
+ write_css 'test.css', 'im updated!'
178
+ sleep 1 # or mtime will be still the same ...
179
+ write_less 'xxx/_test.less', "a{color:blue}"
180
+ Less::More.generate_all
181
+
182
+ assert_equal 'a { color: blue; }', read_css('test.css').strip
183
+ end
184
+ end
95
185
  end
96
186
 
97
- def test_generate_does_not_generate_partials
98
- prepare_for_generate
99
- Less::More.generate_all
100
- assert !File.exist?(File.join(css_path, '_global.css'))
187
+ context :remove_all_generated do
188
+ setup do
189
+ setup_for_generate_test
190
+ end
191
+
192
+ teardown do
193
+ teardown_for_generate_test
194
+ end
195
+
196
+ should "remove all generated css" do
197
+ write_less 'xxx.less', 'a{color:red}'
198
+ write_less 'yyy.css', 'a{color:red}'
199
+ write_less 'xxx/yyy.css', 'a{color:red}'
200
+ Less::More.generate_all
201
+ Less::More.remove_all_generated
202
+ # should be '' ideally, but an empty folder is no thread :)
203
+ assert_equal 'xxx', `ls #{css_path}`.strip
204
+ end
205
+
206
+ should "not remove other files" do
207
+ write_css 'xxx.css', 'a{color:red}'
208
+ Less::More.generate_all
209
+ Less::More.remove_all_generated
210
+ assert_equal 'xxx.css', `ls #{css_path}`.strip
211
+ end
101
212
  end
102
213
  end
@@ -1,14 +1,79 @@
1
- require 'test/unit'
2
-
1
+ # fake Rails with loaded plugin
3
2
  require 'rubygems'
4
3
  require 'active_support'
4
+ require 'action_pack'
5
+ require 'action_controller'
5
6
 
6
- class Rails
7
+ module Rails
7
8
  def self.root
8
9
  File.expand_path(File.dirname(__FILE__))
9
10
  end
11
+
12
+ def self.backtrace_cleaner
13
+ ActiveSupport::BacktraceCleaner.new
14
+ end
10
15
  end
11
16
 
17
+ RAILS_ENV = 'development'
18
+
19
+ # load plugin
12
20
  $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
21
+ require 'less/more'
22
+ load 'init.rb'
23
+
24
+ # load testing libs
25
+ require 'test/unit'
26
+ require 'active_support/test_case'
27
+ begin; require 'redgreen'; rescue LoadError; end
28
+ require 'shoulda'
29
+
30
+ # setup controller testing
31
+ require 'action_controller/test_process'
32
+ ActionController::Base.logger = nil
33
+ ActionController::Routing::Routes.reload rescue nil
34
+
35
+ # test helpers
36
+ def css_path
37
+ "#{Rails.root}/public/css"
38
+ end
39
+
40
+ def less_path
41
+ "#{Rails.root}/less_files"
42
+ end
43
+
44
+ def write_less file, content
45
+ write_content File.join(less_path, file), content
46
+ end
47
+
48
+ def write_css file, content
49
+ write_content File.join(css_path, file), content
50
+ end
51
+
52
+ def write_content file, content
53
+ `mkdir -p #{File.dirname(file)}`
54
+ File.open(file,'w'){|f| f.print content }
55
+ end
56
+
57
+ def read_css(file)
58
+ File.read(File.join(css_path, file)) rescue nil
59
+ end
60
+
61
+ def assert_include(item, obj)
62
+ assert_block("#{obj.inspect}\ndoes not include\n#{item.inspect}."){ obj.include? item }
63
+ end
64
+
65
+ def assert_not_include(item, obj)
66
+ assert_block("#{obj.inspect}\ndoes include\n#{item.inspect}."){ !obj.include? item }
67
+ end
68
+
69
+ def setup_for_generate_test
70
+ Less::More.source_path = 'less_files'
71
+ Less::More.destination_path = 'css'
72
+ Less::More.header = false
73
+ `mkdir -p #{css_path}`
74
+ end
13
75
 
14
- require 'less/more'
76
+ def teardown_for_generate_test
77
+ `rm -rf #{css_path}`
78
+ `rm -rf #{less_path}`
79
+ end
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: more
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ hash: 25
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 1
10
+ version: 0.1.1
5
11
  platform: ruby
6
12
  authors:
7
13
  - August Lilleaas
@@ -10,19 +16,23 @@ autorequire:
10
16
  bindir: bin
11
17
  cert_chain: []
12
18
 
13
- date: 2010-02-13 00:00:00 +01:00
19
+ date: 2010-06-10 00:00:00 +02:00
14
20
  default_executable:
15
21
  dependencies:
16
22
  - !ruby/object:Gem::Dependency
17
23
  name: less
18
- type: :runtime
19
- version_requirement:
20
- version_requirements: !ruby/object:Gem::Requirement
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
21
27
  requirements:
22
28
  - - ">="
23
29
  - !ruby/object:Gem::Version
30
+ hash: 3
31
+ segments:
32
+ - 0
24
33
  version: "0"
25
- version:
34
+ type: :runtime
35
+ version_requirements: *id001
26
36
  description: " More is a plugin for Ruby on Rails applications. It automatically\n parses your applications .less files through LESS and outputs CSS files.\n"
27
37
  email:
28
38
  executables: []
@@ -36,11 +46,11 @@ files:
36
46
  - MIT-LICENSE
37
47
  - Rakefile
38
48
  - init.rb
39
- - lib/controller_extension.rb
40
49
  - rails/init.rb
41
50
  - tasks/more_tasks.rake
42
- - test/more_test.rb
43
51
  - test/test_helper.rb
52
+ - test/controller_test.rb
53
+ - test/more_test.rb
44
54
  has_rdoc: true
45
55
  homepage: http://github.com/cloudhead/more
46
56
  licenses: []
@@ -51,21 +61,27 @@ rdoc_options: []
51
61
  require_paths:
52
62
  - lib
53
63
  required_ruby_version: !ruby/object:Gem::Requirement
64
+ none: false
54
65
  requirements:
55
66
  - - ">="
56
67
  - !ruby/object:Gem::Version
68
+ hash: 3
69
+ segments:
70
+ - 0
57
71
  version: "0"
58
- version:
59
72
  required_rubygems_version: !ruby/object:Gem::Requirement
73
+ none: false
60
74
  requirements:
61
75
  - - ">="
62
76
  - !ruby/object:Gem::Version
77
+ hash: 3
78
+ segments:
79
+ - 0
63
80
  version: "0"
64
- version:
65
81
  requirements: []
66
82
 
67
83
  rubyforge_project:
68
- rubygems_version: 1.3.5
84
+ rubygems_version: 1.3.7
69
85
  signing_key:
70
86
  specification_version: 3
71
87
  summary: LESS on Rails
@@ -1,8 +0,0 @@
1
- class ActionController::Base
2
- def process_with_less(*args)
3
- Less::More.generate_all
4
- process_without_less(*args)
5
- end
6
-
7
- alias_method_chain :process, :less
8
- end