haml2html 0.1.1 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b6e804a6e70b2ee7b505963c8fb1919067cf47502fc0598884d0ac6d288a42e5
4
- data.tar.gz: 5bcc16b7b359cf436f07b55d15a5bb03d28821adcea468a4e7aebdabbe416126
3
+ metadata.gz: bcf730acaf73c99940361793046e483d462069800940912362b1b645d7c2bebc
4
+ data.tar.gz: cd4b1cf2bcbc28e1a80ccc074bc965919d5b3c6d9ec38d2f5398d8bbfd37db2a
5
5
  SHA512:
6
- metadata.gz: 47b3a2683f991ee10b879f3f46f8b4919c4794bd375cd95af16d7818449fbd62325a99863720ffe311c4b0e50db830a889ad6906f397b12772c4d12a10294b8d
7
- data.tar.gz: f3836002ec40c1617aa98a24f0443d348d1951233f2472cd652ad5a6417887fff7cd53f237c64c5c96e69a72348846be4660b8210beec09ba318f72f53cc6db1
6
+ metadata.gz: f6a33a3a82682bca7ad2a5707f5e68c16c468f1d14e9bc7a9d25a3fa3362c8ebf5df756c38a0548dafa144c93aa43e37ab55e286d286b89ff5595f78893bdff1
7
+ data.tar.gz: 8e08fe063629fa885a1596b4456268706611f0f1807b92b7658138829d04a8fceb777d010389963481b7d539136d99d96696f8658546df44bf309f7db4e7e2b8
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.2
4
+
5
+ - Raise the minimum supported Ruby version to 3.2.
6
+ - Switch diagnostics back to `Data.define`.
7
+
3
8
  ## 0.1.1
4
9
 
5
10
  - Add support for `:ruby` filters.
data/README.md CHANGED
@@ -31,26 +31,58 @@ require "haml2html"
31
31
  erb = Haml2html::Converter.new("%p= post.title\n", filename: "show.html.haml").render
