markaby 0.6.9 → 0.6.10
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +4 -0
- data/Markaby.gemspec +8 -2
- data/VERSION +1 -1
- data/lib/markaby/rails/current.rb +14 -2
- data/lib/markaby/rails/rails_builder.rb +27 -5
- data/spec/markaby/rails/views/layouts/layout.mab +11 -0
- data/spec/markaby/rails/views/markaby/double_output.mab +8 -0
- data/spec/markaby/rails/views/markaby/routes.mab +1 -1
- data/spec/markaby/rails/views/markaby/yielding.mab +3 -0
- data/spec/markaby/rails/views/markaby/yielding_content_for_with_block_helper.mab +5 -0
- data/spec/markaby/rails/views/markaby/yielding_two.mab +7 -0
- data/spec/markaby/rails/views/markaby/yielding_with_content_for.mab +3 -0
- data/spec/markaby/rails_spec.rb +115 -25
- metadata +10 -4
data/CHANGELOG.rdoc
CHANGED
data/Markaby.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{markaby}
|
8
|
-
s.version = "0.6.
|
8
|
+
s.version = "0.6.10"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["_why", "Tim Fletcher", "John Barton", "spox", "smtlaissezfaire"]
|
12
|
-
s.date = %q{2010-08-
|
12
|
+
s.date = %q{2010-08-13}
|
13
13
|
s.description = %q{Tim Fletcher and _why's ruby driven HTML templating system}
|
14
14
|
s.email = %q{scott@railsnewbie.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -41,11 +41,13 @@ Gem::Specification.new do |s|
|
|
41
41
|
"spec/markaby/markaby_other_static.mab",
|
42
42
|
"spec/markaby/markaby_spec.rb",
|
43
43
|
"spec/markaby/rails/spec_helper.rb",
|
44
|
+
"spec/markaby/rails/views/layouts/layout.mab",
|
44
45
|
"spec/markaby/rails/views/markaby/_a_partial.mab",
|
45
46
|
"spec/markaby/rails/views/markaby/_partial_child_with_locals.mab",
|
46
47
|
"spec/markaby/rails/views/markaby/access_to_helpers.mab",
|
47
48
|
"spec/markaby/rails/views/markaby/broken.mab",
|
48
49
|
"spec/markaby/rails/views/markaby/correct_template_values.mab",
|
50
|
+
"spec/markaby/rails/views/markaby/double_output.mab",
|
49
51
|
"spec/markaby/rails/views/markaby/form_for.mab",
|
50
52
|
"spec/markaby/rails/views/markaby/form_for_with_fields.mab",
|
51
53
|
"spec/markaby/rails/views/markaby/form_for_with_multiple_fields.mab",
|
@@ -58,6 +60,10 @@ Gem::Specification.new do |s|
|
|
58
60
|
"spec/markaby/rails/views/markaby/render_with_ivar.mab",
|
59
61
|
"spec/markaby/rails/views/markaby/renders_erb.rhtml",
|
60
62
|
"spec/markaby/rails/views/markaby/routes.mab",
|
63
|
+
"spec/markaby/rails/views/markaby/yielding.mab",
|
64
|
+
"spec/markaby/rails/views/markaby/yielding_content_for_with_block_helper.mab",
|
65
|
+
"spec/markaby/rails/views/markaby/yielding_two.mab",
|
66
|
+
"spec/markaby/rails/views/markaby/yielding_with_content_for.mab",
|
61
67
|
"spec/markaby/rails_spec.rb",
|
62
68
|
"spec/markaby/rails_version_spec.rb",
|
63
69
|
"spec/markaby/tilt/erb.erb",
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.6.
|
1
|
+
0.6.10
|
@@ -40,6 +40,16 @@ module Markaby
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
43
|
+
|
44
|
+
module CaptureHelper
|
45
|
+
def capture(*args, &block)
|
46
|
+
if output_buffer.kind_of?(Markaby::Builder)
|
47
|
+
output_buffer.capture(&block)
|
48
|
+
else
|
49
|
+
super
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
43
53
|
end
|
44
54
|
end
|
45
55
|
|
@@ -54,8 +64,6 @@ end
|
|
54
64
|
#
|
55
65
|
# String === options
|
56
66
|
#
|
57
|
-
# We prefer to override url_for rather than String#===
|
58
|
-
#
|
59
67
|
ActionView::Helpers::UrlHelper.class_eval do
|
60
68
|
alias_method :url_for_aliased_by_markaby, :url_for
|
61
69
|
|
@@ -71,4 +79,8 @@ ActionView::Helpers::UrlHelper.class_eval do
|
|
71
79
|
end
|
72
80
|
end
|
73
81
|
|
82
|
+
ActionView::Base.class_eval do
|
83
|
+
include Markaby::Rails::CaptureHelper
|
84
|
+
end
|
85
|
+
|
74
86
|
ActionView::Template.register_template_handler(:mab, Markaby::Rails::TemplateHandler)
|
@@ -2,13 +2,36 @@ module Markaby
|
|
2
2
|
module Rails
|
3
3
|
class RailsBuilder < Markaby::Builder
|
4
4
|
def form_for(*args, &block)
|
5
|
+
@_helper.output_buffer = OutputBuffer.new
|
6
|
+
|
5
7
|
@template.form_for(*args) do |__form_for_variable|
|
6
|
-
|
8
|
+
# flush <form tags> + switch back to markaby
|
9
|
+
text(@_helper.output_buffer)
|
10
|
+
@_helper.output_buffer = self
|
11
|
+
|
12
|
+
yield FormHelperProxy.new(@_helper, __form_for_variable)
|
13
|
+
|
14
|
+
# switch back to output string output buffer and flush
|
15
|
+
# final </form> tag
|
16
|
+
@_helper.output_buffer = OutputBuffer.new
|
7
17
|
end
|
18
|
+
text(@_helper.output_buffer)
|
19
|
+
|
20
|
+
# finally, switch back to our regular buffer
|
21
|
+
@_helper.output_buffer = self
|
8
22
|
end
|
9
23
|
|
10
24
|
alias_method :safe_concat, :concat
|
11
25
|
|
26
|
+
# Rails 2.3.6 calls safe_concat on the output buffer.
|
27
|
+
# Future versions of rails alias safe_concat to concat on the core
|
28
|
+
# class String.
|
29
|
+
#
|
30
|
+
# Obviously, that's a bad idea. Thanks a ton, Rails.
|
31
|
+
class OutputBuffer < String
|
32
|
+
alias_method :safe_concat, :concat
|
33
|
+
end
|
34
|
+
|
12
35
|
# This is used for the block variable given to form_for. Typically, an erb template looks as so:
|
13
36
|
#
|
14
37
|
# <% form_for :foo do |f|
|
@@ -30,8 +53,8 @@ module Markaby
|
|
30
53
|
# f.text_field :bar
|
31
54
|
# end
|
32
55
|
class FormHelperProxy
|
33
|
-
def initialize(
|
34
|
-
@
|
56
|
+
def initialize(view, proxied_object)
|
57
|
+
@view = view
|
35
58
|
@proxied_object = proxied_object
|
36
59
|
end
|
37
60
|
|
@@ -43,8 +66,7 @@ module Markaby
|
|
43
66
|
|
44
67
|
def method_missing(sym, *args, &block)
|
45
68
|
result = @proxied_object.__send__(sym, *args, &block)
|
46
|
-
@
|
47
|
-
result
|
69
|
+
@view.concat(result)
|
48
70
|
end
|
49
71
|
end
|
50
72
|
end
|
@@ -1 +1 @@
|
|
1
|
-
link_to
|
1
|
+
link_to("Foo", new_user_path)
|
data/spec/markaby/rails_spec.rb
CHANGED
@@ -115,6 +115,41 @@ if RUNNING_RAILS
|
|
115
115
|
|
116
116
|
def routes
|
117
117
|
end
|
118
|
+
|
119
|
+
def render_with_yielding
|
120
|
+
render :layout => "layout.mab",
|
121
|
+
:template => "markaby/yielding"
|
122
|
+
end
|
123
|
+
|
124
|
+
def render_with_yielding_where_template_has_two_elements
|
125
|
+
render :layout => "layout.mab",
|
126
|
+
:template => "markaby/yielding_two"
|
127
|
+
end
|
128
|
+
|
129
|
+
def render_with_yielding_content_for_block
|
130
|
+
render :layout => "layout.mab",
|
131
|
+
:template => "markaby/yielding_with_content_for"
|
132
|
+
end
|
133
|
+
|
134
|
+
def render_content_for_with_block_helper
|
135
|
+
@obj = Object.new
|
136
|
+
def @obj.foo
|
137
|
+
"bar"
|
138
|
+
end
|
139
|
+
|
140
|
+
render :layout => "layout.mab",
|
141
|
+
:template => "markaby/yielding_content_for_with_block_helper"
|
142
|
+
end
|
143
|
+
|
144
|
+
def renders_content_for_with_form_for_without_double_render
|
145
|
+
@obj = Object.new
|
146
|
+
def @obj.foo
|
147
|
+
"bar"
|
148
|
+
end
|
149
|
+
|
150
|
+
render :layout => "layout.mab",
|
151
|
+
:template => "markaby/double_output"
|
152
|
+
end
|
118
153
|
end
|
119
154
|
|
120
155
|
class MarkabyOnRailsTest < ActionController::TestCase
|
@@ -212,43 +247,98 @@ if RUNNING_RAILS
|
|
212
247
|
@controller.last_exception.message.to_s
|
213
248
|
end
|
214
249
|
|
215
|
-
def
|
216
|
-
get :
|
217
|
-
|
250
|
+
def test_routes_work
|
251
|
+
get :routes
|
218
252
|
assert_response :success
|
219
253
|
|
220
|
-
|
254
|
+
expected_output = "<a href=\"/users/new\">Foo</a>"
|
255
|
+
assert_equal expected_output, @response.body
|
221
256
|
end
|
222
257
|
|
223
|
-
|
224
|
-
|
258
|
+
if Rails::VERSION::MAJOR >= 2
|
259
|
+
def test_renders_form_for_properly
|
260
|
+
get :renders_form_for
|
225
261
|
|
226
|
-
|
262
|
+
assert_response :success
|
227
263
|
|
228
|
-
|
229
|
-
|
230
|
-
end
|
264
|
+
assert %r(<form.*></form>) =~ @response.body
|
265
|
+
end
|
231
266
|
|
232
|
-
|
233
|
-
|
267
|
+
def test_renders_form_for_with_fields_for
|
268
|
+
get :render_form_for_with_fields
|
234
269
|
|
235
|
-
|
270
|
+
assert_response :success
|
236
271
|
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
expected_output << "</form>"
|
272
|
+
assert_equal "<form action=\"/markaby/render_form_for_with_fields\" method=\"post\"><input id=\"foo_foo\" name=\"foo[foo]\" size=\"30\" type=\"text\" /></form>",
|
273
|
+
@response.body
|
274
|
+
end
|
241
275
|
|
242
|
-
|
243
|
-
|
244
|
-
end
|
276
|
+
def test_renders_form_for_with_multiple_fields
|
277
|
+
get :render_form_for_with_multiple_fields
|
245
278
|
|
246
|
-
|
247
|
-
get :routes
|
248
|
-
assert_response :success
|
279
|
+
assert_response :success
|
249
280
|
|
250
|
-
|
251
|
-
|
281
|
+
expected_output = "<form action=\"/markaby/render_form_for_with_multiple_fields\" method=\"post\">"
|
282
|
+
expected_output << "<input id=\"foo_foo\" name=\"foo[foo]\" size=\"30\" type=\"text\" />"
|
283
|
+
expected_output << "<input id=\"foo_baz\" name=\"foo[baz]\" size=\"30\" type=\"text\" />"
|
284
|
+
expected_output << "</form>"
|
285
|
+
|
286
|
+
assert_equal expected_output,
|
287
|
+
@response.body
|
288
|
+
end
|
289
|
+
|
290
|
+
def test_rendering_with_yield_works
|
291
|
+
get :render_with_yielding
|
292
|
+
assert_response :success
|
293
|
+
|
294
|
+
expected_output = '<div id="main"><p class="hey">hi there</p></div>'
|
295
|
+
assert_equal expected_output, @response.body
|
296
|
+
end
|
297
|
+
|
298
|
+
def test_render_with_yielding_where_template_has_two_elements
|
299
|
+
get :render_with_yielding_where_template_has_two_elements
|
300
|
+
assert_response :success
|
301
|
+
|
302
|
+
expected_output = '<div id="main"><p class="hi">hi there</p><p class="hi">hi again</p></div>'
|
303
|
+
assert_equal expected_output, @response.body
|
304
|
+
end
|
305
|
+
|
306
|
+
def test_render_with_yielding_content_for_block
|
307
|
+
get :render_with_yielding_content_for_block
|
308
|
+
assert_response :success
|
309
|
+
|
310
|
+
expected_output = '<div id="main"></div><div id="foo"><p>in foo content_for</p></div>'
|
311
|
+
assert_equal expected_output, @response.body
|
312
|
+
end
|
313
|
+
|
314
|
+
def test_render_content_for_with_block_helper
|
315
|
+
get :render_content_for_with_block_helper
|
316
|
+
assert_response :success
|
317
|
+
|
318
|
+
expected_output = '<div id="main"></div><div id="foo">'
|
319
|
+
expected_output << '<form action="/markaby/render_content_for_with_block_helper" method="post">'
|
320
|
+
expected_output << '<input id="foo_foo" name="foo[foo]" size="30" type="text" />'
|
321
|
+
expected_output << '</form>'
|
322
|
+
expected_output << '</div>'
|
323
|
+
|
324
|
+
assert_equal expected_output, @response.body
|
325
|
+
end
|
326
|
+
|
327
|
+
def test_renders_content_for_with_form_for_without_double_render
|
328
|
+
get :renders_content_for_with_form_for_without_double_render
|
329
|
+
assert_response :success
|
330
|
+
|
331
|
+
expected_output = '<div id="main"></div><div id="foo">'
|
332
|
+
expected_output << '<form action="/markaby/renders_content_for_with_form_for_without_double_render" method="post">'
|
333
|
+
expected_output << '<p class="foo">'
|
334
|
+
expected_output << '<input id="foo_foo" name="foo[foo]" size="30" type="text" />'
|
335
|
+
expected_output << '<input id="foo_submit" name="commit" type="submit" value="foo" />'
|
336
|
+
expected_output << '</p>'
|
337
|
+
expected_output << '</form>'
|
338
|
+
expected_output << '</div>'
|
339
|
+
|
340
|
+
assert_equal expected_output, @response.body
|
341
|
+
end
|
252
342
|
end
|
253
343
|
end
|
254
344
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: markaby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 6
|
9
|
-
-
|
10
|
-
version: 0.6.
|
9
|
+
- 10
|
10
|
+
version: 0.6.10
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- _why
|
@@ -19,7 +19,7 @@ autorequire:
|
|
19
19
|
bindir: bin
|
20
20
|
cert_chain: []
|
21
21
|
|
22
|
-
date: 2010-08-
|
22
|
+
date: 2010-08-13 00:00:00 -04:00
|
23
23
|
default_executable:
|
24
24
|
dependencies:
|
25
25
|
- !ruby/object:Gem::Dependency
|
@@ -72,11 +72,13 @@ files:
|
|
72
72
|
- spec/markaby/markaby_other_static.mab
|
73
73
|
- spec/markaby/markaby_spec.rb
|
74
74
|
- spec/markaby/rails/spec_helper.rb
|
75
|
+
- spec/markaby/rails/views/layouts/layout.mab
|
75
76
|
- spec/markaby/rails/views/markaby/_a_partial.mab
|
76
77
|
- spec/markaby/rails/views/markaby/_partial_child_with_locals.mab
|
77
78
|
- spec/markaby/rails/views/markaby/access_to_helpers.mab
|
78
79
|
- spec/markaby/rails/views/markaby/broken.mab
|
79
80
|
- spec/markaby/rails/views/markaby/correct_template_values.mab
|
81
|
+
- spec/markaby/rails/views/markaby/double_output.mab
|
80
82
|
- spec/markaby/rails/views/markaby/form_for.mab
|
81
83
|
- spec/markaby/rails/views/markaby/form_for_with_fields.mab
|
82
84
|
- spec/markaby/rails/views/markaby/form_for_with_multiple_fields.mab
|
@@ -89,6 +91,10 @@ files:
|
|
89
91
|
- spec/markaby/rails/views/markaby/render_with_ivar.mab
|
90
92
|
- spec/markaby/rails/views/markaby/renders_erb.rhtml
|
91
93
|
- spec/markaby/rails/views/markaby/routes.mab
|
94
|
+
- spec/markaby/rails/views/markaby/yielding.mab
|
95
|
+
- spec/markaby/rails/views/markaby/yielding_content_for_with_block_helper.mab
|
96
|
+
- spec/markaby/rails/views/markaby/yielding_two.mab
|
97
|
+
- spec/markaby/rails/views/markaby/yielding_with_content_for.mab
|
92
98
|
- spec/markaby/rails_spec.rb
|
93
99
|
- spec/markaby/rails_version_spec.rb
|
94
100
|
- spec/markaby/tilt/erb.erb
|