ember 0.3.0 → 0.3.1

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.
metadata CHANGED
@@ -1,48 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ember
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 3
8
- - 0
9
- version: 0.3.0
4
+ prerelease:
5
+ version: 0.3.1
10
6
  platform: ruby
11
7
  authors:
12
8
  - Suraj N. Kurapati
13
- - Kamil Kukura
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
12
 
18
- date: 2010-04-26 00:00:00 -07:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
22
- name: inochi
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
25
- requirements:
26
- - - ~>
27
- - !ruby/object:Gem::Version
28
- segments:
29
- - 2
30
- version: "2"
31
- type: :development
32
- version_requirements: *id001
33
- - !ruby/object:Gem::Dependency
34
- name: dfect
35
- prerelease: false
36
- requirement: &id002 !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ~>
39
- - !ruby/object:Gem::Version
40
- segments:
41
- - 2
42
- version: "2"
43
- type: :development
44
- version_requirements: *id002
45
- description: Ember (EMBEdded Ruby) is an eRuby template processor that allows debugging, reduces markup, and improves composability of eRuby templates.
13
+ date: 2011-04-22 00:00:00 Z
14
+ dependencies: []
15
+
16
+ description: Ember (EMBEdded Ruby) is an [eRuby] template processor that allows
46
17
  debugging, reduces markup, and improves composability of eRuby templates.
47
18
  email:
48
19
  executables:
49
20
  - ember
@@ -52,15 +23,12 @@ extra_rdoc_files: []
52
23
 
53
24
  files:
54
25
  - bin/ember
55
- - lib/ember.rb
56
- - lib/ember/inochi.rb
57
- - lib/ember/template.rb
58
26
  - lib/ember/helpers/rails_helper.rb
27
+ - lib/ember/template.rb
28
+ - lib/ember/inochi.rb
29
+ - lib/ember.rb
59
30
  - LICENSE
60
- - CREDITS
61
- - man.html
62
- - man/man1/ember.1.gz
63
- has_rdoc: true
31
+ - man/man1/ember.1
64
32
  homepage: http://snk.tuxfamily.org/lib/ember/
65
33
  licenses: []
66
34
 
@@ -70,23 +38,21 @@ rdoc_options: []
70
38
  require_paths:
71
39
  - lib
72
40
  required_ruby_version: !ruby/object:Gem::Requirement
41
+ none: false
73
42
  requirements:
74
43
  - - ">="
75
44
  - !ruby/object:Gem::Version
76
- segments:
77
- - 0
78
45
  version: "0"
79
46
  required_rubygems_version: !ruby/object:Gem::Requirement
47
+ none: false
80
48
  requirements:
81
49
  - - ">="
82
50
  - !ruby/object:Gem::Version
83
- segments:
84
- - 0
85
51
  version: "0"
86
52
  requirements: []
87
53
 
88
54
  rubyforge_project:
89
- rubygems_version: 1.3.6
55
+ rubygems_version: 1.7.2
90
56
  signing_key:
91
57
  specification_version: 3
92
58
  summary: eRuby template processor
data/CREDITS DELETED
@@ -1,13 +0,0 @@
1
- %#----------------------------------------------------------------------------
2
- ## CREDITS
3
- %#----------------------------------------------------------------------------
4
-
5
- Suraj N. Kurapati,
6
- Kamil Kukura
7
-
8
- %#----------------------------------------------------------------------------
9
- ## LICENSE
10
- %#----------------------------------------------------------------------------
11
-
12
- %# See the file named "LICENSE".
13
- %< "LICENSE"
data/man.html DELETED
@@ -1,1031 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <meta http-equiv='content-type' value='text/html;charset=utf8'>
5
- <meta name='generator' value='Ronn/v0.5 (http://github.com/rtomayko/ronn)'>
6
- <title>ember(1) - eRuby template processor</title>
7
- <style type='text/css'>
8
- body {margin:0}
9
- #man, #man code, #man pre, #man tt, #man kbd, #man samp {
10
- font-family:consolas,monospace;
11
- font-size:16px;
12
- line-height:1.3;
13
- color:#343331;
14
- background:#fff; }
15
- #man { max-width:87ex; margin:0 3ex 1ex 1ex; text-align:justify; }
16
- #man div.man-navigation {
17
- position:fixed;
18
- top:0;
19
- left:91ex;
20
- height:100%;
21
- width:100%;
22
- padding:1ex 0 0 2ex;
23
- border-left:0.5ex solid #DCDCDC;
24
- background-color: #F5F5F5;
25
- }
26
- #man div.man-navigation a { display:block; margin-bottom:1.5ex }
27
- #man h1, #man h2, #man h3 { color:#232221;clear:left }
28
- #man h1 { font-size:28px; margin:15px 0 30px 0; text-align:center }
29
- #man h2 { font-size:18px; margin-bottom:0; margin-top:10px; line-height:1.3; }
30
- #man h3 { font-size:16px; margin:0 0 0 4ex; }
31
- #man p, #man ul, #man ol, #man dl, #man pre { margin:0 0 18px 0; }
32
- #man pre {
33
- color:#333231;
34
- background:#edeceb;
35
- padding:5px 7px;
36
- margin:0px 0 20px 0;
37
- border-left:2ex solid #ddd}
38
- #man pre + h2, #man pre + h3 {
39
- margin-top:22px;
40
- }
41
- #man h2 + pre, #man h3 + pre {
42
- margin-top:5px;
43
- }
44
- #man > p, #man > ul, #man > ol, #man > dl, #man > pre { margin-left:8ex; }
45
- #man dt { margin:0; clear:left }
46
- #man dt.flush { float:left; width:8ex }
47
- #man dd { margin:0 0 0 9ex }
48
- #man code, #man strong, #man b { font-weight:bold; color:#131211; }
49
- #man pre code { font-weight:normal; color:#232221; background:inherit }
50
- #man em, var, u {
51
- font-style:normal; color:#333231; border-bottom:1px solid #999; }
52
- #man h1.man-title { display:none; }
53
- #man ol.man, #man ol.man li { margin:2px 0 10px 0; padding:0;
54
- float:left; width:33%; list-style-type:none;
55
- text-transform:uppercase; font-size:18px; color:#999;
56
- letter-spacing:1px;}
57
- #man ol.man { width:100%; }
58
- #man ol.man li.tl { text-align:left }
59
- #man ol.man li.tc { text-align:center;letter-spacing:4px }
60
- #man ol.man li.tr { text-align:right; float: right }
61
- #man ol.man a { color:#999 }
62
- #man ol.man a:hover { color:#333231 }
63
- #man img { display:block; margin:auto }
64
- </style>
65
- <style type='text/css' media='print'>
66
- #man { max-width:none }
67
- #man div.man-navigation { display:none }
68
- #man a[href]:not([href^="#"]):not([data-bare-link]):after {
69
- content:" " attr(href);
70
- }
71
- </style>
72
- </head>
73
- <body>
74
- <div id='man'>
75
-
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>
90
-
91
- <h1 class='man-title'>ember(1)</h1>
92
-
93
- <ol class='head man'>
94
- <li class='tl'>ember(1)</li>
95
- <li class='tc'>Version 0.3.0</li>
96
- <li class='tr'>ember(1)</li>
97
- </ol>
98
-
99
- <h2 id='NAME'>NAME</h2>
100
- <p><code>ember</code> - eRuby template processor</p>
101
-
102
- <h2 id="ABOUT">ABOUT</h2>
103
-
104
- <p>Ember (<em>EMBE</em>dded <em>R</em>uby) is an <a href="http://en.wikipedia.org/wiki/ERuby">eRuby template</a> processor that allows
105
- debugging, reduces markup, and improves composability of eRuby templates.</p>
106
-
107
- <h3 id="Features">Features</h3>
108
-
109
- <ul>
110
- <li><p>Reports correct line numbers in error message stack traces.</p></li>
111
- <li><p>Omits newlines trailing code-only <code>&lt;% ... %&gt;</code> directives.</p></li>
112
- <li><p>Can infer missing <code>&lt;% end %></code> directives based on indentation.</p></li>
113
- <li><p>Can unindent eRuby block bodies hierarchically.</p></li>
114
- <li><p>Written in 361 lines of pure
115
- Ruby.</p></li>
116
- </ul>
117
-
118
-
119
- <h3 id="Resources">Resources</h3>
120
-
121
- <dl>
122
- <dt>Issue tracker (report bugs, request features, get help)</dt><dd><p><a href="http://github.com/sunaku/ember/issues" data-bare-link="true">http://github.com/sunaku/ember/issues</a></p></dd>
123
- <dt>Source code (browse online or obtain with <a href="http://git-scm.com">Git</a>)</dt><dd><p><a href="http://github.com/sunaku/ember" data-bare-link="true">http://github.com/sunaku/ember</a></p></dd>
124
- <dt>API documentation</dt><dd><p><a href="http://snk.tuxfamily.org/lib/ember/api/" data-bare-link="true">http://snk.tuxfamily.org/lib/ember/api/</a></p></dd>
125
- <dt>Announcements feed</dt><dd><p><a href="http://snk.tuxfamily.org/lib/ember/ann.xml" data-bare-link="true">http://snk.tuxfamily.org/lib/ember/ann.xml</a></p></dd>
126
- <dt>Official website</dt><dd><p><a href="http://snk.tuxfamily.org/lib/ember/" data-bare-link="true">http://snk.tuxfamily.org/lib/ember/</a></p></dd>
127
- </dl>
128
-
129
-
130
- <h3 id="Setup">Setup</h3>
131
-
132
- <p>Prerequisites:</p>
133
-
134
- <ul>
135
- <li><p><a href="http://ruby-lang.org">Ruby</a> 1.8.6 or newer.</p></li>
136
- <li><p><a href="http://rubygems.org">RubyGems</a> 1.3.6 or newer.</p></li>
137
- </ul>
138
-
139
-
140
- <p>Installing:</p>
141
-
142
- <pre><code>gem install ember
143
- </code></pre>
144
-
145
- <p>Installing as a <a href="http://rubyonrails.org">Ruby on Rails</a> plugin:</p>
146
-
147
- <pre><code>script/plugin install git://github.com/sunaku/ember.git
148
- </code></pre>
149
-
150
- <p>Upgrading:</p>
151
-
152
- <pre><code>gem update ember
153
- </code></pre>
154
-
155
- <p>Removing:</p>
156
-
157
- <pre><code>gem uninstall ember
158
- </code></pre>
159
-
160
- <h2 id="SYNOPSIS">SYNOPSIS</h2>
161
-
162
- <p><code>ember</code> [<var>OPTIONS</var>] [<var>FILE</var>]</p>
163
-
164
- <h2 id="DESCRIPTION">DESCRIPTION</h2>
165
-
166
- <p>Evaluates eRuby directives (see <strong>SYNTAX</strong> below) in the given <var>FILE</var> and
167
- writes the result to the standard output stream (STDOUT). If <var>FILE</var> is not
168
- given, then the standard input stream (STDIN) is evaluated instead.</p>
169
-
170
- <h2 id="OPTIONS">OPTIONS</h2>
171
-
172
- <dl>
173
- <dt><code>-s</code>, <code>--shorthand</code></dt><dd><p>Treat lines beginning with zero or more whitespace
174
- followed by the "%" character as eRuby directives.</p></dd>
175
- <dt><code>-i</code>, <code>--infer_end</code></dt><dd><p>Add missing <code>&lt;% end %></code> directives based on indentation.</p></dd>
176
- <dt><code>-u</code>, <code>--unindent</code></dt><dd><p>Unindent the bodies of directives that define a
177
- Ruby block (do ... end) or scope (begin ... end).</p></dd>
178
- <dt><code>-c</code>, <code>--compile</code></dt><dd><p>Print underlying Ruby program compiled
179
- from the input eRuby template and exit.</p></dd>
180
- <dt><code>-h</code>, <code>--help</code></dt><dd><p>Display this manual and exit.</p></dd>
181
- <dt><code>-v</code>, <code>--version</code></dt><dd><p>Print version number and exit.</p></dd>
182
- </dl>
183
-
184
-
185
- <h2 id="SYNTAX">SYNTAX</h2>
186
-
187
- <p>This section explains <a href="http://en.wikipedia.org/wiki/ERuby">eRuby template</a> syntax and Ember extensions thereof.</p>
188
-
189
- <p>eRuby templates are plain-text documents that contain special processing
190
- instructions known as <strong>directives</strong>. These instructions are evaluated <em>in
191
- place</em>, meaning that they are replaced by the result of their evaluation.</p>
192
-
193
- <h3 id="Directives">Directives</h3>
194
-
195
- <p>Directives are expressed in either <strong>standard</strong> or <strong>shorthand</strong> notation:</p>
196
-
197
- <pre><code>Notation Directive Head Operation Body Tail
198
- -------- --------- ---- --------- ---- ----
199
- Standard &lt;%XY%> &lt;% X Y %>
200
- Shorthand %XY % X Y
201
- </code></pre>
202
-
203
- <p>In standard notation, the directive is composed of a <strong>head</strong>, an
204
- <strong>operation</strong>, a <strong>body</strong>, and a <strong>tail</strong>; and it may appear anywhere in the
205
- template.</p>
206
-
207
- <p>In shorthand notation, the directive is composed of a <strong>head</strong>, an
208
- <strong>operation</strong>, and a <strong>body</strong>; and it may only appear in the template if it
209
- occupies an entire line (leading whitespace is permitted only in Ember;
210
- trailing whitespace is permitted in both Ember and eRuby).</p>
211
-
212
- <p>Regardless of the notation used, directives are atomic constructs; they cannot
213
- be nested within one another.</p>
214
-
215
- <h3 id="Operations">Operations</h3>
216
-
217
- <p>The first character following the head of a directive is known as an
218
- <strong>operation</strong>. It determines how the directive is processed by Ember.</p>
219
-
220
- <dl>
221
- <dt class="flush"><code>#</code></dt><dd><p>The entire directive is omitted from the output.</p></dd>
222
- <dt class="flush"><code>=</code></dt><dd><p>The body of the directive is evaluated as Ruby code, and the result of
223
- this evaluation is inserted into the output.</p></dd>
224
- <dt class="flush"><code>~</code></dt><dd><p>(only in Ember) The body of the directive is evaluated as an eRuby
225
- template, and the result of this evaluation is inserted into the output.</p></dd>
226
- <dt class="flush"><code>+</code></dt><dd><p>(only in Ember) The body of the directive is evaluated as Ruby code, and
227
- the result of this evaluation is assumed to be a string that specifies the
228
- path (either absolute or relative to the eRuby template file in which this
229
- directive is found) to a file containing an eRuby template. This file is
230
- read and its contents are evaluated as an eRuby template, and the result
231
- of this evaluation is inserted into the output.</p></dd>
232
- <dt class="flush"><code>&lt;</code></dt><dd><p>(only in Ember) The body of the directive is evaluated as Ruby code, and
233
- the result of this evaluation is assumed to be a string that specifies the
234
- path (either absolute or relative to the eRuby template file in which this
235
- directive is found) to a file. This file is read and its contents are
236
- inserted into the output.</p></dd>
237
- <dt class="flush"><code>|</code></dt><dd><p>(only in Ember) The body of the directive is treated as the beginning of a
238
- Ruby block. The <code>do</code> keyword is automatically appended to the body of the
239
- directive if missing.</p></dd>
240
- <dt class="flush"><code>%</code></dt><dd><p>One "%" character is omitted from the head of the directive and the entire
241
- directive is inserted into the output.</p></dd>
242
- <dt>None of the above</dt><dd><p>The body of the directive is evaluated as Ruby code, but the result of
243
- this evaluation <em>is not</em> inserted into the output.</p></dd>
244
- </dl>
245
-
246
-
247
- <h2 id="EXAMPLES">EXAMPLES</h2>
248
-
249
- <p>Begin by loading Ember into Ruby:</p>
250
-
251
- <pre><code>require 'rubygems' # might not be necessary; see HACKING
252
- require 'ember'
253
- </code></pre>
254
-
255
- <p>Instantiate an Ember template processor:</p>
256
-
257
- <pre><code>source = "your eRuby template here"
258
- options = {} # see API documentation
259
- template = Ember::Template.new(source, options)
260
- </code></pre>
261
-
262
- <p>Inspect the Ruby program that was compiled (and is used) by the Ember
263
- template processor to evaluate the eRuby template given as input:</p>
264
-
265
- <pre><code>puts template.program
266
- </code></pre>
267
-
268
- <p>View the result of evaluating the eRuby template:</p>
269
-
270
- <pre><code>puts template.render
271
- </code></pre>
272
-
273
- <p>See the API documentation for more information.</p>
274
-
275
- <h3 id="An-empty-template">An empty template</h3>
276
-
277
- <pre></pre>
278
-
279
-
280
- <p>The above template compiles into:</p>
281
-
282
- <pre><code>(e08afdfb_62c7_485f_87a0_80914e1b4703 = :_erbout; _erbout = []; ; _erbout.join)
283
- </code></pre>
284
-
285
- <p>And renders as:</p>
286
-
287
- <pre></pre>
288
-
289
-
290
- <h3 id="Comment-directives">Comment directives</h3>
291
-
292
- <pre><code>&lt;%# this is a comment %>
293
- %# this is also a comment
294
- &lt;%# this
295
- is
296
- a
297
- multi-line comment %>
298
- </code></pre>
299
-
300
- <p>With <code>{:shorthand=&gt;true}</code> options, the above template compiles into:</p>
301
-
302
- <pre><code>(e08afdfb_62c7_485f_87a0_80914e1b4703 = :_erbout; _erbout = []; _erbout &lt;&lt; "\n"
303
- _erbout &lt;&lt; "\n"
304
-
305
-
306
-
307
-
308
- ; _erbout.join)
309
- </code></pre>
310
-
311
- <p>And renders as:</p>
312
-
313
- <pre>
314
-
315
- </pre>
316
-
317
-
318
- <h3 id="Escaped-directives">Escaped directives</h3>
319
-
320
- <pre><code>&lt;%% this is an escaped directive %>
321
- %% this is an escaped directive
322
- </code></pre>
323
-
324
- <p>With <code>{:shorthand=&gt;true}</code> options, the above template compiles into:</p>
325
-
326
- <pre><code>(e08afdfb_62c7_485f_87a0_80914e1b4703 = :_erbout; _erbout = []; _erbout &lt;&lt; "&lt;% this is an escaped directive %>\n"
327
- _erbout &lt;&lt; "% this is an escaped directive\n"
328
- ; _erbout.join)
329
- </code></pre>
330
-
331
- <p>And renders as:</p>
332
-
333
- <pre><code>&lt;% this is an escaped directive %>
334
- % this is an escaped directive
335
- </code></pre>
336
-
337
- <h3 id="Vocal-directives">Vocal directives</h3>
338
-
339
- <pre><code>&lt;%= "hello" %>
340
- %= "world"
341
- </code></pre>
342
-
343
- <p>With <code>{:shorthand=&gt;true}</code> options, the above template compiles into:</p>
344
-
345
- <pre><code>(e08afdfb_62c7_485f_87a0_80914e1b4703 = :_erbout; _erbout = []; _erbout &lt;&lt; ("hello") &lt;&lt; "\n"
346
- _erbout &lt;&lt; ("world") &lt;&lt; "\n"
347
- ; _erbout.join)
348
- </code></pre>
349
-
350
- <p>And renders as:</p>
351
-
352
- <pre><code>hello
353
- world
354
- </code></pre>
355
-
356
- <h3 id="Silent-directives">Silent directives</h3>
357
-
358
- <pre><code>&lt;% a = "hello" %>
359
- % b = "world"
360
-
361
- &lt;%= a %>
362
- %= b
363
- </code></pre>
364
-
365
- <p>With <code>{:shorthand=&gt;true}</code> options, the above template compiles into:</p>
366
-
367
- <pre><code>(e08afdfb_62c7_485f_87a0_80914e1b4703 = :_erbout; _erbout = []; a = "hello"
368
- b = "world"
369
- _erbout &lt;&lt; "\n"
370
- _erbout &lt;&lt; (a) &lt;&lt; "\n"
371
- _erbout &lt;&lt; (b) &lt;&lt; "\n"
372
- ; _erbout.join)
373
- </code></pre>
374
-
375
- <p>And renders as:</p>
376
-
377
- <pre><code>hello
378
- world
379
- </code></pre>
380
-
381
- <h3 id="Block-directives">Block directives</h3>
382
-
383
- <pre><code>% words = %w[hello world]
384
-
385
- &lt;% words.each do |w| %&gt;
386
- &lt;%= w %>
387
- &lt;% end %>
388
-
389
- % words.each do |w|
390
- %= w
391
- % end
392
-
393
- %|words.each |w|
394
- %= w
395
- % end
396
- </code></pre>
397
-
398
- <p>With <code>{:shorthand=&gt;true}</code> options, the above template compiles into:</p>
399
-
400
- <pre><code>(e08afdfb_62c7_485f_87a0_80914e1b4703 = :_erbout; _erbout = []; words = %w[hello world]
401
- _erbout &lt;&lt; "\n"
402
- words.each do |w|
403
- _erbout &lt;&lt; " " &lt;&lt; (w) &lt;&lt; "\n"
404
- end
405
- _erbout &lt;&lt; "\n"
406
- words.each do |w|
407
- _erbout &lt;&lt; " " &lt;&lt; (w) &lt;&lt; "\n"
408
- end
409
- _erbout &lt;&lt; "\n"
410
- words.each do |w|
411
- _erbout &lt;&lt; " " &lt;&lt; (w) &lt;&lt; "\n"
412
- end
413
- ; _erbout.join)
414
- </code></pre>
415
-
416
- <p>And renders as:</p>
417
-
418
- <pre><code> hello
419
- world
420
-
421
- hello
422
- world
423
-
424
- hello
425
- world
426
- </code></pre>
427
-
428
- <h3 id="Unindent-block-content">Unindent block content</h3>
429
-
430
- <pre><code>&lt;% [1].each do |i| %&gt;
431
- &lt;%= i %>
432
- % [2].each do |j|
433
- %= j
434
- %|[3].each |k|
435
- %= k
436
- % end
437
- % end
438
- &lt;% end %>
439
- </code></pre>
440
-
441
- <p>With <code>{:shorthand=&gt;true, :unindent=&gt;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 &lt;&lt; (i) &lt;&lt; "\n"
445
- [2].each do |j|
446
- _erbout &lt;&lt; (j) &lt;&lt; "\n"
447
- [3].each do |k|
448
- _erbout &lt;&lt; (k) &lt;&lt; "\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>&lt;%
467
- def introducing(subject, &amp;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, &amp;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
- %&gt;
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=&gt;true, :unindent=&gt;true}</code> options, the above template compiles into:</p>
489
-
490
- <pre><code>(e08afdfb_62c7_485f_87a0_80914e1b4703 = :_erbout; _erbout = [];
491
- def introducing(subject, &amp;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, &amp;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 &lt;&lt; "\n"
504
- introducing "Matz" do |number|
505
- _erbout &lt;&lt; "Father of the Ruby programming language,\n"
506
- _erbout &lt;&lt; "and also a jolly and well mannered fellow.\n"
507
- _erbout &lt;&lt; "\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>&lt;%
528
- def introducing(subject, &amp;block)
529
- content = Ember::Template.content_from_block(block, rand(2))
530
-
531
- buffer = Ember::Template.buffer_from_block(block)
532
- buffer &lt;&lt; "introducing(#{subject.inspect}):\n\n#{content.join}"
533
- end
534
-
535
- def coin_toss(pronoun, &amp;block)
536
- content = Ember::Template.content_from_block(block)
537
-
538
- buffer = Ember::Template.buffer_from_block(block)
539
- buffer &lt;&lt; "coin_toss(#{pronoun.inspect}): #{content.join}"
540
- end
541
- %&gt;
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=&gt;true, :unindent=&gt;true}</code> options, the above template compiles into:</p>
552
-
553
- <pre><code>(e08afdfb_62c7_485f_87a0_80914e1b4703 = :_erbout; _erbout = [];
554
- def introducing(subject, &amp;block)
555
- content = Ember::Template.content_from_block(block, rand(2))
556
-
557
- buffer = Ember::Template.buffer_from_block(block)
558
- buffer &lt;&lt; "introducing(#{subject.inspect}):\n\n#{content.join}"
559
- end
560
-
561
- def coin_toss(pronoun, &amp;block)
562
- content = Ember::Template.content_from_block(block)
563
-
564
- buffer = Ember::Template.buffer_from_block(block)
565
- buffer &lt;&lt; "coin_toss(#{pronoun.inspect}): #{content.join}"
566
- end
567
-
568
- _erbout &lt;&lt; "\n"
569
- introducing "Matz" do |number|
570
- _erbout &lt;&lt; "Father of the Ruby programming language,\n"
571
- _erbout &lt;&lt; "and also a jolly and well mannered fellow.\n"
572
- _erbout &lt;&lt; "\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>&lt;%
593
- def introducing(subject, &amp;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! &gt;:-)
598
- #
599
- buffer &lt;&lt; "introducing(#{subject.inspect})"
600
- end
601
- %&gt;
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=&gt;true, :unindent=&gt;true}</code> options, the above template compiles into:</p>
610
-
611
- <pre><code>(e08afdfb_62c7_485f_87a0_80914e1b4703 = :_erbout; _erbout = [];
612
- def introducing(subject, &amp;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! &gt;:-)
617
- #
618
- buffer &lt;&lt; "introducing(#{subject.inspect})"
619
- end
620
-
621
- _erbout &lt;&lt; "\n"
622
- introducing "Matz" do |number|
623
- _erbout &lt;&lt; "Father of the Ruby programming language,\n"
624
- _erbout &lt;&lt; "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
-
634
- <h3 id="Infer-block-endings">Infer block endings</h3>
635
-
636
- <p>Omit <code>&lt;% end %></code> directives from the template:</p>
637
-
638
- <pre><code>% words = %w[hello world]
639
-
640
- &lt;% words.each do |w| %&gt;
641
- &lt;%= w %>
642
-
643
- % words.each do |w|
644
- %= w
645
-
646
- %|words.each |w|
647
- %= w
648
- </code></pre>
649
-
650
- <p>With <code>{:shorthand=&gt;true, :infer_end=&gt;true}</code> options, the above template compiles into:</p>
651
-
652
- <pre><code>(e08afdfb_62c7_485f_87a0_80914e1b4703 = :_erbout; _erbout = []; words = %w[hello world]
653
- _erbout &lt;&lt; "\n"
654
- words.each do |w|
655
- _erbout &lt;&lt; " " &lt;&lt; (w) &lt;&lt; "\n"
656
- end; _erbout &lt;&lt; "\n"
657
- words.each do |w|
658
- _erbout &lt;&lt; " " &lt;&lt; (w) &lt;&lt; "\n"
659
- end; _erbout &lt;&lt; "\n"
660
- words.each do |w|
661
- _erbout &lt;&lt; " " &lt;&lt; (w) &lt;&lt; "\n"
662
- end; _erbout.join)
663
- </code></pre>
664
-
665
- <p>And renders as:</p>
666
-
667
- <pre><code> hello
668
- world
669
-
670
- hello
671
- world
672
-
673
- hello
674
- world
675
- </code></pre>
676
-
677
- <h3 id="Raw-file-inclusion">Raw file inclusion</h3>
678
-
679
- <p>When <code>doc/example.txt</code> contains:</p>
680
-
681
- <pre><code>This is a plain-text file. Notice that &lt;%=
682
- "eRuby directives" %> have no effect here!
683
- </code></pre>
684
-
685
- <p>And the eRuby template is:</p>
686
-
687
- <pre><code>&lt;%&lt; "doc/example.txt" %&gt;
688
-
689
- %&lt; "doc/example.txt"
690
- </code></pre>
691
-
692
- <p>With <code>{:shorthand=&gt;true, :source_file=&gt;"./EXAMPLES"}</code> options, the above template compiles into:</p>
693
-
694
- <pre><code>(e08afdfb_62c7_485f_87a0_80914e1b4703 = :_erbout; _erbout = []; _erbout &lt;&lt; (::Ember::Template.read_file(("doc/example.txt"), {:shorthand=&gt;true, :source_file=&gt;"./EXAMPLES"})) &lt;&lt; "\n"
695
- _erbout &lt;&lt; "\n"
696
- _erbout &lt;&lt; (::Ember::Template.read_file(("doc/example.txt"), {:shorthand=&gt;true, :source_file=&gt;"./EXAMPLES"})) &lt;&lt; "\n"
697
- ; _erbout.join)
698
- </code></pre>
699
-
700
- <p>And renders as:</p>
701
-
702
- <pre><code>This is a plain-text file. Notice that &lt;%=
703
- "eRuby directives" %> have no effect here!
704
-
705
- This is a plain-text file. Notice that &lt;%=
706
- "eRuby directives" %> have no effect here!
707
- </code></pre>
708
-
709
- <h3 id="Template-file-inclusion">Template file inclusion</h3>
710
-
711
- <p>When <code>doc/example.erb</code> contains:</p>
712
-
713
- <pre><code>This is an eRuby template. Notice that &lt;%=
714
- "eRuby directives" %> do take effect here!
715
- </code></pre>
716
-
717
- <p>And the eRuby template is:</p>
718
-
719
- <pre><code>&lt;%+ "doc/example.erb" %&gt;
720
-
721
- %+ "doc/example.erb"
722
- </code></pre>
723
-
724
- <p>With <code>{:shorthand=&gt;true, :source_file=&gt;"./EXAMPLES"}</code> options, the above template compiles into:</p>
725
-
726
- <pre><code>(e08afdfb_62c7_485f_87a0_80914e1b4703 = :_erbout; _erbout = []; ::Ember::Template.load_file(("doc/example.erb"), {:shorthand=&gt;true, :source_file=&gt;"./EXAMPLES"}.merge!(:continue_result =&gt; true)).render(::Kernel.binding); _erbout &lt;&lt; "\n"
727
- _erbout &lt;&lt; "\n"
728
- ::Ember::Template.load_file(("doc/example.erb"), {:shorthand=&gt;true, :source_file=&gt;"./EXAMPLES"}.merge!(:continue_result =&gt; true)).render(::Kernel.binding); _erbout &lt;&lt; "\n"
729
- ; _erbout.join)
730
- </code></pre>
731
-
732
- <p>And renders as:</p>
733
-
734
- <pre><code>This is an eRuby template. Notice that eRuby directives do take effect here!
735
-
736
- This is an eRuby template. Notice that eRuby directives do take effect here!
737
- </code></pre>
738
-
739
- <h3 id="Dynamic-template-evaluation">Dynamic template evaluation</h3>
740
-
741
- <pre><code>&lt;%~ "%= 2 + 2" %>
742
-
743
- %~ "%= 2 + 2"
744
- </code></pre>
745
-
746
- <p>With <code>{:shorthand=&gt;true}</code> options, the above template compiles into:</p>
747
-
748
- <pre><code>(e08afdfb_62c7_485f_87a0_80914e1b4703 = :_erbout; _erbout = []; ::Ember::Template.new(("%= 2 + 2"), {:shorthand=&gt;true}.merge!(:continue_result =&gt; true)).render(::Kernel.binding); _erbout &lt;&lt; "\n"
749
- _erbout &lt;&lt; "\n"
750
- ::Ember::Template.new(("%= 2 + 2"), {:shorthand=&gt;true}.merge!(:continue_result =&gt; true)).render(::Kernel.binding); _erbout &lt;&lt; "\n"
751
- ; _erbout.join)
752
- </code></pre>
753
-
754
- <p>And renders as:</p>
755
-
756
- <pre><code>4
757
-
758
- 4
759
- </code></pre>
760
-
761
- <h2 id="HACKING">HACKING</h2>
762
-
763
- <p>This section is meant for people who want to develop Ember's source code.</p>
764
-
765
- <h3 id="Prerequisites">Prerequisites</h3>
766
-
767
- <p>Install Ruby libraries necessary for development:</p>
768
-
769
- <pre><code>gem install ember --development
770
- </code></pre>
771
-
772
- <h3 id="Infrastructure">Infrastructure</h3>
773
-
774
- <p><a href="http://snk.tuxfamily.org/lib/inochi/">Inochi</a> serves as the project infrastructure for Ember. It handles tasks
775
- such as building this help manual and API documentation, and packaging,
776
- announcing, and publishing new releases. See its help manual and list of
777
- tasks to get started:</p>
778
-
779
- <pre><code>inochi --help # display help manual
780
- inochi --tasks # list available tasks
781
- </code></pre>
782
-
783
- <h3 id="-LOAD_PATH-setup">$LOAD_PATH setup</h3>
784
-
785
- <p>Ensure that the <code>lib/</code> directory is listed in Ruby's <code>$LOAD_PATH</code> before you
786
- use any libraries therein or run any executables in the <code>bin/</code> directory.</p>
787
-
788
- <p>This can be achieved by passing an option to Ruby:</p>
789
-
790
- <pre><code>ruby -Ilib bin/ember
791
- irb -Ilib -r ember
792
- </code></pre>
793
-
794
- <p>Or by setting the <code>$RUBYLIB</code> environment variable:</p>
795
-
796
- <pre><code>export RUBYLIB=lib # bash, ksh, zsh
797
- setenv RUBYLIB lib # csh
798
- set -x RUBYLIB lib # fish
799
-
800
- ruby bin/ember
801
- irb -r ember
802
- </code></pre>
803
-
804
- <p>Or by installing the <a href="http://github.com/chneukirchen/rup">ruby-wrapper</a> tool.</p>
805
-
806
- <h3 id="RubyGems-setup">RubyGems setup</h3>
807
-
808
- <p>If you use Ruby 1.8 or older, then ensure that RubyGems is activated before
809
- you use any libraries in the <code>lib/</code> directory or run any executables in the
810
- <code>bin/</code> directory.</p>
811
-
812
- <p>This can be achieved by passing an option to Ruby:</p>
813
-
814
- <pre><code>ruby -rubygems bin/ember
815
- irb -rubygems -r ember
816
- </code></pre>
817
-
818
- <p>Or by setting the <code>$RUBYOPT</code> environment variable:</p>
819
-
820
- <pre><code>export RUBYOPT=-rubygems # bash, ksh, zsh
821
- setenv RUBYOPT -rubygems # csh
822
- set -x RUBYOPT -rubygems # fish
823
- </code></pre>
824
-
825
- <h3 id="Running-tests">Running tests</h3>
826
-
827
- <p>Simply execute the included test runner, which sets up Ruby's <code>$LOAD_PATH</code> for
828
- testing, loads the included <code>test/test_helper.rb</code> file, and then evaluates all
829
- <code>test/**/*_test.rb</code> files:</p>
830
-
831
- <pre><code>test/runner
832
- </code></pre>
833
-
834
- <p>Its exit status will indicate whether all tests have passed. It may also
835
- print additional pass/fail information depending on the testing library used
836
- in the <code>test/test_helper.rb</code> file.</p>
837
-
838
- <h3 id="Contributing">Contributing</h3>
839
-
840
- <p>Fork this project on GitHub (see <strong>Resources</strong> above) and send a pull request.</p>
841
-
842
- <h2 id="VERSIONS">VERSIONS</h2>
843
-
844
- <p>This section contains release notes of current and past releases.</p>
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
-
877
- <h3 id="Version-0-2-0-2010-04-25-">Version 0.2.0 (2010-04-25)</h3>
878
-
879
- <p>This release adds <a href="http://rubyonrails.org">Ruby on Rails</a> integration.</p>
880
-
881
- <p>New features:</p>
882
-
883
- <ul>
884
- <li><p>Ember can now be used directly as a <a href="http://rubyonrails.org">Ruby on Rails</a> (2.3 or newer) plugin.
885
- The plugin registers Ember as the default Rails template handler for "erb"
886
- and "rhtml" file types. Ember processing options can be set in the Rails
887
- environment file:</p>
888
-
889
- <pre><code>ActionView::TemplateHandlers::Ember.options = {
890
- :unindent =&gt; true,
891
- :shorthand =&gt; true,
892
- :infer_end =&gt; true
893
- }
894
- </code></pre>
895
-
896
- <p>This feature was contributed by Kamil Kukura.</p></li>
897
- </ul>
898
-
899
-
900
- <h3 id="Version-0-1-1-2010-04-20-">Version 0.1.1 (2010-04-20)</h3>
901
-
902
- <p>This release fixes a nested rendering bug, updates the manual, and further
903
- beautifies the Ruby code that results from eRuby template compilation.</p>
904
-
905
- <p>Bug fixes:</p>
906
-
907
- <ul>
908
- <li><p><code>Ember::Template#render()</code> now creates isolated contexts by default to
909
- prevent nested calls from clobbering each other's output!</p>
910
-
911
- <p>For example, if template A calls method X which renders template B
912
- (thinking that template B's rendering is isolated and will not affect the
913
- rendering of template A) then you're in for a wild bug chase! >8-(</p></li>
914
- </ul>
915
-
916
-
917
- <p>Housekeeping:</p>
918
-
919
- <ul>
920
- <li><p>Upgrade to Inochi 2.0.0rc5. Convert manual from ERBook to Ember + Ronn.</p></li>
921
- <li><p>Remove spaces around value insertions in template compilation output.</p></li>
922
- <li><p>Remove logo images from source repository because they're no longer used.</p></li>
923
- </ul>
924
-
925
-
926
- <h3 id="Version-0-1-0-2010-04-03-">Version 0.1.0 (2010-04-03)</h3>
927
-
928
- <p>This release improves the handling of eRuby comment directives, fixes a bug
929
- in the <code>&lt;% end %></code> inference logic, and performs some minor housekeeping.</p>
930
-
931
- <p>New features:</p>
932
-
933
- <ul>
934
- <li><p>Single-line comment directives are now ignored (treated like no-ops)
935
- in input templates. This allows us to surround eRuby block directives
936
- with section separators made from single-line comment directives:</p>
937
-
938
- <pre><code>%|some_block_directive
939
-
940
- Inside some_block_directive.
941
-
942
- %#-------------------------------------------------------------------
943
-
944
- Still inside some_block_directive!
945
-
946
- %#-----------------------------------------------------------------
947
- %| nested_block_directive
948
- %#-----------------------------------------------------------------
949
-
950
- Inside nested_block_directive.
951
- </code></pre></li>
952
- </ul>
953
-
954
-
955
- <p>Bug fixes:</p>
956
-
957
- <ul>
958
- <li><code>&lt;% end %></code> inference did not work for blocks
959
- beginning with <code>def</code>, <code>class</code>, and <code>module</code> keywords.</li>
960
- </ul>
961
-
962
-
963
- <p>Housekeeping:</p>
964
-
965
- <ul>
966
- <li>Upgrade to Inochi 2.0.0-rc3. This project no longer
967
- depends on the "inochi" or "trollop" gems at runtime.</li>
968
- </ul>
969
-
970
-
971
- <h3 id="Version-0-0-1-2009-10-03-">Version 0.0.1 (2009-10-03)</h3>
972
-
973
- <p>This release improves Ruby 1.9 support and revises the user manual.</p>
974
-
975
- <p>Bug fixes:</p>
976
-
977
- <ul>
978
- <li>Nested templates could not access parent's binding in Ruby 1.9</li>
979
- </ul>
980
-
981
-
982
- <p>Housekeeping:</p>
983
-
984
- <ul>
985
- <li><p>Use simpler Copyright reminder at the top of every file.</p></li>
986
- <li><p>Rename internal <code>Program</code> class' methods to be self-documenting.</p></li>
987
- <li><p>Open source is for fun, so <a href="http://loiclemeur.com/english/2009/03/never-criticize-your-competitors.html">be nice</a> and speak of "related works" instead of "competitors".</p></li>
988
- </ul>
989
-
990
-
991
- <h3 id="Version-0-0-0-2009-02-13-">Version 0.0.0 (2009-02-13)</h3>
992
-
993
- <p>This is the first public release of Ember. Enjoy!</p>
994
-
995
- <h2 id="CREDITS">CREDITS</h2>
996
-
997
- <p>Suraj N. Kurapati,
998
- Kamil Kukura</p>
999
-
1000
- <h2 id="LICENSE">LICENSE</h2>
1001
-
1002
- <p>(the ISC license)</p>
1003
-
1004
- <p>Copyright 2009 Suraj N. Kurapati <a href="&#x6d;&#97;&#x69;&#108;&#116;&#x6f;&#x3a;&#115;&#117;&#x6e;&#x61;&#107;&#x75;&#64;&#103;&#109;&#x61;&#x69;&#x6c;&#x2e;&#99;&#111;&#109;" data-bare-link="true">&#x73;&#117;&#110;&#97;&#x6b;&#x75;&#64;&#x67;&#109;&#97;&#105;&#108;&#x2e;&#x63;&#x6f;&#x6d;</a></p>
1005
-
1006
- <p>Permission to use, copy, modify, and/or distribute this software for any
1007
- purpose with or without fee is hereby granted, provided that the above
1008
- copyright notice and this permission notice appear in all copies.</p>
1009
-
1010
- <p>THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
1011
- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1012
- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1013
- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1014
- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1015
- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1016
- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.</p>
1017
-
1018
- <h2 id="SEE-ALSO">SEE ALSO</h2>
1019
-
1020
- <p>erb(1)</p>
1021
-
1022
-
1023
- <ol class='foot man'>
1024
- <li class='tl'></li>
1025
- <li class='tc'>April 2010</li>
1026
- <li class='tr'>ember(1)</li>
1027
- </ol>
1028
-
1029
- </div>
1030
- </body>
1031
- </html>