slim-embedded-minify 0.1.2 → 0.2.0
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 +4 -4
- data/CHANGELOG.md +21 -3
- data/Gemfile +0 -1
- data/README.md +12 -22
- data/lib/slim/embedded/minify/java_script_engine.rb +5 -18
- data/lib/slim/embedded/minify/tag_engine.rb +52 -0
- data/lib/slim/embedded/minify/version.rb +1 -1
- data/lib/slim/embedded/minify.rb +1 -0
- data/slim-embedded-minify.gemspec +1 -1
- metadata +4 -5
- data/.rubocop.yml +0 -13
- data/Gemfile.lock +0 -54
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff321da624a61d8215c09916aa017f32c2ba58c23ef5a95ab43779a92662d9e8
|
4
|
+
data.tar.gz: df8297c4a0af39b8b6529ad909e4fbfde7ffff1938704f27c6b16cb302c1cd4e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a5fcc44e03800cc7c29835c0abe1f0b7649e5162b94f117c2893d3b87c1de89acf0a99ce1514d9b691cf6b8da92d1ac53c49540eb6919f025bf98a38f10b021
|
7
|
+
data.tar.gz: 4b678a3bf1f78606222b31319a6c64c204ba631b4c839f265ce45183a6237529e7b65d2cecb8b66b09e956bc0ca338498d52a30e3aa7f1b9c740839ada082a6f
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,23 @@
|
|
1
|
-
##
|
1
|
+
## Unreleased
|
2
2
|
|
3
|
-
##
|
3
|
+
## 0.2.0 - 2023-07-13
|
4
4
|
|
5
|
-
-
|
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
data/README.md
CHANGED
@@ -1,34 +1,24 @@
|
|
1
|
-
#
|
1
|
+
# SlimEmbeddedMinify
|
2
2
|
|
3
|
-
|
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
|
-
|
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
|
-
|
9
|
+
```
|
10
|
+
gem install slim-embedded-minify
|
11
|
+
```
|
24
12
|
|
25
|
-
|
13
|
+
or if you use bundler put this in your `Gemfile`
|
26
14
|
|
27
|
-
|
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/
|
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/
|
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
|
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
|
-
|
10
|
+
orig_js_on_slim_embedded(engine, minified_body, attrs)
|
11
11
|
end
|
12
12
|
|
13
13
|
private
|
14
14
|
|
15
|
-
def
|
16
|
-
|
17
|
-
|
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
|
data/lib/slim/embedded/minify.rb
CHANGED
@@ -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.
|
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.
|
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
|
+
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.
|
60
|
+
version: 2.7.0
|
62
61
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
62
|
requirements:
|
64
63
|
- - ">="
|
data/.rubocop.yml
DELETED
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
|