slim-embedded-minify 0.1.2 → 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: f110250b84230ebf229b53f681aa383c067f1a852753c9de17d4bb301463b3b9
4
- data.tar.gz: b07d7704ba9620c86177528c075c5bdc41e568e8173d83afa11ac5b8236cc654
3
+ metadata.gz: ff321da624a61d8215c09916aa017f32c2ba58c23ef5a95ab43779a92662d9e8
4
+ data.tar.gz: df8297c4a0af39b8b6529ad909e4fbfde7ffff1938704f27c6b16cb302c1cd4e
5
5
  SHA512:
6
- metadata.gz: f7f7587f90c3c6f317db08d7e844eb151cf14921acf4570be397c048e0d3311b5ec31fa9433d5a7f4dc408d166e38274e81fbcca683fa8f812465e0f77b9d38a
7
- data.tar.gz: 611fc8e5cdc302c03a563ed17d2812752ef7dbe622fd32a5dcb95fbd17e07d6b86075dd746473d92c6036d8adf353eccf2a895fd85470faa5e0fab3c711bbfe6
6
+ metadata.gz: 8a5fcc44e03800cc7c29835c0abe1f0b7649e5162b94f117c2893d3b87c1de89acf0a99ce1514d9b691cf6b8da92d1ac53c49540eb6919f025bf98a38f10b021
7
+ data.tar.gz: 4b678a3bf1f78606222b31319a6c64c204ba631b4c839f265ce45183a6237529e7b65d2cecb8b66b09e956bc0ca338498d52a30e3aa7f1b9c740839ada082a6f
data/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
- ## [Unreleased]
1
+ ## Unreleased
2
2
 
3
- ## [0.1.0] - 2023-07-11
3
+ ## 0.2.0 - 2023-07-13
4
4
 
5
- - Initial release
5
+ - Add support for css minify.
6
+
7
+ ## 0.1.3 - 2023-07-12
8
+
9
+ - Fix to disregard comments if enclosed in quotation marks.
10
+ - Fix deletion of lines when a line is not just a comment.
11
+
12
+ ## 0.1.2 - 2023-07-11
13
+
14
+ - Fix to remove comments after the second line.
15
+
16
+ ## 0.1.1 - 2023-07-11
17
+
18
+ - Fix bundle install error.
19
+ - Fix dependency error.
20
+
21
+ ## 0.1.0 - 2023-07-11
22
+
23
+ - Initial release.
data/Gemfile CHANGED
@@ -7,4 +7,3 @@ gemspec
7
7
 
8
8
  gem "minitest", "~> 5.15"
9
9
  gem "rake", "~> 13.0"
10
- gem "rubocop", "~> 1.21"
data/README.md CHANGED
@@ -1,34 +1,24 @@
1
- # Slim::Embedded::Minify
1
+ # SlimEmbeddedMinify
2
2
 
3
- TODO: Delete this and the text below, and describe your gem
4
-
5
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/slim/embedded/minify`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ A slim file to minify embedded code.
6
4
 
7
5
  ## Installation
8
6
 
9
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
-
11
- Install the gem and add to the application's Gemfile by executing:
12
-
13
- $ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
14
-
15
- If bundler is not being used to manage dependencies, install the gem by executing:
16
-
17
- $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
18
-
19
- ## Usage
20
-
21
- TODO: Write usage instructions here
7
+ Just install the slim-embedded-minify gem
22
8
 
23
- ## Development
9
+ ```
10
+ gem install slim-embedded-minify
11
+ ```
24
12
 
25
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
13
+ or if you use bundler put this in your `Gemfile`
26
14
 
27
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
15
+ ```
16
+ gem 'slim-embedded-minify'
17
+ ```
28
18
 
29
19
  ## Contributing
30
20
 
31
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/slim-embedded-minify. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/slim-embedded-minify/blob/main/CODE_OF_CONDUCT.md).
21
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ydah/slim-embedded-minify. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/ydah/slim-embedded-minify/blob/main/CODE_OF_CONDUCT.md).
32
22
 
33
23
  ## License
34
24
 
@@ -36,4 +26,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
36
26
 
37
27
  ## Code of Conduct
38
28
 
39
- Everyone interacting in the Slim::Embedded::Minify project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/slim-embedded-minify/blob/main/CODE_OF_CONDUCT.md).
29
+ Everyone interacting in the Slim::Embedded::Minify project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/ydah/slim-embedded-minify/blob/main/CODE_OF_CONDUCT.md).
@@ -3,31 +3,18 @@
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.filter do |line|
18
- if line.instance_of?(Array) && line.first == :slim
19
- if line.last.match?(%r{\A/\*})
20
- multiline_comment = true
21
- next false
22
- elsif multiline_comment
23
- multiline_comment = false if line.last.match?(%r{\*/})
24
- next false
25
- end
26
- !line.last.match?(%r{//})
27
- else
28
- true
29
- end
30
- end
15
+ def remove_comments!(line)
16
+ line.last.gsub!(/((?<!['"])\/\*[^*\/]*\*\/?(?<!['"]))/, '')
17
+ line.last.gsub!(/((?<!['"])\/\/.*[^'"]+)/, '')
31
18
  end
32
19
  end
33
20
  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.2"
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"
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
  spec.summary = "A slim file to minify embedded code."
12
12
  spec.homepage = "https://github.com/ydah/slim-embedded-minify"
13
13
  spec.license = "MIT"
14
- spec.required_ruby_version = ">= 2.6.0"
14
+ spec.required_ruby_version = ">= 2.7.0"
15
15
 
16
16
  spec.metadata["homepage_uri"] = spec.homepage
17
17
  spec.metadata["source_code_uri"] = spec.homepage
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.2
4
+ version: 0.2.0
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-11 00:00:00.000000000 Z
11
+ date: 2023-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: slim
@@ -31,16 +31,15 @@ executables: []
31
31
  extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
- - ".rubocop.yml"
35
34
  - CHANGELOG.md
36
35
  - CODE_OF_CONDUCT.md
37
36
  - Gemfile
38
- - Gemfile.lock
39
37
  - LICENSE.txt
40
38
  - README.md
41
39
  - Rakefile
42
40
  - lib/slim/embedded/minify.rb
43
41
  - lib/slim/embedded/minify/java_script_engine.rb
42
+ - lib/slim/embedded/minify/tag_engine.rb
44
43
  - lib/slim/embedded/minify/version.rb
45
44
  - slim-embedded-minify.gemspec
46
45
  homepage: https://github.com/ydah/slim-embedded-minify
@@ -58,7 +57,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
58
57
  requirements:
59
58
  - - ">="
60
59
  - !ruby/object:Gem::Version
61
- version: 2.6.0
60
+ version: 2.7.0
62
61
  required_rubygems_version: !ruby/object:Gem::Requirement
63
62
  requirements:
64
63
  - - ">="
data/.rubocop.yml DELETED
@@ -1,13 +0,0 @@
1
- AllCops:
2
- TargetRubyVersion: 2.6
3
-
4
- Style/StringLiterals:
5
- Enabled: true
6
- EnforcedStyle: double_quotes
7
-
8
- Style/StringLiteralsInInterpolation:
9
- Enabled: true
10
- EnforcedStyle: double_quotes
11
-
12
- Layout/LineLength:
13
- Max: 120
data/Gemfile.lock DELETED
@@ -1,54 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- slim-embedded-minify (0.1.1)
5
- slim (~> 5.1)
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- ast (2.4.2)
11
- json (2.6.3)
12
- language_server-protocol (3.17.0.3)
13
- minitest (5.18.1)
14
- parallel (1.23.0)
15
- parser (3.2.2.3)
16
- ast (~> 2.4.1)
17
- racc
18
- racc (1.7.1)
19
- rainbow (3.1.1)
20
- rake (13.0.6)
21
- regexp_parser (2.8.1)
22
- rexml (3.2.5)
23
- rubocop (1.54.1)
24
- json (~> 2.3)
25
- language_server-protocol (>= 3.17.0)
26
- parallel (~> 1.10)
27
- parser (>= 3.2.2.3)
28
- rainbow (>= 2.2.2, < 4.0)
29
- regexp_parser (>= 1.8, < 3.0)
30
- rexml (>= 3.2.5, < 4.0)
31
- rubocop-ast (>= 1.28.0, < 2.0)
32
- ruby-progressbar (~> 1.7)
33
- unicode-display_width (>= 2.4.0, < 3.0)
34
- rubocop-ast (1.29.0)
35
- parser (>= 3.2.1.0)
36
- ruby-progressbar (1.13.0)
37
- slim (5.1.1)
38
- temple (~> 0.10.0)
39
- tilt (>= 2.1.0)
40
- temple (0.10.2)
41
- tilt (2.2.0)
42
- unicode-display_width (2.4.2)
43
-
44
- PLATFORMS
45
- x86_64-darwin-21
46
-
47
- DEPENDENCIES
48
- minitest (~> 5.15)
49
- rake (~> 13.0)
50
- rubocop (~> 1.21)
51
- slim-embedded-minify!
52
-
53
- BUNDLED WITH
54
- 2.4.13