32
32
  ```
33
33
 
34
+ ## Examples
35
+
36
+ Haml:
37
+
38
+ ```haml
39
+ = form_with model: post do |form|
40
+ = form.text_field :title
41
+ ```
42
+
43
+ ERB:
44
+
45
+ ```erb
46
+ <%= form_with model: post do |form| %>
47
+ <%= form.text_field :title %>
48
+ <% end %>
49
+ ```
50
+
51
+ Haml:
52
+
53
+ ```haml
54
+ :ruby
55
+ if published
56
+ status = "Published"
57
+ else
58
+ status = "Draft"
59
+ end
60
+ %p= status
61
+ ```
62
+
63
+ ERB:
64
+
65
+ ```erb
66
+ <%
67
+ if published
68
+ status = "Published"
69
+ else
70
+ status = "Draft"
71
+ end
72
+ %>
73
+ <p><%= status %></p>
74
+ ```
75
+
34
76
  ## Supported
35
77
 
36
78
  - Haml tags, nesting, static attributes, text, interpolation.
37
79
  - Ruby output and control flow: `=`, `!=`, `- if`, `- each do`, and similar blocks.
38
80
  - Public comments and silent comments.
39
- - `:plain`, `:escaped`, `:javascript`, `:css`, and `:erb` filters.
40
- - Dynamic Haml attributes and object references through `Haml::AttributeBuilder`.
41
-
42
- Generated ERB may call `Haml::AttributeBuilder` for dynamic attributes and object references. Keep `haml` available at runtime until those converted templates are simplified.
81
+ - `:plain`, `:escaped`, `:javascript`, `:css`, `:erb`, and `:ruby` filters.
82
+ - Dynamic Haml attributes through Rails `tag.attributes`.
43
83
 
44
84
  ## Limitations
45
85
 
46
86
  This is a migration tool, not a full source-preserving formatter. Output whitespace and quote style may differ from Haml output, while rendered HTML should remain equivalent for supported constructs. Unsupported filters or nodes fail with diagnostics instead of emitting known-wrong ERB.
47
87
 
48
- Batch directory conversion is planned after the single-file converter is stable.
49
-
50
- ## Publishing Checklist
51
-
52
- 1. Verify gemspec URLs match the final repository URL.
53
- 2. Run `rake test`.
54
- 3. Run `gem build haml2html.gemspec --strict`.
55
- 4. Inspect package contents with `gem spec haml2html-0.1.0.gem files`.
56
- 5. Publish with RubyGems MFA enabled.
88
+ Object references such as `%div[user]` are not converted yet.
@@ -88,7 +88,7 @@ module Haml2html
88
88
  return nil if value[:parse].nil? && blank?(value[:value])
89
89
 
90
90
  if value[:parse]
91
- marker = raw_script_line?(node) ? "<%==" : "<%="
91
+ marker = raw_script?(node) ? "<%==" : "<%="
92
92
  raw = "#{marker} #{value[:value].to_s.strip} %>"
93
93
  value[:preserve_script] ? raw : raw
94
94
  else
@@ -98,12 +98,13 @@ module Haml2html
98
98
 
99
99
  def emit_attributes(node)
100
100
  value = node.value
101
- return runtime_attributes(value) if runtime_attributes?(value)
101
+ attrs = static_attributes(value)
102
+ diagnose_object_ref(node, value)
102
103
 
103
- attrs = value[:attributes].sort.map do |name, attr_value|
104
- %( #{name}="#{escape_attr(interpolate_text(attr_value.to_s))}")
105
- end
106
- attrs.join
104
+ dynamic = dynamic_attributes_expression(value[:dynamic_attributes])
105
+ return attrs unless dynamic
106
+
107
+ "#{attrs}#{dynamic_attributes(dynamic)}"
107
108
  end
108
109
 
109
110
  def emit_script(node, indent)
@@ -112,7 +113,7 @@ module Haml2html
112
113
  return "#{spaces(indent)}#{interpolate_text(unquote_string_literal(code))}\n"
113
114
  end
114
115
 
115
- marker = raw_script_line?(node) ? "<%==" : "<%="
116
+ marker = raw_script?(node) ? "<%==" : "<%="
116
117
  if node.children.any?
117
118
  output = +"#{spaces(indent)}#{marker} #{code} %>\n"
118
119
  output << emit_children(node.children, indent + 1)
@@ -176,40 +177,24 @@ module Haml2html
176
177
  end
177
178
  end
178
179
 
179
- def runtime_attributes?(value)
180
- object_ref = value[:object_ref]
181
- return true unless object_ref.nil? || object_ref == :nil
182
-
183
- dynamic = value[:dynamic_attributes]
184
- return false unless dynamic
185
-
186
- dynamic_literals(dynamic).any?
187
- end
188
-
189
- def runtime_attributes(value)
190
- args = ["true", '"\\"".freeze', ":html", object_ref_literal(value[:object_ref])]
191
- args << value[:attributes].inspect unless value[:attributes].empty?
192
- args.concat(dynamic_literals(value[:dynamic_attributes]))
193
-
194
- %(<%== (require "haml"; ::Haml::AttributeBuilder.build(#{args.join(", ")})) %>)
180
+ def static_attributes(value)
181
+ value[:attributes].sort.map do |name, attr_value|
182
+ %( #{name}="#{escape_attr(interpolate_text(attr_value.to_s))}")
183
+ end.join
195
184
  end
196
185
 
197
- def object_ref_literal(object_ref)
198
- return "nil" if object_ref.nil? || object_ref == :nil
199
-
200
- object_ref
186
+ def dynamic_attributes(dynamic)
187
+ %(<%== tag.attributes(**#{dynamic}).then { |attrs| attrs.empty? ? "" : " \#{attrs}" } %>)
201
188
  end
202
189
 
203
- def dynamic_literals(dynamic)
204
- return [] unless dynamic
205
-
206
- [dynamic.new, stripped_old_dynamic_literal(dynamic.old)].compact
207
- end
190
+ def dynamic_attributes_expression(dynamic)
191
+ return nil unless dynamic
208
192
 
209
- def stripped_old_dynamic_literal(old)
210
- return nil if old.nil?
193
+ expressions = [dynamic.new, dynamic.old].compact
194
+ return nil if expressions.empty?
195
+ return expressions.first if expressions.one?
211
196
 
212
- old.dup.sub(/\A{/, "").sub(/}\z/m, "")
197
+ expressions.reduce("{}") { |merged, expression| "#{merged}.merge(#{expression})" }
213
198
  end
214
199
 
215
200
  def diagnose_object_ref(node, value)
@@ -219,19 +204,6 @@ module Haml2html
219
204
  unsupported(node, "object reference", "object references cannot be faithfully converted to inline attrs")
220
205
  end
221
206
 
222
- def diagnose_dynamic_attributes(node, value)
223
- dynamic = value[:dynamic_attributes]
224
- return unless dynamic
225
-
226
- if dynamic.respond_to?(:new) && dynamic.new
227
- unsupported(node, "dynamic attributes", "new-style dynamic attributes are not supported")
228
- end
229
-
230
- if dynamic.respond_to?(:old) && dynamic.old
231
- unsupported(node, "dynamic attributes", "old-style dynamic attributes are not supported")
232
- end
233
- end
234
-
235
207
  def closes_with_end?(node)
236
208
  keyword = node.value[:keyword].to_s
237
209
  return true if %w[if unless case begin for while until].include?(keyword)
@@ -263,9 +235,11 @@ module Haml2html
263
235
  diagnostics << Diagnostic.new(filename: @filename, line: node.line, feature: feature.to_s, message: message)
264
236
  end
265
237
 
266
- def raw_script_line?(node)
238
+ def raw_script?(node)
239
+ return true if node.type == :tag && node.value[:preserve_script] == false
240
+
267
241
  line = @lines.fetch(node.line.to_i - 1, "")
268
- line.lstrip.start_with?("!=") || line.include?("!=")
242
+ line.lstrip.start_with?("!=")
269
243
  end
270
244
 
271
245
  def blank?(value)
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Haml2html
4
- Diagnostic = Struct.new(:filename, :line, :feature, :message, keyword_init: true) do
4
+ Diagnostic = Data.define(:filename, :line, :feature, :message) do
5
5
  def to_s
6
6
  location = [filename, line].compact.join(":")
7
7
  location = "haml" if location.empty?
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Haml2html
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: haml2html
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kyle
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-05-06 00:00:00.000000000 Z
11
+ date: 2026-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: haml
@@ -44,6 +44,20 @@ dependencies:
44
44
  - - "<"
45
45
  - !ruby/object:Gem::Version
46
46
  version: '9.0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: herb
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '0.10'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '0.10'
47
61
  - !ruby/object:Gem::Dependency
48
62
  name: minitest
49
63
  requirement: !ruby/object:Gem::Requirement
@@ -88,13 +102,13 @@ files:
88
102
  - lib/haml2html/converter.rb
89
103
  - lib/haml2html/diagnostic.rb
90
104
  - lib/haml2html/version.rb
91
- homepage: https://github.com/kyle/haml2html
105
+ homepage: https://github.com/KDunc11/haml2html
92
106
  licenses:
93
107
  - MIT
94
108
  metadata:
95
- homepage_uri: https://github.com/kyle/haml2html
96
- source_code_uri: https://github.com/kyle/haml2html/tree/main
97
- changelog_uri: https://github.com/kyle/haml2html/blob/main/CHANGELOG.md
109
+ homepage_uri: https://github.com/KDunc11/haml2html
110
+ source_code_uri: https://github.com/KDunc11/haml2html/tree/main
111
+ changelog_uri: https://github.com/KDunc11/haml2html/blob/main/CHANGELOG.md
98
112
  post_install_message:
99
113
  rdoc_options: []
100
114
  require_paths:
@@ -103,7 +117,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
103
117
  requirements:
104
118
  - - ">="
105
119
  - !ruby/object:Gem::Version
106
- version: '3.1'
120
+ version: '3.2'
107
121
  required_rubygems_version: !ruby/object:Gem::Requirement
108
122
  requirements:
109
123
  - - ">="