sassc-rails 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 607d6ebf5f495a80e3d4cada4f6ee28939db8221
4
- data.tar.gz: 846873d730c106fd751f70fe94db8adff1864465
3
+ metadata.gz: 078582cf7ffcfded8c2ad89c4b79eb42edd7d36f
4
+ data.tar.gz: 73a3aa78f26ff4458327c91f8cfd26344c9969d6
5
5
  SHA512:
6
- metadata.gz: 9d7bcd45f41f36c9cbbce561dba0746ac67ae3f233a86c6ff3165f665f4e0fa47bca4198302313a4fb6acb6e2a156bfbddd4efbaaa89e8c765388165244e7fcf
7
- data.tar.gz: 2f6b7d28784bd732876b831d75959b285968b4b26b585e8edc55e5ceefdcb7c5551fbebd8b0ff34a75a1b9518dcafeb5855a3d9f31d01b128a6498b43aef469f
6
+ metadata.gz: 898c33b217fadacde7a691e9eeb863af815f41babd9e384db38096a4043d312fff175dc2b1b1b22df882edf18905a9f4676b7d64e56c56218cc52e82b23bf2f7
7
+ data.tar.gz: 1548c14632589db9b8124806e46b25e4882d624f40589446ddb4923b39015051b5b6b2193e392e3dd7648c851dd5ef7a8c193faa1fac4b92a590c48f3f2672ee
@@ -10,7 +10,7 @@ module SassC
10
10
  @postfix = postfix
11
11
  end
12
12
 
13
- def import_for(original_path, parent_path, full_path, options)
13
+ def import_for(full_path, parent_dir, options)
14
14
  SassC::Importer::Import.new(full_path)
15
15
  end
16
16
  end
@@ -20,7 +20,7 @@ module SassC
20
20
  ".css"
21
21
  end
22
22
 
23
- def import_for(original_path, parent_path, full_path, options)
23
+ def import_for(full_path, parent_dir, options)
24
24
  import_path = full_path.gsub(/\.css$/,"")
25
25
  SassC::Importer::Import.new(import_path)
26
26
  end
@@ -31,7 +31,7 @@ module SassC
31
31
  ".css.scss"
32
32
  end
33
33
 
34
- def import_for(original_path, parent_path, full_path, options)
34
+ def import_for(full_path, parent_dir, options)
35
35
  source = File.open(full_path, 'rb') { |f| f.read }
36
36
  SassC::Importer::Import.new(full_path, source: source)
37
37
  end
@@ -42,7 +42,7 @@ module SassC
42
42
  ".css.sass"
43
43
  end
44
44
 
45
- def import_for(original_path, parent_path, full_path, options)
45
+ def import_for(full_path, parent_dir, options)
46
46
  sass = File.open(full_path, 'rb') { |f| f.read }
47
47
  parsed_scss = SassC::Sass2Scss.convert(sass)
48
48
  SassC::Importer::Import.new(full_path, source: parsed_scss)
@@ -54,7 +54,7 @@ module SassC
54
54
  ".sass.erb"
55
55
  end
56
56
 
57
- def import_for(original_path, parent_path, full_path, options)
57
+ def import_for(full_path, parent_dir, options)
58
58
  template = Tilt::ERBTemplate.new(full_path)
59
59
  parsed_erb = template.render(options[:sprockets][:context], {})
60
60
  parsed_scss = SassC::Sass2Scss.convert(parsed_erb)
@@ -63,7 +63,7 @@ module SassC
63
63
  end
64
64
 
65
65
  class ERBExtension < Extension
66
- def import_for(original_path, parent_path, full_path, options)
66
+ def import_for(full_path, parent_dir, options)
67
67
  template = Tilt::ERBTemplate.new(full_path)
68
68
  parsed_erb = template.render(options[:sprockets][:context], {})
69
69
  SassC::Importer::Import.new(full_path, source: parsed_erb)
@@ -71,22 +71,29 @@ module SassC
71
71
  end
72
72
 
73
73
  EXTENSIONS = [
74
+ CssScssExtension.new,
75
+ CssSassExtension.new,
74
76
  Extension.new(".scss"),
75
77
  Extension.new(".sass"),
76
78
  CSSExtension.new,
77
79
  ERBExtension.new(".scss.erb"),
78
80
  ERBExtension.new(".css.erb"),
79
- SassERBExtension.new,
80
- CssScssExtension.new,
81
- CssSassExtension.new
81
+ SassERBExtension.new
82
82
  ]
83
83
 
84
84
  PREFIXS = [ "", "_" ]
85
+ GLOB = /(\A|\/)(\*|\*\*\/\*)\z/
85
86
 
