brb-templates 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 95c2115da0e8d5c63faf5b616b15ffc0bfb69ace0fc3acb03ad79da917f6b28d
4
- data.tar.gz: 239cd354e9a666dd3d8a883d8ac44f8fa091bb909245785083cc320ee5d8729f
3
+ metadata.gz: 6e97cdefdd6b330fb27d992b001da7ce8da38972a53d0637c685e0cd49bfa984
4
+ data.tar.gz: b32f4fbeeeb03c988df6ff174f3f3678043d498c9421c0ff5de34b7a1c3b9545
5
5
  SHA512:
6
- metadata.gz: d5d04521fa9d22453e408d140dd2a0702345081c5e2cace1649f0b5d9e7d3dab7fcc9225d5a3190ce357e12c99d8589c377d7772a81a4d34a2c44df6fd383c40
7
- data.tar.gz: b04b179f4989a1c2f6377bd432e7b8a6c5d4a8529c8525651158dfafe70030c10a1745e392c50afe313ae2e0ba8fad18ca8346bbffd5bdd5737a58db7347d642
6
+ metadata.gz: 01a26f45b62b7d5e7649fca6086096ec65255179d33d81d26f2142da23b68dd5ba4c26d801bf88d85aa594afcceddc632db8df7d7eaa5f34184245bf1ceb35d8
7
+ data.tar.gz: 7ac2bb29e62e7bfb64dbce22dccfe8439203a8b8ff45a81d5d8c728da550a152a825981c70a4e9bc10ed28edef4313e2469f89c386b373164868052a5ca95ac6
data/README.md CHANGED
@@ -91,11 +91,11 @@ Bundle BRB and call `BRB.enable` during your Rails app boot to use it.
91
91
 
92
92
  Install the gem and add to the application's Gemfile by executing:
93
93
 
94
- $ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
94
+ $ bundle add brb-templates
95
95
 
96
96
  If bundler is not being used to manage dependencies, install the gem by executing:
97
97
 
98
- $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
98
+ $ gem install brb-templates
99
99
 
100
100
  ## Development
101
101
 
@@ -0,0 +1 @@
1
+ require_relative "../brb"
data/lib/brb/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BRB
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
data/lib/brb.rb CHANGED
@@ -13,7 +13,7 @@ module BRB
13
13
  @logger = Logger.new "/dev/null"
14
14
  def self.debug = @logger = Logger.new(STDOUT)
15
15
 
16
- def self.enable = ActionView::Template::Handlers::ERB.erb_implementation = BRB::Erubi
16
+ def self.enable = ActionView::Template::Handlers::ERB.erb_implementation = BRB::Parser
17
17
 
18
18
  module Sigil
19
19
  def self.names = @values.keys
@@ -21,14 +21,27 @@ module BRB
21
21
 
22
22
  def self.replace(scanner, key)
23
23
  @values.fetch(key).then do |template|
24
- if (key == "t" && scanner.scan(/(\.[\.\w]+)/)) || scanner.scan(/\((.*?)\)/)
25
- template.sub ":value", scanner[1]
24
+ case
25
+ when key == "t" && scanner.scan(/\.[\.\w]+/) then template.sub ":value", scanner.matched
26
+ when scanner.check(/\(/) then template.sub ":value", scan_arguments(scanner)
26
27
  else
27
28
  template
28
29
  end
29
30
  end
30
31
  end
31
32
 
33
+ def self.scan_arguments(scanner)
34
+ arguments, open_parens = +"", 0
35
+
36
+ begin
37
+ arguments << scanner.scan_until(/\(|\)/)
38
+ open_parens += arguments.last == "(" ? 1 : -1
39
+ end until open_parens.zero?
40
+
41
+ arguments[1..-2]
42
+ end
43
+
44
+
32
45
  def self.register(key, replacer)
33
46
  @values[key.to_s] = replacer
34
47
  end
@@ -45,7 +58,7 @@ module BRB
45
58
  end_of_lorem
46
59
  end
47
60
 
48
- class Erubi < ::ActionView::Template::Handlers::ERB::Erubi
61
+ class Parser < ::ActionView::Template::Handlers::ERB::Erubi
49
62
  def initialize(input, ...)
50
63
  frontmatter = $1 if input.sub! /\A(.*?)~~~\n/m, ""
51
64
  backmatter = $1 if input.sub! /~~~\n(.*?)\z/m, ""
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brb-templates
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kasper Timm Hansen
@@ -51,6 +51,7 @@ files:
51
51
  - README.md
52
52
  - Rakefile
53
53
  - lib/brb.rb
54
+ - lib/brb/templates.rb
54
55
  - lib/brb/version.rb
55
56
  homepage: https://github.com/kaspth/brb
56
57
  licenses:
@@ -75,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
76
  - !ruby/object:Gem::Version
76
77
  version: '0'
77
78
  requirements: []
78
- rubygems_version: 3.5.3
79
+ rubygems_version: 3.5.4
79
80
  signing_key:
80
81
  specification_version: 4
81
82
  summary: BRB is backslashed Ruby, a template system that lets you be-right-back to