Version not found. Please check the version and try again.

ruby2html 1.6.6 → 2.1.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.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +211 -0
  3. data/LICENSE +21 -0
  4. data/README.md +155 -225
  5. data/ext/java/Ruby2htmlJrubyService.java +95 -0
  6. data/ext/ruby2html/attributes.c +200 -0
  7. data/ext/ruby2html/buffer.h +43 -0
  8. data/ext/ruby2html/content.c +120 -0
  9. data/ext/ruby2html/extconf.rb +40 -9
  10. data/ext/ruby2html/html_escape.c +252 -0
  11. data/ext/ruby2html/ruby2html.c +15 -107
  12. data/ext/ruby2html/ruby2html.h +32 -0
  13. data/ext/ruby2html/tag_render.c +179 -0
  14. data/lib/gem/ruby2html/component.rb +120 -0
  15. data/lib/gem/ruby2html/component_helper.rb +36 -15
  16. data/lib/gem/ruby2html/html_beautifier_middleware.rb +55 -9
  17. data/lib/gem/ruby2html/rails_components/base_component.rb +10 -1
  18. data/lib/gem/ruby2html/rails_components/button_to.rb +3 -3
  19. data/lib/gem/ruby2html/rails_components/form_with.rb +41 -67
  20. data/lib/gem/ruby2html/rails_components/image_tag.rb +3 -3
  21. data/lib/gem/ruby2html/rails_components/link_to.rb +3 -3
  22. data/lib/gem/ruby2html/rails_components/output_capture.rb +41 -0
  23. data/lib/gem/ruby2html/rails_components/template_collector.rb +62 -0
  24. data/lib/gem/ruby2html/rails_components/template_compiler.rb +92 -0
  25. data/lib/gem/ruby2html/rails_components/template_helpers.rb +77 -0
  26. data/lib/gem/ruby2html/rails_helper.rb +8 -4
  27. data/lib/gem/ruby2html/railtie.rb +104 -25
  28. data/lib/gem/ruby2html/render/pure_ruby.rb +219 -0
  29. data/lib/gem/ruby2html/render.rb +67 -98
  30. data/lib/gem/ruby2html/version.rb +1 -1
  31. data/lib/gem/ruby2html.rb +28 -7
  32. metadata +23 -78
  33. data/lib/ruby2html/ruby2html.so +0 -0
  34. data/ruby2html.gemspec +0 -43
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b9facaf1e5fd158fda51032d0cc119539e6089ae2487edef8309c1afbe48c706
4
- data.tar.gz: 0f12a85045331d691f07286bd4f233a1962c854e83369e02a502656534fa0ea3
3
+ metadata.gz: 7c3bc5f1d40d12683edafbe453a291165275d9dc1b2552007a0d757954793a6a
4
+ data.tar.gz: 2fd1df901225789e4327576d414dd16be60bea5b9c2f11020c16a6ce0e7ef1cb
5
5
  SHA512:
