herb 0.0.1 → 0.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.
- checksums.yaml +5 -5
- data/{LICENSE → LICENSE.txt} +4 -3
- data/Makefile +121 -0
- data/README.md +102 -107
- data/Rakefile +184 -0
- data/exe/herb +5 -0
- data/ext/herb/error_helpers.c +302 -0
- data/ext/herb/error_helpers.h +15 -0
- data/ext/herb/extconf.rb +75 -0
- data/ext/herb/extension.c +110 -0
- data/ext/herb/extension.h +6 -0
- data/ext/herb/extension_helpers.c +117 -0
- data/ext/herb/extension_helpers.h +24 -0
- data/ext/herb/nodes.c +936 -0
- data/ext/herb/nodes.h +12 -0
- data/herb.gemspec +49 -0
- data/lib/herb/ast/node.rb +61 -0
- data/lib/herb/ast/nodes.rb +1542 -0
- data/lib/herb/ast.rb +6 -0
- data/lib/herb/cli.rb +164 -0
- data/lib/herb/errors.rb +352 -0
- data/lib/herb/lex_result.rb +20 -0
- data/lib/herb/libherb/array.rb +48 -0
- data/lib/herb/libherb/ast_node.rb +47 -0
- data/lib/herb/libherb/buffer.rb +53 -0
- data/lib/herb/libherb/extract_result.rb +17 -0
- data/lib/herb/libherb/lex_result.rb +29 -0
- data/lib/herb/libherb/libherb.rb +49 -0
- data/lib/herb/libherb/parse_result.rb +17 -0
- data/lib/herb/libherb/token.rb +43 -0
- data/lib/herb/libherb.rb +32 -0
- data/lib/herb/location.rb +42 -0
- data/lib/herb/parse_result.rb +26 -0
- data/lib/herb/position.rb +36 -0
- data/lib/herb/project.rb +361 -0
- data/lib/herb/range.rb +40 -0
- data/lib/herb/result.rb +21 -0
- data/lib/herb/token.rb +43 -0
- data/lib/herb/token_list.rb +11 -0
- data/lib/herb/version.rb +5 -0
- data/lib/herb.rb +21 -68
- data/src/analyze.c +989 -0
- data/src/analyze_helpers.c +241 -0
- data/src/analyzed_ruby.c +35 -0
- data/src/array.c +137 -0
- data/src/ast_node.c +81 -0
- data/src/ast_nodes.c +866 -0
- data/src/ast_pretty_print.c +588 -0
- data/src/buffer.c +199 -0
- data/src/errors.c +740 -0
- data/src/extract.c +110 -0
- data/src/herb.c +103 -0
- data/src/html_util.c +143 -0
- data/src/include/analyze.h +36 -0
- data/src/include/analyze_helpers.h +43 -0
- data/src/include/analyzed_ruby.h +33 -0
- data/src/include/array.h +33 -0
- data/src/include/ast_node.h +35 -0
- data/src/include/ast_nodes.h +303 -0
- data/src/include/ast_pretty_print.h +17 -0
- data/src/include/buffer.h +36 -0
- data/src/include/errors.h +125 -0
- data/src/include/extract.h +20 -0
- data/src/include/herb.h +32 -0
- data/src/include/html_util.h +13 -0
- data/src/include/io.h +9 -0
- data/src/include/json.h +28 -0
- data/src/include/lexer.h +13 -0
- data/src/include/lexer_peek_helpers.h +23 -0
- data/src/include/lexer_struct.h +32 -0
- data/src/include/location.h +25 -0
- data/src/include/macros.h +10 -0
- data/src/include/memory.h +12 -0
- data/src/include/parser.h +22 -0
- data/src/include/parser_helpers.h +33 -0
- data/src/include/position.h +22 -0
- data/src/include/pretty_print.h +53 -0
- data/src/include/prism_helpers.h +18 -0
- data/src/include/range.h +23 -0
- data/src/include/ruby_parser.h +6 -0
- data/src/include/token.h +25 -0
- data/src/include/token_matchers.h +21 -0
- data/src/include/token_struct.h +51 -0
- data/src/include/util.h +25 -0
- data/src/include/version.h +6 -0
- data/src/include/visitor.h +11 -0
- data/src/io.c +30 -0
- data/src/json.c +205 -0
- data/src/lexer.c +284 -0
- data/src/lexer_peek_helpers.c +59 -0
- data/src/location.c +41 -0
- data/src/main.c +162 -0
- data/src/memory.c +53 -0
- data/src/parser.c +704 -0
- data/src/parser_helpers.c +161 -0
- data/src/position.c +33 -0
- data/src/pretty_print.c +242 -0
- data/src/prism_helpers.c +50 -0
- data/src/range.c +38 -0
- data/src/ruby_parser.c +47 -0
- data/src/token.c +194 -0
- data/src/token_matchers.c +32 -0
- data/src/util.c +128 -0
- data/src/visitor.c +321 -0
- metadata +126 -82
- data/test/helper.rb +0 -7
- data/test/helpers_test.rb +0 -25
- data/test/parsing_test.rb +0 -110
metadata
CHANGED
@@ -1,88 +1,137 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: herb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
8
|
-
|
9
|
-
bindir: bin
|
7
|
+
- Marco Roth
|
8
|
+
bindir: exe
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
13
|
-
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '5.8'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: minitest-sugar
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '2.1'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '2.1'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rake
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '11.0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '11.0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: rubocop
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0.39'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0.39'
|
69
|
-
description: ERB-like template engine that escapes HTML by default
|
70
|
-
email: frodsan@protonmail.com
|
71
|
-
executables: []
|
72
|
-
extensions: []
|
10
|
+
date: 2025-04-15 00:00:00.000000000 Z
|
11
|
+
dependencies: []
|
12
|
+
description: Powerful and seamless HTML-aware ERB parsing.
|
13
|
+
email:
|
14
|
+
- marco.roth@intergga.ch
|
15
|
+
executables:
|
16
|
+
- herb
|
17
|
+
extensions:
|
18
|
+
- ext/herb/extconf.rb
|
73
19
|
extra_rdoc_files: []
|
74
20
|
files:
|
75
|
-
- LICENSE
|
21
|
+
- LICENSE.txt
|
22
|
+
- Makefile
|
76
23
|
- README.md
|
24
|
+
- Rakefile
|
25
|
+
- exe/herb
|
26
|
+
- ext/herb/error_helpers.c
|
27
|
+
- ext/herb/error_helpers.h
|
28
|
+
- ext/herb/extconf.rb
|
29
|
+
- ext/herb/extension.c
|
30
|
+
- ext/herb/extension.h
|
31
|
+
- ext/herb/extension_helpers.c
|
32
|
+
- ext/herb/extension_helpers.h
|
33
|
+
- ext/herb/nodes.c
|
34
|
+
- ext/herb/nodes.h
|
35
|
+
- herb.gemspec
|
77
36
|
- lib/herb.rb
|
78
|
-
-
|
79
|
-
-
|
80
|
-
-
|
81
|
-
|
37
|
+
- lib/herb/ast.rb
|
38
|
+
- lib/herb/ast/node.rb
|
39
|
+
- lib/herb/ast/nodes.rb
|
40
|
+
- lib/herb/cli.rb
|
41
|
+
- lib/herb/errors.rb
|
42
|
+
- lib/herb/lex_result.rb
|
43
|
+
- lib/herb/libherb.rb
|
44
|
+
- lib/herb/libherb/array.rb
|
45
|
+
- lib/herb/libherb/ast_node.rb
|
46
|
+
- lib/herb/libherb/buffer.rb
|
47
|
+
- lib/herb/libherb/extract_result.rb
|
48
|
+
- lib/herb/libherb/lex_result.rb
|
49
|
+
- lib/herb/libherb/libherb.rb
|
50
|
+
- lib/herb/libherb/parse_result.rb
|
51
|
+
- lib/herb/libherb/token.rb
|
52
|
+
- lib/herb/location.rb
|
53
|
+
- lib/herb/parse_result.rb
|
54
|
+
- lib/herb/position.rb
|
55
|
+
- lib/herb/project.rb
|
56
|
+
- lib/herb/range.rb
|
57
|
+
- lib/herb/result.rb
|
58
|
+
- lib/herb/token.rb
|
59
|
+
- lib/herb/token_list.rb
|
60
|
+
- lib/herb/version.rb
|
61
|
+
- src/analyze.c
|
62
|
+
- src/analyze_helpers.c
|
63
|
+
- src/analyzed_ruby.c
|
64
|
+
- src/array.c
|
65
|
+
- src/ast_node.c
|
66
|
+
- src/ast_nodes.c
|
67
|
+
- src/ast_pretty_print.c
|
68
|
+
- src/buffer.c
|
69
|
+
- src/errors.c
|
70
|
+
- src/extract.c
|
71
|
+
- src/herb.c
|
72
|
+
- src/html_util.c
|
73
|
+
- src/include/analyze.h
|
74
|
+
- src/include/analyze_helpers.h
|
75
|
+
- src/include/analyzed_ruby.h
|
76
|
+
- src/include/array.h
|
77
|
+
- src/include/ast_node.h
|
78
|
+
- src/include/ast_nodes.h
|
79
|
+
- src/include/ast_pretty_print.h
|
80
|
+
- src/include/buffer.h
|
81
|
+
- src/include/errors.h
|
82
|
+
- src/include/extract.h
|
83
|
+
- src/include/herb.h
|
84
|
+
- src/include/html_util.h
|
85
|
+
- src/include/io.h
|
86
|
+
- src/include/json.h
|
87
|
+
- src/include/lexer.h
|
88
|
+
- src/include/lexer_peek_helpers.h
|
89
|
+
- src/include/lexer_struct.h
|
90
|
+
- src/include/location.h
|
91
|
+
- src/include/macros.h
|
92
|
+
- src/include/memory.h
|
93
|
+
- src/include/parser.h
|
94
|
+
- src/include/parser_helpers.h
|
95
|
+
- src/include/position.h
|
96
|
+
- src/include/pretty_print.h
|
97
|
+
- src/include/prism_helpers.h
|
98
|
+
- src/include/range.h
|
99
|
+
- src/include/ruby_parser.h
|
100
|
+
- src/include/token.h
|
101
|
+
- src/include/token_matchers.h
|
102
|
+
- src/include/token_struct.h
|
103
|
+
- src/include/util.h
|
104
|
+
- src/include/version.h
|
105
|
+
- src/include/visitor.h
|
106
|
+
- src/io.c
|
107
|
+
- src/json.c
|
108
|
+
- src/lexer.c
|
109
|
+
- src/lexer_peek_helpers.c
|
110
|
+
- src/location.c
|
111
|
+
- src/main.c
|
112
|
+
- src/memory.c
|
113
|
+
- src/parser.c
|
114
|
+
- src/parser_helpers.c
|
115
|
+
- src/position.c
|
116
|
+
- src/pretty_print.c
|
117
|
+
- src/prism_helpers.c
|
118
|
+
- src/range.c
|
119
|
+
- src/ruby_parser.c
|
120
|
+
- src/token.c
|
121
|
+
- src/token_matchers.c
|
122
|
+
- src/util.c
|
123
|
+
- src/visitor.c
|
124
|
+
homepage: https://herb-tools.dev
|
82
125
|
licenses:
|
83
126
|
- MIT
|
84
|
-
metadata:
|
85
|
-
|
127
|
+
metadata:
|
128
|
+
allowed_push_host: https://rubygems.org
|
129
|
+
rubygems_mfa_required: 'true'
|
130
|
+
homepage_uri: https://herb-tools.dev
|
131
|
+
changelog_uri: https://github.com/marcoroth/herb/releases
|
132
|
+
source_code_uri: https://github.com/marcoroth/herb
|
133
|
+
bug_tracker_uri: https://github.com/marcoroth/herb/issues
|
134
|
+
documentation_uri: https://docs.herb-tools.dev
|
86
135
|
rdoc_options: []
|
87
136
|
require_paths:
|
88
137
|
- lib
|
@@ -90,19 +139,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
90
139
|
requirements:
|
91
140
|
- - ">="
|
92
141
|
- !ruby/object:Gem::Version
|
93
|
-
version:
|
142
|
+
version: 3.0.0
|
94
143
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
144
|
requirements:
|
96
145
|
- - ">="
|
97
146
|
- !ruby/object:Gem::Version
|
98
147
|
version: '0'
|
99
148
|
requirements: []
|
100
|
-
|
101
|
-
rubygems_version: 2.5.1
|
102
|
-
signing_key:
|
149
|
+
rubygems_version: 3.6.2
|
103
150
|
specification_version: 4
|
104
|
-
summary:
|
105
|
-
test_files:
|
106
|
-
- test/helper.rb
|
107
|
-
- test/helpers_test.rb
|
108
|
-
- test/parsing_test.rb
|
151
|
+
summary: Powerful and seamless HTML-aware ERB parsing.
|
152
|
+
test_files: []
|
data/test/helper.rb
DELETED
data/test/helpers_test.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "helper"
|
4
|
-
|
5
|
-
class HelpersTest < Minitest::Test
|
6
|
-
include Herb::Helpers
|
7
|
-
|
8
|
-
setup do
|
9
|
-
herb_cache.clear
|
10
|
-
end
|
11
|
-
|
12
|
-
def foo
|
13
|
-
"foo"
|
14
|
-
end
|
15
|
-
|
16
|
-
test "using functions in the context" do
|
17
|
-
assert_equal("foo\n", herb("test/views/foo.erb"))
|
18
|
-
end
|
19
|
-
|
20
|
-
test "passing in a context" do
|
21
|
-
assert_raises(NameError) do
|
22
|
-
herb("test/views/foo.erb", {}, TOPLEVEL_BINDING)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
data/test/parsing_test.rb
DELETED
@@ -1,110 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "helper"
|
4
|
-
|
5
|
-
class ParsingTest < Minitest::Test
|
6
|
-
test "assignment" do
|
7
|
-
template = Herb.parse("<%= 1 + 2 %>")
|
8
|
-
|
9
|
-
assert_equal("3", template.call)
|
10
|
-
end
|
11
|
-
|
12
|
-
test "control flow" do
|
13
|
-
template = <<-EOT.gsub(/ {4}/, "")
|
14
|
-
<% if false %>
|
15
|
-
false
|
16
|
-
<% else %>
|
17
|
-
true
|
18
|
-
<% end %>
|
19
|
-
EOT
|
20
|
-
|
21
|
-
result = Herb.parse(template).call
|
22
|
-
|
23
|
-
assert_equal(" true\n", result)
|
24
|
-
end
|
25
|
-
|
26
|
-
test "parameters" do
|
27
|
-
template = <<-EOT.gsub(/ {4}/, "")
|
28
|
-
<% params[:n].times do %>
|
29
|
-
*
|
30
|
-
<% end %>
|
31
|
-
EOT
|
32
|
-
|
33
|
-
example = Herb.parse(template)
|
34
|
-
|
35
|
-
assert_equal("*\n*\n*\n", example[n: 3])
|
36
|
-
assert_equal("*\n*\n*\n*\n", example[n: 4])
|
37
|
-
end
|
38
|
-
|
39
|
-
test "multiline" do
|
40
|
-
example = Herb.parse("The\nMan\nAnd\n<%=\"The\"%>\nSea")
|
41
|
-
|
42
|
-
assert_equal("The\nMan\nAnd\nThe\nSea", example.call)
|
43
|
-
end
|
44
|
-
|
45
|
-
test "quotes" do
|
46
|
-
example = Herb.parse("'foo' 'bar' 'baz'")
|
47
|
-
|
48
|
-
assert_equal("'foo' 'bar' 'baz'", example.call)
|
49
|
-
end
|
50
|
-
|
51
|
-
test "context" do
|
52
|
-
context = Object.new
|
53
|
-
|
54
|
-
def context.user
|
55
|
-
"Bruno"
|
56
|
-
end
|
57
|
-
|
58
|
-
example = Herb.parse("<%= user %>", [], context)
|
59
|
-
|
60
|
-
assert_equal("Bruno", example.call)
|
61
|
-
end
|
62
|
-
|
63
|
-
test "locals" do
|
64
|
-
example = Herb.parse("<%= user %>", [:user], self)
|
65
|
-
|
66
|
-
assert_equal("Mayn", example.call(user: "Mayn"))
|
67
|
-
end
|
68
|
-
|
69
|
-
test "nil" do
|
70
|
-
example = Herb.parse("<%= params[:user] %>", [], TOPLEVEL_BINDING)
|
71
|
-
|
72
|
-
assert_equal("", example.call(user: nil))
|
73
|
-
end
|
74
|
-
|
75
|
-
test "multi-line" do
|
76
|
-
template = <<-EOT.gsub(/^ /, "")
|
77
|
-
<%
|
78
|
-
# Multiline code evaluation
|
79
|
-
lucky = [1, 3, 7, 9, 13, 15]
|
80
|
-
prime = [2, 3, 5, 7, 11, 13]
|
81
|
-
%>
|
82
|
-
|
83
|
-
<%= lucky & prime %>
|
84
|
-
EOT
|
85
|
-
|
86
|
-
example = Herb.parse(template)
|
87
|
-
|
88
|
-
assert_equal "\n[3, 7, 13]\n", example.call
|
89
|
-
end
|
90
|
-
|
91
|
-
test "escapes by default" do
|
92
|
-
text = %q(<>&"')
|
93
|
-
|
94
|
-
template = Herb.parse("<%= params[:text] %>")
|
95
|
-
|
96
|
-
result = template.call(text: text)
|
97
|
-
|
98
|
-
assert_equal("<>&'"", result)
|
99
|
-
end
|
100
|
-
|
101
|
-
test "no escaping please" do
|
102
|
-
text = %q(<>&"')
|
103
|
-
|
104
|
-
template = Herb.parse("<%== params[:text] %>")
|
105
|
-
|
106
|
-
result = template.call(text: text)
|
107
|
-
|
108
|
-
assert_equal(text, result)
|
109
|
-
end
|
110
|
-
end
|