86
87
  def imports(path, parent_path)
87
88
  parent_dir, _ = File.split(parent_path)
88
89
  specified_dir, specified_file = File.split(path)
89
90
 
91
+ if m = path.match(GLOB)
92
+ path = path.sub(m[0], "")
93
+ base = File.expand_path(path, File.dirname(parent_path))
94
+ return glob_imports(base, m[2], parent_path)
95
+ end
96
+
90
97
  search_paths = ([parent_dir] + load_paths).uniq
91
98
 
92
99
  if specified_dir != "."
@@ -103,17 +110,24 @@ module SassC
103
110
  try_path = File.join(search_path, file_name + extension.postfix)
104
111
  if File.exists?(try_path)
105
112
  record_import_as_dependency try_path
106
- return extension.import_for(path, parent_path, try_path, options)
113
+ return extension.import_for(try_path, parent_dir, options)
107
114
  end
108
115
  end
109
116
  end
110
117
  end
111
118
 
112
- Import.new(path)
119
+ # TODO: Raise an error from SassC here
120
+ raise ArgumentError.new("file not found: #{path}")
113
121
  end
114
122
 
115
123
  private
116
124
 
125
+ def extension_for_file(file)
126
+ EXTENSIONS.detect do |extension|
127
+ file.include? extension.postfix
128
+ end
129
+ end
130
+
117
131
  def record_import_as_dependency(path)
118
132
  context.depend_on path
119
133
  end
@@ -125,6 +139,39 @@ module SassC
125
139
  def load_paths
126
140
  options[:load_paths]
127
141
  end
142
+
143
+ def glob_imports(base, glob, current_file)
144
+ files = globbed_files(base, glob)
145
+ files = files.reject { |f| f == current_file }
146
+
147
+ files.map do |filename|
148
+ record_import_as_dependency(filename)
149
+ extension = extension_for_file(filename)
150
+ extension.import_for(filename, base, options)
151
+ end
152
+ end
153
+
154
+ def globbed_files(base, glob)
155
+ # TODO: Raise an error from SassC here
156
+ raise ArgumentError unless glob == "*" || glob == "**/*"
157
+
158
+ extensions = EXTENSIONS.map(&:postfix)
159
+ exts = extensions.map { |ext| Regexp.escape("#{ext}") }.join("|")
160
+ sass_re = Regexp.compile("(#{exts})$")
161
+
162
+ record_import_as_dependency(base)
163
+
164
+ files = Dir["#{base}/#{glob}"].sort.map do |path|
165
+ if File.directory?(path)
166
+ record_import_as_dependency(path)
167
+ nil
168
+ elsif sass_re =~ path
169
+ path
170
+ end
171
+ end
172
+
173
+ files.compact
174
+ end
128
175
  end
129
176
  end
130
177
  end
@@ -1,5 +1,5 @@
1
1
  module SassC
2
2
  module Rails
3
- VERSION = "0.0.6"
3
+ VERSION = "0.0.7"
4
4
  end
5
5
  end
data/sassc-rails.gemspec CHANGED
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
26
26
  # unfortunately we require sass for now, so that we can
27
27
  # reuse portions of the sprockets template
28
28
  spec.add_dependency 'sass'
29
- spec.add_dependency "sassc", "1.1.1"
29
+ spec.add_dependency "sassc", "~> 1.1.2"
30
30
 
31
31
  spec.add_dependency "tilt"
32
32
 
@@ -0,0 +1 @@
1
+ @import "globbed/**/*";
@@ -1,7 +1,7 @@
1
1
  @import "partials/css_sass_import";
2
2
  @import "partials/sass_import";
3
3
  @import "partials/scss_import";
4
- // //@import "globbed/**/*";
4
+ @import "globbed/**/*";
5
5
  @import "subfolder/plain";
6
6
  @import "subfolder/second_level";
7
7
  @import "partials/without_css_ext";
@@ -133,9 +133,8 @@ class SassRailsTest < MiniTest::Unit::TestCase
133
133
 
134
134
  assert_match /default-old-css/, css_output
135
135
 
136
- # skip for now
137
- # assert_match /globbed/, css_output
138
- # assert_match /nested-glob/, css_output
136
+ assert_match /globbed/, css_output
137
+ assert_match /nested-glob/, css_output
139
138
  end
140
139
 
141
140
  def test_style_config_item_is_defaulted_to_expanded_in_development_mode
@@ -198,41 +197,50 @@ class SassRailsTest < MiniTest::Unit::TestCase
198
197
  # assert_match /\.import-css-application/, css_output
199
198
  #end
200
199
 