6
- metadata.gz: 8631ad7b2d701b17132368d00611968c4ab7ce54ef882d33a5bdd45840c3b976b8af5d2c4baf32c17dd1e88a01571b1cc126c30050df405baed4cdbda85ea4b5
7
- data.tar.gz: ba664d1eb8d3abab3f62e23b5a6e91bb12e3948b223571e662053c5f70578eb15aa0140d1d2102deab6bd0d27bacda73753f71bd24f4bd4d5addcf96d5450d63
6
+ metadata.gz: bc63552f617578a8d98938490e564a7c483e7f6179faefa5800452b8ad90d6cc1dfa921f0626bfa2c1a4046e79f298facdef9c7fb337a1e3a481f46049c0fd7a
7
+ data.tar.gz: 2e25baa9f3ecce618f5eac307767e66ee9592216d441444e4fb1da39def3a7a454ac97f6a1b3fc007a3f402ac50eb5e2cdfee42bdb81719b44fe60376205c17c
data/CHANGELOG.md ADDED
@@ -0,0 +1,211 @@
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.1.0] - 2026-10-31
10
+
11
+ ### Added
12
+
13
+ - JRuby now ships a small Java extension (`Ruby2html::JavaNative`) that accelerates HTML escaping — the renderer's hot path — over the pure-Ruby implementation. About 1.9x faster end-to-end rendering on JRuby; output is byte-identical. Distributed as a `ruby2html-<version>-java` platform gem with the jar prebuilt (no JDK needed to install); everything else stays pure Ruby.
14
+
15
+ ### Changed
16
+
17
+ - `Ruby2html::Component#render_in` accepts Rails' keyword options (`locals:`), as Rails main (8.2) passes them and deprecates `render_in` without options.
18
+ - TruffleRuby now uses the pure-Ruby implementation instead of the C extension. TruffleRuby runs C extensions through Sulong but JITs pure Ruby with Graal, which here renders ~28x faster; `Ruby2html.native?` is now `false` on TruffleRuby.
19
+ - On CRuby, a C extension that fails to load now prints one warning with the reason (`ruby2html: C extension not loaded (...); using the pure-Ruby renderer`) instead of silently rendering about 3x slower. JRuby/TruffleRuby and `RUBY2HTML_DISABLE_EXT=1` stay silent.
20
+ - Development and single-version CI jobs now run on the latest stable Ruby (4.0). The CRuby test matrix already tracks the official maintained-versions list automatically (currently 3.3, 3.4, 4.0).
21
+
22
+ ## [2.0.0] - 2026-10-31
23
+
24
+ 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.**
25
+
26
+ ### Performance
27
+
28
+ Measured on Ruby 3.4.7 x86_64 (`bench/render_bench.rb`, a 100-item page with attributes and escaped text):
29
+
30
+ - About 4.7x faster than 1.6.6 (≈620 → ≈2,950 renders/s) with about 8x fewer allocations per render (3,531 → 419).
31
+ - Faster than Erubi (Rails' ERB engine) and Phlex on the same page; see the README snapshot and the CI benchmark workflow for current numbers.
32
+ - HTML escaping uses SSE2 (x86_64) / NEON (arm64): up to 5.9x faster on large clean text, about 2x on typical strings.
33
+ - `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.
34
+
35
+ ### Added
36
+
37
+ - `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.
38
+ - 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.
39
+ - `Ruby2html.escape_html(obj)`.
40
+ - 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']`).
41
+ - `.html.rb` templates are compiled with Prism to run directly in the view/component (no instance-variable copying, no `method_missing`).
42
+ - `capture`, `content_for` and `provide` with blocks of ruby2html tags work in `.html.rb` templates.
43
+ - Support for Rails 8.1, ViewComponent 4, JRuby and TruffleRuby; fiber-safe rendering (no thread/fiber-global state).
44
+ - `llms.txt`: complete reference for AI coding tools; `AGENTS.md` (with `CLAUDE.md` symlinked to it) and Claude Code skills/agents for maintainers.
45
+ - 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).
46
+ - 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/`).
47
+
48
+ ### Fixed
49
+
50
+ - Attribute cache keyed by `Object#hash`: a hash collision could render another element's attributes; the cache also grew without bound. Removed.
51
+ - `link_to` rendered a `button_to` form.
52
+ - `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`.
53
+ - Tags inside `link_to`/`button_to` blocks were emitted before the link instead of inside it.
54
+ - `html_safe` content was escaped twice; non-String content (`p 42`) was silently dropped.
55
+ - A block's String return value replaced markup the block had already written.
56
+ - The `<output>` tag was unusable (shadowed by `Render#output`).
57
+ - 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).
58
+ - A rescued exception while writing attributes left a half-written start tag in the output.
59
+ - `HtmlBeautifierMiddleware` beautified each streamed chunk separately, didn't close the body, and touched gzip/204/304 responses.
60
+ - The packaged gem shipped a locally compiled `.so`; `rake build` didn't build a gem.
61
+
62
+ ### Upgrading to 2.0
63
+
64
+ Templates and components:
65
+ 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.
66
+ 2. `Thread.current[:__ruby2html_renderer__]` is gone. The active renderer lives on the component/view; use `component.__ruby2html_renderer__`.
67
+ 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`.
68
+ 4. `Ruby2html::ComponentHelper#method_missing` is now private.
69
+
70
+ HTML output:
71
+ 5. Non-String content renders: `p 42` → `<p>42</p>` (1.x: `<p></p>`); `nil` renders nothing.
72
+ 6. `html_safe` strings passed as content or returned from a block are inserted raw (1.x escaped them).
73
+ 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).
74
+ 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`.
75
+ 9. Tag methods accept at most one positional argument (extra arguments raise `ArgumentError`).
76
+ 10. The output buffer is UTF-8; strings in other encodings are transcoded (raising `EncodingError` if impossible).
77
+
78
+ Removed / packaging:
79
+ 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`.
80
+ 12. Ruby >= 3.1 and (for Rails integration) Rails >= 7.2 are required.
81
+ 13. `htmlbeautifier` is no longer a dependency: add `gem 'htmlbeautifier'` if you use `Ruby2html::HtmlBeautifierMiddleware`.
82
+ 14. The gem's require path is `lib/gem` only.
83
+
84
+ ## [1.6.6] - 2025-02-10
85
+
86
+ ### Fixed
87
+ - Stop shipping a prebuilt `lib/ruby2html/ruby2html.so`; the extension is compiled on install (`*.so` gitignored).
88
+
89
+ ## [1.6.4] - 2025-02-09
90
+
91
+ ### Fixed
92
+ - Renderer fixes following the C extension introduction.
93
+
94
+ ## [1.6.3] - 2025-02-09
95
+
96
+ ### Fixed
97
+ - Template handler, `form_with` and gemspec fixes for the C extension build.
98
+
99
+ ## [1.6.2] - 2025-02-09
100
+ ## [1.6.1] - 2025-02-09
101
+
102
+ Published to RubyGems; no separate commits in the repository history.
103
+
104
+ ## [1.6.0] - 2025-02-09
105
+
106
+ ### Added
107
+ - C extension (`ext/ruby2html`) for HTML escaping, attribute serialization and buffer appends; `rake compile` via rake-compiler.
108
+
109
+ ## [1.5.8] - 2024-11-01
110
+ ## [1.5.7] - 2024-11-01
111
+
112
+ ### Changed
113
+ - Load `htmlbeautifier` from the main entry file; renderer cleanup. Dependency updates.
114
+
115
+ ## [1.5.6] - 2024-08-17
116
+ ## [1.5.5] - 2024-08-17
117
+
118
+ ### Changed
119
+ - Template handler declares `handles_encoding?`; Railtie cleanup.
120
+
121
+ ## [1.5.4] - 2024-08-12
122
+
123
+ ### Changed
124
+ - Gemspec cleanup.
125
+
126
+ ## [1.5.3] - 2024-08-12
127
+
128
+ ### Added
129
+ - `turbo_stream` tag (`<turbo-stream>`).
130
+
131
+ ## [1.5.2] - 2024-08-12
132
+
133
+ ### Added
134
+ - `turbo_frame` tag (`<turbo-frame>`).
135
+
136
+ ## [1.5.1] - 2024-08-12
137
+
138
+ ### Fixed
139
+ - `link_to` wrapper simplified.
140
+
141
+ ## [1.5.0] - 2024-08-12
142
+
143
+ ### Added
144
+ - Rails helper wrappers: `form_with` (with `label`, `text_field`, `hidden_field`, `password_field`, `file_field`, `submit`), `button_to`, `link_to`, `image_tag`.
145
+
146
+ ## [1.4.0] - 2024-08-10
147
+
148
+ ### Added
149
+ - `Ruby2html::HtmlBeautifierMiddleware`; runtime dependency on `htmlbeautifier`.
150
+
151
+ ## [1.3.3] - 2024-08-10
152
+
153
+ ### Added
154
+ - Support for `config.action_view.annotate_rendered_view_with_filenames`.
155
+
156
+ ## [1.3.2] - 2024-08-09
157
+
158
+ ### Fixed
159
+ - Keyword option handling in tag methods.
160
+
161
+ ## [1.3.1] - 2024-08-09
162
+
163
+ ### Fixed
164
+ - `ComponentHelper` renderer bug.
165
+
166
+ ## [1.3.0] - 2024-08-09
167
+
168
+ ### Added
169
+ - Calling component methods from component templates; nested renderer tracking.
170
+
171
+ ## [1.2.0] - 2024-08-09
172
+
173
+ ### Added
174
+ - ViewComponent support: `.html.rb` component templates, `Ruby2html::ComponentHelper`.
175
+
176
+ ## [1.1.0] - 2024-08-08
177
+
178
+ ### Added
179
+ - `.rb` ActionView template handler (`*.html.rb` views and partials).
180
+
181
+ ## [1.0.0] - 2024-08-08
182
+
183
+ ### Added
184
+ - Initial release: `Ruby2html::Render` DSL, `Ruby2html::RailsHelper#html` for ERB.
185
+
186
+ [Unreleased]: https://github.com/sebyx07/ruby2html/compare/v2.1.0...HEAD
187
+ [2.1.0]: https://github.com/sebyx07/ruby2html/compare/v2.0.0...v2.1.0
188
+ [2.0.0]: https://github.com/sebyx07/ruby2html/releases/tag/v2.0.0
189
+ [1.6.6]: https://rubygems.org/gems/ruby2html/versions/1.6.6
190
+ [1.6.4]: https://rubygems.org/gems/ruby2html/versions/1.6.4
191
+ [1.6.3]: https://rubygems.org/gems/ruby2html/versions/1.6.3
192
+ [1.6.2]: https://rubygems.org/gems/ruby2html/versions/1.6.2
193
+ [1.6.1]: https://rubygems.org/gems/ruby2html/versions/1.6.1
194
+ [1.6.0]: https://rubygems.org/gems/ruby2html/versions/1.6.0
195
+ [1.5.8]: https://rubygems.org/gems/ruby2html/versions/1.5.8
196
+ [1.5.7]: https://rubygems.org/gems/ruby2html/versions/1.5.7
197
+ [1.5.6]: https://rubygems.org/gems/ruby2html/versions/1.5.6
198
+ [1.5.5]: https://rubygems.org/gems/ruby2html/versions/1.5.5
199
+ [1.5.4]: https://rubygems.org/gems/ruby2html/versions/1.5.4
200
+ [1.5.3]: https://rubygems.org/gems/ruby2html/versions/1.5.3
201
+ [1.5.2]: https://rubygems.org/gems/ruby2html/versions/1.5.2
202
+ [1.5.1]: https://rubygems.org/gems/ruby2html/versions/1.5.1
203
+ [1.5.0]: https://rubygems.org/gems/ruby2html/versions/1.5.0
204
+ [1.4.0]: https://rubygems.org/gems/ruby2html/versions/1.4.0
205
+ [1.3.3]: https://rubygems.org/gems/ruby2html/versions/1.3.3
206
+ [1.3.2]: https://rubygems.org/gems/ruby2html/versions/1.3.2
207
+ [1.3.1]: https://rubygems.org/gems/ruby2html/versions/1.3.1
208
+ [1.3.0]: https://rubygems.org/gems/ruby2html/versions/1.3.0
209
+ [1.2.0]: https://rubygems.org/gems/ruby2html/versions/1.2.0
210
+ [1.1.0]: https://rubygems.org/gems/ruby2html/versions/1.1.0
211
+ [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.