braai 1.1.1 → 1.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.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- braai (1.1.0)
4
+ braai (1.1.2)
5
5
  activesupport
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -25,25 +25,25 @@ Braai comes shipped with two simple matchers for you, but you can easily add you
25
25
 
26
26
  The first matcher is a simple <code>to_s</code> matcher. It will match a single variable and then call <code>to_s</code> on it:
27
27
 
28
- <pre><code>
28
+ ```ruby
29
29
  template = "Hi {{ name }}!"
30
30
  response = Braai::Template.new(template).render(name: "Mark")
31
31
  response.should eql "Hi Mark!"
32
- </code></pre>
32
+ ```
33
33
 
34
34
  The second matcher will call a method on the variable.
35
35
 
36
- <pre><code>
36
+ ```ruby
37
37
  template = "Hi {{ name.upcase }}!"
38
38
  response = Braai::Template.new(template).render(name: "Mark")
39
39
  response.should eql "Hi MARK!"
40
- </code></pre>
40
+ ```
41
41
 
42
42
  ### Custom Matchers
43
43
 
44
44
  Braai let's you easily define your own matchers to do whatever you would like to do.
45
45
 
46
- <pre><code>
46
+ ```ruby
47
47
  template = "I'm {{ name }} and {{ mmm... bbq }}!"
48
48
  Braai::Template.map(/({{\s*mmm\.\.\. bbq\s*}})/i) do |template, key, matches|
49
49
  "Damn, I love BBQ!"
@@ -55,13 +55,13 @@ end
55
55
 
56
56
  response = Braai::Template.new(template).render(name: "mark")
57
57
  response.should eql "I'm MARK and Damn, I love BBQ!!"
58
- </code></pre>
58
+ ```
59
59
 
60
60
  ### For Loops
61
61
 
62
62
  Braai supports looping right out of the box.
63
63
 
64
- <pre><code>
64
+ ```ruby
65
65
  template = &lt;&lt;-EOF
66
66
  &lt;h1>{{ greet }}&lt;/h1>
67
67
  &lt;ul>
@@ -85,7 +85,7 @@ res.should match("&lt;li>truck&lt;/li>")
85
85
  res.should match("&lt;p>apple&lt;/p>")
86
86
  res.should match("&lt;p>orange&lt;/p>")
87
87
  res.should match("&lt;h2>MARK&lt;/h2>")
88
- </code></pre>
88
+ ```
89
89
 
90
90
  ## Contributing
91
91
 
@@ -94,3 +94,8 @@ res.should match("&lt;h2>MARK&lt;/h2>")
94
94
  3. Commit your changes (`git commit -am 'Add some feature'`)
95
95
  4. Push to the branch (`git push origin my-new-feature`)
96
96
  5. Create new Pull Request
97
+
98
+ ## Contributers
99
+
100
+ * Mark Bates
101
+ * Kevin Incorvia
data/lib/braai/context.rb CHANGED
@@ -16,7 +16,7 @@ class Braai::Context
16
16
  regex = Regexp.new(regex)
17
17
  matches = self.template.scan(regex)
18
18
  matches.each do |set|
19
- set = [set].flatten.map {|m| m.strip}
19
+ set = [set].flatten.map {|m| m.strip unless m.nil? }
20
20
  val = matcher.call(self, set[0], set)
21
21
  self.template.gsub!(set[0], val.to_s) if val
22
22
  end
@@ -29,4 +29,4 @@ class Braai::Context
29
29
  end
30
30
  end
31
31
 
32
- end
32
+ end
data/lib/braai/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Braai
2
- VERSION = "1.1.1"
2
+ VERSION = "1.1.2"
3
3
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Braai::Template do
4
-
4
+
5
5
  let(:greet_regex) { /^greet$/i }
6
6
  let(:greet_matcher) do
7
7
  ->(view, key, matches) {
@@ -16,7 +16,7 @@ describe Braai::Template do
16
16
  Braai::Template.map(greet_regex, &greet_matcher)
17
17
  Braai::Template.matchers.should have_key(greet_regex.to_s)
18
18
  end
19
-
19
+
20
20
  end
21
21
 
22
22
  describe '#render' do
@@ -24,7 +24,7 @@ describe Braai::Template do
24
24
  before(:each) do
25
25
  Braai::Template.map(greet_regex, &greet_matcher)
26
26
  end
27
-
27
+
28
28
  it "renders a simple template" do
29
29
  res = Braai::Template.new("{{ greet }}").render(greet: "Hi Mark")
30
30
  res.should eql("Hi Mark")
@@ -36,8 +36,33 @@ describe Braai::Template do
36
36
  res.should eql("<h1>Hi Mark</h1><h2>Hi Mark</h2>")
37
37
  end
38
38
 
39
+ context 'matches' do
40
+
41
+ context 'multimatches' do
42
+
43
+ let(:multi_regex) { /({{\s*(greet)\s*(mark)?\s*}})/ }
44
+ let(:multi_matcher) do
45
+ ->(view, key, matches) {
46
+ "#{matches[1]}#{matches[2]}"
47
+ }
48
+ end
49
+
50
+ before(:each) do
51
+ Braai::Template.map(multi_regex, &multi_matcher)
52
+ end
53
+
54
+ it "allows nil matches" do
55
+ template = "<h1>{{ greet }}</h1><h2>{{ greet mark }}</h2>"
56
+ res = Braai::Template.new(template).render
57
+ res.should eql("<h1>greet</h1><h2>greetmark</h2>")
58
+ end
59
+
60
+ end
61
+
62
+ end
63
+
39
64
  context "for loops" do
40
-
65
+
41
66
  let(:template) do
42
67
  <<-EOF
43
68
  <h1>{{ greet }}</h1>
@@ -69,7 +94,7 @@ EOF
69
94
  end
70
95
 
71
96
  context "default matcher" do
72
-
97
+
73
98
  let(:template) { "{{ greet }} {{ name.upcase }}" }
74
99
 
75
100
  it "uses the default matcher to render" do
@@ -85,17 +110,17 @@ EOF
85
110
  end
86
111
 
87
112
  context "matcher errors" do
88
-
113
+
89
114
  before(:each) do
90
115
  Braai::Template.map(/foo/) do |view, key, matches|
91
- raise ArgumentError
116
+ raise ArgumentError
92
117
  end
93
118
  end
94
119
 
95
120
  let(:template) { "foo" }
96
121
 
97
122
  context "swallow_matcher_errors is true" do
98
-
123
+
99
124
  it "swallows errors in the matcher" do
100
125
  expect {
101
126
  res = Braai::Template.new(template).render()
@@ -109,7 +134,7 @@ EOF
109
134
  before(:each) do
110
135
  Braai.config.swallow_matcher_errors = false
111
136
  end
112
-
137
+
113
138
  it "raises the errors from the matcher" do
114
139
  expect {
115
140
  res = Braai::Template.new(template).render
@@ -122,4 +147,4 @@ EOF
122
147
 
123
148
  end
124
149
 
125
- end
150
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: braai
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-26 00:00:00.000000000 Z
12
+ date: 2012-10-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport