ember 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY +79 -0
- data/INSTALL +31 -0
- data/MANUAL +25 -0
- data/README +54 -0
- data/THEORY +151 -0
- data/USAGE +250 -0
- data/bin/ember +58 -20
- data/doc/ann.xml +93 -0
- data/doc/api/Ember.html +436 -0
- data/doc/api/Ember/Template.html +774 -0
- data/doc/api/Ember/Template/Program.html +877 -0
- data/doc/api/Ember/Template/Program/Statement.html +181 -0
- data/doc/api/_index.html +139 -0
- data/doc/api/class_list.html +36 -0
- data/doc/api/css/common.css +1 -0
- data/doc/api/css/full_list.css +50 -0
- data/doc/api/css/style.css +273 -0
- data/doc/api/file.LICENSE.html +73 -0
- data/doc/api/file_list.html +38 -0
- data/doc/api/frames.html +13 -0
- data/doc/api/index.html +72 -13
- data/doc/api/js/app.js +111 -0
- data/doc/api/js/full_list.js +117 -0
- data/doc/api/js/{jquery-1.3.2.min.js → jquery.js} +0 -0
- data/doc/api/method_list.html +179 -0
- data/doc/api/top-level-namespace.html +87 -0
- data/doc/index.html +1353 -682
- data/inochi.opts +31 -0
- data/lib/ember.rb +1 -15
- data/lib/ember/inochi.rb +103 -0
- data/lib/ember/template.rb +66 -78
- data/test/combinatorics.rb +188 -0
- data/test/ember/template_test.rb +137 -0
- data/test/runner +25 -0
- data/test/test_helper.rb +5 -0
- metadata +61 -51
- data/doc/api/apple-touch-icon.png +0 -0
- data/doc/api/classes/Ember.html +0 -61
- data/doc/api/classes/Ember/Template.html +0 -413
- data/doc/api/classes/Ember/Template/Program.html +0 -60
- data/doc/api/created.rid +0 -1
- data/doc/api/css/main.css +0 -263
- data/doc/api/css/panel.css +0 -383
- data/doc/api/css/reset.css +0 -53
- data/doc/api/favicon.ico +0 -0
- data/doc/api/files/LICENSE.html +0 -76
- data/doc/api/files/lib/ember/template_rb.html +0 -66
- data/doc/api/files/lib/ember_rb.html +0 -63
- data/doc/api/i/arrows.png +0 -0
- data/doc/api/i/results_bg.png +0 -0
- data/doc/api/i/tree_bg.png +0 -0
- data/doc/api/js/jquery-effect.js +0 -593
- data/doc/api/js/main.js +0 -22
- data/doc/api/js/searchdoc.js +0 -628
- data/doc/api/panel/index.html +0 -71
- data/doc/api/panel/search_index.js +0 -1
- data/doc/api/panel/tree.js +0 -1
- data/doc/history.erb +0 -34
- data/doc/index.erb +0 -11
- data/doc/intro.erb +0 -53
- data/doc/setup.erb +0 -78
- data/doc/usage.erb +0 -280
- data/rakefile +0 -14
- data/test/ember.rb +0 -17
- data/test/ember/template.rb +0 -141
data/HISTORY
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
%# #%
|
2
|
+
%# You can read this document in its full glory by #%
|
3
|
+
%# opening ./doc/index.html in your favorite Web browser. #%
|
4
|
+
%# #%
|
5
|
+
|
6
|
+
%#----------------------------------------------------------------------------
|
7
|
+
%| section "Version 0.1.0 (2010-04-03)"
|
8
|
+
%#----------------------------------------------------------------------------
|
9
|
+
|
10
|
+
This release improves the handling of eRuby comment directives, fixes a bug
|
11
|
+
in the `<%% end %>` inference logic, and performs some minor housekeeping.
|
12
|
+
|
13
|
+
%#--------------------------------------------------------------------------
|
14
|
+
%| paragraph "New features"
|
15
|
+
%#--------------------------------------------------------------------------
|
16
|
+
|
17
|
+
* Single-line comment directives are now ignored (treated like no-ops)
|
18
|
+
in input templates. This allows us to surround eRuby block directives
|
19
|
+
with section separators made from single-line comment directives:
|
20
|
+
|
21
|
+
%%|some_block_directive
|
22
|
+
|
23
|
+
Inside some_block_directive.
|
24
|
+
|
25
|
+
%%#-----------------------------------------------------------------
|
26
|
+
|
27
|
+
Still inside some_block_directive!
|
28
|
+
|
29
|
+
%%#---------------------------------------------------------------
|
30
|
+
%%| nested_block_directive
|
31
|
+
%%#---------------------------------------------------------------
|
32
|
+
|
33
|
+
Inside nested_block_directive.
|
34
|
+
|
35
|
+
%#--------------------------------------------------------------------------
|
36
|
+
%| paragraph "Bug fixes"
|
37
|
+
%#--------------------------------------------------------------------------
|
38
|
+
|
39
|
+
* `<%% end %>` inference did not work for blocks
|
40
|
+
beginning with `def`, `class`, and `module` keywords.
|
41
|
+
|
42
|
+
%#--------------------------------------------------------------------------
|
43
|
+
%| paragraph "Housekeeping"
|
44
|
+
%#--------------------------------------------------------------------------
|
45
|
+
|
46
|
+
* Upgrade to Inochi 2.0.0-rc3. This project no longer
|
47
|
+
depends on the "inochi" or "trollop" gems at runtime.
|
48
|
+
|
49
|
+
%#----------------------------------------------------------------------------
|
50
|
+
%| section "Version 0.0.1 (2009-10-03)"
|
51
|
+
%#----------------------------------------------------------------------------
|
52
|
+
|
53
|
+
This release improves Ruby 1.9 support and revises the user manual.
|
54
|
+
|
55
|
+
%#--------------------------------------------------------------------------
|
56
|
+
%| paragraph "Bug fixes"
|
57
|
+
%#--------------------------------------------------------------------------
|
58
|
+
|
59
|
+
* Nested templates could not access parent's binding in Ruby 1.9
|
60
|
+
|
61
|
+
%#--------------------------------------------------------------------------
|
62
|
+
%| paragraph "Housekeeping"
|
63
|
+
%#--------------------------------------------------------------------------
|
64
|
+
|
65
|
+
* Use simpler Copyright reminder at the top of every file.
|
66
|
+
|
67
|
+
* Rename internal `Program` class' methods to be self-documenting.
|
68
|
+
|
69
|
+
* Open source is for fun, so [be nice][1]: speak
|
70
|
+
of "related works" instead of "competitors".
|
71
|
+
|
72
|
+
[1]: http://loiclemeur.com/english/2009/03/never-criticize-your-competitors.html
|
73
|
+
|
74
|
+
%#----------------------------------------------------------------------------
|
75
|
+
%| section "Version 0.0.0 (2009-02-13)"
|
76
|
+
%#----------------------------------------------------------------------------
|
77
|
+
|
78
|
+
This is the first public release of Ember. Enjoy!
|
79
|
+
|
data/INSTALL
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
%# #%
|
2
|
+
%# You can read this document in its full glory by #%
|
3
|
+
%# opening ./doc/index.html in your favorite Web browser. #%
|
4
|
+
%# #%
|
5
|
+
|
6
|
+
%#----------------------------------------------------------------------------
|
7
|
+
%| section "Prerequisites"
|
8
|
+
%#----------------------------------------------------------------------------
|
9
|
+
|
10
|
+
* [Ruby](http://ruby-lang.org) 1.8.6 or newer.
|
11
|
+
|
12
|
+
* [RubyGems](http://rubygems.org) 1.3.6 or newer.
|
13
|
+
|
14
|
+
%#----------------------------------------------------------------------------
|
15
|
+
%| section "Installing"
|
16
|
+
%#----------------------------------------------------------------------------
|
17
|
+
|
18
|
+
%|command! "gem install ember"
|
19
|
+
|
20
|
+
%#----------------------------------------------------------------------------
|
21
|
+
%| section "Upgrading"
|
22
|
+
%#----------------------------------------------------------------------------
|
23
|
+
|
24
|
+
%|command! "gem update ember"
|
25
|
+
|
26
|
+
%#----------------------------------------------------------------------------
|
27
|
+
%| section "Uninstalling"
|
28
|
+
%#----------------------------------------------------------------------------
|
29
|
+
|
30
|
+
%|command! "gem uninstall ember"
|
31
|
+
|
data/MANUAL
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
%# #%
|
2
|
+
%# You can read this document in its full glory by #%
|
3
|
+
%# opening ./doc/index.html in your favorite Web browser. #%
|
4
|
+
%# #%
|
5
|
+
|
6
|
+
% api_reference_url = 'api/index.html'
|
7
|
+
% source_code_tool = '[Git](http://git-scm.com)'
|
8
|
+
% source_code_url = 'http://github.com/sunaku/ember'
|
9
|
+
% issue_tracker_url = 'http://github.com/sunaku/ember/issues'
|
10
|
+
|
11
|
+
%|part "Welcome"
|
12
|
+
%+ "README"
|
13
|
+
|
14
|
+
%|part "Setup"
|
15
|
+
%+ "INSTALL"
|
16
|
+
|
17
|
+
%|part "Theory"
|
18
|
+
%+ "THEORY"
|
19
|
+
|
20
|
+
%|part "Usage"
|
21
|
+
%+ "USAGE"
|
22
|
+
|
23
|
+
%|part "History"
|
24
|
+
%|project_history
|
25
|
+
%+ "HISTORY"
|
data/README
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
%# #%
|
2
|
+
%# You can read this document in its full glory by #%
|
3
|
+
%# opening ./doc/index.html in your favorite Web browser. #%
|
4
|
+
%# #%
|
5
|
+
|
6
|
+
%#----------------------------------------------------------------------------
|
7
|
+
%| project_summary
|
8
|
+
%#----------------------------------------------------------------------------
|
9
|
+
|
10
|
+
Ember (*EMBE*dded *R*uby) is an [eRuby template][1] processor that enables
|
11
|
+
debugging, reduces markup, and improves composability of eRuby templates.
|
12
|
+
|
13
|
+
* It reports correct line numbers in error message stack traces.
|
14
|
+
* It can infer <tt><%% end %></tt> based on indentation.
|
15
|
+
* It can unindent block content hierarchically.
|
16
|
+
* It completely silences code-only eRuby directives.
|
17
|
+
* It is implemented in <%= `sloccount lib`[/^\d+/] %> lines of pure Ruby.
|
18
|
+
|
19
|
+
[1]: http://en.wikipedia.org/wiki/ERuby
|
20
|
+
|
21
|
+
%#----------------------------------------------------------------------------
|
22
|
+
%| section "Resources"
|
23
|
+
%#----------------------------------------------------------------------------
|
24
|
+
|
25
|
+
* <%= xref "History", "What's new?" %> ---
|
26
|
+
release notes and project history.
|
27
|
+
|
28
|
+
* [Issue tracker](<%= issue_tracker_url %>) ---
|
29
|
+
report bugs, request features, or ask for help.
|
30
|
+
|
31
|
+
* [Source code](<%= source_code_url %>) ---
|
32
|
+
browse online or obtain using <%= source_code_tool %>
|
33
|
+
|
34
|
+
* [API reference](<%= api_reference_url %>) ---
|
35
|
+
documentation for source code.
|
36
|
+
|
37
|
+
* [Project home](<%= Ember::WEBSITE %>) ---
|
38
|
+
the official project home page.
|
39
|
+
|
40
|
+
%#----------------------------------------------------------------------------
|
41
|
+
%| section "License"
|
42
|
+
%#----------------------------------------------------------------------------
|
43
|
+
|
44
|
+
%# See the file named "LICENSE" for details.
|
45
|
+
%< "LICENSE"
|
46
|
+
|
47
|
+
%#----------------------------------------------------------------------------
|
48
|
+
%| section "Related works"
|
49
|
+
%#----------------------------------------------------------------------------
|
50
|
+
|
51
|
+
* [ERB](http://www.ruby-doc.org/stdlib/libdoc/erb/rdoc/)
|
52
|
+
* [Erubis](http://www.kuwata-lab.com/erubis/)
|
53
|
+
* [eruby](http://modruby.net/en/)
|
54
|
+
|
data/THEORY
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
%#----------------------------------------------------------------------------
|
2
|
+
%| section "Directives"
|
3
|
+
%#----------------------------------------------------------------------------
|
4
|
+
|
5
|
+
eRuby templates are plain-text documents that contain special processing
|
6
|
+
instructions known as **directives**, which may be expressed using either
|
7
|
+
**standard** or **shorthand** notation:
|
8
|
+
|
9
|
+
%|table
|
10
|
+
%|thead
|
11
|
+
%|tr
|
12
|
+
%|th
|
13
|
+
Notation
|
14
|
+
%|th
|
15
|
+
Directive
|
16
|
+
%|th
|
17
|
+
Head
|
18
|
+
%|th
|
19
|
+
Operation
|
20
|
+
%|th
|
21
|
+
Body
|
22
|
+
%|th
|
23
|
+
Tail
|
24
|
+
%|tbody
|
25
|
+
%|tr
|
26
|
+
%|td
|
27
|
+
Standard
|
28
|
+
%|td
|
29
|
+
<%%XY%>
|
30
|
+
%|td
|
31
|
+
<%%
|
32
|
+
%|td
|
33
|
+
X
|
34
|
+
%|td
|
35
|
+
Y
|
36
|
+
%|td
|
37
|
+
%%>
|
38
|
+
%|tr
|
39
|
+
%|td
|
40
|
+
Shorthand
|
41
|
+
%|td
|
42
|
+
%%XY
|
43
|
+
%|td
|
44
|
+
%%
|
45
|
+
%|td
|
46
|
+
X
|
47
|
+
%|td
|
48
|
+
Y
|
49
|
+
%|td
|
50
|
+
|
51
|
+
In standard notation, the directive is composed of a head, <%= xref \
|
52
|
+
"Operations", "an operation" %>, a body, and a tail. In addition, the
|
53
|
+
directive may appear anywhere in the text.
|
54
|
+
|
55
|
+
In shorthand notation, the directive is composed of a head, <%= xref \
|
56
|
+
"Operations", "an operation" %> and a body. However, the directive may only
|
57
|
+
appear in the text if it occupies an entire line (arbitrary amounts of
|
58
|
+
leading whitespace are permitted).
|
59
|
+
|
60
|
+
In any case, directives are atomic constructs; they cannot be nested.
|
61
|
+
|
62
|
+
%#--------------------------------------------------------------------------
|
63
|
+
%| section "Operations"
|
64
|
+
%#--------------------------------------------------------------------------
|
65
|
+
|
66
|
+
The first character that follows the head of a directive is known as an
|
67
|
+
**operation**. It prescribes how the directive should be processed:
|
68
|
+
|
69
|
+
%|table
|
70
|
+
%|thead
|
71
|
+
%|tr
|
72
|
+
%|th
|
73
|
+
Operation
|
74
|
+
%|th
|
75
|
+
Effect
|
76
|
+
%|th
|
77
|
+
Example
|
78
|
+
%|tbody
|
79
|
+
%|tr
|
80
|
+
%|td
|
81
|
+
`<%= Ember::Template::OPERATION_COMMENT_LINE %>`
|
82
|
+
%|td
|
83
|
+
The entire directive is omitted from the output.
|
84
|
+
%|td
|
85
|
+
%= xref "Comment directives"
|
86
|
+
%|tr
|
87
|
+
%|td
|
88
|
+
`<%= Ember::Template::OPERATION_EVAL_EXPRESSION %>`
|
89
|
+
%|td
|
90
|
+
The body of the directive is evaluated as Ruby code, and the
|
91
|
+
result of this evaluation is inserted into the output.
|
92
|
+
%|td
|
93
|
+
%= xref "Vocal directives"
|
94
|
+
%|tr
|
95
|
+
%|td
|
96
|
+
`<%= Ember::Template::OPERATION_EVAL_TEMPLATE_STRING %>`
|
97
|
+
%|td
|
98
|
+
The body of the directive is evaluated as an eRuby template, and
|
99
|
+
the result of this evaluation is inserted into the output.
|
100
|
+
%|td
|
101
|
+
%= xref "Dynamic template evaluation"
|
102
|
+
%|tr
|
103
|
+
%|td
|
104
|
+
`<%= Ember::Template::OPERATION_EVAL_TEMPLATE_FILE %>`
|
105
|
+
%|td
|
106
|
+
The body of the directive is evaluated as Ruby code, and the
|
107
|
+
result of this evaluation is assumed to be a string that specifies
|
108
|
+
the path (either absolute or relative to the eRuby template file
|
109
|
+
in which this directive is found) to a file containing an eRuby
|
110
|
+
template. This file is read and its contents are evaluated as an
|
111
|
+
eRuby template, and the result of this evaluation is inserted into
|
112
|
+
the output.
|
113
|
+
%|td
|
114
|
+
%= xref "Template file inclusion"
|
115
|
+
%|tr
|
116
|
+
%|td
|
117
|
+
`<%= Ember::Template::OPERATION_INSERT_PLAIN_FILE %>`
|
118
|
+
%|td
|
119
|
+
The body of the directive is evaluated as Ruby code, and the
|
120
|
+
result of this evaluation is assumed to be a string that specifies
|
121
|
+
the path (either absolute or relative to the eRuby template file
|
122
|
+
in which this directive is found) to a file. This file is read
|
123
|
+
and its contents are inserted into the output.
|
124
|
+
%|td
|
125
|
+
%= xref "Raw file inclusion"
|
126
|
+
%|tr
|
127
|
+
%|td
|
128
|
+
`<%= Ember::Template::OPERATION_BEGIN_LAMBDA %>`
|
129
|
+
%|td
|
130
|
+
The body of the directive is treated as the beginning of a Ruby
|
131
|
+
block. The `do` keyword is automatically appended to the body of
|
132
|
+
the directive if missing.
|
133
|
+
%|td
|
134
|
+
%= xref "Block directives"
|
135
|
+
%|tr
|
136
|
+
%|td
|
137
|
+
`%`
|
138
|
+
%|td
|
139
|
+
One "%" character is omitted from the head of the directive and
|
140
|
+
the entire directive is inserted into the output.
|
141
|
+
%|td
|
142
|
+
%= xref "Escaped directives"
|
143
|
+
%|tr
|
144
|
+
%|td
|
145
|
+
(none of the above)
|
146
|
+
%|td
|
147
|
+
The body of the directive is evaluated as Ruby code, but the
|
148
|
+
result of this evaluation *is not* inserted into the output.
|
149
|
+
%|td
|
150
|
+
%= xref "Silent directives"
|
151
|
+
|
data/USAGE
ADDED
@@ -0,0 +1,250 @@
|
|
1
|
+
%# #%
|
2
|
+
%# You can read this document in its full glory by #%
|
3
|
+
%# opening ./doc/index.html in your favorite Web browser. #%
|
4
|
+
%# #%
|
5
|
+
|
6
|
+
%#----------------------------------------------------------------------------
|
7
|
+
%| section "Shell command"
|
8
|
+
%#----------------------------------------------------------------------------
|
9
|
+
|
10
|
+
%|command! "ember --help" do |node|
|
11
|
+
%|text
|
12
|
+
%= verbatim `ruby bin/#{node.title}`
|
13
|
+
|
14
|
+
%#----------------------------------------------------------------------------
|
15
|
+
%| section "Ruby library"
|
16
|
+
%#----------------------------------------------------------------------------
|
17
|
+
|
18
|
+
Begin by loading Ember into Ruby:
|
19
|
+
|
20
|
+
%|code
|
21
|
+
require 'rubygems' # only necessary if you are using Ruby 1.8
|
22
|
+
require 'ember'
|
23
|
+
|
24
|
+
Instantiate an Ember template processor:
|
25
|
+
|
26
|
+
%|code
|
27
|
+
source = "your eRuby template here"
|
28
|
+
options = { :unindent => true, :shorthand => true }
|
29
|
+
template = Ember::Template.new(source, options)
|
30
|
+
|
31
|
+
Inspect the Ruby program that was compiled (and is used) by the Ember
|
32
|
+
template processor to evaluate the eRuby template given as input:
|
33
|
+
|
34
|
+
%|code
|
35
|
+
puts template.program
|
36
|
+
|
37
|
+
View the result of evaluating the eRuby template:
|
38
|
+
|
39
|
+
%|code
|
40
|
+
puts template.render
|
41
|
+
|
42
|
+
See the [API documentation](api/index.html) for more information.
|
43
|
+
|
44
|
+
%#--------------------------------------------------------------------------
|
45
|
+
<%
|
46
|
+
standard_directive = lambda do |body|
|
47
|
+
'<' + '%' + body + ' %' + '>'
|
48
|
+
end
|
49
|
+
|
50
|
+
shorthand_directive = lambda do |body|
|
51
|
+
'%' + body
|
52
|
+
end
|
53
|
+
%>
|
54
|
+
|
55
|
+
%|template_example = lambda do |input, options|
|
56
|
+
% input = input.strip.gsub(/^ {4}/, '') << "\n" # remove indentation
|
57
|
+
% template = Ember::Template.new(input, options)
|
58
|
+
|
59
|
+
% text { input }
|
60
|
+
|
61
|
+
<%=
|
62
|
+
if options.empty?
|
63
|
+
"The"
|
64
|
+
else
|
65
|
+
"With `#{options.inspect}` options, the"
|
66
|
+
end
|
67
|
+
%> above template compiles into:
|
68
|
+
|
69
|
+
% code { template.program }
|
70
|
+
|
71
|
+
And renders as:
|
72
|
+
|
73
|
+
% text { template.render }
|
74
|
+
|
75
|
+
%#--------------------------------------------------------------------------
|
76
|
+
%| example! "An empty template"
|
77
|
+
%#--------------------------------------------------------------------------
|
78
|
+
|
79
|
+
Begin with an empty template:
|
80
|
+
|
81
|
+
%= template_example.call "", {}
|
82
|
+
|
83
|
+
%#--------------------------------------------------------------------------
|
84
|
+
%| example! "Comment directives"
|
85
|
+
%#--------------------------------------------------------------------------
|
86
|
+
|
87
|
+
Add comment directives:
|
88
|
+
|
89
|
+
<%=
|
90
|
+
template_example.call %{
|
91
|
+
#{standard_directive.call '# this is a comment'}
|
92
|
+
#{shorthand_directive.call '# this is also a comment'}
|
93
|
+
|
94
|
+
#{standard_directive.call "# this\nis\na\nmulti-line comment"}
|
95
|
+
}, :shorthand => true
|
96
|
+
%>
|
97
|
+
|
98
|
+
%#--------------------------------------------------------------------------
|
99
|
+
%| example! "Escaped directives"
|
100
|
+
%#--------------------------------------------------------------------------
|
101
|
+
|
102
|
+
Add escaped directives:
|
103
|
+
|
104
|
+
<%=
|
105
|
+
example = '% this is an escaped directive'
|
106
|
+
|
107
|
+
template_example.call %{
|
108
|
+
#{standard_directive.call example}
|
109
|
+
#{shorthand_directive.call example}
|
110
|
+
}, :shorthand => true
|
111
|
+
%>
|
112
|
+
|
113
|
+
%#--------------------------------------------------------------------------
|
114
|
+
%| example! "Vocal directives"
|
115
|
+
%#--------------------------------------------------------------------------
|
116
|
+
|
117
|
+
Add vocal directives, which produce output:
|
118
|
+
|
119
|
+
<%=
|
120
|
+
template_example.call %{
|
121
|
+
#{standard_directive.call '= "hello"'}
|
122
|
+
#{shorthand_directive.call '= "world"'}
|
123
|
+
|
124
|
+
}, :shorthand => true
|
125
|
+
%>
|
126
|
+
|
127
|
+
%#--------------------------------------------------------------------------
|
128
|
+
%| example! "Silent directives"
|
129
|
+
%#--------------------------------------------------------------------------
|
130
|
+
|
131
|
+
Add silent directives, which do not produce output:
|
132
|
+
|
133
|
+
<%=
|
134
|
+
template_example.call %{
|
135
|
+
#{standard_directive.call ' a = "hello"'}
|
136
|
+
#{shorthand_directive.call ' b = "world"'}
|
137
|
+
|
138
|
+
#{standard_directive.call '= a'}
|
139
|
+
#{shorthand_directive.call '= b'}
|
140
|
+
|
141
|
+
}, :shorthand => true
|
142
|
+
%>
|
143
|
+
|
144
|
+
%#--------------------------------------------------------------------------
|
145
|
+
%| example! "Block directives"
|
146
|
+
%#--------------------------------------------------------------------------
|
147
|
+
|
148
|
+
Add some Ruby blocks:
|
149
|
+
|
150
|
+
<%=
|
151
|
+
template_example.call %{
|
152
|
+
#{shorthand_directive.call ' words = %w[hello world]'}
|
153
|
+
|
154
|
+
#{standard_directive.call ' words.each do |w|'}
|
155
|
+
#{standard_directive.call '= w'}
|
156
|
+
#{standard_directive.call ' end'}
|
157
|
+
|
158
|
+
#{shorthand_directive.call ' words.each do |w|'}
|
159
|
+
#{shorthand_directive.call '= w'}
|
160
|
+
#{shorthand_directive.call ' end'}
|
161
|
+
|
162
|
+
#{shorthand_directive.call '|words.each |w|'}
|
163
|
+
#{shorthand_directive.call '= w'}
|
164
|
+
#{shorthand_directive.call ' end'}
|
165
|
+
|
166
|
+
}, :shorthand => true
|
167
|
+
%>
|
168
|
+
|
169
|
+
%#--------------------------------------------------------------------------
|
170
|
+
%| example! "Infer block endings"
|
171
|
+
%#--------------------------------------------------------------------------
|
172
|
+
|
173
|
+
Omit <tt><%= standard_directive.call ' end' %></tt> directives from the
|
174
|
+
template:
|
175
|
+
|
176
|
+
<%=
|
177
|
+
template_example.call %{
|
178
|
+
#{shorthand_directive.call ' words = %w[hello world]'}
|
179
|
+
|
180
|
+
#{standard_directive.call ' words.each do |w|'}
|
181
|
+
#{standard_directive.call '= w'}
|
182
|
+
|
183
|
+
#{shorthand_directive.call ' words.each do |w|'}
|
184
|
+
#{shorthand_directive.call '= w'}
|
185
|
+
|
186
|
+
#{shorthand_directive.call '|words.each |w|'}
|
187
|
+
#{shorthand_directive.call '= w'}
|
188
|
+
|
189
|
+
}, :shorthand => true, :infer_end => true
|
190
|
+
%>
|
191
|
+
|
192
|
+
%#--------------------------------------------------------------------------
|
193
|
+
%| example! "Raw file inclusion"
|
194
|
+
%#--------------------------------------------------------------------------
|
195
|
+
|
196
|
+
When <tt>doc/example.txt</tt> contains:
|
197
|
+
|
198
|
+
%|text
|
199
|
+
%< "doc/example.txt"
|
200
|
+
|
201
|
+
And the eRuby template is:
|
202
|
+
|
203
|
+
<%=
|
204
|
+
example = '< "doc/example.txt"'
|
205
|
+
|
206
|
+
template_example.call %{
|
207
|
+
#{standard_directive.call example}
|
208
|
+
|
209
|
+
#{shorthand_directive.call example}
|
210
|
+
|
211
|
+
}, :shorthand => true, :source_file => __FILE__
|
212
|
+
%>
|
213
|
+
|
214
|
+
%#--------------------------------------------------------------------------
|
215
|
+
%| example! "Template file inclusion"
|
216
|
+
%#--------------------------------------------------------------------------
|
217
|
+
|
218
|
+
When <tt>doc/example.erb</tt> contains:
|
219
|
+
|
220
|
+
%|code :rhtml
|
221
|
+
%< "doc/example.erb"
|
222
|
+
|
223
|
+
And the eRuby template is:
|
224
|
+
|
225
|
+
<%=
|
226
|
+
example = '+ "doc/example.erb"'
|
227
|
+
|
228
|
+
template_example.call %{
|
229
|
+
#{standard_directive.call example}
|
230
|
+
|
231
|
+
#{shorthand_directive.call example}
|
232
|
+
|
233
|
+
}, :shorthand => true, :source_file => __FILE__
|
234
|
+
%>
|
235
|
+
|
236
|
+
%#--------------------------------------------------------------------------
|
237
|
+
%| example! "Dynamic template evaluation"
|
238
|
+
%#--------------------------------------------------------------------------
|
239
|
+
|
240
|
+
<%=
|
241
|
+
example = %{~ "#{shorthand_directive.call '= 2 + 2'}"}
|
242
|
+
|
243
|
+
template_example.call %{
|
244
|
+
#{standard_directive.call example}
|
245
|
+
|
246
|
+
#{shorthand_directive.call example}
|
247
|
+
|
248
|
+
}, :shorthand => true
|
249
|
+
%>
|
250
|
+
|