ember 0.1.0 → 0.1.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.
data/bin/ember CHANGED
@@ -1,63 +1,11 @@
1
1
  #!/usr/bin/env ruby
2
- #
3
- # Evaluates eRuby directives in the given eRuby template and
4
- # writes the result to the standard output stream (STDOUT).
5
- #
6
- # Usage:
7
- #
8
- # ember [Options] [TemplateFile]
9
- #
10
- # TemplateFile:
11
- #
12
- # Path to the eRuby template file that you want to evaluate. If
13
- # this parameter is not specified, then the result of reading the
14
- # standard input stream (STDIN) will be used as the eRuby template.
15
- #
16
- # Options:
17
- #
18
- # -s, --shorthand:
19
- #
20
- # Treat lines beginning with zero or more whitespace
21
- # followed by the "%" character as eRuby directives.
22
- #
23
- # -i, --infer_end:
24
- #
25
- # Add missing <% end %> directives based on indentation.
26
- #
27
- # -u, --unindent:
28
- #
29
- # Unindent the bodies of eRuby blocks.
30
- #
31
- # -c, --compile:
32
- #
33
- # Print underlying Ruby program compiled
34
- # from the input eRuby template and exit.
35
- #
36
- # -h, --help:
37
- #
38
- # Print this message and exit.
39
- #
40
- # -v, --version:
41
- #
42
- # Print version number and exit.
43
- #
44
2
 
45
- $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
46
3
  require 'ember'
47
4
 
48
- # parse command line
49
5
  if ARGV.delete('-h') or ARGV.delete('--help')
