ruby2html 1.6.6 → 2.0.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 +197 -0
- data/LICENSE +21 -0
- data/README.md +155 -225
- data/ext/ruby2html/attributes.c +200 -0
- data/ext/ruby2html/buffer.h +43 -0
- data/ext/ruby2html/content.c +120 -0
- data/ext/ruby2html/extconf.rb +36 -9
- data/ext/ruby2html/html_escape.c +252 -0
- data/ext/ruby2html/ruby2html.c +15 -107
- data/ext/ruby2html/ruby2html.h +32 -0
- data/ext/ruby2html/tag_render.c +179 -0
- data/lib/gem/ruby2html/component.rb +118 -0
- data/lib/gem/ruby2html/component_helper.rb +36 -15
- data/lib/gem/ruby2html/html_beautifier_middleware.rb +55 -9
- data/lib/gem/ruby2html/rails_components/base_component.rb +10 -1
- data/lib/gem/ruby2html/rails_components/button_to.rb +3 -3
- data/lib/gem/ruby2html/rails_components/form_with.rb +41 -67
- data/lib/gem/ruby2html/rails_components/image_tag.rb +3 -3
- data/lib/gem/ruby2html/rails_components/link_to.rb +3 -3
- data/lib/gem/ruby2html/rails_components/output_capture.rb +41 -0
- data/lib/gem/ruby2html/rails_components/template_collector.rb +62 -0
- data/lib/gem/ruby2html/rails_components/template_compiler.rb +92 -0
- data/lib/gem/ruby2html/rails_components/template_helpers.rb +77 -0
- data/lib/gem/ruby2html/rails_helper.rb +8 -4
- data/lib/gem/ruby2html/railtie.rb +104 -25
- data/lib/gem/ruby2html/render/pure_ruby.rb +202 -0
- data/lib/gem/ruby2html/render.rb +60 -98
- data/lib/gem/ruby2html/version.rb +1 -1
- data/lib/gem/ruby2html.rb +28 -7
- metadata +22 -78
- data/lib/ruby2html/ruby2html.so +0 -0
- data/ruby2html.gemspec +0 -43
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5ba119a7769924fec25bf5a7b80128f2086dd82fc3c81bd60b0d817e19a8232f
|
|
4
|
+
data.tar.gz: b4decdfd8c01b34813e0d092de84d90abc64bbf78417ab38f4ff3e44719e3ac5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3e93a318476275d137fab0f8149df9ac26a9bdf78e6ddd23b63b630ee662d1e4f87aaa039b22f7f8dd3ebef1a38c334423714ebc3544e2d8cd02869574da5d69
|
|
7
|
+
data.tar.gz: 5b57bb1eda59d05452e12c7b43161d3b210fd063c597f7ad42c3ccb1320b48fc5378ea2771ebc9a1185384e4ed29eb97e2e7372c697d235d33cbb1c6e93a979a
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented here.
|
|
4
|
+
Format: [Keep a Changelog](https://keepachangelog.com/en/1.1.0/); versioning: [SemVer](https://semver.org/spec/v2.0.0.html).
|
|
5
|
+
Entries before 1.6.6 were reconstructed from `git log` and RubyGems release dates (the repo has no git tags for them); they are best-effort summaries.
|
|
6
|
+
|
|
7
|
+
## [Unreleased]
|
|
8
|
+
|
|
9
|
+
## [2.0.0] - 2026-10-31
|
|
10
|
+
|
|
11
|
+
A rewrite of the renderer for speed, memory and correctness, plus a new component class, Rails 8.1 / ViewComponent 4 support, JRuby/TruffleRuby support and full CI/release automation. **Contains breaking changes: read "Upgrading to 2.0" below.**
|
|
12
|
+
|
|
13
|
+
### Performance
|
|
14
|
+
|
|
15
|
+
Measured on Ruby 3.4.7 x86_64 (`bench/render_bench.rb`, a 100-item page with attributes and escaped text):
|
|
16
|
+
|
|
17
|
+
- About 4.7x faster than 1.6.6 (≈620 → ≈2,950 renders/s) with about 8x fewer allocations per render (3,531 → 419).
|
|
18
|
+
- Faster than Erubi (Rails' ERB engine) and Phlex on the same page; see the README snapshot and the CI benchmark workflow for current numbers.
|
|
19
|
+
- HTML escaping uses SSE2 (x86_64) / NEON (arm64): up to 5.9x faster on large clean text, about 2x on typical strings.
|
|
20
|
+
- `require 'ruby2html'` costs about 0.4 MB and 19 ms (was about 9.5 MB and 116 ms): Prism, the Rails glue and htmlbeautifier load only when used; in eager-loading (production) Rails apps they load at boot instead.
|
|
21
|
+
|
|
22
|
+
### Added
|
|
23
|
+
|
|
24
|
+
- `Ruby2html::Component`: a lightweight component base class (no ViewComponent needed) with `view_template`/`call`, `render_in`, `helpers` and `content`; nested components write straight into the parent's buffer.
|
|
25
|
+
- Pure-Ruby implementation with byte-identical output (`Ruby2html::PureRuby`), used on JRuby, when the extension can't be built, or with `RUBY2HTML_DISABLE_EXT=1`. `Ruby2html.native?` and `Ruby2html::IMPLEMENTATION` tell which one is loaded.
|
|
26
|
+
- `Ruby2html.escape_html(obj)`.
|
|
27
|
+
- Attributes: `true` renders a bare attribute, `false` omits it; nested `data:`/`aria:` Hashes expand to `data-user-id="1"`; Arrays render as space-separated tokens (`class: ['btn', active && 'on']`).
|
|
28
|
+
- `.html.rb` templates are compiled with Prism to run directly in the view/component (no instance-variable copying, no `method_missing`).
|
|
29
|
+
- `capture`, `content_for` and `provide` with blocks of ruby2html tags work in `.html.rb` templates.
|
|
30
|
+
- Support for Rails 8.1, ViewComponent 4, JRuby and TruffleRuby; fiber-safe rendering (no thread/fiber-global state).
|
|
31
|
+
- `llms.txt`: complete reference for AI coding tools; `AGENTS.md` (with `CLAUDE.md` symlinked to it) and Claude Code skills/agents for maintainers.
|
|
32
|
+
- CI: generated CRuby matrix (all maintained versions), Rails matrix, Linux x86_64/arm64 and macOS builds, `-Werror` gcc/clang builds, sanitizers, JRuby/TruffleRuby, gem install smoke test, benchmarks in every PR; Dependabot; releases published automatically when a version bump merges (RubyGems trusted publishing).
|
|
33
|
+
- Maintained by [developerz.ai](https://developerz.ai): its maintainer agent triages issues, reviews PRs, merges on green, runs daily health and release checkups, and opens release PRs (`.dz/`).
|
|
34
|
+
|
|
35
|
+
### Fixed
|
|
36
|
+
|
|
37
|
+
- Attribute cache keyed by `Object#hash`: a hash collision could render another element's attributes; the cache also grew without bound. Removed.
|
|
38
|
+
- `link_to` rendered a `button_to` form.
|
|
39
|
+
- `form_with` emitted its fields as escaped text, ignored `patch`/`delete` (`_method`), crashed on `submit` without a label, and ignored Rails' CSRF/`data-remote` settings. It now delegates to Rails' own `form_with` and `FormBuilder`.
|
|
40
|
+
- Tags inside `link_to`/`button_to` blocks were emitted before the link instead of inside it.
|
|
41
|
+
- `html_safe` content was escaped twice; non-String content (`p 42`) was silently dropped.
|
|
42
|
+
- A block's String return value replaced markup the block had already written.
|
|
43
|
+
- The `<output>` tag was unusable (shadowed by `Render#output`).
|
|
44
|
+
- Template backtraces were off by 3 lines; the renderer wasn't restored when a template raised; template locals could clash with internal variables or be rewritten into tag calls (`h2 title` in a partial with a `title` local).
|
|
45
|
+
- A rescued exception while writing attributes left a half-written start tag in the output.
|
|
46
|
+
- `HtmlBeautifierMiddleware` beautified each streamed chunk separately, didn't close the body, and touched gzip/204/304 responses.
|
|
47
|
+
- The packaged gem shipped a locally compiled `.so`; `rake build` didn't build a gem.
|
|
48
|
+
|
|
49
|
+
### Upgrading to 2.0
|
|
50
|
+
|
|
51
|
+
Templates and components:
|
|
52
|
+
1. `self` in `.html.rb` templates is now the view (or component), not a `Ruby2html::Render`. Replace `self.div` / `self.plain` with `div` / `plain`. Without Prism (Ruby < 3.3 and no `prism` gem) templates still use the 1.x path.
|
|
53
|
+
2. `Thread.current[:__ruby2html_renderer__]` is gone. The active renderer lives on the component/view; use `component.__ruby2html_renderer__`.
|
|
54
|
+
3. `form_with` output now matches Rails (`_method`, `accept-charset`, no forced `data-remote`, no `utf8` field); its builder is a proxy around Rails' `FormBuilder`.
|
|
55
|
+
4. `Ruby2html::ComponentHelper#method_missing` is now private.
|
|
56
|
+
|
|
57
|
+
HTML output:
|
|
58
|
+
5. Non-String content renders: `p 42` → `<p>42</p>` (1.x: `<p></p>`); `nil` renders nothing.
|
|
59
|
+
6. `html_safe` strings passed as content or returned from a block are inserted raw (1.x escaped them).
|
|
60
|
+
7. A block's return value is used only if the block wrote nothing, and only for String/Symbol/Numeric (1.x: a returned String replaced everything the block wrote).
|
|
61
|
+
8. Attributes: `true` → bare attribute and `false` omitted (except `data-*`, `aria-*`, `draggable`, `spellcheck`, `contenteditable`, which keep `"true"`/`"false"`); Hash values expand; Arrays join with spaces; invalid attribute names raise `ArgumentError`; Hashes/Arrays nested deeper than 32 levels raise `ArgumentError`.
|
|
62
|
+
9. Tag methods accept at most one positional argument (extra arguments raise `ArgumentError`).
|
|
63
|
+
10. The output buffer is UTF-8; strings in other encodings are transcoded (raising `EncodingError` if impossible).
|
|
64
|
+
|
|
65
|
+
Removed / packaging:
|
|
66
|
+
11. `Ruby2html::ATTRIBUTE_CACHE`, `Render::METHOD_DEFINITIONS`, `Render#output` and the `Render#fast_escape_html` / `#fast_attributes_to_s` / `#fast_buffer_append` / `#fast_render_tag` methods are removed. Use `Ruby2html.escape_html`, the value returned by `render`, or `current_output`.
|
|
67
|
+
12. Ruby >= 3.1 and (for Rails integration) Rails >= 7.2 are required.
|
|
68
|
+
13. `htmlbeautifier` is no longer a dependency: add `gem 'htmlbeautifier'` if you use `Ruby2html::HtmlBeautifierMiddleware`.
|
|
69
|
+
14. The gem's require path is `lib/gem` only.
|
|
70
|
+
|
|
71
|
+
## [1.6.6] - 2025-02-10
|
|
72
|
+
|
|
73
|
+
### Fixed
|
|
74
|
+
- Stop shipping a prebuilt `lib/ruby2html/ruby2html.so`; the extension is compiled on install (`*.so` gitignored).
|
|
75
|
+
|
|
76
|
+
## [1.6.4] - 2025-02-09
|
|
77
|
+
|
|
78
|
+
### Fixed
|
|
79
|
+
- Renderer fixes following the C extension introduction.
|
|
80
|
+
|
|
81
|
+
## [1.6.3] - 2025-02-09
|
|
82
|
+
|
|
83
|
+
### Fixed
|
|
84
|
+
- Template handler, `form_with` and gemspec fixes for the C extension build.
|
|
85
|
+
|
|
86
|
+
## [1.6.2] - 2025-02-09
|
|
87
|
+
## [1.6.1] - 2025-02-09
|
|
88
|
+
|
|
89
|
+
Published to RubyGems; no separate commits in the repository history.
|
|
90
|
+
|
|
91
|
+
## [1.6.0] - 2025-02-09
|
|
92
|
+
|
|
93
|
+
### Added
|
|
94
|
+
- C extension (`ext/ruby2html`) for HTML escaping, attribute serialization and buffer appends; `rake compile` via rake-compiler.
|
|
95
|
+
|
|
96
|
+
## [1.5.8] - 2024-11-01
|
|
97
|
+
## [1.5.7] - 2024-11-01
|
|
98
|
+
|
|
99
|
+
### Changed
|
|
100
|
+
- Load `htmlbeautifier` from the main entry file; renderer cleanup. Dependency updates.
|
|
101
|
+
|
|
102
|
+
## [1.5.6] - 2024-08-17
|
|
103
|
+
## [1.5.5] - 2024-08-17
|
|
104
|
+
|
|
105
|
+
### Changed
|
|
106
|
+
- Template handler declares `handles_encoding?`; Railtie cleanup.
|
|
107
|
+
|
|
108
|
+
## [1.5.4] - 2024-08-12
|
|
109
|
+
|
|
110
|
+
### Changed
|
|
111
|
+
- Gemspec cleanup.
|
|
112
|
+
|
|
113
|
+
## [1.5.3] - 2024-08-12
|
|
114
|
+
|
|
115
|
+
### Added
|
|
116
|
+
- `turbo_stream` tag (`<turbo-stream>`).
|
|
117
|
+
|
|
118
|
+
## [1.5.2] - 2024-08-12
|
|
119
|
+
|
|
120
|
+
### Added
|
|
121
|
+
- `turbo_frame` tag (`<turbo-frame>`).
|
|
122
|
+
|
|
123
|
+
## [1.5.1] - 2024-08-12
|
|
124
|
+
|
|
125
|
+
### Fixed
|
|
126
|
+
- `link_to` wrapper simplified.
|
|
127
|
+
|
|
128
|
+
## [1.5.0] - 2024-08-12
|
|
129
|
+
|
|
130
|
+
### Added
|
|
131
|
+
- Rails helper wrappers: `form_with` (with `label`, `text_field`, `hidden_field`, `password_field`, `file_field`, `submit`), `button_to`, `link_to`, `image_tag`.
|
|
132
|
+
|
|
133
|
+
## [1.4.0] - 2024-08-10
|
|
134
|
+
|
|
135
|
+
### Added
|
|
136
|
+
- `Ruby2html::HtmlBeautifierMiddleware`; runtime dependency on `htmlbeautifier`.
|
|
137
|
+
|
|
138
|
+
## [1.3.3] - 2024-08-10
|
|
139
|
+
|
|
140
|
+
### Added
|
|
141
|
+
- Support for `config.action_view.annotate_rendered_view_with_filenames`.
|
|
142
|
+
|
|
143
|
+
## [1.3.2] - 2024-08-09
|
|
144
|
+
|
|
145
|
+
### Fixed
|
|
146
|
+
- Keyword option handling in tag methods.
|
|
147
|
+
|
|
148
|
+
## [1.3.1] - 2024-08-09
|
|
149
|
+
|
|
150
|
+
### Fixed
|
|
151
|
+
- `ComponentHelper` renderer bug.
|
|
152
|
+
|
|
153
|
+
## [1.3.0] - 2024-08-09
|
|
154
|
+
|
|
155
|
+
### Added
|
|
156
|
+
- Calling component methods from component templates; nested renderer tracking.
|
|
157
|
+
|
|
158
|
+
## [1.2.0] - 2024-08-09
|
|
159
|
+
|
|
160
|
+
### Added
|
|
161
|
+
- ViewComponent support: `.html.rb` component templates, `Ruby2html::ComponentHelper`.
|
|
162
|
+
|
|
163
|
+
## [1.1.0] - 2024-08-08
|
|
164
|
+
|
|
165
|
+
### Added
|
|
166
|
+
- `.rb` ActionView template handler (`*.html.rb` views and partials).
|
|
167
|
+
|
|
168
|
+
## [1.0.0] - 2024-08-08
|
|
169
|
+
|
|
170
|
+
### Added
|
|
171
|
+
- Initial release: `Ruby2html::Render` DSL, `Ruby2html::RailsHelper#html` for ERB.
|
|
172
|
+
|
|
173
|
+
[Unreleased]: https://github.com/sebyx07/ruby2html/compare/v2.0.0...HEAD
|
|
174
|
+
[2.0.0]: https://github.com/sebyx07/ruby2html/releases/tag/v2.0.0
|
|
175
|
+
[1.6.6]: https://rubygems.org/gems/ruby2html/versions/1.6.6
|
|
176
|
+
[1.6.4]: https://rubygems.org/gems/ruby2html/versions/1.6.4
|
|
177
|
+
[1.6.3]: https://rubygems.org/gems/ruby2html/versions/1.6.3
|
|
178
|
+
[1.6.2]: https://rubygems.org/gems/ruby2html/versions/1.6.2
|
|
179
|
+
[1.6.1]: https://rubygems.org/gems/ruby2html/versions/1.6.1
|
|
180
|
+
[1.6.0]: https://rubygems.org/gems/ruby2html/versions/1.6.0
|
|
181
|
+
[1.5.8]: https://rubygems.org/gems/ruby2html/versions/1.5.8
|
|
182
|
+
[1.5.7]: https://rubygems.org/gems/ruby2html/versions/1.5.7
|
|
183
|
+
[1.5.6]: https://rubygems.org/gems/ruby2html/versions/1.5.6
|
|
184
|
+
[1.5.5]: https://rubygems.org/gems/ruby2html/versions/1.5.5
|
|
185
|
+
[1.5.4]: https://rubygems.org/gems/ruby2html/versions/1.5.4
|
|
186
|
+
[1.5.3]: https://rubygems.org/gems/ruby2html/versions/1.5.3
|
|
187
|
+
[1.5.2]: https://rubygems.org/gems/ruby2html/versions/1.5.2
|
|
188
|
+
[1.5.1]: https://rubygems.org/gems/ruby2html/versions/1.5.1
|
|
189
|
+
[1.5.0]: https://rubygems.org/gems/ruby2html/versions/1.5.0
|
|
190
|
+
[1.4.0]: https://rubygems.org/gems/ruby2html/versions/1.4.0
|
|
191
|
+
[1.3.3]: https://rubygems.org/gems/ruby2html/versions/1.3.3
|
|
192
|
+
[1.3.2]: https://rubygems.org/gems/ruby2html/versions/1.3.2
|
|
193
|
+
[1.3.1]: https://rubygems.org/gems/ruby2html/versions/1.3.1
|
|
194
|
+
[1.3.0]: https://rubygems.org/gems/ruby2html/versions/1.3.0
|
|
195
|
+
[1.2.0]: https://rubygems.org/gems/ruby2html/versions/1.2.0
|
|
196
|
+
[1.1.0]: https://rubygems.org/gems/ruby2html/versions/1.1.0
|
|
197
|
+
[1.0.0]: https://rubygems.org/gems/ruby2html/versions/1.0.0
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 sebi
|
|
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 all
|
|
13
|
+
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 THE
|
|
21
|
+
SOFTWARE.
|