braai 1.1.2 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- braai (1.1.2)
4
+ braai (1.2.0)
5
5
  activesupport
6
6
 
7
7
  GEM
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 = <<-EOF
66
- <h1>{{ greet }}</h1>
67
- <ul>
65
+ template = <<-EOF
66
+ <h1>{{ greet }}</h1>
67
+ <ul>
68
68
  {{ for product in products }}
69
- &lt;li>{{ product }}&lt;/li>
69
+ <li>{{ product }}</li>
70
70
  {{ /for }}
71
- &lt;/ul>
72
- &lt;div>
71
+ </ul>
72
+ <div>
73
73
  {{ for food in foods }}
74
- &lt;p>{{ food }}&lt;/p>
74
+ <p>{{ food }}</p>
75
75
  {{ /for }}
76
- &lt;/div>
77
- &lt;h2>{{greet.upcase}}&lt;/h2>
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("&lt;h1>mark&lt;/h1>")
82
- res.should match("&lt;li>car&lt;/li>")
83
- res.should match("&lt;li>boat&lt;/li>")
84
- res.should match("&lt;li>truck&lt;/li>")
85
- res.should match("&lt;p>apple&lt;/p>")
86
- res.should match("&lt;p>orange&lt;/p>")
87
- res.should match("&lt;h2>MARK&lt;/h2>")
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
@@ -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)
@@ -1,3 +1,3 @@
1
1
  module Braai
2
- VERSION = "1.1.2"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -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.1.2
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-02 00:00:00.000000000 Z
12
+ date: 2012-10-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport