tuna_roll 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +51 -0
- data/Rakefile +8 -0
- data/exe/tunaroll +6 -0
- data/lib/tuna_roll/class_unroller.rb +34 -0
- data/lib/tuna_roll/engines/erb_engine.rb +13 -0
- data/lib/tuna_roll/engines/slim_engine.rb +12 -0
- data/lib/tuna_roll/generators/static_generator.rb +18 -0
- data/lib/tuna_roll/version.rb +5 -0
- data/lib/tuna_roll.rb +16 -0
- data/sig/tuna_roll.rbs +4 -0
- metadata +113 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 92bd693112f16c935082bd8d1a05e6000375d378a1e3aa2056f27ef8a1c11582
|
4
|
+
data.tar.gz: 199032cf8f1623516eb927a0b944026b336bfbb3182d8b8a0e58912332eec9ee
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0b2b45501e83685519779d085f032328cd80aba8c430a82de3d6b96483172fdab341caa417a979ae25659e7a3cfbb0ca79f690f975137ff226cdbeeea50349b8
|
7
|
+
data.tar.gz: d1da9a0555a5dba2fe07968a2dcd4bfcfca974c2bc47fb287b6007cb71e3fcad8dc23ae2ad9aa14bce0e7c59a606a564fa3c6ab9bb8241bc1ca47bb11c0de73b
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2025 Danielle Smith
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# TunaRoll
|
2
|
+
|
3
|
+
Find all the HTML classes used in your templates. Super-duper experimental, only works on Slim and ERB (although any Temple engine can be adapted), and only find classes statically in the templates themselves.
|
4
|
+
|
5
|
+
It works by rendering the template without any Ruby code (so it renders every possible branch) and just extracts all the class attributes. Yeah I know it's really dumb, but anything smarter would be a ridiculous amount of effort.
|
6
|
+
|
7
|
+
If it detects any classes with a dynamic portion, it just replaces that portion with the string `%DYNAMIC%`.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Install the gem and add to the application's Gemfile by executing:
|
12
|
+
|
13
|
+
```bash
|
14
|
+
bundle add tuna_roll
|
15
|
+
```
|
16
|
+
|
17
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
18
|
+
|
19
|
+
```bash
|
20
|
+
gem install tuna_roll
|
21
|
+
```
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
```
|
26
|
+
$ tunarall app/views/**/*.erb
|
27
|
+
```
|
28
|
+
|
29
|
+
Outputs all the classes to stdout. Can take a few seconds if your app is large.
|
30
|
+
|
31
|
+
Internally it's just calling `TunaRoll::ClassUnroller.new(path).call` on every file.
|
32
|
+
|
33
|
+
###
|
34
|
+
|
35
|
+
## Why is it called TunaRoll?
|
36
|
+
|
37
|
+
Because it unrolls templates into flat HTML to get all the classes, so template-unroll -> tunroll -> TunaRoll.
|
38
|
+
|
39
|
+
## Development
|
40
|
+
|
41
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
42
|
+
|
43
|
+
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).
|
44
|
+
|
45
|
+
## Contributing
|
46
|
+
|
47
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/danini-the-panini/tuna_roll.
|
48
|
+
|
49
|
+
## License
|
50
|
+
|
51
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/exe/tunaroll
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "nokogiri"
|
4
|
+
|
5
|
+
require_relative "engines/erb_engine"
|
6
|
+
require_relative "engines/slim_engine"
|
7
|
+
|
8
|
+
module TunaRoll
|
9
|
+
class ClassUnroller
|
10
|
+
|
11
|
+
def initialize(path)
|
12
|
+
@path = path
|
13
|
+
end
|
14
|
+
|
15
|
+
def call
|
16
|
+
html = engine.call(File.read(@path))
|
17
|
+
doc = Nokogiri::HTML(html)
|
18
|
+
doc.css('[class]').flat_map { it.attr('class').split(/\s+/) }.uniq.sort
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def engine
|
24
|
+
ext = File.extname(@path)
|
25
|
+
case ext
|
26
|
+
when '.erb' then ERBEngine.new
|
27
|
+
when '.slim' then SlimEngine.new
|
28
|
+
when '.html' then :itself.to_proc
|
29
|
+
else warn "unrecognised file extension '#{ext}'"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "temple"
|
4
|
+
require "temple/erb/engine"
|
5
|
+
|
6
|
+
require_relative "../generators/static_generator"
|
7
|
+
|
8
|
+
module TunaRoll
|
9
|
+
class ERBEngine < Temple::ERB::Engine
|
10
|
+
remove :ArrayBuffer # generator
|
11
|
+
use StaticGenerator
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "temple"
|
4
|
+
|
5
|
+
module TunaRoll
|
6
|
+
class StaticGenerator < Temple::Generator
|
7
|
+
def save_buffer = nil
|
8
|
+
def restore_buffer = nil
|
9
|
+
def return_buffer = nil
|
10
|
+
|
11
|
+
def on_multi(*exp) = exp.map { compile(it) }.join
|
12
|
+
def on_newline = nil
|
13
|
+
def on_capture(*) = nil
|
14
|
+
def on_static(text) = text
|
15
|
+
def on_dynamic(*) = '%DYNAMIC%'
|
16
|
+
def on_code(*) = nil
|
17
|
+
end
|
18
|
+
end
|
data/lib/tuna_roll.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "progress"
|
4
|
+
|
5
|
+
require_relative "tuna_roll/version"
|
6
|
+
require_relative "tuna_roll/class_unroller"
|
7
|
+
|
8
|
+
module TunaRoll
|
9
|
+
class Error < StandardError; end
|
10
|
+
|
11
|
+
def self.unroll_classes(*paths)
|
12
|
+
paths.each.with_progress.reduce([]) { |classes, path|
|
13
|
+
classes | ClassUnroller.new(path).call
|
14
|
+
}.sort
|
15
|
+
end
|
16
|
+
end
|
data/sig/tuna_roll.rbs
ADDED
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tuna_roll
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Danielle Smith
|
8
|
+
bindir: exe
|
9
|
+
cert_chain: []
|
10
|
+
date: 2025-01-06 00:00:00.000000000 Z
|
11
|
+
dependencies:
|
12
|
+
- !ruby/object:Gem::Dependency
|
13
|
+
name: nokogiri
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - "~>"
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '1.11'
|
19
|
+
type: :runtime
|
20
|
+
prerelease: false
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
requirements:
|
23
|
+
- - "~>"
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: '1.11'
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: temple
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - "~>"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.10.3
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 0.10.3
|
40
|
+
- !ruby/object:Gem::Dependency
|
41
|
+
name: slim
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '5.2'
|
47
|
+
type: :runtime
|
48
|
+
prerelease: false
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '5.2'
|
54
|
+
- !ruby/object:Gem::Dependency
|
55
|
+
name: progress
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '3.6'
|
61
|
+
type: :runtime
|
62
|
+
prerelease: false
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '3.6'
|
68
|
+
description: Find all the HTML classes used in your templates. Super-duper experimental,
|
69
|
+
only works on Slim and ERB (although any Temple engine can be adapted), and only
|
70
|
+
find classes statically in the templates themselves.
|
71
|
+
email:
|
72
|
+
- danielle.smith@platform45.com
|
73
|
+
executables:
|
74
|
+
- tunaroll
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files: []
|
77
|
+
files:
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- exe/tunaroll
|
82
|
+
- lib/tuna_roll.rb
|
83
|
+
- lib/tuna_roll/class_unroller.rb
|
84
|
+
- lib/tuna_roll/engines/erb_engine.rb
|
85
|
+
- lib/tuna_roll/engines/slim_engine.rb
|
86
|
+
- lib/tuna_roll/generators/static_generator.rb
|
87
|
+
- lib/tuna_roll/version.rb
|
88
|
+
- sig/tuna_roll.rbs
|
89
|
+
homepage: https://github.com/danini-the-panini/tuna_roll
|
90
|
+
licenses:
|
91
|
+
- MIT
|
92
|
+
metadata:
|
93
|
+
homepage_uri: https://github.com/danini-the-panini/tuna_roll
|
94
|
+
source_code_uri: https://github.com/danini-the-panini/tuna_roll
|
95
|
+
changelog_uri: https://github.com/danini-the-panini/tuna_roll/releases
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 3.4.0
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubygems_version: 3.6.2
|
111
|
+
specification_version: 4
|
112
|
+
summary: Find all the HTML classes used in your templates.
|
113
|
+
test_files: []
|