slim-embedded-minify 0.1.3 → 0.2.0

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
  SHA256:
3
- metadata.gz: 96adb71b1316030a44d192230add79fa7092107bacecaed687648fc6dfedd522
4
- data.tar.gz: b7365dc0225d9fce7e87f12ac9654c3591b91c2103bae188953a4733e94369fd
3
+ metadata.gz: ff321da624a61d8215c09916aa017f32c2ba58c23ef5a95ab43779a92662d9e8
4
+ data.tar.gz: df8297c4a0af39b8b6529ad909e4fbfde7ffff1938704f27c6b16cb302c1cd4e
5
5
  SHA512:
6
- metadata.gz: ad928fa19f709f194af85f2120c74e765c159878b84fa65dbafab046c8a092612b800116443d945d4ce5d04da64f414eab16abf1d335b69401619911cf30996a
7
- data.tar.gz: b5e861e8fe734aaecf229d4914eb51d7bfb9a3b7be8c91a3aca23186bd46ef1a3e644d06a6bc03e98571bd357013b5173ca8027b548f8798972ba457f1ab9c68
6
+ metadata.gz: 8a5fcc44e03800cc7c29835c0abe1f0b7649e5162b94f117c2893d3b87c1de89acf0a99ce1514d9b691cf6b8da92d1ac53c49540eb6919f025bf98a38f10b021
7
+ data.tar.gz: 4b678a3bf1f78606222b31319a6c64c204ba631b4c839f265ce45183a6237529e7b65d2cecb8b66b09e956bc0ca338498d52a30e3aa7f1b9c740839ada082a6f
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  ## Unreleased
2
2
 
3
+ ## 0.2.0 - 2023-07-13
4
+
5
+ - Add support for css minify.
6
+
7
+ ## 0.1.3 - 2023-07-12
8
+
3
9
  - Fix to disregard comments if enclosed in quotation marks.
4
10
  - Fix deletion of lines when a line is not just a comment.
5
11
 
@@ -3,51 +3,19 @@
3
3
  module Slim
4
4
  class Embedded < Filter
5
5
  class JavaScriptEngine < TagEngine
6
- alias original_on_slim_embedded on_slim_embedded
6
+ alias orig_js_on_slim_embedded on_slim_embedded
7
7
 
8
8
  def on_slim_embedded(engine, body, attrs)
9
9
  minified_body = minify(body)
10
- super(engine, [:html, :js, minified_body], attrs)
10
+ orig_js_on_slim_embedded(engine, minified_body, attrs)
11
11
  end
12
12
 
13
13
  private
14
14
 
15
- def minify(body)
16
- multiline_comment = false
17
- body.map do |line|
18
- if line.instance_of?(Array) && line.first == :slim
19
- remove_comments!(line)
20
- remove_whitespace!(line)
21
-
22
- stripped_quotes = stripped_quotes(line)
23
- if stripped_quotes.match?(%r{/\*})
24
- multiline_comment = true
25
- next
26
- elsif multiline_comment
27
- multiline_comment = false if stripped_quotes.match?(%r{\*/})
28
- next
29
- end
30
- line
31
- else
32
- line
33
- end
34
- end.compact
35
- end
36
-
37
15
  def remove_comments!(line)
38
16
  line.last.gsub!(/((?<!['"])\/\*[^*\/]*\*\/?(?<!['"]))/, '')
39
17
  line.last.gsub!(/((?<!['"])\/\/.*[^'"]+)/, '')
40
18
  end
41
-
42
- def remove_whitespace!(line)
43
- if line.last.gsub(/\n/, '').match?(/^\s*$/)
44
- line.last.gsub!(/^\s*$/, '')
45
- end
46
- end
47
-
48
- def stripped_quotes(line)
49
- line.last.gsub(/(['"]).*?\1/, '')
50
- end
51
19
  end
52
20
  end
53
21
  end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Slim
4
+ class Embedded < Filter
5
+ class TagEngine < Engine
6
+ alias orig_tag_on_slim_embedded on_slim_embedded
7
+
8
+ def on_slim_embedded(engine, body, attrs)
9
+ body = minify(body) if engine == :css
10
+ orig_tag_on_slim_embedded(engine, body, attrs)
11
+ end
12
+
13
+ private
14
+
15
+ def minify(body)
16
+ multiline_comment = false
17
+ body.map do |line|
18
+ if line.instance_of?(Array) && line.first == :slim
19
+ remove_comments!(line)
20
+ remove_whitespace!(line)
21
+
22
+ stripped_quotes = stripped_quotes(line)
23
+ if stripped_quotes.match?(%r{/\*})
24
+ multiline_comment = true
25
+ next
26
+ elsif multiline_comment
27
+ multiline_comment = false if stripped_quotes.match?(%r{\*/})
28
+ next
29
+ end
30
+ line
31
+ else
32
+ line
33
+ end
34
+ end.compact
35
+ end
36
+
37
+ def remove_comments!(line)
38
+ line.last.gsub!(/((?<!['"])\/\*[^*\/]*\*\/?(?<!['"]))/, '')
39
+ end
40
+
41
+ def remove_whitespace!(line)
42
+ if line.last.gsub(/\n/, '').match?(/^\s*$/)
43
+ line.last.gsub!(/^\s*$/, '')
44
+ end
45
+ end
46
+
47
+ def stripped_quotes(line)
48
+ line.last.gsub(/(['"]).*?\1/, '')
49
+ end
50
+ end
51
+ end
52
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SlimEmbeddedMinify
4
- VERSION = "0.1.3"
4
+ VERSION = "0.2.0"
5
5
  end
@@ -4,3 +4,4 @@ require "slim"
4
4
 
5
5
  require_relative "minify/version"
6
6
  require_relative "minify/java_script_engine"
7
+ require_relative "minify/tag_engine"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slim-embedded-minify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yudai Takada
@@ -34,12 +34,12 @@ files:
34
34
  - CHANGELOG.md
35
35
  - CODE_OF_CONDUCT.md
36
36
  - Gemfile
37
- - Gemfile.lock
38
37
  - LICENSE.txt
39
38
  - README.md
40
39
  - Rakefile
41
40
  - lib/slim/embedded/minify.rb
42
41
  - lib/slim/embedded/minify/java_script_engine.rb
42
+ - lib/slim/embedded/minify/tag_engine.rb
43
43
  - lib/slim/embedded/minify/version.rb
44
44
  - slim-embedded-minify.gemspec
45
45
  homepage: https://github.com/ydah/slim-embedded-minify
data/Gemfile.lock DELETED
@@ -1,29 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- slim-embedded-minify (0.1.2)
5
- slim (~> 5.1)
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- minitest (5.18.1)
11
- rake (13.0.6)
12
- slim (5.1.1)
13
- temple (~> 0.10.0)
14
- tilt (>= 2.1.0)
15
- temple (0.10.2)
16
- tilt (2.2.0)
17
-
18
- PLATFORMS
19
- universal-java-11
20
- x86_64-darwin-21
21
- x86_64-linux
22
-
23
- DEPENDENCIES
24
- minitest (~> 5.15)
25
- rake (~> 13.0)
26
- slim-embedded-minify!
27
-
28
- BUNDLED WITH
29
- 2.4.13