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 +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +45 -13
- data/lib/haml2html/converter.rb +24 -50
- data/lib/haml2html/diagnostic.rb +1 -1
- data/lib/haml2html/version.rb +1 -1
- metadata +21 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bcf730acaf73c99940361793046e483d462069800940912362b1b645d7c2bebc
|
|
4
|
+
data.tar.gz: cd4b1cf2bcbc28e1a80ccc074bc965919d5b3c6d9ec38d2f5398d8bbfd37db2a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f6a33a3a82682bca7ad2a5707f5e68c16c468f1d14e9bc7a9d25a3fa3362c8ebf5df756c38a0548dafa144c93aa43e37ab55e286d286b89ff5595f78893bdff1
|
|
7
|
+
data.tar.gz: 8e08fe063629fa885a1596b4456268706611f0f1807b92b7658138829d04a8fceb777d010389963481b7d539136d99d96696f8658546df44bf309f7db4e7e2b8
|
data/CHANGELOG.md
CHANGED
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 `:
|
|
40
|
-
- Dynamic Haml attributes
|
|
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
|
-
|
|
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.
|
data/lib/haml2html/converter.rb
CHANGED
|
@@ -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 =
|
|
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
|
-
|
|
101
|
+
attrs = static_attributes(value)
|
|
102
|
+
diagnose_object_ref(node, value)
|
|
102
103
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
attrs
|
|
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 =
|
|
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
|
|
180
|
-
|
|
181
|
-
|
|
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
|
|
198
|
-
|
|
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
|
|
204
|
-
return
|
|
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
|
-
|
|
210
|
-
return nil if
|
|
193
|
+
expressions = [dynamic.new, dynamic.old].compact
|
|
194
|
+
return nil if expressions.empty?
|
|
195
|
+
return expressions.first if expressions.one?
|
|
211
196
|
|
|
212
|
-
|
|
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
|
|
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?("!=")
|
|
242
|
+
line.lstrip.start_with?("!=")
|
|
269
243
|
end
|
|
270
244
|
|
|
271
245
|
def blank?(value)
|
data/lib/haml2html/diagnostic.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Haml2html
|
|
4
|
-
Diagnostic =
|
|
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?
|
data/lib/haml2html/version.rb
CHANGED
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.
|
|
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-
|
|
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/
|
|
105
|
+
homepage: https://github.com/KDunc11/haml2html
|
|
92
106
|
licenses:
|
|
93
107
|
- MIT
|
|
94
108
|
metadata:
|
|
95
|
-
homepage_uri: https://github.com/
|
|
96
|
-
source_code_uri: https://github.com/
|
|
97
|
-
changelog_uri: https://github.com/
|
|
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.
|
|
120
|
+
version: '3.2'
|
|
107
121
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
122
|
requirements:
|
|
109
123
|
- - ">="
|