201
- #test 'globbed imports work when new file is added' do
202
- # skip
200
+ def test_globbed_imports_work_when_globbed_file_is_changed
201
+ skip "This seems to work in practice, possible test setup problem"
203
202
 
204
- # project = 'scss_project'
205
- # filename = 'application.scss'
203
+ begin
204
+ initialize!
206
205
 
207
- # within_rails_app(project) do |tmpdir|
208
- # asset_output(filename)
206
+ new_file = File.join(File.dirname(__FILE__), 'dummy', 'app', 'assets', 'stylesheets', 'globbed', 'new_glob.scss')
209
207
 
210
- # new_file = File.join(tmpdir, 'app', 'assets', 'stylesheets', 'globbed', 'new.scss')
211
- # File.open(new_file, 'w') do |file|
212
- # file.puts '.new-file-test { color: #000; }'
213
- # end
208
+ File.open(new_file, 'w') do |file|
209
+ file.puts '.new-file-test { color: #000; }'
210
+ end
214
211
 
215
- # css_output = asset_output(filename)
216
- # assert_match /new-file-test/, css_output
217
- # end
218
- #end
212
+ css_output = render_asset("glob_test.scss")
213
+ assert_match /new-file-test/, css_output
219
214
 
220
- #test 'globbed imports work when globbed file is changed' do
221
- # skip
215
+ File.open(new_file, 'w') do |file|
216
+ file.puts '.changed-file-test { color: #000; }'
217
+ end
222
218
 
223
- # project = 'scss_project'
224
- # filename = 'application.scss'
219
+ new_css_output = render_asset("glob_test.scss")
220
+ assert_match /changed-file-test/, new_css_output
221
+ refute_equal css_output, new_css_output
222
+ ensure
223
+ File.delete(new_file)
224
+ end
225
+ end
225
226
 
226
- # within_rails_app(project) do |tmpdir|
227
- # asset_output(filename)
227
+ def test_globbed_imports_work_when_globbed_file_is_added
228
+ begin
229
+ initialize!
228
230
 
229
- # new_file = File.join(tmpdir, 'app', 'assets', 'stylesheets', 'globbed', 'globbed.scss')
230
- # File.open(new_file, 'w') do |file|
231
- # file.puts '.changed-file-test { color: #000; }'
232
- # end
231
+ css_output = render_asset("glob_test.scss")
232
+ refute_match /changed-file-test/, css_output
233
+ new_file = File.join(File.dirname(__FILE__), 'dummy', 'app', 'assets', 'stylesheets', 'globbed', 'new_glob.scss')
233
234
 
234
- # css_output = asset_output(filename)
235
- # assert_match /changed-file-test/, css_output
236
- # end
237
- #end
235
+ File.open(new_file, 'w') do |file|
236
+ file.puts '.changed-file-test { color: #000; }'
237
+ end
238
+
239
+ new_css_output = render_asset("glob_test.scss")
240
+ assert_match /changed-file-test/, new_css_output
241
+ refute_equal css_output, new_css_output
242
+ ensure
243
+ File.delete(new_file)
244
+ end
245
+ end
238
246
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sassc-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Boland
@@ -84,16 +84,16 @@ dependencies:
84
84
  name: sassc
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '='
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 1.1.1
89
+ version: 1.1.2
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '='
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 1.1.1
96
+ version: 1.1.2
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: tilt
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -176,6 +176,7 @@ files:
176
176
  - test/dummy/app/assets/stylesheets/css_scss_erb_handler.scss.erb
177
177
  - test/dummy/app/assets/stylesheets/css_scss_handler.css.scss
178
178
  - test/dummy/app/assets/stylesheets/erb_render_with_context.css.erb
179
+ - test/dummy/app/assets/stylesheets/glob_test.scss
179
180
  - test/dummy/app/assets/stylesheets/globbed/globbed.scss
180
181
  - test/dummy/app/assets/stylesheets/globbed/nested/nested_glob.scss
181
182
  - test/dummy/app/assets/stylesheets/helpers_test.scss
@@ -447,6 +448,7 @@ test_files:
447
448
  - test/dummy/app/assets/stylesheets/css_scss_erb_handler.scss.erb
448
449
  - test/dummy/app/assets/stylesheets/css_scss_handler.css.scss
449
450
  - test/dummy/app/assets/stylesheets/erb_render_with_context.css.erb
451
+ - test/dummy/app/assets/stylesheets/glob_test.scss
450
452
  - test/dummy/app/assets/stylesheets/globbed/globbed.scss
451
453
  - test/dummy/app/assets/stylesheets/globbed/nested/nested_glob.scss
452
454
  - test/dummy/app/assets/stylesheets/helpers_test.scss