ember 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ember/inochi.rb +2 -2
- data/lib/ember/template.rb +77 -14
- data/man.html +280 -85
- data/man/man1/ember.1.gz +0 -0
- metadata +3 -3
data/lib/ember/inochi.rb
CHANGED
@@ -18,12 +18,12 @@ module Ember
|
|
18
18
|
##
|
19
19
|
# Number of this release of this project.
|
20
20
|
#
|
21
|
-
VERSION = "0.
|
21
|
+
VERSION = "0.3.0"
|
22
22
|
|
23
23
|
##
|
24
24
|
# Date of this release of this project.
|
25
25
|
#
|
26
|
-
RELDATE = "2010-04-
|
26
|
+
RELDATE = "2010-04-26"
|
27
27
|
|
28
28
|
##
|
29
29
|
# Description of this release of this project.
|
data/lib/ember/template.rb
CHANGED
@@ -61,24 +61,14 @@ module Ember
|
|
61
61
|
@compile
|
62
62
|
end
|
63
63
|
|
64
|
-
@@contexts = {}
|
65
|
-
|
66
64
|
##
|
67
65
|
# Returns the result of executing the Ruby program for this template
|
68
66
|
# (provided by the {#program} method) inside the given context binding.
|
69
67
|
#
|
70
|
-
def render context =
|
71
|
-
context
|
72
|
-
@@contexts[parent_context_id] || # inherit parent context
|
73
|
-
Object.new.instance_eval('binding') # create new context
|
74
|
-
@@contexts[@render_context_id] = context # provide to children
|
75
|
-
|
76
|
-
result = eval @compile, context,
|
68
|
+
def render context = Object.new.instance_eval('binding')
|
69
|
+
eval @compile, context,
|
77
70
|
(@options[:source_file] || :SOURCE).to_s,
|
78
71
|
(@options[:source_line] || 1).to_i
|
79
|
-
|
80
|
-
@@contexts.delete @render_context_id # free the memory
|
81
|
-
result
|
82
72
|
end
|
83
73
|
|
84
74
|
class << self
|
@@ -104,6 +94,69 @@ module Ember
|
|
104
94
|
File.read resolve_path(path, options)
|
105
95
|
end
|
106
96
|
|
97
|
+
##
|
98
|
+
# Returns the template evaluation result buffer
|
99
|
+
# associated with the given content block.
|
100
|
+
#
|
101
|
+
def buffer_from_block content_block
|
102
|
+
context = content_block.binding
|
103
|
+
result_variable = eval(Program::RESULT_VARIABLE_BACKDOOR, context)
|
104
|
+
eval result_variable.to_s, context
|
105
|
+
end
|
106
|
+
|
107
|
+
##
|
108
|
+
# Invokes the given block while passing the given arguments to
|
109
|
+
# it and then returns an Array of things that the given block
|
110
|
+
# tried to append to its template evaluation result buffer.
|
111
|
+
#
|
112
|
+
# If the given block did not try to append anything, then the
|
113
|
+
# result of invoking the given block is returned as an Array.
|
114
|
+
#
|
115
|
+
def content_from_block content_block, *content_block_args
|
116
|
+
context = content_block.binding
|
117
|
+
|
118
|
+
orig_result_variable = eval(Program::RESULT_VARIABLE_BACKDOOR, context)
|
119
|
+
temp_result_variable = "#{orig_result_variable}_#{context.object_id.abs}"
|
120
|
+
eval "#{temp_result_variable} = #{orig_result_variable}", context
|
121
|
+
|
122
|
+
begin
|
123
|
+
# the content block appends to the result buffer when invoked.
|
124
|
+
# so we temporarily replace the result buffer with an empty one,
|
125
|
+
# invoke the content block, and viola! we now have its content.
|
126
|
+
block_content = eval("#{orig_result_variable} = []", context)
|
127
|
+
return_value = content_block.call(*content_block_args)
|
128
|
+
ensure
|
129
|
+
eval "#{orig_result_variable} = #{temp_result_variable}", context
|
130
|
+
end
|
131
|
+
|
132
|
+
if block_content.empty?
|
133
|
+
# no content was appended to the result buffer when the content
|
134
|
+
# block was invoked because it did not contain any vocal directives.
|
135
|
+
# so we return the return value of content block invocation instead.
|
136
|
+
Array(return_value)
|
137
|
+
else
|
138
|
+
block_content
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
##
|
143
|
+
# Passes the given content block's content (obtained by invoking
|
144
|
+
# the given content block with the given arguments) as an argument
|
145
|
+
# to given wrapper block. The result of the wrapper block is (1)
|
146
|
+
# appended to the template evaluation result buffer associated with
|
147
|
+
# the given content block and is (2) returned by this method.
|
148
|
+
#
|
149
|
+
def wrap_content_block content_block, *content_block_args, &wrapper
|
150
|
+
raise ArgumentError, 'wrapper block must be given' unless wrapper
|
151
|
+
|
152
|
+
buffer = buffer_from_block(content_block)
|
153
|
+
content = content_from_block(content_block, *content_block_args)
|
154
|
+
|
155
|
+
wrapped_content = wrapper.call(content)
|
156
|
+
buffer << wrapped_content
|
157
|
+
wrapped_content
|
158
|
+
end
|
159
|
+
|
107
160
|
private
|
108
161
|
|
109
162
|
def resolve_path path, options = {}
|
@@ -368,7 +421,7 @@ module Ember
|
|
368
421
|
nest_template_with = lambda do |meth|
|
369
422
|
@program.emit_code "#{template_class_name}.#{meth}(#{
|
370
423
|
nested_template_args
|
371
|
-
}.merge!(:continue_result => true)).render(
|
424
|
+
}.merge!(:continue_result => true)).render(::Kernel.binding)"
|
372
425
|
end
|
373
426
|
|
374
427
|
case operation
|
@@ -425,6 +478,13 @@ module Ember
|
|
425
478
|
end
|
426
479
|
|
427
480
|
class Program #:nodoc:
|
481
|
+
##
|
482
|
+
# Name of a variable whose value is the
|
483
|
+
# name of the result variable in the
|
484
|
+
# Ruby code produced by this program.
|
485
|
+
#
|
486
|
+
RESULT_VARIABLE_BACKDOOR = 'e08afdfb_62c7_485f_87a0_80914e1b4703' # UUID
|
487
|
+
|
428
488
|
##
|
429
489
|
# Transforms this program into Ruby code which uses
|
430
490
|
# the given variable name as the evaluation buffer.
|
@@ -527,7 +587,10 @@ module Ember
|
|
527
587
|
# Transforms this program into executable Ruby source code.
|
528
588
|
#
|
529
589
|
def compile
|
530
|
-
'(%s %s []; %s; %s.join)' % [
|
590
|
+
'(%s = %s; %s %s []; %s; %s.join)' % [
|
591
|
+
RESULT_VARIABLE_BACKDOOR,
|
592
|
+
@result_variable.inspect,
|
593
|
+
|
531
594
|
@result_variable,
|
532
595
|
@continue_result ? '||=' : '=',
|
533
596
|
|
data/man.html
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
<html>
|
3
3
|
<head>
|
4
4
|
<meta http-equiv='content-type' value='text/html;charset=utf8'>
|
5
|
-
<meta name='generator' value='Ronn/v0.5'>
|
5
|
+
<meta name='generator' value='Ronn/v0.5 (http://github.com/rtomayko/ronn)'>
|
6
6
|
<title>ember(1) - eRuby template processor</title>
|
7
7
|
<style type='text/css'>
|
8
8
|
body {margin:0}
|
@@ -73,13 +73,26 @@
|
|
73
73
|
<body>
|
74
74
|
<div id='man'>
|
75
75
|
|
76
|
-
<div class='man-navigation'
|
76
|
+
<div class='man-navigation'>
|
77
|
+
<a href="#NAME">NAME</a>
|
78
|
+
<a href="#ABOUT">ABOUT</a>
|
79
|
+
<a href="#SYNOPSIS">SYNOPSIS</a>
|
80
|
+
<a href="#DESCRIPTION">DESCRIPTION</a>
|
81
|
+
<a href="#OPTIONS">OPTIONS</a>
|
82
|
+
<a href="#SYNTAX">SYNTAX</a>
|
83
|
+
<a href="#EXAMPLES">EXAMPLES</a>
|
84
|
+
<a href="#HACKING">HACKING</a>
|
85
|
+
<a href="#VERSIONS">VERSIONS</a>
|
86
|
+
<a href="#CREDITS">CREDITS</a>
|
87
|
+
<a href="#LICENSE">LICENSE</a>
|
88
|
+
<a href="#SEE-ALSO">SEE ALSO</a>
|
89
|
+
</div>
|
77
90
|
|
78
91
|
<h1 class='man-title'>ember(1)</h1>
|
79
92
|
|
80
93
|
<ol class='head man'>
|
81
94
|
<li class='tl'>ember(1)</li>
|
82
|
-
<li class='tc'>Version 0.
|
95
|
+
<li class='tc'>Version 0.3.0</li>
|
83
96
|
<li class='tr'>ember(1)</li>
|
84
97
|
</ol>
|
85
98
|
|
@@ -98,7 +111,7 @@ debugging, reduces markup, and improves composability of eRuby templates.</p>
|
|
98
111
|
<li><p>Omits newlines trailing code-only <code><% ... %></code> directives.</p></li>
|
99
112
|
<li><p>Can infer missing <code><% end %></code> directives based on indentation.</p></li>
|
100
113
|
<li><p>Can unindent eRuby block bodies hierarchically.</p></li>
|
101
|
-
<li><p>Written in
|
114
|
+
<li><p>Written in 361 lines of pure
|
102
115
|
Ruby.</p></li>
|
103
116
|
</ul>
|
104
117
|
|
@@ -261,50 +274,37 @@ template processor to evaluate the eRuby template given as input:</p>
|
|
261
274
|
|
262
275
|
<h3 id="An-empty-template">An empty template</h3>
|
263
276
|
|
264
|
-
<
|
277
|
+
<pre></pre>
|
265
278
|
|
266
|
-
<pre>
|
267
|
-
</pre>
|
268
279
|
|
280
|
+
<p>The above template compiles into:</p>
|
269
281
|
|
270
|
-
<
|
271
|
-
above template compiles into:</p>
|
272
|
-
|
273
|
-
<pre><code>(_erbout = []; _erbout << "\n"
|
274
|
-
; _erbout.join)
|
282
|
+
<pre><code>(e08afdfb_62c7_485f_87a0_80914e1b4703 = :_erbout; _erbout = []; ; _erbout.join)
|
275
283
|
</code></pre>
|
276
284
|
|
277
285
|
<p>And renders as:</p>
|
278
286
|
|
279
|
-
<pre>
|
280
|
-
</pre>
|
287
|
+
<pre></pre>
|
281
288
|
|
282
289
|
|
283
290
|
<h3 id="Comment-directives">Comment directives</h3>
|
284
291
|
|
285
|
-
<p>Add comment directives:</p>
|
286
|
-
|
287
292
|
<pre><code><%# this is a comment %>
|
288
293
|
%# this is also a comment
|
289
|
-
|
290
294
|
<%# this
|
291
295
|
is
|
292
296
|
a
|
293
297
|
multi-line comment %>
|
294
298
|
</code></pre>
|
295
299
|
|
296
|
-
<p>With <code>{:shorthand=>true}</code> options, the
|
297
|
-
above template compiles into:</p>
|
300
|
+
<p>With <code>{:shorthand=>true}</code> options, the above template compiles into:</p>
|
298
301
|
|
299
|
-
<pre><code>(_erbout = []; _erbout << "\n"
|
300
|
-
_erbout << "\n"
|
301
|
-
_erbout << "\n"
|
302
|
+
<pre><code>(e08afdfb_62c7_485f_87a0_80914e1b4703 = :_erbout; _erbout = []; _erbout << "\n"
|
302
303
|
_erbout << "\n"
|
303
304
|
|
304
305
|
|
305
306
|
|
306
307
|
|
307
|
-
_erbout << " \n"
|
308
308
|
; _erbout.join)
|
309
309
|
</code></pre>
|
310
310
|
|
@@ -312,27 +312,19 @@ _erbout << " \n"
|
|
312
312
|
|
313
313
|
<pre>
|
314
314
|
|
315
|
-
|
316
|
-
|
317
|
-
|
318
315
|
</pre>
|
319
316
|
|
320
317
|
|
321
318
|
<h3 id="Escaped-directives">Escaped directives</h3>
|
322
319
|
|
323
|
-
<p>Add escaped directives:</p>
|
324
|
-
|
325
320
|
<pre><code><%% this is an escaped directive %>
|
326
321
|
%% this is an escaped directive
|
327
322
|
</code></pre>
|
328
323
|
|
329
|
-
<p>With <code>{:shorthand=>true}</code> options, the
|
330
|
-
above template compiles into:</p>
|
324
|
+
<p>With <code>{:shorthand=>true}</code> options, the above template compiles into:</p>
|
331
325
|
|
332
|
-
<pre><code>(_erbout = []; _erbout << "
|
333
|
-
_erbout << "<% this is an escaped directive %>\n"
|
326
|
+
<pre><code>(e08afdfb_62c7_485f_87a0_80914e1b4703 = :_erbout; _erbout = []; _erbout << "<% this is an escaped directive %>\n"
|
334
327
|
_erbout << "% this is an escaped directive\n"
|
335
|
-
_erbout << " \n"
|
336
328
|
; _erbout.join)
|
337
329
|
</code></pre>
|
338
330
|
|
@@ -344,20 +336,14 @@ _erbout << " \n"
|
|
344
336
|
|
345
337
|
<h3 id="Vocal-directives">Vocal directives</h3>
|
346
338
|
|
347
|
-
<p>Add vocal directives, which produce output:</p>
|
348
|
-
|
349
339
|
<pre><code><%= "hello" %>
|
350
340
|
%= "world"
|
351
341
|
</code></pre>
|
352
342
|
|
353
|
-
<p>With <code>{:shorthand=>true}</code> options, the
|
354
|
-
above template compiles into:</p>
|
343
|
+
<p>With <code>{:shorthand=>true}</code> options, the above template compiles into:</p>
|
355
344
|
|
356
|
-
<pre><code>(_erbout = []; _erbout << "\n"
|
357
|
-
_erbout << ("hello") << "\n"
|
345
|
+
<pre><code>(e08afdfb_62c7_485f_87a0_80914e1b4703 = :_erbout; _erbout = []; _erbout << ("hello") << "\n"
|
358
346
|
_erbout << ("world") << "\n"
|
359
|
-
_erbout << "\n"
|
360
|
-
_erbout << " \n"
|
361
347
|
; _erbout.join)
|
362
348
|
</code></pre>
|
363
349
|
|
@@ -369,8 +355,6 @@ world
|
|
369
355
|
|
370
356
|
<h3 id="Silent-directives">Silent directives</h3>
|
371
357
|
|
372
|
-
<p>Add silent directives, which do not produce output:</p>
|
373
|
-
|
374
358
|
<pre><code><% a = "hello" %>
|
375
359
|
% b = "world"
|
376
360
|
|
@@ -378,17 +362,13 @@ world
|
|
378
362
|
%= b
|
379
363
|
</code></pre>
|
380
364
|
|
381
|
-
<p>With <code>{:shorthand=>true}</code> options, the
|
382
|
-
above template compiles into:</p>
|
365
|
+
<p>With <code>{:shorthand=>true}</code> options, the above template compiles into:</p>
|
383
366
|
|
384
|
-
<pre><code>(_erbout = [];
|
385
|
-
a = "hello"
|
367
|
+
<pre><code>(e08afdfb_62c7_485f_87a0_80914e1b4703 = :_erbout; _erbout = []; a = "hello"
|
386
368
|
b = "world"
|
387
369
|
_erbout << "\n"
|
388
370
|
_erbout << (a) << "\n"
|
389
371
|
_erbout << (b) << "\n"
|
390
|
-
_erbout << "\n"
|
391
|
-
_erbout << " \n"
|
392
372
|
; _erbout.join)
|
393
373
|
</code></pre>
|
394
374
|
|
@@ -400,8 +380,6 @@ world
|
|
400
380
|
|
401
381
|
<h3 id="Block-directives">Block directives</h3>
|
402
382
|
|
403
|
-
<p>Add some Ruby blocks:</p>
|
404
|
-
|
405
383
|
<pre><code>% words = %w[hello world]
|
406
384
|
|
407
385
|
<% words.each do |w| %>
|
@@ -417,11 +395,9 @@ world
|
|
417
395
|
% end
|
418
396
|
</code></pre>
|
419
397
|
|
420
|
-
<p>With <code>{:shorthand=>true}</code> options, the
|
421
|
-
above template compiles into:</p>
|
398
|
+
<p>With <code>{:shorthand=>true}</code> options, the above template compiles into:</p>
|
422
399
|
|
423
|
-
<pre><code>(_erbout = [];
|
424
|
-
words = %w[hello world]
|
400
|
+
<pre><code>(e08afdfb_62c7_485f_87a0_80914e1b4703 = :_erbout; _erbout = []; words = %w[hello world]
|
425
401
|
_erbout << "\n"
|
426
402
|
words.each do |w|
|
427
403
|
_erbout << " " << (w) << "\n"
|
@@ -434,8 +410,6 @@ _erbout << "\n"
|
|
434
410
|
words.each do |w|
|
435
411
|
_erbout << " " << (w) << "\n"
|
436
412
|
end
|
437
|
-
_erbout << "\n"
|
438
|
-
_erbout << " \n"
|
439
413
|
; _erbout.join)
|
440
414
|
</code></pre>
|
441
415
|
|
@@ -451,6 +425,212 @@ _erbout << " \n"
|
|
451
425
|
world
|
452
426
|
</code></pre>
|
453
427
|
|
428
|
+
<h3 id="Unindent-block-content">Unindent block content</h3>
|
429
|
+
|
430
|
+
<pre><code><% [1].each do |i| %>
|
431
|
+
<%= i %>
|
432
|
+
% [2].each do |j|
|
433
|
+
%= j
|
434
|
+
%|[3].each |k|
|
435
|
+
%= k
|
436
|
+
% end
|
437
|
+
% end
|
438
|
+
<% end %>
|
439
|
+
</code></pre>
|
440
|
+
|
441
|
+
<p>With <code>{:shorthand=>true, :unindent=>true}</code> options, the above template compiles into:</p>
|
442
|
+
|
443
|
+
<pre><code>(e08afdfb_62c7_485f_87a0_80914e1b4703 = :_erbout; _erbout = []; [1].each do |i|
|
444
|
+
_erbout << (i) << "\n"
|
445
|
+
[2].each do |j|
|
446
|
+
_erbout << (j) << "\n"
|
447
|
+
[3].each do |k|
|
448
|
+
_erbout << (k) << "\n"
|
449
|
+
end
|
450
|
+
end
|
451
|
+
end
|
452
|
+
; _erbout.join)
|
453
|
+
</code></pre>
|
454
|
+
|
455
|
+
<p>And renders as:</p>
|
456
|
+
|
457
|
+
<pre><code>1
|
458
|
+
2
|
459
|
+
3
|
460
|
+
</code></pre>
|
461
|
+
|
462
|
+
<h3 id="Wrap-block-content">Wrap block content</h3>
|
463
|
+
|
464
|
+
<p>In this manner, you can create domain specific languages in eRuby.</p>
|
465
|
+
|
466
|
+
<pre><code><%
|
467
|
+
def introducing(subject, &block)
|
468
|
+
Ember::Template.wrap_content_block(block, rand(10)) do |content|
|
469
|
+
"And now I would like to introduce #{subject}:\n\n#{content.join}"
|
470
|
+
end
|
471
|
+
end
|
472
|
+
|
473
|
+
def coin_toss(pronoun, &block)
|
474
|
+
Ember::Template.wrap_content_block(block) do |content|
|
475
|
+
"#{pronoun} favorite side of a coin toss is #{content.join}."
|
476
|
+
end
|
477
|
+
end
|
478
|
+
%>
|
479
|
+
|
480
|
+
% introducing "Matz" do |number|
|
481
|
+
Father of the Ruby programming language,
|
482
|
+
and also a jolly and well mannered fellow.
|
483
|
+
|
484
|
+
% coin_toss("His") { number % 2 == 0 ? "heads" : "tails" }
|
485
|
+
% end
|
486
|
+
</code></pre>
|
487
|
+
|
488
|
+
<p>With <code>{:shorthand=>true, :unindent=>true}</code> options, the above template compiles into:</p>
|
489
|
+
|
490
|
+
<pre><code>(e08afdfb_62c7_485f_87a0_80914e1b4703 = :_erbout; _erbout = [];
|
491
|
+
def introducing(subject, &block)
|
492
|
+
Ember::Template.wrap_content_block(block, rand(10)) do |content|
|
493
|
+
"And now I would like to introduce #{subject}:\n\n#{content.join}"
|
494
|
+
end
|
495
|
+
end
|
496
|
+
|
497
|
+
def coin_toss(pronoun, &block)
|
498
|
+
Ember::Template.wrap_content_block(block) do |content|
|
499
|
+
"#{pronoun} favorite side of a coin toss is #{content.join}."
|
500
|
+
end
|
501
|
+
end
|
502
|
+
|
503
|
+
_erbout << "\n"
|
504
|
+
introducing "Matz" do |number|
|
505
|
+
_erbout << "Father of the Ruby programming language,\n"
|
506
|
+
_erbout << "and also a jolly and well mannered fellow.\n"
|
507
|
+
_erbout << "\n"
|
508
|
+
coin_toss("His") { number % 2 == 0 ? "heads" : "tails" }
|
509
|
+
end
|
510
|
+
; _erbout.join)
|
511
|
+
</code></pre>
|
512
|
+
|
513
|
+
<p>And renders as:</p>
|
514
|
+
|
515
|
+
<pre><code>And now I would like to introduce Matz:
|
516
|
+
|
517
|
+
Father of the Ruby programming language,
|
518
|
+
and also a jolly and well mannered fellow.
|
519
|
+
|
520
|
+
His favorite side of a coin toss is tails.
|
521
|
+
</code></pre>
|
522
|
+
|
523
|
+
<h3 id="Capture-block-content">Capture block content</h3>
|
524
|
+
|
525
|
+
<p>In this manner, you can create domain specific languages in eRuby.</p>
|
526
|
+
|
527
|
+
<pre><code><%
|
528
|
+
def introducing(subject, &block)
|
529
|
+
content = Ember::Template.content_from_block(block, rand(2))
|
530
|
+
|
531
|
+
buffer = Ember::Template.buffer_from_block(block)
|
532
|
+
buffer << "introducing(#{subject.inspect}):\n\n#{content.join}"
|
533
|
+
end
|
534
|
+
|
535
|
+
def coin_toss(pronoun, &block)
|
536
|
+
content = Ember::Template.content_from_block(block)
|
537
|
+
|
538
|
+
buffer = Ember::Template.buffer_from_block(block)
|
539
|
+
buffer << "coin_toss(#{pronoun.inspect}): #{content.join}"
|
540
|
+
end
|
541
|
+
%>
|
542
|
+
|
543
|
+
% introducing "Matz" do |number|
|
544
|
+
Father of the Ruby programming language,
|
545
|
+
and also a jolly and well mannered fellow.
|
546
|
+
|
547
|
+
% coin_toss("His") { number % 2 == 0 ? "heads" : "tails" }
|
548
|
+
% end
|
549
|
+
</code></pre>
|
550
|
+
|
551
|
+
<p>With <code>{:shorthand=>true, :unindent=>true}</code> options, the above template compiles into:</p>
|
552
|
+
|
553
|
+
<pre><code>(e08afdfb_62c7_485f_87a0_80914e1b4703 = :_erbout; _erbout = [];
|
554
|
+
def introducing(subject, &block)
|
555
|
+
content = Ember::Template.content_from_block(block, rand(2))
|
556
|
+
|
557
|
+
buffer = Ember::Template.buffer_from_block(block)
|
558
|
+
buffer << "introducing(#{subject.inspect}):\n\n#{content.join}"
|
559
|
+
end
|
560
|
+
|
561
|
+
def coin_toss(pronoun, &block)
|
562
|
+
content = Ember::Template.content_from_block(block)
|
563
|
+
|
564
|
+
buffer = Ember::Template.buffer_from_block(block)
|
565
|
+
buffer << "coin_toss(#{pronoun.inspect}): #{content.join}"
|
566
|
+
end
|
567
|
+
|
568
|
+
_erbout << "\n"
|
569
|
+
introducing "Matz" do |number|
|
570
|
+
_erbout << "Father of the Ruby programming language,\n"
|
571
|
+
_erbout << "and also a jolly and well mannered fellow.\n"
|
572
|
+
_erbout << "\n"
|
573
|
+
coin_toss("His") { number % 2 == 0 ? "heads" : "tails" }
|
574
|
+
end
|
575
|
+
; _erbout.join)
|
576
|
+
</code></pre>
|
577
|
+
|
578
|
+
<p>And renders as:</p>
|
579
|
+
|
580
|
+
<pre><code>introducing("Matz"):
|
581
|
+
|
582
|
+
Father of the Ruby programming language,
|
583
|
+
and also a jolly and well mannered fellow.
|
584
|
+
|
585
|
+
coin_toss("His"): heads
|
586
|
+
</code></pre>
|
587
|
+
|
588
|
+
<h3 id="Template-evaluation-result-buffer">Template evaluation result buffer</h3>
|
589
|
+
|
590
|
+
<p>In this manner, you can create domain specific languages in eRuby.</p>
|
591
|
+
|
592
|
+
<pre><code><%
|
593
|
+
def introducing(subject, &block)
|
594
|
+
buffer = Ember::Template.buffer_from_block(block)
|
595
|
+
#
|
596
|
+
# you can do whatever you want with buffer,
|
597
|
+
# now that you have a reference to it! >:-)
|
598
|
+
#
|
599
|
+
buffer << "introducing(#{subject.inspect})"
|
600
|
+
end
|
601
|
+
%>
|
602
|
+
|
603
|
+
% introducing "Matz" do |number|
|
604
|
+
Father of the Ruby programming language,
|
605
|
+
and also a jolly and well mannered fellow.
|
606
|
+
% end
|
607
|
+
</code></pre>
|
608
|
+
|
609
|
+
<p>With <code>{:shorthand=>true, :unindent=>true}</code> options, the above template compiles into:</p>
|
610
|
+
|
611
|
+
<pre><code>(e08afdfb_62c7_485f_87a0_80914e1b4703 = :_erbout; _erbout = [];
|
612
|
+
def introducing(subject, &block)
|
613
|
+
buffer = Ember::Template.buffer_from_block(block)
|
614
|
+
#
|
615
|
+
# you can do whatever you want with buffer,
|
616
|
+
# now that you have a reference to it! >:-)
|
617
|
+
#
|
618
|
+
buffer << "introducing(#{subject.inspect})"
|
619
|
+
end
|
620
|
+
|
621
|
+
_erbout << "\n"
|
622
|
+
introducing "Matz" do |number|
|
623
|
+
_erbout << "Father of the Ruby programming language,\n"
|
624
|
+
_erbout << "and also a jolly and well mannered fellow.\n"
|
625
|
+
end
|
626
|
+
; _erbout.join)
|
627
|
+
</code></pre>
|
628
|
+
|
629
|
+
<p>And renders as:</p>
|
630
|
+
|
631
|
+
<pre><code>introducing("Matz")
|
632
|
+
</code></pre>
|
633
|
+
|
454
634
|
<h3 id="Infer-block-endings">Infer block endings</h3>
|
455
635
|
|
456
636
|
<p>Omit <code><% end %></code> directives from the template:</p>
|
@@ -467,11 +647,9 @@ _erbout << " \n"
|
|
467
647
|
%= w
|
468
648
|
</code></pre>
|
469
649
|
|
470
|
-
<p>With <code>{:shorthand=>true, :infer_end=>true}</code> options, the
|
471
|
-
above template compiles into:</p>
|
650
|
+
<p>With <code>{:shorthand=>true, :infer_end=>true}</code> options, the above template compiles into:</p>
|
472
651
|
|
473
|
-
<pre><code>(_erbout = [];
|
474
|
-
words = %w[hello world]
|
652
|
+
<pre><code>(e08afdfb_62c7_485f_87a0_80914e1b4703 = :_erbout; _erbout = []; words = %w[hello world]
|
475
653
|
_erbout << "\n"
|
476
654
|
words.each do |w|
|
477
655
|
_erbout << " " << (w) << "\n"
|
@@ -481,9 +659,7 @@ _erbout << " " << (w) << "\n"
|
|
481
659
|
end; _erbout << "\n"
|
482
660
|
words.each do |w|
|
483
661
|
_erbout << " " << (w) << "\n"
|
484
|
-
end; _erbout
|
485
|
-
_erbout << " \n"
|
486
|
-
; _erbout.join)
|
662
|
+
end; _erbout.join)
|
487
663
|
</code></pre>
|
488
664
|
|
489
665
|
<p>And renders as:</p>
|
@@ -513,15 +689,11 @@ _erbout << " \n"
|
|
513
689
|
%< "doc/example.txt"
|
514
690
|
</code></pre>
|
515
691
|
|
516
|
-
<p>With <code>{:shorthand=>true, :source_file=>"./EXAMPLES"}</code> options, the
|
517
|
-
above template compiles into:</p>
|
692
|
+
<p>With <code>{:shorthand=>true, :source_file=>"./EXAMPLES"}</code> options, the above template compiles into:</p>
|
518
693
|
|
519
|
-
<pre><code>(_erbout = []; _erbout << "\n"
|
520
|
-
_erbout << (::Ember::Template.read_file(("doc/example.txt"), {:shorthand=>true, :source_file=>"./EXAMPLES"})) << "\n"
|
694
|
+
<pre><code>(e08afdfb_62c7_485f_87a0_80914e1b4703 = :_erbout; _erbout = []; _erbout << (::Ember::Template.read_file(("doc/example.txt"), {:shorthand=>true, :source_file=>"./EXAMPLES"})) << "\n"
|
521
695
|
_erbout << "\n"
|
522
696
|
_erbout << (::Ember::Template.read_file(("doc/example.txt"), {:shorthand=>true, :source_file=>"./EXAMPLES"})) << "\n"
|
523
|
-
_erbout << "\n"
|
524
|
-
_erbout << " \n"
|
525
697
|
; _erbout.join)
|
526
698
|
</code></pre>
|
527
699
|
|
@@ -549,15 +721,11 @@ This is a plain-text file. Notice that <%=
|
|
549
721
|
%+ "doc/example.erb"
|
550
722
|
</code></pre>
|
551
723
|
|
552
|
-
<p>With <code>{:shorthand=>true, :source_file=>"./EXAMPLES"}</code> options, the
|
553
|
-
above template compiles into:</p>
|
724
|
+
<p>With <code>{:shorthand=>true, :source_file=>"./EXAMPLES"}</code> options, the above template compiles into:</p>
|
554
725
|
|
555
|
-
<pre><code>(_erbout = []; _erbout << "\n"
|
556
|
-
::Ember::Template.load_file(("doc/example.erb"), {:shorthand=>true, :source_file=>"./EXAMPLES"}.merge!(:continue_result => true)).render(nil, 78416100); _erbout << "\n"
|
557
|
-
_erbout << "\n"
|
558
|
-
::Ember::Template.load_file(("doc/example.erb"), {:shorthand=>true, :source_file=>"./EXAMPLES"}.merge!(:continue_result => true)).render(nil, 78416100); _erbout << "\n"
|
726
|
+
<pre><code>(e08afdfb_62c7_485f_87a0_80914e1b4703 = :_erbout; _erbout = []; ::Ember::Template.load_file(("doc/example.erb"), {:shorthand=>true, :source_file=>"./EXAMPLES"}.merge!(:continue_result => true)).render(::Kernel.binding); _erbout << "\n"
|
559
727
|
_erbout << "\n"
|
560
|
-
_erbout << "
|
728
|
+
::Ember::Template.load_file(("doc/example.erb"), {:shorthand=>true, :source_file=>"./EXAMPLES"}.merge!(:continue_result => true)).render(::Kernel.binding); _erbout << "\n"
|
561
729
|
; _erbout.join)
|
562
730
|
</code></pre>
|
563
731
|
|
@@ -575,15 +743,11 @@ This is an eRuby template. Notice that eRuby directives do take effect here!
|
|
575
743
|
%~ "%= 2 + 2"
|
576
744
|
</code></pre>
|
577
745
|
|
578
|
-
<p>With <code>{:shorthand=>true}</code> options, the
|
579
|
-
above template compiles into:</p>
|
746
|
+
<p>With <code>{:shorthand=>true}</code> options, the above template compiles into:</p>
|
580
747
|
|
581
|
-
<pre><code>(_erbout = []; _erbout << "\n"
|
582
|
-
::Ember::Template.new(("%= 2 + 2"), {:shorthand=>true}.merge!(:continue_result => true)).render(nil, 77958272); _erbout << "\n"
|
748
|
+
<pre><code>(e08afdfb_62c7_485f_87a0_80914e1b4703 = :_erbout; _erbout = []; ::Ember::Template.new(("%= 2 + 2"), {:shorthand=>true}.merge!(:continue_result => true)).render(::Kernel.binding); _erbout << "\n"
|
583
749
|
_erbout << "\n"
|
584
|
-
::Ember::Template.new(("%= 2 + 2"), {:shorthand=>true}.merge!(:continue_result => true)).render(
|
585
|
-
_erbout << "\n"
|
586
|
-
_erbout << " \n"
|
750
|
+
::Ember::Template.new(("%= 2 + 2"), {:shorthand=>true}.merge!(:continue_result => true)).render(::Kernel.binding); _erbout << "\n"
|
587
751
|
; _erbout.join)
|
588
752
|
</code></pre>
|
589
753
|
|
@@ -679,6 +843,37 @@ in the <code>test/test_helper.rb</code> file.</p>
|
|
679
843
|
|
680
844
|
<p>This section contains release notes of current and past releases.</p>
|
681
845
|
|
846
|
+
<h3 id="Version-0-3-0-2010-04-26-">Version 0.3.0 (2010-04-26)</h3>
|
847
|
+
|
848
|
+
<p>This release adds <em>class methods</em> that let you (portably and more easily)
|
849
|
+
create your own domain specific languages in eRuby; adds more usage
|
850
|
+
<strong>EXAMPLES</strong> in the help manual; and removes a binding inheritance hack.</p>
|
851
|
+
|
852
|
+
<p>New features:</p>
|
853
|
+
|
854
|
+
<dl>
|
855
|
+
<dt><code>Ember::Template::wrap_content_block()</code></dt><dd><p>Wraps eRuby block content appending.</p></dd>
|
856
|
+
<dt><code>Ember::Template::content_from_block()</code></dt><dd><p>Extracts content from eRuby blocks.</p></dd>
|
857
|
+
<dt><code>Ember::Template::buffer_from_block()</code></dt><dd><p>Gives access to template evalutaion result buffer.</p></dd>
|
858
|
+
</dl>
|
859
|
+
|
860
|
+
|
861
|
+
<p>Bug fixes:</p>
|
862
|
+
|
863
|
+
<ul>
|
864
|
+
<li>Remove hack for inheriting parent template binding.</li>
|
865
|
+
</ul>
|
866
|
+
|
867
|
+
|
868
|
+
<p>Housekeeping:</p>
|
869
|
+
|
870
|
+
<ul>
|
871
|
+
<li><p>Add example on unindenting node content and eRuby DSL examples that use
|
872
|
+
the new content block methods.</p></li>
|
873
|
+
<li><p>Simplify code examples using the new wrap_content_block() method.</p></li>
|
874
|
+
</ul>
|
875
|
+
|
876
|
+
|
682
877
|
<h3 id="Version-0-2-0-2010-04-25-">Version 0.2.0 (2010-04-25)</h3>
|
683
878
|
|
684
879
|
<p>This release adds <a href="http://rubyonrails.org">Ruby on Rails</a> integration.</p>
|
@@ -806,7 +1001,7 @@ Kamil Kukura</p>
|
|
806
1001
|
|
807
1002
|
<p>(the ISC license)</p>
|
808
1003
|
|
809
|
-
<p>Copyright 2009 Suraj N. Kurapati <a href="mailt&#
|
1004
|
+
<p>Copyright 2009 Suraj N. Kurapati <a href="mailto:sunaku@gmail.com" data-bare-link="true">sunaku@gmail.com</a></p>
|
810
1005
|
|
811
1006
|
<p>Permission to use, copy, modify, and/or distribute this software for any
|
812
1007
|
purpose with or without fee is hereby granted, provided that the above
|
data/man/man1/ember.1.gz
CHANGED
Binary file
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
7
|
+
- 3
|
8
8
|
- 0
|
9
|
-
version: 0.
|
9
|
+
version: 0.3.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Suraj N. Kurapati
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-04-
|
18
|
+
date: 2010-04-26 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|