gtx 0.1.0 → 0.1.1
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/README.md +8 -6
- data/lib/gtx/version.rb +1 -1
- data/lib/gtx.rb +7 -7
- metadata +23 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 446e58fe7bda41bc25c52f8c016e8ba28872eec6730613cd771e1a0b822c7cf5
|
4
|
+
data.tar.gz: 1acf529b5a6857875ba43d04d0e23239afb2d34286a87f40c078792534c2f02a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 72c0358a893e02b3b366f8eae4e27dfeda5e97dca505fe30ba4681254fdb096b9126edc16e66594a7eb24e4b8bb79ee1cd73a47e452920220226dc66fa269552
|
7
|
+
data.tar.gz: d20f9ba23d67cd5576d77ce1fc4965d7e99f6303265b6213d7099cc6159b10374fc2abe5622e84b5147a7cfc808037d8112753088142eebbccf1ac9d8ea80b1e
|
data/README.md
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
[](https://badge.fury.io/rb/gtx)
|
4
4
|
[](https://github.com/DannyBen/gtx/actions?query=workflow%3ATest)
|
5
|
+
[](https://codeclimate.com/github/DannyBen/gtx/maintainability)
|
5
6
|
|
6
7
|
---
|
7
8
|
|
@@ -56,8 +57,8 @@ loopy text <%= i + 1 %>
|
|
56
57
|
|
57
58
|
</td></tr></table>
|
58
59
|
|
59
|
-
The conversion is specifically kept at 1:1 ratio, so that the correct line
|
60
|
-
can be referenced in case of an error.
|
60
|
+
The conversion is specifically kept at 1:1 line ratio, so that the correct line
|
61
|
+
number can be referenced in case of an error.
|
61
62
|
|
62
63
|
### Explanation
|
63
64
|
|
@@ -87,7 +88,7 @@ that is expected to be a part of the output.
|
|
87
88
|
Any other line, will be treated as Ruby code and will be enclosed using ERB's
|
88
89
|
`<%- ... -%>` syntax.
|
89
90
|
|
90
|
-
See the [example template](examples/full.
|
91
|
+
See the [example template](examples/full.gtx) for additional nuances.
|
91
92
|
|
92
93
|
## Usage
|
93
94
|
|
@@ -138,9 +139,9 @@ GTX.render string, context: optional_object, filename: optional_filename
|
|
138
139
|
## But... why?
|
139
140
|
|
140
141
|
GTX was created to provide a code-first alternative to ERB, specifically for
|
141
|
-
the code generation templates used by [Bashly][bashly].
|
142
|
-
inside ERB tags, and ensuring there are no excess empty
|
143
|
-
template yielded some hard-to-maintain templates.
|
142
|
+
the [code generation templates][bashly-views] used by [Bashly][bashly].
|
143
|
+
Enclosing Ruby code inside ERB tags, and ensuring there are no excess empty
|
144
|
+
lines in the ERB template yielded some hard-to-maintain templates.
|
144
145
|
|
145
146
|
|
146
147
|
## Contributing / Support
|
@@ -152,4 +153,5 @@ to contribute, feel free to [open an issue][issues].
|
|
152
153
|
|
153
154
|
[issues]: https://github.com/DannyBen/gtx/issues
|
154
155
|
[bashly]: https://bashly.dannyb.co/
|
156
|
+
[bashly-views]: https://github.com/DannyBen/bashly/tree/master/lib/bashly/views
|
155
157
|
|
data/lib/gtx/version.rb
CHANGED
data/lib/gtx.rb
CHANGED
@@ -7,7 +7,7 @@ class GTX
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def load_file(path, filename: nil)
|
10
|
-
new File.read(path), filename:
|
10
|
+
new File.read(path), filename: filename || path
|
11
11
|
end
|
12
12
|
|
13
13
|
def render_file(path, context: nil, filename: nil)
|
@@ -18,11 +18,12 @@ class GTX
|
|
18
18
|
attr_reader :template, :filename
|
19
19
|
|
20
20
|
def initialize(template, filename: nil)
|
21
|
-
@template
|
21
|
+
@template = template
|
22
|
+
@filename = filename
|
22
23
|
end
|
23
24
|
|
24
25
|
def erb_source
|
25
|
-
template.
|
26
|
+
template.strip.lines.map do |line|
|
26
27
|
case line
|
27
28
|
when /^\s*> ?(.*)/ then eval_vars $1
|
28
29
|
when /^\s*= ?(.*)/ then "<%= #{eval_vars $1.strip} %>"
|
@@ -34,7 +35,7 @@ class GTX
|
|
34
35
|
def erb
|
35
36
|
ERB.new(erb_source, trim_mode: '-').tap { |a| a.filename = filename }
|
36
37
|
end
|
37
|
-
|
38
|
+
|
38
39
|
def parse(context = nil)
|
39
40
|
context ||= self
|
40
41
|
context = context.instance_eval { binding } unless context.is_a? Binding
|
@@ -45,8 +46,7 @@ protected
|
|
45
46
|
|
46
47
|
def eval_vars(string)
|
47
48
|
string.gsub(/{{([^{].*?)}}/, '<%=\1%>')
|
48
|
-
.gsub(
|
49
|
-
.gsub(
|
49
|
+
.gsub('\\}\\}', '}}')
|
50
|
+
.gsub('\\{\\{', '{{')
|
50
51
|
end
|
51
|
-
|
52
52
|
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gtx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Danny Ben Shitrit
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
11
|
+
date: 2024-11-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: erb
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.0'
|
13
27
|
description: Create templates that transpile to ERB
|
14
28
|
email: db@dannyben.com
|
15
29
|
executables: []
|
@@ -25,9 +39,9 @@ licenses:
|
|
25
39
|
metadata:
|
26
40
|
bug_tracker_uri: https://github.com/DannyBen/gtx/issues
|
27
41
|
changelog_uri: https://github.com/DannyBen/gtx/blob/master/CHANGELOG.md
|
28
|
-
homepage_uri: https://github.com/dannyben/gtx
|
29
42
|
source_code_uri: https://github.com/dannyben/gtx
|
30
|
-
|
43
|
+
rubygems_mfa_required: 'true'
|
44
|
+
post_install_message:
|
31
45
|
rdoc_options: []
|
32
46
|
require_paths:
|
33
47
|
- lib
|
@@ -35,15 +49,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
35
49
|
requirements:
|
36
50
|
- - ">="
|
37
51
|
- !ruby/object:Gem::Version
|
38
|
-
version:
|
52
|
+
version: '3.0'
|
39
53
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
40
54
|
requirements:
|
41
55
|
- - ">="
|
42
56
|
- !ruby/object:Gem::Version
|
43
57
|
version: '0'
|
44
58
|
requirements: []
|
45
|
-
rubygems_version: 3.
|
46
|
-
signing_key:
|
59
|
+
rubygems_version: 3.5.22
|
60
|
+
signing_key:
|
47
61
|
specification_version: 4
|
48
62
|
summary: GTX Template Engine
|
49
63
|
test_files: []
|