tap 0.17.1 → 0.18.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/History +22 -0
- data/README +15 -14
- data/cmd/console.rb +1 -1
- data/cmd/manifest.rb +25 -5
- data/cmd/run.rb +60 -25
- data/doc/API +37 -38
- data/doc/Class Reference +36 -46
- data/doc/Examples/Workflow +1 -1
- data/lib/tap.rb +1 -1
- data/lib/tap/app.rb +15 -80
- data/lib/tap/app/node.rb +0 -14
- data/lib/tap/env.rb +55 -27
- data/lib/tap/env/manifest.rb +2 -2
- data/lib/tap/intern.rb +50 -0
- data/lib/tap/join.rb +12 -9
- data/lib/tap/middleware.rb +56 -0
- data/lib/tap/schema.rb +182 -14
- data/lib/tap/schema/utils.rb +5 -3
- data/lib/tap/task.rb +53 -130
- data/lib/tap/tasks/dump.rb +1 -1
- data/lib/tap/tasks/load.rb +8 -9
- data/lib/tap/templater.rb +203 -0
- data/lib/tap/{constants.rb → version.rb} +2 -2
- metadata +6 -5
- data/lib/tap/support/intern.rb +0 -53
- data/lib/tap/support/templater.rb +0 -207
data/lib/tap/tasks/dump.rb
CHANGED
data/lib/tap/tasks/load.rb
CHANGED
@@ -22,7 +22,7 @@ module Tap
|
|
22
22
|
# :startdoc::task-
|
23
23
|
#
|
24
24
|
# Load serves as a baseclass for more complicated loads. A YAML load
|
25
|
-
#
|
25
|
+
# could look like this:
|
26
26
|
#
|
27
27
|
# class Yaml < Tap::Tasks::Load
|
28
28
|
# def load(io)
|
@@ -30,10 +30,9 @@ module Tap
|
|
30
30
|
# end
|
31
31
|
# end
|
32
32
|
#
|
33
|
-
# Load
|
34
|
-
#
|
35
|
-
#
|
36
|
-
# overriding the complete? method. An example is a prompt task:
|
33
|
+
# Load subclasses may be constructed to reque itself in cases where objects
|
34
|
+
# are sequentially loaded from the same io. Load will reque until the
|
35
|
+
# complete? method returns true. An example is a prompt task:
|
37
36
|
#
|
38
37
|
# class Prompt < Tap::Tasks::Load
|
39
38
|
# config :exit_seq, "\n"
|
@@ -87,7 +86,7 @@ module Tap
|
|
87
86
|
# * Returning all other objects
|
88
87
|
#
|
89
88
|
def open(io)
|
90
|
-
return File.open(io) if file
|
89
|
+
return(io.kind_of?(File) ? io : File.open(io)) if file
|
91
90
|
|
92
91
|
case io
|
93
92
|
when String
|
@@ -110,10 +109,10 @@ module Tap
|
|
110
109
|
io.close
|
111
110
|
end
|
112
111
|
|
113
|
-
# Returns
|
114
|
-
# (see process).
|
112
|
+
# Returns true by default. Override in subclasses to allow recurrent
|
113
|
+
# loading (see process).
|
115
114
|
def complete?(io, last)
|
116
|
-
|
115
|
+
true
|
117
116
|
end
|
118
117
|
end
|
119
118
|
end
|
@@ -0,0 +1,203 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
autoload(:ERB, 'erb')
|
3
|
+
autoload(:YAML, 'yaml')
|
4
|
+
|
5
|
+
module Tap
|
6
|
+
# Templater is a convenience class for creating ERB templates. As
|
7
|
+
# a subclass of OpenStruct, attributes can be assigned/unassigned
|
8
|
+
# directly. When the template is built, all the method of
|
9
|
+
# Templater (and hence all the assigned attributes) are available.
|
10
|
+
#
|
11
|
+
# t = Templater.new( "key: <%= value %>")
|
12
|
+
# t.value = "default"
|
13
|
+
# t.build # => "key: default"
|
14
|
+
#
|
15
|
+
# t.value = "another"
|
16
|
+
# t.build # => "key: another"
|
17
|
+
#
|
18
|
+
# Templater includes the Templater::Utils utility methods.
|
19
|
+
#
|
20
|
+
# === ERB Redirection
|
21
|
+
#
|
22
|
+
# Templater hooks into the ERB templating mechanism by providing itself
|
23
|
+
# as the ERB output target (_erbout). ERB concatenates each line of an
|
24
|
+
# ERB template to _erbout, as can be seen here:
|
25
|
+
#
|
26
|
+
# e = ERB.new("<%= 1 + 2 %>")
|
27
|
+
# e.src # => "_erbout = ''; _erbout.concat(( 1 + 2 ).to_s); _erbout"
|
28
|
+
#
|
29
|
+
# By setting itself as _erbout, instances of Templater can redirect
|
30
|
+
# output to a temporary target and perform string transformations.
|
31
|
+
# For example, redirection allows indentation of nested content:
|
32
|
+
#
|
33
|
+
# template = %Q{
|
34
|
+
# # Un-nested content
|
35
|
+
# <% redirect do |target| %>
|
36
|
+
# # Nested content
|
37
|
+
# <% module_nest("Nesting::Module") { target } %>
|
38
|
+
# <% end %>
|
39
|
+
# }
|
40
|
+
#
|
41
|
+
# t = Templater.new(template)
|
42
|
+
# t.build
|
43
|
+
# # => %Q{
|
44
|
+
# # # Un-nested content
|
45
|
+
# # module Nesting
|
46
|
+
# # module Module
|
47
|
+
# # # Nested content
|
48
|
+
# #
|
49
|
+
# # end
|
50
|
+
# # end}
|
51
|
+
#
|
52
|
+
class Templater < OpenStruct
|
53
|
+
|
54
|
+
# Utility methods for Templater; mostly string manipulations
|
55
|
+
# useful in creating documentation.
|
56
|
+
module Utils
|
57
|
+
|
58
|
+
# yamlize converts the object to YAML (using to_yaml), omitting
|
59
|
+
# the header and final newline:
|
60
|
+
#
|
61
|
+
# {'key' => 'value'}.to_yaml # => "--- \nkey: value\n"
|
62
|
+
# yamlize {'key' => 'value'} # => "key: value"
|
63
|
+
def yamlize(object)
|
64
|
+
object == nil ? "~" : YAML.dump(object)[4...-1].strip
|
65
|
+
end
|
66
|
+
|
67
|
+
# Comments out the string.
|
68
|
+
def comment(str)
|
69
|
+
str.split("\n").collect {|line| "# #{line}" }.join("\n")
|
70
|
+
end
|
71
|
+
|
72
|
+
# Nest the return of the block in the nesting lines.
|
73
|
+
#
|
74
|
+
# nest([["\nmodule Some", "end\n"],["module Nested", "end"]]) { "class Const\nend" }
|
75
|
+
# # => %Q{
|
76
|
+
# # module Some
|
77
|
+
# # module Nested
|
78
|
+
# # class Const
|
79
|
+
# # end
|
80
|
+
# # end
|
81
|
+
# # end
|
82
|
+
# # }
|
83
|
+
#
|
84
|
+
def nest(nesting, indent=" ", line_sep="\n")
|
85
|
+
content = yield
|
86
|
+
return content if nesting.empty?
|
87
|
+
|
88
|
+
depth = nesting.length
|
89
|
+
lines = [indent * depth + content.gsub(/#{line_sep}/, line_sep + indent * depth)]
|
90
|
+
|
91
|
+
nesting.reverse_each do |(start_line, end_line)|
|
92
|
+
depth -= 1
|
93
|
+
lines.unshift(indent * depth + start_line)
|
94
|
+
lines << (indent * depth + end_line)
|
95
|
+
end
|
96
|
+
|
97
|
+
lines.join(line_sep)
|
98
|
+
end
|
99
|
+
|
100
|
+
# Nest the return of the block in the nesting module.
|
101
|
+
#
|
102
|
+
# module_nest('Some::Nested') { "class Const\nend" }
|
103
|
+
# # => %Q{
|
104
|
+
# # module Some
|
105
|
+
# # module Nested
|
106
|
+
# # class Const
|
107
|
+
# # end
|
108
|
+
# # end
|
109
|
+
# # end
|
110
|
+
# # }.strip
|
111
|
+
#
|
112
|
+
def module_nest(const_name, indent=" ", line_sep="\n")
|
113
|
+
nesting = const_name.split(/::/).collect do |name|
|
114
|
+
["module #{name}", "end"]
|
115
|
+
end
|
116
|
+
|
117
|
+
nest(nesting, indent, line_sep) { yield }
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
class << self
|
122
|
+
|
123
|
+
# Builds the erb template with the specified attributes.
|
124
|
+
def build(template, attributes={}, filename=nil)
|
125
|
+
new(template, attributes, filename).build
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
include Utils
|
130
|
+
|
131
|
+
# Initialized a new Templater. An ERB or String may be provided as the
|
132
|
+
# template. If a String is provided, it will be used to initialize an
|
133
|
+
# ERB with a trim_mode of "<>".
|
134
|
+
def initialize(template, attributes={})
|
135
|
+
@template = case template
|
136
|
+
when ERB
|
137
|
+
# matching w/wo the coding effectively checks @src
|
138
|
+
# across ruby versions (encoding appears in 1.9)
|
139
|
+
if template.instance_variable_get(:@src) !~ /^(#coding:US-ASCII\n)?_erbout =/
|
140
|
+
raise ArgumentError, "Templater does not work with ERB templates where eoutvar != '_erbout'"
|
141
|
+
end
|
142
|
+
template
|
143
|
+
when String then ERB.new(template, nil, "<>")
|
144
|
+
else raise ArgumentError, "cannot convert #{template.class} into an ERB template"
|
145
|
+
end
|
146
|
+
|
147
|
+
src = @template.instance_variable_get(:@src)
|
148
|
+
@template.instance_variable_set(:@src, "self." + src)
|
149
|
+
|
150
|
+
super(attributes)
|
151
|
+
end
|
152
|
+
|
153
|
+
# Returns self (not the underlying erbout storage that actually receives
|
154
|
+
# the output lines). In the ERB context, this method directs erb outputs
|
155
|
+
# to Templater#concat and into the redirect mechanism.
|
156
|
+
def _erbout
|
157
|
+
self
|
158
|
+
end
|
159
|
+
|
160
|
+
# Sets the underlying erbout storage to input.
|
161
|
+
def _erbout=(input)
|
162
|
+
@_erbout = input
|
163
|
+
end
|
164
|
+
|
165
|
+
unless RUBY_VERSION < "1.9"
|
166
|
+
#-- TODO
|
167
|
+
# check if this is still needed...
|
168
|
+
def force_encoding(encoding)
|
169
|
+
@_erbout.force_encoding(encoding)
|
170
|
+
@_erbout
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
# Redirects output of erb to the redirected_erbout string
|
175
|
+
# for the duration of the block. When redirect completes,
|
176
|
+
# the redirected_erbout is concatenated to the main
|
177
|
+
# erbout storage.
|
178
|
+
def redirect # :yields: redirected_erbout
|
179
|
+
current = @_erbout
|
180
|
+
@_erbout = ""
|
181
|
+
result = yield(@_erbout)
|
182
|
+
@_erbout = current
|
183
|
+
concat(result)
|
184
|
+
end
|
185
|
+
|
186
|
+
# Concatenates the specified input to the underlying erbout storage.
|
187
|
+
def concat(input)
|
188
|
+
@_erbout << input
|
189
|
+
end
|
190
|
+
|
191
|
+
# Build the template, setting the attributes and filename if specified.
|
192
|
+
# All methods of self will be accessible in the template.
|
193
|
+
def build(attrs=nil, filename=nil)
|
194
|
+
attrs.each_pair do |key, value|
|
195
|
+
send("#{key}=", value)
|
196
|
+
end if attrs
|
197
|
+
|
198
|
+
@template.filename = filename
|
199
|
+
@template.result(binding)
|
200
|
+
@_erbout
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.18.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simon Chiang
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-06-
|
12
|
+
date: 2009-06-17 00:00:00 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -46,7 +46,7 @@ files:
|
|
46
46
|
- lib/tap/app/queue.rb
|
47
47
|
- lib/tap/app/stack.rb
|
48
48
|
- lib/tap/app/state.rb
|
49
|
-
- lib/tap/
|
49
|
+
- lib/tap/version.rb
|
50
50
|
- lib/tap/tasks/dump.rb
|
51
51
|
- lib/tap/env.rb
|
52
52
|
- lib/tap/env/constant.rb
|
@@ -59,6 +59,7 @@ files:
|
|
59
59
|
- lib/tap/joins.rb
|
60
60
|
- lib/tap/joins/switch.rb
|
61
61
|
- lib/tap/joins/sync.rb
|
62
|
+
- lib/tap/middleware.rb
|
62
63
|
- lib/tap/tasks/load.rb
|
63
64
|
- lib/tap/root.rb
|
64
65
|
- lib/tap/root/utils.rb
|
@@ -66,8 +67,8 @@ files:
|
|
66
67
|
- lib/tap/schema.rb
|
67
68
|
- lib/tap/schema/parser.rb
|
68
69
|
- lib/tap/schema/utils.rb
|
69
|
-
- lib/tap/
|
70
|
-
- lib/tap/
|
70
|
+
- lib/tap/intern.rb
|
71
|
+
- lib/tap/templater.rb
|
71
72
|
- lib/tap/task.rb
|
72
73
|
- README
|
73
74
|
- MIT-LICENSE
|
data/lib/tap/support/intern.rb
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
module Tap
|
2
|
-
module Support
|
3
|
-
|
4
|
-
# Generates an Intern module to override the specified method_name. Intern
|
5
|
-
# modules are useful to override a tiny bit of functionality without having
|
6
|
-
# to generate a full subclass.
|
7
|
-
#
|
8
|
-
# An Intern module:
|
9
|
-
#
|
10
|
-
# - adds an accessor for <method_name>_block
|
11
|
-
# - overrides <method_name> to call the block, prepending self to
|
12
|
-
# the input arguments
|
13
|
-
#
|
14
|
-
# For example:
|
15
|
-
#
|
16
|
-
# array = [1,2,3].extend Intern(:last)
|
17
|
-
#
|
18
|
-
# array.last # => 3
|
19
|
-
# array.last_block = lambda {|arr| arr.first }
|
20
|
-
# array.last # => 3
|
21
|
-
#
|
22
|
-
def self.Intern(method_name)
|
23
|
-
mod = INTERN_MODULES[method_name.to_sym]
|
24
|
-
return mod unless mod == nil
|
25
|
-
|
26
|
-
mod = INTERN_MODULES[method_name.to_sym] = Module.new
|
27
|
-
mod.module_eval %Q{
|
28
|
-
attr_accessor :#{method_name}_block
|
29
|
-
|
30
|
-
def #{method_name}(*inputs)
|
31
|
-
return super unless #{method_name}_block
|
32
|
-
inputs.unshift(self)
|
33
|
-
|
34
|
-
arity = #{method_name}_block.arity
|
35
|
-
n = inputs.length
|
36
|
-
unless n == arity || (arity < 0 && (-1-n) <= arity)
|
37
|
-
raise ArgumentError.new("wrong number of arguments (\#{n} for \#{arity})")
|
38
|
-
end
|
39
|
-
|
40
|
-
#{method_name}_block.call(*inputs)
|
41
|
-
end
|
42
|
-
}
|
43
|
-
mod
|
44
|
-
end
|
45
|
-
|
46
|
-
# An array of already-declared intern modules,
|
47
|
-
# keyed by method_name.
|
48
|
-
INTERN_MODULES = {}
|
49
|
-
|
50
|
-
# An Intern module for :process.
|
51
|
-
Intern = Support.Intern(:process)
|
52
|
-
end
|
53
|
-
end
|
@@ -1,207 +0,0 @@
|
|
1
|
-
require 'ostruct'
|
2
|
-
autoload(:ERB, 'erb')
|
3
|
-
autoload(:YAML, 'yaml')
|
4
|
-
|
5
|
-
module Tap
|
6
|
-
module Support
|
7
|
-
|
8
|
-
# Templater is a convenience class for creating ERB templates. As
|
9
|
-
# a subclass of OpenStruct, attributes can be assigned/unassigned
|
10
|
-
# directly. When the template is built, all the method of
|
11
|
-
# Templater (and hence all the assigned attributes) are available.
|
12
|
-
#
|
13
|
-
# t = Templater.new( "key: <%= value %>")
|
14
|
-
# t.value = "default"
|
15
|
-
# t.build # => "key: default"
|
16
|
-
#
|
17
|
-
# t.value = "another"
|
18
|
-
# t.build # => "key: another"
|
19
|
-
#
|
20
|
-
# Templater includes the Templater::Utils utility methods.
|
21
|
-
#
|
22
|
-
# === ERB Redirection
|
23
|
-
#
|
24
|
-
# Templater hooks into the ERB templating mechanism by providing itself
|
25
|
-
# as the ERB output target (_erbout). ERB concatenates each line of an
|
26
|
-
# ERB template to _erbout, as can be seen here:
|
27
|
-
#
|
28
|
-
# e = ERB.new("<%= 1 + 2 %>")
|
29
|
-
# e.src # => "_erbout = ''; _erbout.concat(( 1 + 2 ).to_s); _erbout"
|
30
|
-
#
|
31
|
-
# By setting itself as _erbout, instances of Templater can redirect
|
32
|
-
# output to a temporary target and perform string transformations.
|
33
|
-
# For example, redirection allows indentation of nested content:
|
34
|
-
#
|
35
|
-
# template = %Q{
|
36
|
-
# # Un-nested content
|
37
|
-
# <% redirect do |target| %>
|
38
|
-
# # Nested content
|
39
|
-
# <% module_nest("Nesting::Module") { target } %>
|
40
|
-
# <% end %>
|
41
|
-
# }
|
42
|
-
#
|
43
|
-
# t = Templater.new(template)
|
44
|
-
# t.build
|
45
|
-
# # => %Q{
|
46
|
-
# # # Un-nested content
|
47
|
-
# # module Nesting
|
48
|
-
# # module Module
|
49
|
-
# # # Nested content
|
50
|
-
# #
|
51
|
-
# # end
|
52
|
-
# # end}
|
53
|
-
#
|
54
|
-
class Templater < OpenStruct
|
55
|
-
|
56
|
-
# Utility methods for Templater; mostly string manipulations
|
57
|
-
# useful in creating documentation.
|
58
|
-
module Utils
|
59
|
-
|
60
|
-
# yamlize converts the object to YAML (using to_yaml), omitting
|
61
|
-
# the header and final newline:
|
62
|
-
#
|
63
|
-
# {'key' => 'value'}.to_yaml # => "--- \nkey: value\n"
|
64
|
-
# yamlize {'key' => 'value'} # => "key: value"
|
65
|
-
def yamlize(object)
|
66
|
-
object == nil ? "~" : YAML.dump(object)[4...-1].strip
|
67
|
-
end
|
68
|
-
|
69
|
-
# Comments out the string.
|
70
|
-
def comment(str)
|
71
|
-
str.split("\n").collect {|line| "# #{line}" }.join("\n")
|
72
|
-
end
|
73
|
-
|
74
|
-
# Nest the return of the block in the nesting lines.
|
75
|
-
#
|
76
|
-
# nest([["\nmodule Some", "end\n"],["module Nested", "end"]]) { "class Const\nend" }
|
77
|
-
# # => %Q{
|
78
|
-
# # module Some
|
79
|
-
# # module Nested
|
80
|
-
# # class Const
|
81
|
-
# # end
|
82
|
-
# # end
|
83
|
-
# # end
|
84
|
-
# # }
|
85
|
-
#
|
86
|
-
def nest(nesting, indent=" ", line_sep="\n")
|
87
|
-
content = yield
|
88
|
-
return content if nesting.empty?
|
89
|
-
|
90
|
-
depth = nesting.length
|
91
|
-
lines = [indent * depth + content.gsub(/#{line_sep}/, line_sep + indent * depth)]
|
92
|
-
|
93
|
-
nesting.reverse_each do |(start_line, end_line)|
|
94
|
-
depth -= 1
|
95
|
-
lines.unshift(indent * depth + start_line)
|
96
|
-
lines << (indent * depth + end_line)
|
97
|
-
end
|
98
|
-
|
99
|
-
lines.join(line_sep)
|
100
|
-
end
|
101
|
-
|
102
|
-
# Nest the return of the block in the nesting module.
|
103
|
-
#
|
104
|
-
# module_nest('Some::Nested') { "class Const\nend" }
|
105
|
-
# # => %Q{
|
106
|
-
# # module Some
|
107
|
-
# # module Nested
|
108
|
-
# # class Const
|
109
|
-
# # end
|
110
|
-
# # end
|
111
|
-
# # end
|
112
|
-
# # }.strip
|
113
|
-
#
|
114
|
-
def module_nest(const_name, indent=" ", line_sep="\n")
|
115
|
-
nesting = const_name.split(/::/).collect do |name|
|
116
|
-
["module #{name}", "end"]
|
117
|
-
end
|
118
|
-
|
119
|
-
nest(nesting, indent, line_sep) { yield }
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
class << self
|
124
|
-
|
125
|
-
# Builds the erb template with the specified attributes.
|
126
|
-
def build(template, attributes={}, filename=nil)
|
127
|
-
new(template, attributes, filename).build
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
include Utils
|
132
|
-
|
133
|
-
# Initialized a new Templater. An ERB or String may be provided as the
|
134
|
-
# template. If a String is provided, it will be used to initialize an
|
135
|
-
# ERB with a trim_mode of "<>".
|
136
|
-
def initialize(template, attributes={})
|
137
|
-
@template = case template
|
138
|
-
when ERB
|
139
|
-
# matching w/wo the coding effectively checks @src
|
140
|
-
# across ruby versions (encoding appears in 1.9)
|
141
|
-
if template.instance_variable_get(:@src) !~ /^(#coding:US-ASCII\n)?_erbout =/
|
142
|
-
raise ArgumentError, "Templater does not work with ERB templates where eoutvar != '_erbout'"
|
143
|
-
end
|
144
|
-
template
|
145
|
-
when String then ERB.new(template, nil, "<>")
|
146
|
-
else raise ArgumentError, "cannot convert #{template.class} into an ERB template"
|
147
|
-
end
|
148
|
-
|
149
|
-
src = @template.instance_variable_get(:@src)
|
150
|
-
@template.instance_variable_set(:@src, "self." + src)
|
151
|
-
|
152
|
-
super(attributes)
|
153
|
-
end
|
154
|
-
|
155
|
-
# Returns self (not the underlying erbout storage that actually receives
|
156
|
-
# the output lines). In the ERB context, this method directs erb outputs
|
157
|
-
# to Templater#concat and into the redirect mechanism.
|
158
|
-
def _erbout
|
159
|
-
self
|
160
|
-
end
|
161
|
-
|
162
|
-
# Sets the underlying erbout storage to input.
|
163
|
-
def _erbout=(input)
|
164
|
-
@_erbout = input
|
165
|
-
end
|
166
|
-
|
167
|
-
unless RUBY_VERSION < "1.9"
|
168
|
-
#-- TODO
|
169
|
-
# check if this is still needed...
|
170
|
-
def force_encoding(encoding)
|
171
|
-
@_erbout.force_encoding(encoding)
|
172
|
-
@_erbout
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
# Redirects output of erb to the redirected_erbout string
|
177
|
-
# for the duration of the block. When redirect completes,
|
178
|
-
# the redirected_erbout is concatenated to the main
|
179
|
-
# erbout storage.
|
180
|
-
def redirect # :yields: redirected_erbout
|
181
|
-
current = @_erbout
|
182
|
-
@_erbout = ""
|
183
|
-
result = yield(@_erbout)
|
184
|
-
@_erbout = current
|
185
|
-
concat(result)
|
186
|
-
end
|
187
|
-
|
188
|
-
# Concatenates the specified input to the underlying erbout storage.
|
189
|
-
def concat(input)
|
190
|
-
@_erbout << input
|
191
|
-
end
|
192
|
-
|
193
|
-
# Build the template. All methods of self will be
|
194
|
-
# accessible in the template.
|
195
|
-
def build(attrs={}, filename=nil)
|
196
|
-
attrs.each_pair do |key, value|
|
197
|
-
send("#{key}=", value)
|
198
|
-
end
|
199
|
-
|
200
|
-
@template.filename = filename
|
201
|
-
@template.result(binding)
|
202
|
-
@_erbout
|
203
|
-
end
|
204
|
-
|
205
|
-
end
|
206
|
-
end
|
207
|
-
end
|