50
- puts
51
- puts [Ember::PROJECT, Ember::TAGLINE].join(' - ')
52
- puts
53
- puts File.read(__FILE__)[/^#(\r?\n)(.*?)\1\1/m, 2].gsub(/^# ?/, '')
54
- puts
55
- puts 'See the user manual for more information:'
56
- puts
57
- puts ' ' + File.join(Ember::INSTDIR, 'doc', 'index.html')
58
- puts
59
- puts ' ' + Ember::WEBSITE
60
- puts
6
+ man_dir = File.join(Ember::INSTDIR, 'man')
7
+ system 'man', '-M', man_dir, '-a', 'ember' or
8
+ puts Dir["#{man_dir}/**/*.html"].push(Ember::WEBSITE).map {|s| "See #{s}" }
61
9
  exit
62
10
  elsif ARGV.delete('-v') or ARGV.delete('--version')
63
11
  puts Ember::VERSION
@@ -1,2 +1,5 @@
1
1
  require 'ember/inochi'
2
- require 'ember/template'
2
+
3
+ module Ember
4
+ autoload :Template, 'ember/template'
5
+ end
@@ -18,12 +18,12 @@ module Ember
18
18
  ##
19
19
  # Number of this release of this project.
20
20
  #
21
- VERSION = "0.1.0"
21
+ VERSION = "0.1.1"
22
22
 
23
23
  ##
24
24
  # Date of this release of this project.
25
25
  #
26
- RELDATE = "2010-04-03"
26
+ RELDATE = "2010-04-20"
27
27
 
28
28
  ##
29
29
  # Description of this release of this project.
@@ -67,8 +67,10 @@ module Ember
67
67
  # Returns the result of executing the Ruby program for this template
68
68
  # (provided by the {#program} method) inside the given context binding.
69
69
  #
70
- def render context = TOPLEVEL_BINDING, parent_context_id = nil
71
- context ||= @@contexts[parent_context_id] # inherit parent context
70
+ def render context = nil, parent_context_id = nil
71
+ context ||=
72
+ @@contexts[parent_context_id] || # inherit parent context
73
+ Object.new.instance_eval('binding') # create new context
72
74
  @@contexts[@render_context_id] = context # provide to children
73
75
 
74
76
  result = eval @compile, context,
@@ -544,7 +546,7 @@ module Ember
544
546
  else
545
547
  code =
546
548
  if is_expr
547
- " << (#{stmt.value})"
549
+ " << (#{stmt.value.strip})"
548
550
  else
549
551
  " << #{stmt.value.inspect}"
550
552
  end
Binary file
@@ -0,0 +1,805 @@
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'>
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:81ex; text-align:justify; margin:0 25px 25px 25px }
16
+ #man div.man-navigation {
17
+ position:fixed;
18
+ top:0;
19
+ left:87ex;
20
+ height:100%;
21
+ width:100%;
22
+ padding-top:1ex;
23
+ padding-left:2ex;
24
+ border-left:1ex solid #DCDCDC;
25
+ background-color: #F5F5F5;
26
+ }
27
+ #man div.man-navigation a { display:block; margin-bottom:15px }
28
+ #man h1, #man h2, #man h3 { color:#232221;clear:left }
29
+ #man h1 { font-size:28px; margin:15px 0 30px 0; text-align:center }
30
+ #man h2 { font-size:18px; margin-bottom:0; margin-top:10px; line-height:1.3; }
31
+ #man h3 { font-size:16px; margin:0 0 0 4ex; }
32
+ #man p, #man ul, #man ol, #man dl, #man pre { margin:0 0 18px 0; }
33
+ #man pre {
34
+ color:#333231;
35
+ background:#edeceb;
36
+ padding:5px 7px;
37
+ margin:0px 0 20px 0;
38
+ border-left:2ex solid #ddd}
39
+ #man pre + h2, #man pre + h3 {
40
+ margin-top:22px;
41
+ }
42
+ #man h2 + pre, #man h3 + pre {
43
+ margin-top:5px;
44
+ }
45
+ #man > p, #man > ul, #man > ol, #man > dl, #man > pre { margin-left:8ex; }
46
+ #man dt { margin:0; clear:left }
47
+ #man dt.flush { float:left; width:8ex }
48
+ #man dd { margin:0 0 0 9ex }
49
+ #man code, #man strong, #man b { font-weight:bold; color:#131211; }
50
+ #man pre code { font-weight:normal; color:#232221; background:inherit }
51
+ #man em, var, u {
52
+ font-style:normal; color:#333231; border-bottom:1px solid #999; }
53
+ #man h1.man-title { display:none; }
54
+ #man ol.man, #man ol.man li { margin:2px 0 10px 0; padding:0;
55
+ float:left; width:33%; list-style-type:none;
56
+ text-transform:uppercase; font-size:18px; color:#999;
57
+ letter-spacing:1px;}
58
+ #man ol.man { width:100%; }
59
+ #man ol.man li.tl { text-align:left }
60
+ #man ol.man li.tc { text-align:center;letter-spacing:4px }
61
+ #man ol.man li.tr { text-align:right; float: right }
62
+ #man ol.man a { color:#999 }
63
+ #man ol.man a:hover { color:#333231 }
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'><a href='#NAME'>NAME</a> <a href='#ABOUT'>ABOUT</a> <a href='#SYNOPSIS'>SYNOPSIS</a> <a href='#DESCRIPTION'>DESCRIPTION</a> <a href='#OPTIONS'>OPTIONS</a> <a href='#SYNTAX'>SYNTAX</a> <a href='#EXAMPLES'>EXAMPLES</a> <a href='#HACKING'>HACKING</a> <a href='#VERSIONS'>VERSIONS</a> <a href='#CREDITS'>CREDITS</a> <a href='#LICENSE'>LICENSE</a> <a href='#SEE-ALSO'>SEE ALSO</a></div>
77
+
78
+ <h1 class='man-title'>ember(1)</h1>
79
+
80
+ <ol class='head man'>
81
+ <li class='tl'>ember(1)</li>
82
+ <li class='tc'>Version 0.1.1</li>
83
+ <li class='tr'>ember(1)</li>
84
+ </ol>
85
+
86
+ <h2 id='NAME'>NAME</h2>
87
+ <p><code>ember</code> - eRuby template processor</p>
88
+
89
+ <h2 id="ABOUT">ABOUT</h2>
90
+
91
+ <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
92
+ debugging, reduces markup, and improves composability of eRuby templates.</p>
93
+
94
+ <h3 id="Features">Features</h3>
95
+
96
+ <ul>
97
+ <li><p>Reports correct line numbers in error message stack traces.</p></li>
98
+ <li><p>Omits newlines trailing code-only <code>&lt;% ... %&gt;</code> directives.</p></li>
99
+ <li><p>Can infer missing <code>&lt;% end %></code> directives based on indentation.</p></li>
100
+ <li><p>Can unindent eRuby block bodies hierarchically.</p></li>
101
+ <li><p>Written in 335 lines of pure
102
+ Ruby.</p></li>
103
+ </ul>
104
+
105
+
106
+ <h3 id="Resources">Resources</h3>
107
+
108
+ <dl>
109
+ <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>
110
+ <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>
111
+ <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>
112
+ <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>
113
+ <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>
114
+ </dl>
115
+
116
+
117
+ <h3 id="Setup">Setup</h3>
118
+
119
+ <p>Prerequisites:</p>
120
+
121
+ <ul>
122
+ <li><p><a href="http://ruby-lang.org">Ruby</a> 1.8.6 or newer.</p></li>
123
+ <li><p><a href="http://rubygems.org">RubyGems</a> 1.3.6 or newer.</p></li>
124
+ </ul>
125
+
126
+
127
+ <p>Installing:</p>
128
+
129
+ <pre><code>gem install ember
130
+ </code></pre>
131
+
132
+ <p>Upgrading:</p>
133
+
134
+ <pre><code>gem update ember
135
+ </code></pre>
136
+
137
+ <p>Removing:</p>
138
+
139
+ <pre><code>gem uninstall ember
140
+ </code></pre>
141
+
142
+ <h2 id="SYNOPSIS">SYNOPSIS</h2>
143
+
144
+ <p><code>ember</code> [<var>OPTIONS</var>] [<var>FILE</var>]</p>
145
+
146
+ <h2 id="DESCRIPTION">DESCRIPTION</h2>
147
+
148
+ <p>Evaluates eRuby directives (see <strong>SYNTAX</strong> below) in the given <var>FILE</var> and
149
+ writes the result to the standard output stream (STDOUT). If <var>FILE</var> is not
150
+ given, then the standard input stream (STDIN) is evaluated instead.</p>
151
+
152
+ <h2 id="OPTIONS">OPTIONS</h2>
153
+
154
+ <dl>
155
+ <dt><code>-s</code>, <code>--shorthand</code></dt><dd><p> Treat lines beginning with zero or more whitespace
156
+ followed by the "%" character as eRuby directives.</p></dd>
157
+ <dt><code>-i</code>, <code>--infer_end</code></dt><dd><p> Add missing <code>&lt;% end %></code> directives based on indentation.</p></dd>
158
+ <dt><code>-u</code>, <code>--unindent</code></dt><dd><p> Unindent the bodies of directives that define a
159
+ Ruby block (do ... end) or scope (begin ... end).</p></dd>
160
+ <dt><code>-c</code>, <code>--compile</code></dt><dd><p> Print underlying Ruby program compiled
161
+ from the input eRuby template and exit.</p></dd>
162
+ <dt><code>-h</code>, <code>--help</code></dt><dd><p> Print this message and exit.</p></dd>
163
+ <dt><code>-v</code>, <code>--version</code></dt><dd><p> Print version number and exit.</p></dd>
164
+ </dl>
165
+
166
+
167
+ <h2 id="SYNTAX">SYNTAX</h2>
168
+
169
+ <p>This section explains <a href="http://en.wikipedia.org/wiki/ERuby">eRuby template</a> syntax and Ember extensions thereof.</p>
170
+
171
+ <p>eRuby templates are plain-text documents that contain special processing
172
+ instructions known as <strong>directives</strong>. These instructions are evaluated <em>in
173
+ place</em>, meaning that they are replaced by the result of their evaluation.</p>
174
+
175
+ <h3 id="Directives">Directives</h3>
176
+
177
+ <p>Directives are expressed in either <strong>standard</strong> or <strong>shorthand</strong> notation:</p>
178
+
179
+ <pre><code>Notation Directive Head Operation Body Tail
180
+ -------- --------- ---- --------- ---- ----
181
+ Standard &lt;%XY%> &lt;% X Y %>
182
+ Shorthand %XY % X Y
183
+ </code></pre>
184
+
185
+ <p>In standard notation, the directive is composed of a <strong>head</strong>, an
186
+ <strong>operation</strong>, a <strong>body</strong>, and a <strong>tail</strong>; and it may appear anywhere in the
187
+ template.</p>
188
+
189
+ <p>In shorthand notation, the directive is composed of a <strong>head</strong>, an
190
+ <strong>operation</strong>, and a <strong>body</strong>; and it may only appear in the template if it
191
+ occupies an entire line (leading whitespace is permitted only in Ember;
192
+ trailing whitespace is permitted in both Ember and eRuby).</p>
193
+
194
+ <p>Regardless of the notation used, directives are atomic constructs; they cannot
195
+ be nested within one another.</p>
196
+
197
+ <h3 id="Operations">Operations</h3>
198
+
199
+ <p>The first character following the head of a directive is known as an
200
+ <strong>operation</strong>. It determines how the directive is processed by Ember.</p>
201
+
202
+ <dl>
203
+ <dt class="flush"><code>#</code></dt><dd><p>The entire directive is omitted from the output.</p></dd>
204
+ <dt class="flush"><code>=</code></dt><dd><p>The body of the directive is evaluated as Ruby code, and the result of
205
+ this evaluation is inserted into the output.</p></dd>
206
+ <dt class="flush"><code>~</code></dt><dd><p>(only in Ember) The body of the directive is evaluated as an eRuby
207
+ template, and the result of this evaluation is inserted into the output.</p></dd>
208
+ <dt class="flush"><code>+</code></dt><dd><p>(only in Ember) The body of the directive is evaluated as Ruby code, and
209
+ the result of this evaluation is assumed to be a string that specifies the
210
+ path (either absolute or relative to the eRuby template file in which this
211
+ directive is found) to a file containing an eRuby template. This file is
212
+ read and its contents are evaluated as an eRuby template, and the result
213
+ of this evaluation is inserted into the output.</p></dd>
214
+ <dt class="flush"><code>&lt;</code></dt><dd><p>(only in Ember) The body of the directive is evaluated as Ruby code, and
215
+ the result of this evaluation is assumed to be a string that specifies the
216
+ path (either absolute or relative to the eRuby template file in which this
217
+ directive is found) to a file. This file is read and its contents are
218
+ inserted into the output.</p></dd>
219
+ <dt class="flush"><code>|</code></dt><dd><p>(only in Ember) The body of the directive is treated as the beginning of a
220
+ Ruby block. The <code>do</code> keyword is automatically appended to the body of the
221
+ directive if missing.</p></dd>
222
+ <dt class="flush"><code>%</code></dt><dd><p>One "%" character is omitted from the head of the directive and the entire
223
+ directive is inserted into the output.</p></dd>
224
+ <dt>None of the above</dt><dd><p>The body of the directive is evaluated as Ruby code, but the result of
225
+ this evaluation <em>is not</em> inserted into the output.</p></dd>
226
+ </dl>
227
+
228
+
229
+ <h2 id="EXAMPLES">EXAMPLES</h2>
230
+
231
+ <p>Begin by loading Ember into Ruby:</p>
232
+
233
+ <pre><code>require 'rubygems' # might not be necessary; see HACKING
234
+ require 'ember'
235
+ </code></pre>
236
+
237
+ <p>Instantiate an Ember template processor:</p>
238
+
239
+ <pre><code>source = "your eRuby template here"
240
+ options = {} # see API documentation
241
+ template = Ember::Template.new(source, options)
242
+ </code></pre>
243
+
244
+ <p>Inspect the Ruby program that was compiled (and is used) by the Ember
245
+ template processor to evaluate the eRuby template given as input:</p>
246
+
247
+ <pre><code>puts template.program
248
+ </code></pre>
249
+
250
+ <p>View the result of evaluating the eRuby template:</p>
251
+
252
+ <pre><code>puts template.render
253
+ </code></pre>
254
+
255
+ <p>See the API documentation for more information.</p>
256
+
257
+ <h3 id="An-empty-template">An empty template</h3>
258
+
259
+ <p>Begin with an empty template:</p>
260
+
261
+ <pre>
262
+ </pre>
263
+
264
+
265
+ <p>The
266
+ above template compiles into:</p>
267
+
268
+ <pre><code>(_erbout = []; _erbout &lt;&lt; "\n"
269
+ ; _erbout.join)
270
+ </code></pre>
271
+
272
+ <p>And renders as:</p>
273
+
274
+ <pre>
275
+ </pre>
276
+
277
+
278
+ <h3 id="Comment-directives">Comment directives</h3>
279
+
280
+ <p>Add comment directives:</p>
281
+
282
+ <pre><code>&lt;%# this is a comment %>
283
+ %# this is also a comment
284
+
285
+ &lt;%# this
286
+ is
287
+ a
288
+ multi-line comment %>
289
+ </code></pre>
290
+
291
+ <p>With <code>{:shorthand=&gt;true}</code> options, the
292
+ above template compiles into:</p>
293
+
294
+ <pre><code>(_erbout = []; _erbout &lt;&lt; "\n"
295
+ _erbout &lt;&lt; "\n"
296
+ _erbout &lt;&lt; "\n"
297
+ _erbout &lt;&lt; "\n"
298
+
299
+
300
+
301
+
302
+ _erbout &lt;&lt; " \n"
303
+ ; _erbout.join)
304
+ </code></pre>
305
+
306
+ <p>And renders as:</p>
307
+
308
+ <pre>
309
+
310
+
311
+
312
+
313
+ </pre>
314
+
315
+
316
+ <h3 id="Escaped-directives">Escaped directives</h3>
317
+
318
+ <p>Add escaped directives:</p>
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
325
+ above template compiles into:</p>
326
+
327
+ <pre><code>(_erbout = []; _erbout &lt;&lt; "\n"
328
+ _erbout &lt;&lt; "&lt;% this is an escaped directive %>\n"
329
+ _erbout &lt;&lt; "% this is an escaped directive\n"
330
+ _erbout &lt;&lt; " \n"
331
+ ; _erbout.join)
332
+ </code></pre>
333
+
334
+ <p>And renders as:</p>
335
+
336
+ <pre><code>&lt;% this is an escaped directive %>
337
+ % this is an escaped directive
338
+ </code></pre>
339
+
340
+ <h3 id="Vocal-directives">Vocal directives</h3>
341
+
342
+ <p>Add vocal directives, which produce output:</p>
343
+
344
+ <pre><code>&lt;%= "hello" %>
345
+ %= "world"
346
+ </code></pre>
347
+
348
+ <p>With <code>{:shorthand=&gt;true}</code> options, the
349
+ above template compiles into:</p>
350
+
351
+ <pre><code>(_erbout = []; _erbout &lt;&lt; "\n"
352
+ _erbout &lt;&lt; ("hello") &lt;&lt; "\n"
353
+ _erbout &lt;&lt; ("world") &lt;&lt; "\n"
354
+ _erbout &lt;&lt; "\n"
355
+ _erbout &lt;&lt; " \n"
356
+ ; _erbout.join)
357
+ </code></pre>
358
+
359
+ <p>And renders as:</p>
360
+
361
+ <pre><code>hello
362
+ world
363
+ </code></pre>
364
+
365
+ <h3 id="Silent-directives">Silent directives</h3>
366
+
367
+ <p>Add silent directives, which do not produce output:</p>
368
+
369
+ <pre><code>&lt;% a = "hello" %>
370
+ % b = "world"
371
+
372
+ &lt;%= a %>
373
+ %= b
374
+ </code></pre>
375
+
376
+ <p>With <code>{:shorthand=&gt;true}</code> options, the
377
+ above template compiles into:</p>
378
+
379
+ <pre><code>(_erbout = []; _erbout &lt;&lt; "\n"
380
+ a = "hello"
381
+ b = "world"
382
+ _erbout &lt;&lt; "\n"
383
+ _erbout &lt;&lt; (a) &lt;&lt; "\n"
384
+ _erbout &lt;&lt; (b) &lt;&lt; "\n"
385
+ _erbout &lt;&lt; "\n"
386
+ _erbout &lt;&lt; " \n"
387
+ ; _erbout.join)
388
+ </code></pre>
389
+
390
+ <p>And renders as:</p>
391
+
392
+ <pre><code>hello
393
+ world
394
+ </code></pre>
395
+
396
+ <h3 id="Block-directives">Block directives</h3>
397
+
398
+ <p>Add some Ruby blocks:</p>
399
+
400
+ <pre><code>% words = %w[hello world]
401
+
402
+ &lt;% words.each do |w| %&gt;
403
+ &lt;%= w %>
404
+ &lt;% end %>
405
+
406
+ % words.each do |w|
407
+ %= w
408
+ % end
409
+
410
+ %|words.each |w|
411
+ %= w
412
+ % end
413
+ </code></pre>
414
+
415
+ <p>With <code>{:shorthand=&gt;true}</code> options, the
416
+ above template compiles into:</p>
417
+
418
+ <pre><code>(_erbout = []; _erbout &lt;&lt; "\n"
419
+ words = %w[hello world]
420
+ _erbout &lt;&lt; "\n"
421
+ words.each do |w|
422
+ _erbout &lt;&lt; " " &lt;&lt; (w) &lt;&lt; "\n"
423
+ end
424
+ _erbout &lt;&lt; "\n"
425
+ words.each do |w|
426
+ _erbout &lt;&lt; " " &lt;&lt; (w) &lt;&lt; "\n"
427
+ end
428
+ _erbout &lt;&lt; "\n"
429
+ words.each do |w|
430
+ _erbout &lt;&lt; " " &lt;&lt; (w) &lt;&lt; "\n"
431
+ end
432
+ _erbout &lt;&lt; "\n"
433
+ _erbout &lt;&lt; " \n"
434
+ ; _erbout.join)
435
+ </code></pre>
436
+
437
+ <p>And renders as:</p>
438
+
439
+ <pre><code> hello
440
+ world
441
+
442
+ hello
443
+ world
444
+
445
+ hello
446
+ world
447
+ </code></pre>
448
+
449
+ <h3 id="Infer-block-endings">Infer block endings</h3>
450
+
451
+ <p>Omit <code>&lt;% end %></code> directives from the template:</p>
452
+
453
+ <pre><code>% words = %w[hello world]
454
+
455
+ &lt;% words.each do |w| %&gt;
456
+ &lt;%= w %>
457
+
458
+ % words.each do |w|
459
+ %= w
460
+
461
+ %|words.each |w|
462
+ %= w
463
+ </code></pre>
464
+
465
+ <p>With <code>{:shorthand=&gt;true, :infer_end=&gt;true}</code> options, the
466
+ above template compiles into:</p>
467
+
468
+ <pre><code>(_erbout = []; _erbout &lt;&lt; "\n"
469
+ words = %w[hello world]
470
+ _erbout &lt;&lt; "\n"
471
+ words.each do |w|
472
+ _erbout &lt;&lt; " " &lt;&lt; (w) &lt;&lt; "\n"
473
+ end; _erbout &lt;&lt; "\n"
474
+ words.each do |w|
475
+ _erbout &lt;&lt; " " &lt;&lt; (w) &lt;&lt; "\n"
476
+ end; _erbout &lt;&lt; "\n"
477
+ words.each do |w|
478
+ _erbout &lt;&lt; " " &lt;&lt; (w) &lt;&lt; "\n"
479
+ end; _erbout &lt;&lt; "\n"
480
+ _erbout &lt;&lt; " \n"
481
+ ; _erbout.join)
482
+ </code></pre>
483
+
484
+ <p>And renders as:</p>
485
+
486
+ <pre><code> hello
487
+ world
488
+
489
+ hello
490
+ world
491
+
492
+ hello
493
+ world
494
+ </code></pre>
495
+
496
+ <h3 id="Raw-file-inclusion">Raw file inclusion</h3>
497
+
498
+ <p>When <code>doc/example.txt</code> contains:</p>
499
+
500
+ <pre><code>This is a plain-text file. Notice that &lt;%=
501
+ "eRuby directives" %> have no effect here!
502
+ </code></pre>
503
+
504
+ <p>And the eRuby template is:</p>
505
+
506
+ <pre><code>&lt;%&lt; "doc/example.txt" %&gt;
507
+
508
+ %&lt; "doc/example.txt"
509
+ </code></pre>
510
+
511
+ <p>With <code>{:shorthand=&gt;true, :source_file=&gt;"./EXAMPLES"}</code> options, the
512
+ above template compiles into:</p>
513
+
514
+ <pre><code>(_erbout = []; _erbout &lt;&lt; "\n"
515
+ _erbout &lt;&lt; (::Ember::Template.read_file(( "doc/example.txt" ), {:shorthand=&gt;true, :source_file=&gt;"./EXAMPLES"})) &lt;&lt; "\n"
516
+ _erbout &lt;&lt; "\n"
517
+ _erbout &lt;&lt; (::Ember::Template.read_file(( "doc/example.txt"), {:shorthand=&gt;true, :source_file=&gt;"./EXAMPLES"})) &lt;&lt; "\n"
518
+ _erbout &lt;&lt; "\n"
519
+ _erbout &lt;&lt; " \n"
520
+ ; _erbout.join)
521
+ </code></pre>
522
+
523
+ <p>And renders as:</p>
524
+
525
+ <pre><code>This is a plain-text file. Notice that &lt;%=
526
+ "eRuby directives" %> have no effect here!
527
+
528
+ This is a plain-text file. Notice that &lt;%=
529
+ "eRuby directives" %> have no effect here!
530
+ </code></pre>
531
+
532
+ <h3 id="Template-file-inclusion">Template file inclusion</h3>
533
+
534
+ <p>When <code>doc/example.erb</code> contains:</p>
535
+
536
+ <pre><code>This is an eRuby template. Notice that &lt;%=
537
+ "eRuby directives" %> do take effect here!
538
+ </code></pre>
539
+
540
+ <p>And the eRuby template is:</p>
541
+
542
+ <pre><code>&lt;%+ "doc/example.erb" %&gt;
543
+
544
+ %+ "doc/example.erb"
545
+ </code></pre>
546
+
547
+ <p>With <code>{:shorthand=&gt;true, :source_file=&gt;"./EXAMPLES"}</code> options, the
548
+ above template compiles into:</p>
549
+
550
+ <pre><code>(_erbout = []; _erbout &lt;&lt; "\n"
551
+ ::Ember::Template.load_file(( "doc/example.erb" ), {:shorthand=&gt;true, :source_file=&gt;"./EXAMPLES"}.merge!(:continue_result =&gt; true)).render(nil, 79777922); _erbout &lt;&lt; "\n"
552
+ _erbout &lt;&lt; "\n"
553
+ ::Ember::Template.load_file(( "doc/example.erb"), {:shorthand=&gt;true, :source_file=&gt;"./EXAMPLES"}.merge!(:continue_result =&gt; true)).render(nil, 79777922); _erbout &lt;&lt; "\n"
554
+ _erbout &lt;&lt; "\n"
555
+ _erbout &lt;&lt; " \n"
556
+ ; _erbout.join)
557
+ </code></pre>
558
+
559
+ <p>And renders as:</p>
560
+
561
+ <pre><code>This is an eRuby template. Notice that eRuby directives do take effect here!
562
+
563
+ This is an eRuby template. Notice that eRuby directives do take effect here!
564
+ </code></pre>
565
+
566
+ <h3 id="Dynamic-template-evaluation">Dynamic template evaluation</h3>
567
+
568
+ <pre><code>&lt;%~ "%= 2 + 2" %>
569
+
570
+ %~ "%= 2 + 2"
571
+ </code></pre>
572
+
573
+ <p>With <code>{:shorthand=&gt;true}</code> options, the
574
+ above template compiles into:</p>
575
+
576
+ <pre><code>(_erbout = []; _erbout &lt;&lt; "\n"
577
+ ::Ember::Template.new(( "%= 2 + 2" ), {:shorthand=&gt;true}.merge!(:continue_result =&gt; true)).render(nil, 79408546); _erbout &lt;&lt; "\n"
578
+ _erbout &lt;&lt; "\n"
579
+ ::Ember::Template.new(( "%= 2 + 2"), {:shorthand=&gt;true}.merge!(:continue_result =&gt; true)).render(nil, 79408546); _erbout &lt;&lt; "\n"
580
+ _erbout &lt;&lt; "\n"
581
+ _erbout &lt;&lt; " \n"
582
+ ; _erbout.join)
583
+ </code></pre>
584
+
585
+ <p>And renders as:</p>
586
+
587
+ <pre><code>4
588
+
589
+ 4
590
+ </code></pre>
591
+
592
+ <h2 id="HACKING">HACKING</h2>
593
+
594
+ <p>This section is meant for people who want to develop Ember's source code.</p>
595
+
596
+ <h3 id="Prerequisites">Prerequisites</h3>
597
+
598
+ <p>Install Ruby libraries necessary for development:</p>
599
+
600
+ <pre><code>gem install ember --development
601
+ </code></pre>
602
+
603
+ <h3 id="Infrastructure">Infrastructure</h3>
604
+
605
+ <p><a href="http://snk.tuxfamily.org/lib/inochi/">Inochi</a> serves as Ember's project infrastructure.
606
+ It handles tasks such as building this manual and API documentation, and
607
+ packaging, announcing, and publishing new releases. See its manual to get
608
+ started:</p>
609
+
610
+ <pre><code>inochi --help
611
+ </code></pre>
612
+
613
+ <h3 id="-LOAD_PATH-setup">$LOAD_PATH setup</h3>
614
+
615
+ <p>Ensure that the <code>lib/</code> directory is listed in Ruby's <code>$LOAD_PATH</code> before you
616
+ use any libraries therein or run any executables in the <code>bin/</code> directory.</p>
617
+
618
+ <p>This can be achieved by passing an option to Ruby:</p>
619
+
620
+ <pre><code>ruby -Ilib
621
+ </code></pre>
622
+
623
+ <p>Or by setting the <code>$RUBYLIB</code> environment variable:</p>
624
+
625
+ <pre><code>export RUBYLIB=lib # bash, ksh, zsh
626
+ setenv RUBYLIB lib # csh
627
+ set -x RUBYLIB lib # fish
628
+ </code></pre>
629
+
630
+ <p>Or by installing the <a href="http://github.com/chneukirchen/rup">ruby-wrapper</a> tool.</p>
631
+
632
+ <h3 id="RubyGems-setup">RubyGems setup</h3>
633
+
634
+ <p>If you use Ruby 1.8 and RubyGems to manage your Ruby software, then ensure
635
+ that RubyGems is activated before you use any libraries in the <code>lib/</code>
636
+ directory or run any executables in the <code>bin/</code> directory.</p>
637
+
638
+ <p>This can be achieved by passing an option to Ruby:</p>
639
+
640
+ <pre><code>ruby -rubygems
641
+ </code></pre>
642
+
643
+ <p>Or by setting the <code>$RUBYOPT</code> environment variable:</p>
644
+
645
+ <pre><code>export RUBYOPT=-rubygems # bash, ksh, zsh
646
+ setenv RUBYOPT -rubygems # csh
647
+ set -x RUBYOPT -rubygems # fish
648
+ </code></pre>
649
+
650
+ <h3 id="Running-tests">Running tests</h3>
651
+
652
+ <p>Simply execute the included test runner, which sets up Ruby's <code>$LOAD_PATH</code> for
653
+ testing, loads the included <code>test/test_helper.rb</code> file, and then evaluates all
654
+ <code>test/**/*_test.rb</code> files:</p>
655
+
656
+ <pre><code>test/runner
657
+ </code></pre>
658
+
659
+ <p>Its exit status will indicate whether all tests have passed. It may also
660
+ print additional pass/fail information depending on the testing library used
661
+ in the <code>test/test_helper.rb</code> file.</p>
662
+
663
+ <h3 id="Contributing">Contributing</h3>
664
+
665
+ <p>Fork this project on GitHub (see <strong>Resources</strong> above) and send a pull request.</p>
666
+
667
+ <h2 id="VERSIONS">VERSIONS</h2>
668
+
669
+ <p>This section contains release notes of current and past releases.</p>
670
+
671
+ <h3 id="Version-0-1-1-2010-04-20-">Version 0.1.1 (2010-04-20)</h3>
672
+
673
+ <p>This release fixes a nested rendering bug, updates the manual, and further
674
+ beautifies the Ruby code that results from eRuby template compilation.</p>
675
+
676
+ <p>Bug fixes:</p>
677
+
678
+ <ul>
679
+ <li><p><code>Ember::Template#render()</code> now creates isolated contexts by default to
680
+ prevent nested calls from clobbering each other's output!</p>
681
+
682
+ <p>For example, if template A calls method X which renders template B (thinking
683
+ that template B's rendering is isolated and will not affect the rendering of
684
+ template A) then you're in for a hell of a wild bug chase! >8-(</p></li>
685
+ </ul>
686
+
687
+
688
+ <p>Housekeeping:</p>
689
+
690
+ <ul>
691
+ <li><p>Upgrade to Inochi 2.0.0rc5. Convert manual from ERBook to Ember + Ronn.</p></li>
692
+ <li><p>Remove spaces around value insertions in template compilation output.</p></li>
693
+ <li><p>Remove logo images from source repository because they're no longer used.</p></li>
694
+ </ul>
695
+
696
+
697
+ <h3 id="Version-0-1-0-2010-04-03-">Version 0.1.0 (2010-04-03)</h3>
698
+
699
+ <p>This release improves the handling of eRuby comment directives, fixes a bug
700
+ in the <code>&lt;% end %></code> inference logic, and performs some minor housekeeping.</p>
701
+
702
+ <p>New features:</p>
703
+
704
+ <ul>
705
+ <li><p>Single-line comment directives are now ignored (treated like no-ops)
706
+ in input templates. This allows us to surround eRuby block directives
707
+ with section separators made from single-line comment directives:</p>
708
+
709
+ <pre><code>%|some_block_directive
710
+
711
+ Inside some_block_directive.
712
+
713
+ %#---------------------------------------------------------------------
714
+
715
+ Still inside some_block_directive!
716
+
717
+ %#-------------------------------------------------------------------
718
+ %| nested_block_directive
719
+ %#-------------------------------------------------------------------
720
+
721
+ Inside nested_block_directive.
722
+ </code></pre></li>
723
+ </ul>
724
+
725
+
726
+ <p>Bug fixes:</p>
727
+
728
+ <ul>
729
+ <li><code>&lt;% end %></code> inference did not work for blocks
730
+ beginning with <code>def</code>, <code>class</code>, and <code>module</code> keywords.</li>
731
+ </ul>
732
+
733
+
734
+ <p>Housekeeping:</p>
735
+
736
+ <ul>
737
+ <li>Upgrade to Inochi 2.0.0-rc3. This project no longer
738
+ depends on the "inochi" or "trollop" gems at runtime.</li>
739
+ </ul>
740
+
741
+
742
+ <h3 id="Version-0-0-1-2009-10-03-">Version 0.0.1 (2009-10-03)</h3>
743
+
744
+ <p>This release improves Ruby 1.9 support and revises the user manual.</p>
745
+
746
+ <p>Bug fixes:</p>
747
+
748
+ <ul>
749
+ <li>Nested templates could not access parent's binding in Ruby 1.9</li>
750
+ </ul>
751
+
752
+
753
+ <p>Housekeeping:</p>
754
+
755
+ <ul>
756
+ <li><p>Use simpler Copyright reminder at the top of every file.</p></li>
757
+ <li><p>Rename internal <code>Program</code> class' methods to be self-documenting.</p></li>
758
+ <li><p>Open source is for fun, so <a href="http://loiclemeur.com/english/2009/03/never-criticize-your-competitors.html">be
759
+ nice</a>
760
+ and speak of "related works" instead of "competitors".</p></li>
761
+ </ul>
762
+
763
+
764
+ <h3 id="Version-0-0-0-2009-02-13-">Version 0.0.0 (2009-02-13)</h3>
765
+
766
+ <p>This is the first public release of Ember. Enjoy!</p>
767
+
768
+ <h2 id="CREDITS">CREDITS</h2>
769
+
770
+ <p>Suraj N. Kurapati</p>
771
+
772
+ <h2 id="LICENSE">LICENSE</h2>
773
+
774
+ <p>(the ISC license)</p>
775
+
776
+ <p>Copyright 2009 Suraj N. Kurapati <a href="&#109;&#97;&#105;&#x6c;&#x74;&#111;&#x3a;&#x73;&#x75;&#110;&#x61;&#107;&#117;&#64;&#x67;&#109;&#x61;&#105;&#x6c;&#x2e;&#x63;&#x6f;&#109;" data-bare-link="true">&#115;&#x75;&#x6e;&#x61;&#x6b;&#117;&#x40;&#103;&#109;&#x61;&#105;&#x6c;&#x2e;&#99;&#111;&#109;</a></p>
777
+
778
+ <p>Permission to use, copy, modify, and/or distribute this software for any
779
+ purpose with or without fee is hereby granted, provided that the above
780
+ copyright notice and this permission notice appear in all copies.</p>
781
+
782
+ <p>THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
783
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
784
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
785
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
786
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
787
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
788
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.</p>
789
+
790
+ <h2 id="SEE-ALSO">SEE ALSO</h2>
791
+
792
+ <p>erb(1),
793
+ <a href="http://www.kuwata-lab.com/erubis/">Erubis</a>,
794
+ <a href="http://modruby.net/en/">eruby</a></p>
795
+
796
+
797
+ <ol class='foot man'>
798
+ <li class='tl'></li>
799
+ <li class='tc'>April 2010</li>
800
+ <li class='tr'>ember(1)</li>
801
+ </ol>
802
+
803
+ </div>
804
+ </body>
805
+ </html>