slim-embedded-minify 0.1.3 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 96adb71b1316030a44d192230add79fa7092107bacecaed687648fc6dfedd522
4
- data.tar.gz: b7365dc0225d9fce7e87f12ac9654c3591b91c2103bae188953a4733e94369fd
3
+ metadata.gz: 697b542e806ec204502d7380a4a58a6ff124e35b4a122a1f91dcabb49443f10e
4
+ data.tar.gz: dc79454cac050709c4cac6f9d2d8471e856d2601b4d7b6ad5c74478b72a91155
5
5
  SHA512:
6
- metadata.gz: ad928fa19f709f194af85f2120c74e765c159878b84fa65dbafab046c8a092612b800116443d945d4ce5d04da64f414eab16abf1d335b69401619911cf30996a
7
- data.tar.gz: b5e861e8fe734aaecf229d4914eb51d7bfb9a3b7be8c91a3aca23186bd46ef1a3e644d06a6bc03e98571bd357013b5173ca8027b548f8798972ba457f1ab9c68
6
+ metadata.gz: 332eb59aa954df089d98101630fd6b7bfb0dee70b752e5f422adde76eac4f8ea18027cbc415bedb5c3375232566390f39f9065d7d78cb8bba6c6fbb81eca1b7e
7
+ data.tar.gz: 826969cc768ed7d071fbb87fb273acc76454100d72182a423310e59f6ed8a1e6858f0e96f0344da64cc001d4f4cc334d45e3ca17811e4d1987f32e8733fc7f55
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  ## Unreleased
2
2
 
3
+ ## 0.2.1 - 2023-07-18
4
+
5
+ - Refactor code.
6
+
7
+ ## 0.2.0 - 2023-07-13
8
+
9
+ - Add support for css minify.
10
+
11
+ ## 0.1.3 - 2023-07-12
12
+
3
13
  - Fix to disregard comments if enclosed in quotation marks.
4
14
  - Fix deletion of lines when a line is not just a comment.
5
15
 
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # SlimEmbeddedMinify
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/slim-embedded-minify.svg)](https://badge.fury.io/rb/slim-embedded-minify)
4
+
3
5
  A slim file to minify embedded code.
4
6
 
5
7
  ## Installation
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Slim
4
+ class Embedded < Filter
5
+ module Minify
6
+ module Javascript
7
+ include Tag
8
+
9
+ def on_slim_embedded(engine, body, attrs)
10
+ minified_body = minify(body)
11
+ super(engine, minified_body, attrs)
12
+ end
13
+
14
+ private
15
+
16
+ def remove_comments!(line)
17
+ line.last.gsub!(/((?<!['"])\/\*[^*\/]*\*\/?(?<!['"]))/, '')
18
+ line.last.gsub!(/((?<!['"])\/\/.*[^'"]+)/, '')
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Slim
4
+ class Embedded < Filter
5
+ module Minify
6
+ module Tag
7
+ def on_slim_embedded(engine, body, attrs)
8
+ body = minify(body) if engine == :css
9
+ super(engine, body, attrs)
10
+ end
11
+
12
+ private
13
+
14
+ def minify(body)
15
+ multiline_comment = false
16
+ body.map do |line|
17
+ if line.instance_of?(Array) && line.first == :slim
18
+ remove_comments!(line)
19
+ remove_whitespace!(line)
20
+
21
+ stripped_quotes = stripped_quotes(line)
22
+ if stripped_quotes.match?(%r{/\*})
23
+ multiline_comment = true
24
+ next
25
+ elsif multiline_comment
26
+ multiline_comment = false if stripped_quotes.match?(%r{\*/})
27
+ next
28
+ end
29
+ line
30
+ else
31
+ line
32
+ end
33
+ end.compact
34
+ end
35
+
36
+ def remove_comments!(line)
37
+ line.last.gsub!(/((?<!['"])\/\*[^*\/]*\*\/?(?<!['"]))/, '')
38
+ end
39
+
40
+ def remove_whitespace!(line)
41
+ if line.last.gsub(/\n/, '').match?(/^\s*$/)
42
+ line.last.gsub!(/^\s*$/, '')
43
+ end
44
+ end
45
+
46
+ def stripped_quotes(line)
47
+ line.last.gsub(/(['"]).*?\1/, '')
48
+ end
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.1"
5
5
  end
@@ -3,4 +3,18 @@
3
3
  require "slim"
4
4
 
5
5
  require_relative "minify/version"
6
- require_relative "minify/java_script_engine"
6
+
7
+ require_relative "minify/tag"
8
+ require_relative "minify/javascript"
9
+
10
+ module Slim
11
+ class Embedded < Filter
12
+ class TagEngine < Engine
13
+ prepend Minify::Tag
14
+ end
15
+
16
+ class JavaScriptEngine < TagEngine
17
+ prepend Minify::Javascript
18
+ end
19
+ end
20
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
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.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yudai Takada
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-07-13 00:00:00.000000000 Z
11
+ date: 2023-07-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: slim
@@ -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
- - lib/slim/embedded/minify/java_script_engine.rb
41
+ - lib/slim/embedded/minify/javascript.rb
42
+ - lib/slim/embedded/minify/tag.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
@@ -1,53 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Slim
4
- class Embedded < Filter
5
- class JavaScriptEngine < TagEngine
6
- alias original_on_slim_embedded on_slim_embedded
7
-
8
- def on_slim_embedded(engine, body, attrs)
9
- minified_body = minify(body)
10
- super(engine, [:html, :js, minified_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
- line.last.gsub!(/((?<!['"])\/\/.*[^'"]+)/, '')
40
- 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
- end
52
- end
53
- end