herbie 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,10 @@
1
+ require 'tilt'
2
+ require 'erubis'
3
+
1
4
  module Herbie
2
5
  module Helpers
3
6
  private
7
+
4
8
  def erb_with_output_buffer(buf = '')
5
9
  @_out_buf, old_buffer = buf, @_out_buf
6
10
  yield
@@ -2,8 +2,7 @@ module Herbie
2
2
  module Helpers
3
3
  def tag(name, attrs={}, &block)
4
4
  if block_given?
5
- erb_concat "<#{name}#{' ' + attributes(attrs) unless attrs.nil? || attrs.empty?}>#{capture_erb(&block)}</#{name}>" # if we're capturing ERB...
6
- "<#{name}#{' ' + attributes(attrs) unless attrs.empty?}>#{block.call}</#{name}>" # if we're nesting function calls...
5
+ erb_concat "<#{name}#{' ' + attributes(attrs) unless attrs.nil? || attrs.empty?}>#{capture_erb(&block)}</#{name}>"
7
6
  elsif !attrs[:content].nil?
8
7
  content = attrs.delete :content
9
8
  "<#{name}#{' ' + attributes(attrs) unless attrs.empty?}>#{content}</#{name}>"
@@ -12,7 +11,7 @@ module Herbie
12
11
  end
13
12
  end
14
13
 
15
- # work in progress...
14
+ # work in progress
16
15
  def tags(name, collection, attrs={}, &block)
17
16
  cycle = attrs.delete :cycle
18
17
  result = ""
data/lib/herbie.rb CHANGED
@@ -3,5 +3,5 @@ require 'herbie/generic_helpers.rb'
3
3
  require 'herbie/html_helpers.rb'
4
4
 
5
5
  module Herbie
6
- VERSION = '0.1.2'
6
+ VERSION = '0.1.3'
7
7
  end
data/spec/herbie_spec.rb CHANGED
@@ -38,7 +38,26 @@ describe Herbie::Helpers do
38
38
  tag(:input, attrs).should == "<input type=\"#{attrs[:type]}\" name=\"#{attrs[:name]}\" value=\"#{attrs[:value]}\" checked>"
39
39
  end
40
40
 
41
+ it "should output tags mixed with ERB" do
42
+ pending "Need a mechanism for capturing erb output within a passed block"
43
+ erb_fragment = <<-ERB
44
+ <% tag :div, :class => "container" do %>
45
+ Hello world!
46
+ <% end %>
47
+ ERB
48
+
49
+ html_fragment = <<-HTML
50
+ <div class="container">
51
+ Hello world!
52
+ </div>
53
+ HTML
54
+
55
+ template = Tilt['erb'].new { erb_fragment }
56
+ template.render.should == html_fragment
57
+ end
58
+
41
59
  it "should output all nested tag method calls" do
60
+ pending "Need a mechanism for capturing erb output within a passed block"
42
61
  markup = "<div class=\"container\"><h1>Status Report</h1></div>"
43
62
  result = tag :div, :class => "container" do
44
63
  tag :h1, :content => "Status Report"
@@ -47,6 +66,7 @@ describe Herbie::Helpers do
47
66
  end
48
67
 
49
68
  it "should output a collection of tags" do
69
+ pending "Need a mechanism for capturing erb output within a passed block"
50
70
  markup = <<-MARKUP
51
71
  <li><a href="/" title="Back to the homepage">Home</a></li>
52
72
  <li><a href="/shop" title="View all our products">Shop</a></li>
@@ -69,6 +89,7 @@ MARKUP
69
89
  end
70
90
 
71
91
  it "should allow an arbitrary class to be added to alternating elements within the collection" do
92
+ pending "Need a mechanism for capturing erb output within a passed block"
72
93
  markup = <<-MARKUP
73
94
  <li class="even">Annie</li>
74
95
  <li>Brenda</li>
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: herbie
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.2
5
+ version: 0.1.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Ben Darlow
@@ -14,27 +14,49 @@ date: 2011-10-10 00:00:00 +01:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
- name: rspec
17
+ name: tilt
18
18
  prerelease: false
19
19
  requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: "0"
25
+ type: :runtime
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: erubis
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: "0"
36
+ type: :runtime
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: rspec
40
+ prerelease: false
41
+ requirement: &id003 !ruby/object:Gem::Requirement
20
42
  none: false
21
43
  requirements:
22
44
  - - ~>
23
45
  - !ruby/object:Gem::Version
24
46
  version: "2.6"
25
47
  type: :development
26
- version_requirements: *id001
48
+ version_requirements: *id003
27
49
  - !ruby/object:Gem::Dependency
28
50
  name: colored
29
51
  prerelease: false
30
- requirement: &id002 !ruby/object:Gem::Requirement
52
+ requirement: &id004 !ruby/object:Gem::Requirement
31
53
  none: false
32
54
  requirements:
33
55
  - - ">="
34
56
  - !ruby/object:Gem::Version
35
57
  version: "0"
36
58
  type: :development
37
- version_requirements: *id002
59
+ version_requirements: *id004
38
60
  description: Lovable HTML view helpers for use with ERB.
39
61
  email: ben@kapowaz.net
40
62
  executables: []