gtx 0.1.0 → 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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +8 -12
  3. data/lib/gtx/version.rb +1 -1
  4. data/lib/gtx.rb +7 -7
  5. metadata +30 -13
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dbf48aaa95d8b915bf90f634babcbf37ef5b95527000b84677f273cde39fa8a5
4
- data.tar.gz: f95cae7c6a9b04b5de554a2600040fe943a628667d0601a2e8afdbf1745b8c4c
3
+ metadata.gz: 6f01ace96e00c867836897ecd1c76f503df9b8344c2a06ee44abe511cf5bc62a
4
+ data.tar.gz: 528d2d6765b76f4d189394070768adedff88779e76344e3a2f842fd52db5aff0
5
5
  SHA512:
6
- metadata.gz: a7929b4d3985d2a146dac93693f51a74ea78d8745505980fb717e0fbd4c32ad07b7ac5d60ea202a030ff742631666ea0a3b1cdc2c1607c6f192aeb913fa0ec4b
7
- data.tar.gz: b9e3b4427d0d4f23fa6130cbf2bf73f531cf7fcc1f3465fa405852b434b7554c8d04fefda00725662e3124f2e685c543b5bed8025fa384864b11b0a63629e604
6
+ metadata.gz: bf373ff47416c5117a493e4b5bffabb36da01d758375a073eacbdb8578a5b898768d1998ce8235926a22c21a0e3367f641b0f724f2dc9b6a67524c7ae39f56b8
7
+ data.tar.gz: b7b9d3372cb703654f27d8a87053e38c6d672e6e91d22dc385ed2426e47131ef278247e78cbb0d63ee6f25ab274028204bd80112632ca284f3436ae4b5995069
data/README.md CHANGED
@@ -1,10 +1,5 @@
1
1
  # GTX - Minimal Template Engine
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/gtx.svg)](https://badge.fury.io/rb/gtx)
4
- [![Build Status](https://github.com/DannyBen/gtx/workflows/Test/badge.svg)](https://github.com/DannyBen/gtx/actions?query=workflow%3ATest)
5
-
6
- ---
7
-
8
3
  GTX is a minimal template engine that transpiles to ERB before using it to
9
4
  generate the output.
10
5
 
@@ -56,8 +51,8 @@ loopy text <%= i + 1 %>
56
51
 
57
52
  </td></tr></table>
58
53
 
59
- The conversion is specifically kept at 1:1 ratio, so that the correct line number
60
- can be referenced in case of an error.
54
+ The conversion is specifically kept at 1:1 line ratio, so that the correct line
55
+ number can be referenced in case of an error.
61
56
 
62
57
  ### Explanation
63
58
 
@@ -87,7 +82,7 @@ that is expected to be a part of the output.
87
82
  Any other line, will be treated as Ruby code and will be enclosed using ERB's
88
83
  `<%- ... -%>` syntax.
89
84
 
90
- See the [example template](examples/full.rb) for additional nuances.
85
+ See the [example template](examples/full.gtx) for additional nuances.
91
86
 
92
87
  ## Usage
93
88
 
@@ -138,9 +133,9 @@ GTX.render string, context: optional_object, filename: optional_filename
138
133
  ## But... why?
139
134
 
140
135
  GTX was created to provide a code-first alternative to ERB, specifically for
141
- the code generation templates used by [Bashly][bashly]. Enclosing Ruby code
142
- inside ERB tags, and ensuring there are no excess empty lines in the ERB
143
- template yielded some hard-to-maintain templates.
136
+ the [code generation templates][bashly-views] used by [Bashly][bashly].
137
+ Enclosing Ruby code inside ERB tags, and ensuring there are no excess empty
138
+ lines in the ERB template yielded some hard-to-maintain templates.
144
139
 
145
140
 
146
141
  ## Contributing / Support
@@ -150,6 +145,7 @@ to contribute, feel free to [open an issue][issues].
150
145
 
151
146
  ---
152
147
 
153
- [issues]: https://github.com/DannyBen/gtx/issues
148
+ [issues]: https://github.com/bashly-framework/gtx/issues
154
149
  [bashly]: https://bashly.dannyb.co/
150
+ [bashly-views]: https://github.com/DannyBen/bashly/tree/master/lib/bashly/views
155
151
 
data/lib/gtx/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class GTX
2
- VERSION = "0.1.0"
2
+ VERSION = '0.1.2'
3
3
  end
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: (filename || path)
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, @filename = template, filename
21
+ @template = template
22
+ @filename = filename
22
23
  end
23
24
 
24
25
  def erb_source
25
- template.each_line.map do |line|
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,34 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gtx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Ben Shitrit
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2022-06-13 00:00:00.000000000 Z
12
- dependencies: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: erb
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '4.0'
19
+ - - "<"
20
+ - !ruby/object:Gem::Version
21
+ version: '7'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: '4.0'
29
+ - - "<"
30
+ - !ruby/object:Gem::Version
31
+ version: '7'
13
32
  description: Create templates that transpile to ERB
14
33
  email: db@dannyben.com
15
34
  executables: []
@@ -19,15 +38,14 @@ files:
19
38
  - README.md
20
39
  - lib/gtx.rb
21
40
  - lib/gtx/version.rb
22
- homepage: https://github.com/dannyben/gtx
41
+ homepage: https://github.com/bashly-framework/gtx
23
42
  licenses:
24
43
  - MIT
25
44
  metadata:
26
- bug_tracker_uri: https://github.com/DannyBen/gtx/issues
27
- changelog_uri: https://github.com/DannyBen/gtx/blob/master/CHANGELOG.md
28
- homepage_uri: https://github.com/dannyben/gtx
29
- source_code_uri: https://github.com/dannyben/gtx
30
- post_install_message:
45
+ bug_tracker_uri: https://github.com/bashly-framework/gtx/issues
46
+ changelog_uri: https://github.com/bashly-framework/gtx/blob/master/CHANGELOG.md
47
+ source_code_uri: https://github.com/bashly-framework/gtx
48
+ rubygems_mfa_required: 'true'
31
49
  rdoc_options: []
32
50
  require_paths:
33
51
  - lib
@@ -35,15 +53,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
35
53
  requirements:
36
54
  - - ">="
37
55
  - !ruby/object:Gem::Version
38
- version: 2.7.0
56
+ version: '3.2'
39
57
  required_rubygems_version: !ruby/object:Gem::Requirement
40
58
  requirements:
41
59
  - - ">="
42
60
  - !ruby/object:Gem::Version
43
61
  version: '0'
44
62
  requirements: []
45
- rubygems_version: 3.3.14
46
- signing_key:
63
+ rubygems_version: 4.0.3
47
64
  specification_version: 4
48
65
  summary: GTX Template Engine
49
66
  test_files: []