braai 1.1.2 → 1.2.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.
- data/Gemfile.lock +1 -1
- data/README.md +16 -16
- data/lib/braai/matchers.rb +2 -2
- data/lib/braai/version.rb +1 -1
- data/spec/braai/template_spec.rb +18 -1
- metadata +2 -2
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -62,29 +62,29 @@ response.should eql "I'm MARK and Damn, I love BBQ!!"
|
|
62
62
|
Braai supports looping right out of the box.
|
63
63
|
|
64
64
|
```ruby
|
65
|
-
template =
|
66
|
-
|
67
|
-
|
65
|
+
template = <<-EOF
|
66
|
+
<h1>{{ greet }}</h1>
|
67
|
+
<ul>
|
68
68
|
{{ for product in products }}
|
69
|
-
|
69
|
+
<li>{{ product }}</li>
|
70
70
|
{{ /for }}
|
71
|
-
|
72
|
-
|
71
|
+
</ul>
|
72
|
+
<div>
|
73
73
|
{{ for food in foods }}
|
74
|
-
|
74
|
+
<p>{{ food }}</p>
|
75
75
|
{{ /for }}
|
76
|
-
|
77
|
-
|
76
|
+
</div>
|
77
|
+
<h2>{{greet.upcase}}</h2>
|
78
78
|
EOF
|
79
79
|
|
80
80
|
res = Braai::Template.new(template).render(greet: "mark", products: %w{car boat truck}, foods: %w{apple orange})
|
81
|
-
res.should match("
|
82
|
-
res.should match("
|
83
|
-
res.should match("
|
84
|
-
res.should match("
|
85
|
-
res.should match("
|
86
|
-
res.should match("
|
87
|
-
res.should match("
|
81
|
+
res.should match("<h1>mark</h1>")
|
82
|
+
res.should match("<li>car</li>")
|
83
|
+
res.should match("<li>boat</li>")
|
84
|
+
res.should match("<li>truck</li>")
|
85
|
+
res.should match("<p>apple</p>")
|
86
|
+
res.should match("<p>orange</p>")
|
87
|
+
res.should match("<h2>MARK</h2>")
|
88
88
|
```
|
89
89
|
|
90
90
|
## Contributing
|
data/lib/braai/matchers.rb
CHANGED
@@ -4,8 +4,8 @@ module Braai::Matchers
|
|
4
4
|
@matchers ||= reset!
|
5
5
|
end
|
6
6
|
|
7
|
-
def map(regex, &block)
|
8
|
-
@matchers = {regex.to_s => block}.merge(self.matchers)
|
7
|
+
def map(regex, handler = nil, &block)
|
8
|
+
@matchers = {regex.to_s => handler || block}.merge(self.matchers)
|
9
9
|
end
|
10
10
|
|
11
11
|
def unmap(regex)
|
data/lib/braai/version.rb
CHANGED
data/spec/braai/template_spec.rb
CHANGED
@@ -2,6 +2,12 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Braai::Template do
|
4
4
|
|
5
|
+
class GreetHandler
|
6
|
+
def self.call(template, key, matches)
|
7
|
+
template.attributes[:greet].upcase
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
5
11
|
let(:greet_regex) { /^greet$/i }
|
6
12
|
let(:greet_matcher) do
|
7
13
|
->(view, key, matches) {
|
@@ -17,19 +23,30 @@ describe Braai::Template do
|
|
17
23
|
Braai::Template.matchers.should have_key(greet_regex.to_s)
|
18
24
|
end
|
19
25
|
|
26
|
+
it "takes a class that responds to call" do
|
27
|
+
Braai::Template.map(greet_regex, GreetHandler)
|
28
|
+
Braai::Template.matchers.should have_key(greet_regex.to_s)
|
29
|
+
end
|
30
|
+
|
20
31
|
end
|
21
32
|
|
22
33
|
describe '#render' do
|
23
34
|
|
24
35
|
before(:each) do
|
25
36
|
Braai::Template.map(greet_regex, &greet_matcher)
|
37
|
+
Braai::Template.map(/{{ greetings }}/i, GreetHandler)
|
26
38
|
end
|
27
39
|
|
28
|
-
it "renders a simple template" do
|
40
|
+
it "renders a simple template using a block" do
|
29
41
|
res = Braai::Template.new("{{ greet }}").render(greet: "Hi Mark")
|
30
42
|
res.should eql("Hi Mark")
|
31
43
|
end
|
32
44
|
|
45
|
+
it "renders a simple template using a handler class" do
|
46
|
+
res = Braai::Template.new("{{ greetings }}").render(greet: "Hi Mark")
|
47
|
+
res.should eql("HI MARK")
|
48
|
+
end
|
49
|
+
|
33
50
|
it "doesn't care about spaces" do
|
34
51
|
template = "<h1>{{greet}}</h1><h2>{{ greet }}</h2>"
|
35
52
|
res = Braai::Template.new(template).render(greet: "Hi Mark")
|
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.
|
4
|
+
version: 1.2.0
|
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-10-
|
12
|
+
date: 2012-10-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|