condenser 1.2 → 1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/lib/condenser/asset.rb +19 -16
  3. data/lib/condenser/build_cache.rb +1 -1
  4. data/lib/condenser/context.rb +9 -25
  5. data/lib/condenser/helpers/parse_helpers.rb +1 -1
  6. data/lib/condenser/manifest.rb +3 -1
  7. data/lib/condenser/pipeline.rb +8 -3
  8. data/lib/condenser/processors/babel_processor.rb +1 -1
  9. data/lib/condenser/processors/css_media_combiner_processor.rb +81 -0
  10. data/lib/condenser/processors/js_analyzer.rb +0 -2
  11. data/lib/condenser/processors/purgecss_processor.rb +6 -4
  12. data/lib/condenser/processors/rollup_processor.rb +37 -35
  13. data/lib/condenser/resolve.rb +1 -3
  14. data/lib/condenser/templating_engine/ejs.rb +1 -1
  15. data/lib/condenser/transformers/dart_sass_transformer.rb +285 -0
  16. data/lib/condenser/transformers/jst_transformer.rb +67 -17
  17. data/lib/condenser/transformers/sass/functions.rb +133 -0
  18. data/lib/condenser/transformers/sass/importer.rb +48 -0
  19. data/lib/condenser/transformers/sass.rb +4 -0
  20. data/lib/condenser/transformers/sass_transformer.rb +124 -281
  21. data/lib/condenser/transformers/svg_transformer/base.rb +26 -0
  22. data/lib/condenser/transformers/svg_transformer/tag.rb +54 -0
  23. data/lib/condenser/transformers/svg_transformer/template.rb +151 -0
  24. data/lib/condenser/transformers/svg_transformer/template_error.rb +2 -0
  25. data/lib/condenser/transformers/svg_transformer/value.rb +13 -0
  26. data/lib/condenser/transformers/svg_transformer/var_generator.rb +10 -0
  27. data/lib/condenser/transformers/svg_transformer.rb +19 -0
  28. data/lib/condenser/version.rb +1 -1
  29. data/lib/condenser.rb +17 -5
  30. data/test/cache_test.rb +46 -2
  31. data/test/dependency_test.rb +2 -2
  32. data/test/manifest_test.rb +34 -0
  33. data/test/minifiers/terser_minifier_test.rb +0 -1
  34. data/test/minifiers/uglify_minifier_test.rb +0 -1
  35. data/test/postprocessors/css_media_combiner_test.rb +107 -0
  36. data/test/postprocessors/purgecss_test.rb +62 -0
  37. data/test/preprocessor/babel_test.rb +693 -299
  38. data/test/preprocessor/js_analyzer_test.rb +0 -2
  39. data/test/processors/rollup_test.rb +50 -20
  40. data/test/resolve_test.rb +8 -9
  41. data/test/server_test.rb +6 -1
  42. data/test/templates/ejs_test.rb +2 -11
  43. data/test/templates/erb_test.rb +0 -5
  44. data/test/test_helper.rb +3 -1
  45. data/test/transformers/dart_scss_test.rb +139 -0
  46. data/test/transformers/jst_test.rb +165 -21
  47. data/test/transformers/scss_test.rb +14 -0
  48. data/test/transformers/svg_test.rb +40 -0
  49. metadata +23 -6
  50. data/lib/condenser/transformers/sass_transformer/importer.rb +0 -50
@@ -0,0 +1,40 @@
1
+ require 'test_helper'
2
+
3
+ class SVGTransformerTest < ActiveSupport::TestCase
4
+
5
+ test 'svg transoformation' do
6
+ file 'test.svg', <<~SCSS
7
+ <?xml version="1.0" encoding="utf-8"?>
8
+ <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
9
+ <svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="612px" height="612px" viewBox="0 0 612 612" xml:space="preserve">
10
+ <path fill="#fff" d="M5.817,606.299c7.729,7.614,20.277,7.614,28.007,0L192.448,450.2c44.267,35.333,100.622,56.586,162.067,56.586c142.211,0,257.487-113.439,257.487-253.393C612.003,113.439,496.727,0,354.516,0S97.028,113.439,97.009,253.393c0,65.424,25.424,124.879,66.802,169.834L5.8,578.714C-1.929,586.328-1.929,598.686,5.817,606.299z"/>
11
+ </svg>
12
+ SCSS
13
+
14
+ assert_file 'test.js', 'application/javascript', <<~JS
15
+ export default function (svgAttributes) {
16
+ var __a = document.createElementNS("http://www.w3.org/2000/svg", "svg");
17
+ __a.setAttribute("version", "1.1");
18
+ __a.setAttribute("xmlns", "http://www.w3.org/2000/svg");
19
+ __a.setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
20
+ __a.setAttribute("width", "612px");
21
+ __a.setAttribute("height", "612px");
22
+ __a.setAttribute("viewBox", "0 0 612 612");
23
+ __a.setAttribute("xml:space", "preserve");
24
+ var __b = document.createElementNS("http://www.w3.org/2000/svg", "path");
25
+ __b.setAttribute("fill", "#fff");
26
+ __b.setAttribute("d", "M5.817,606.299c7.729,7.614,20.277,7.614,28.007,0L192.448,450.2c44.267,35.333,100.622,56.586,162.067,56.586c142.211,0,257.487-113.439,257.487-253.393C612.003,113.439,496.727,0,354.516,0S97.028,113.439,97.009,253.393c0,65.424,25.424,124.879,66.802,169.834L5.8,578.714C-1.929,586.328-1.929,598.686,5.817,606.299z");
27
+ __a.append(__b);
28
+
29
+ if (svgAttributes) {
30
+ Object.keys(svgAttributes).forEach(function (key) {
31
+ __a.setAttribute(key, svgAttributes[key]);
32
+ });
33
+ }
34
+
35
+ return __a;
36
+ }
37
+ JS
38
+ end
39
+
40
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: condenser
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.2'
4
+ version: '1.3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Bracy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-18 00:00:00.000000000 Z
11
+ date: 2023-12-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: erubi
@@ -238,14 +238,14 @@ dependencies:
238
238
  requirements:
239
239
  - - "~>"
240
240
  - !ruby/object:Gem::Version
241
- version: 0.0.7
241
+ version: 0.1.0
242
242
  type: :development
243
243
  prerelease: false
244
244
  version_requirements: !ruby/object:Gem::Requirement
245
245
  requirements:
246
246
  - - "~>"
247
247
  - !ruby/object:Gem::Version
248
- version: 0.0.7
248
+ version: 0.1.0
249
249
  description: Condenser is a Rack-based asset packaging system that concatenates and
250
250
  serves JavaScript, CSS, Sass, and SCSS.
251
251
  email:
@@ -324,6 +324,7 @@ files:
324
324
  - lib/condenser/minifiers/uglify_minifier.rb
325
325
  - lib/condenser/pipeline.rb
326
326
  - lib/condenser/processors/babel_processor.rb
327
+ - lib/condenser/processors/css_media_combiner_processor.rb
327
328
  - lib/condenser/processors/js_analyzer.rb
328
329
  - lib/condenser/processors/node_processor.rb
329
330
  - lib/condenser/processors/purgecss_processor.rb
@@ -332,9 +333,19 @@ files:
332
333
  - lib/condenser/server.rb
333
334
  - lib/condenser/templating_engine/ejs.rb
334
335
  - lib/condenser/templating_engine/erb.rb
336
+ - lib/condenser/transformers/dart_sass_transformer.rb
335
337
  - lib/condenser/transformers/jst_transformer.rb
338
+ - lib/condenser/transformers/sass.rb
339
+ - lib/condenser/transformers/sass/functions.rb
340
+ - lib/condenser/transformers/sass/importer.rb
336
341
  - lib/condenser/transformers/sass_transformer.rb
337
- - lib/condenser/transformers/sass_transformer/importer.rb
342
+ - lib/condenser/transformers/svg_transformer.rb
343
+ - lib/condenser/transformers/svg_transformer/base.rb
344
+ - lib/condenser/transformers/svg_transformer/tag.rb
345
+ - lib/condenser/transformers/svg_transformer/template.rb
346
+ - lib/condenser/transformers/svg_transformer/template_error.rb
347
+ - lib/condenser/transformers/svg_transformer/value.rb
348
+ - lib/condenser/transformers/svg_transformer/var_generator.rb
338
349
  - lib/condenser/utils.rb
