deas-erbtags 0.4.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -1
- data/deas-tags.gemspec +3 -1
- data/lib/deas-erbtags/capture.rb +12 -10
- data/lib/deas-erbtags/version.rb +1 -1
- data/test/support/factory.rb +6 -2
- data/test/unit/capture_tests.rb +17 -13
- metadata +25 -9
data/README.md
CHANGED
@@ -64,7 +64,7 @@ template_helpers(Deas::ErbTags::Capture)
|
|
64
64
|
|
65
65
|
The `capture_render` method is used to make Deas template `render` calls with nested erb markup. It calls `render` with the given args, and captures its output. Call it just as you would `render`, just invoke the call using `<% ... %>`.
|
66
66
|
|
67
|
-
### `
|
67
|
+
### `capture_partial`
|
68
68
|
|
69
69
|
```ruby
|
70
70
|
template_helpers(Deas::ErbTags::Capture)
|
data/deas-tags.gemspec
CHANGED
@@ -17,6 +17,8 @@ Gem::Specification.new do |gem|
|
|
17
17
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
18
|
gem.require_paths = ["lib"]
|
19
19
|
|
20
|
-
gem.
|
20
|
+
gem.add_dependency("deas", ["~> 0.23"])
|
21
|
+
|
22
|
+
gem.add_development_dependency("assert", ["~> 2.3"])
|
21
23
|
|
22
24
|
end
|
data/lib/deas-erbtags/capture.rb
CHANGED
@@ -17,18 +17,17 @@ module Deas::ErbTags
|
|
17
17
|
instance_variable_get(self.erb_outvar_name)
|
18
18
|
end
|
19
19
|
|
20
|
-
def
|
20
|
+
def erb_write(content)
|
21
21
|
self.erb_outvar << "#{content}\n"
|
22
22
|
end
|
23
23
|
|
24
|
-
def
|
25
|
-
opts = args.last.kind_of?(::Hash) ? args.pop : {}
|
24
|
+
def capture(&content)
|
26
25
|
outvar = self.erb_outvar_name
|
27
|
-
|
26
|
+
begin
|
28
27
|
orig_outvar = self.erb_outvar
|
29
28
|
instance_variable_set(outvar, "\n")
|
30
29
|
|
31
|
-
result = instance_eval(&content
|
30
|
+
result = instance_eval(&(content || Proc.new {}))
|
32
31
|
|
33
32
|
if instance_variable_get(outvar) == "\n"
|
34
33
|
"\n#{result}"
|
@@ -38,16 +37,19 @@ module Deas::ErbTags
|
|
38
37
|
ensure
|
39
38
|
instance_variable_set(outvar, orig_outvar)
|
40
39
|
end
|
40
|
+
end
|
41
41
|
|
42
|
-
|
42
|
+
def capture_tag(name, *args, &content)
|
43
|
+
opts = args.last.kind_of?(::Hash) ? args.pop : {}
|
44
|
+
self.erb_write tag(name, "#{capture(&content)}\n", opts)
|
43
45
|
end
|
44
46
|
|
45
|
-
def capture_render(*args, &
|
46
|
-
self.
|
47
|
+
def capture_render(*args, &content)
|
48
|
+
self.erb_write self.render(*args, &Proc.new{ capture(&content) })
|
47
49
|
end
|
48
50
|
|
49
|
-
def capture_partial(*args, &
|
50
|
-
self.
|
51
|
+
def capture_partial(*args, &content)
|
52
|
+
self.erb_write self.partial(*args, &Proc.new{ capture(&content) })
|
51
53
|
end
|
52
54
|
|
53
55
|
end
|
data/lib/deas-erbtags/version.rb
CHANGED
data/test/support/factory.rb
CHANGED
@@ -23,11 +23,13 @@ module Factory
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def render(*args, &block)
|
26
|
-
|
26
|
+
cap_content = "#{(block || Proc.new {}).call}"
|
27
|
+
RenderArgs.new(args, cap_content).inspect
|
27
28
|
end
|
28
29
|
|
29
30
|
def partial(*args, &block)
|
30
|
-
|
31
|
+
cap_content = "#{(block || Proc.new {}).call}"
|
32
|
+
RenderArgs.new(args, cap_content).inspect
|
31
33
|
end
|
32
34
|
|
33
35
|
end
|
@@ -39,4 +41,6 @@ module Factory
|
|
39
41
|
Deas::ErbTags::Utils.html_attrs(opts)
|
40
42
|
end
|
41
43
|
|
44
|
+
RenderArgs = Struct.new(:args, :captured_content)
|
45
|
+
|
42
46
|
end
|
data/test/unit/capture_tests.rb
CHANGED
@@ -4,14 +4,14 @@ require 'deas-erbtags/capture'
|
|
4
4
|
|
5
5
|
module Deas::ErbTags::Capture
|
6
6
|
|
7
|
-
class
|
7
|
+
class UnitTests < Assert::Context
|
8
8
|
desc "the `Capture` module"
|
9
9
|
setup do
|
10
10
|
@template = Factory.template(Deas::ErbTags::Capture)
|
11
11
|
end
|
12
12
|
subject{ @template }
|
13
13
|
|
14
|
-
should have_imeths :erb_outvar_name, :erb_outvar
|
14
|
+
should have_imeths :erb_outvar_name, :erb_outvar, :erb_write
|
15
15
|
should have_imeths :capture, :capture_tag, :capture_render, :capture_partial
|
16
16
|
|
17
17
|
should "include the `Tag` module" do
|
@@ -20,7 +20,7 @@ module Deas::ErbTags::Capture
|
|
20
20
|
|
21
21
|
end
|
22
22
|
|
23
|
-
class CaptureTagTests <
|
23
|
+
class CaptureTagTests < UnitTests
|
24
24
|
|
25
25
|
should "create content by capturing content from a given block" do
|
26
26
|
div_div = subject.tag(:div, "\n#{subject.tag(:div, "\ninner\n")}\n\n", {
|
@@ -51,28 +51,32 @@ module Deas::ErbTags::Capture
|
|
51
51
|
|
52
52
|
end
|
53
53
|
|
54
|
-
class CaptureRenderTests <
|
54
|
+
class CaptureRenderTests < UnitTests
|
55
55
|
|
56
56
|
should "capture output from Deas' template `render` call" do
|
57
|
-
exp_output = "#{subject.render('something')}\n"
|
58
57
|
assert_empty subject._out_buf
|
59
58
|
|
60
|
-
|
61
|
-
|
62
|
-
|
59
|
+
content = Proc.new{ '_some_content_' }
|
60
|
+
exp_out = "#{subject.render('something', &Proc.new{ subject.capture(&content) })}\n"
|
61
|
+
cap_out = subject.capture_render('something') { '_some_content_' }
|
62
|
+
|
63
|
+
assert_equal exp_out, cap_out
|
64
|
+
assert_equal exp_out, subject._out_buf
|
63
65
|
end
|
64
66
|
|
65
67
|
end
|
66
68
|
|
67
|
-
class CapturePartialTests <
|
69
|
+
class CapturePartialTests < UnitTests
|
68
70
|
|
69
71
|
should "capture output from Deas' template `partial` call" do
|
70
|
-
exp_output = "#{subject.partial('something')}\n"
|
71
72
|
assert_empty subject._out_buf
|
72
73
|
|
73
|
-
|
74
|
-
|
75
|
-
|
74
|
+
content = Proc.new{ }
|
75
|
+
exp_out = "#{subject.partial('something', &Proc.new{ subject.capture(&content) })}\n"
|
76
|
+
cap_out = subject.capture_partial('something')
|
77
|
+
|
78
|
+
assert_equal exp_out, cap_out
|
79
|
+
assert_equal exp_out, subject._out_buf
|
76
80
|
end
|
77
81
|
|
78
82
|
end
|
metadata
CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 5
|
9
|
+
- 0
|
10
|
+
version: 0.5.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Kelly Redding
|
@@ -16,22 +16,38 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2013-
|
19
|
+
date: 2013-10-15 00:00:00 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
-
name:
|
22
|
+
name: deas
|
23
23
|
prerelease: false
|
24
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
26
|
requirements:
|
27
|
-
- -
|
27
|
+
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
hash:
|
29
|
+
hash: 37
|
30
30
|
segments:
|
31
31
|
- 0
|
32
|
-
|
33
|
-
|
32
|
+
- 23
|
33
|
+
version: "0.23"
|
34
|
+
type: :runtime
|
34
35
|
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: assert
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 5
|
45
|
+
segments:
|
46
|
+
- 2
|
47
|
+
- 3
|
48
|
+
version: "2.3"
|
49
|
+
type: :development
|
50
|
+
version_requirements: *id002
|
35
51
|
description: Deas template helpers for creating HTML tags using Erb.
|
36
52
|
email:
|
37
53
|
- kelly@kellyredding.com
|