339
350
  - lib/condenser/version.rb
340
351
  - lib/condenser/writers/brotli_writer.rb
@@ -350,6 +361,7 @@ files:
350
361
  - test/minifiers/terser_minifier_test.rb
351
362
  - test/minifiers/uglify_minifier_test.rb
352
363
  - test/pipeline_test.rb
364
+ - test/postprocessors/css_media_combiner_test.rb
353
365
  - test/postprocessors/purgecss_test.rb
354
366
  - test/preprocessor/babel_test.rb
355
367
  - test/preprocessor/js_analyzer_test.rb
@@ -359,8 +371,10 @@ files:
359
371
  - test/templates/ejs_test.rb
360
372
  - test/templates/erb_test.rb
361
373
  - test/test_helper.rb
374
+ - test/transformers/dart_scss_test.rb
362
375
  - test/transformers/jst_test.rb
363
376
  - test/transformers/scss_test.rb
377
+ - test/transformers/svg_test.rb
364
378
  - test/writers/brotli_writer_test.rb
365
379
  - test/writers/zlib_writer_test.rb
366
380
  homepage: https://github.com/malomalo/condenser
@@ -384,7 +398,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
384
398
  - !ruby/object:Gem::Version
385
399
  version: '0'
386
400
  requirements: []
387
- rubygems_version: 3.1.4
401
+ rubygems_version: 3.4.13
388
402
  signing_key:
389
403
  specification_version: 4
390
404
  summary: A Rack-based asset packaging system
@@ -398,6 +412,7 @@ test_files:
398
412
  - test/minifiers/terser_minifier_test.rb
399
413
  - test/minifiers/uglify_minifier_test.rb
400
414
  - test/pipeline_test.rb
415
+ - test/postprocessors/css_media_combiner_test.rb
401
416
  - test/postprocessors/purgecss_test.rb
402
417
  - test/preprocessor/babel_test.rb
403
418
  - test/preprocessor/js_analyzer_test.rb
@@ -407,7 +422,9 @@ test_files:
407
422
  - test/templates/ejs_test.rb
408
423
  - test/templates/erb_test.rb
409
424
  - test/test_helper.rb
425
+ - test/transformers/dart_scss_test.rb
410
426
  - test/transformers/jst_test.rb
411
427
  - test/transformers/scss_test.rb
428
+ - test/transformers/svg_test.rb
412
429
  - test/writers/brotli_writer_test.rb
413
430
  - test/writers/zlib_writer_test.rb
@@ -1,50 +0,0 @@
1
- require "sassc"
2
-
3
- class Condenser::SassTransformer
4
- class Importer < SassC::Importer
5
-
6
- def imports(name, base)
7
- name = expand_path(name, base)
8
- env = options[:condenser][:environment]
9
- accept = extensions.keys.map { |x| options[:condenser][:environment].extensions[x] }
10
-
11
- options[:asset][:process_dependencies] << [name, accept.map{ |i| [i] }]
12
-
13
- imports = []
14
- env.resolve(name, accept: accept).sort_by(&:filename).each do |asset|
15
- next if asset.filename == options[:filename]
16
- imports << Import.new(asset.filename, source: asset.source, source_map_path: nil)
17
- end
18
-
19
- if imports.empty? && env.npm_path
20
- package = File.join(env.npm_path, name, 'package.json')
21
- if File.exists?(package)
22
- package = JSON.parse(File.read(package))
23
- if package['style']
24
- imports << Import.new(name, source: File.read(File.join(env.npm_path, name, package['style'])), source_map_path: nil)
25
- end
26
- end
27
- end
28
-
29
- raise Condenser::FileNotFound, "couldn't find file '#{name}'" if imports.empty?
30
-
31
- imports
32
- end
33
-
34
- # Allow .css files to be @imported
35
- def extensions
36
- { '.sass' => :sass, '.scss' => :scss, '.css' => :scss }
37
- end
38
-
39
- private
40
-
41
- def expand_path(path, base=nil)
42
- if path.start_with?('.')
43
- File.expand_path(path, File.dirname(base)).delete_prefix(File.expand_path('.') + '/')
44
- else
45
- File.expand_path(path).delete_prefix(File.expand_path('.') + '/')
46
- end
47
- end
48
-
49
- end
50
- end