walrus 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (208) hide show
  1. data/bin/walrus +44 -0
  2. data/ext/jindex/extconf.rb +11 -0
  3. data/ext/jindex/jindex.c +79 -0
  4. data/ext/mkdtemp/extconf.rb +11 -0
  5. data/ext/mkdtemp/mkdtemp.c +41 -0
  6. data/lib/walrus/additions/module.rb +36 -0
  7. data/lib/walrus/additions/string.rb +37 -0
  8. data/lib/walrus/additions/test/unit/error_collector.rb +62 -0
  9. data/lib/walrus/compile_error.rb +28 -0
  10. data/lib/walrus/compiler.rb +124 -0
  11. data/lib/walrus/contrib/spec/walruscloth_spec.rb +32 -0
  12. data/lib/walrus/contrib/walruscloth.rb +82 -0
  13. data/lib/walrus/diff.rb +89 -0
  14. data/lib/walrus/document.rb +98 -0
  15. data/lib/walrus/grammar/additions/proc.rb +20 -0
  16. data/lib/walrus/grammar/additions/regexp.rb +21 -0
  17. data/lib/walrus/grammar/additions/string.rb +52 -0
  18. data/lib/walrus/grammar/additions/symbol.rb +42 -0
  19. data/lib/walrus/grammar/and_predicate.rb +40 -0
  20. data/lib/walrus/grammar/array_result.rb +19 -0
  21. data/lib/walrus/grammar/continuation_wrapper_exception.rb +28 -0
  22. data/lib/walrus/grammar/left_recursion_exception.rb +27 -0
  23. data/lib/walrus/grammar/location_tracking.rb +105 -0
  24. data/lib/walrus/grammar/match_data_wrapper.rb +65 -0
  25. data/lib/walrus/grammar/memoizing.rb +41 -0
  26. data/lib/walrus/grammar/memoizing_cache.rb +94 -0
  27. data/lib/walrus/grammar/node.rb +60 -0
  28. data/lib/walrus/grammar/not_predicate.rb +40 -0
  29. data/lib/walrus/grammar/parse_error.rb +39 -0
  30. data/lib/walrus/grammar/parser_state.rb +181 -0
  31. data/lib/walrus/grammar/parslet.rb +28 -0
  32. data/lib/walrus/grammar/parslet_choice.rb +120 -0
  33. data/lib/walrus/grammar/parslet_combination.rb +26 -0
  34. data/lib/walrus/grammar/parslet_combining.rb +154 -0
  35. data/lib/walrus/grammar/parslet_merge.rb +88 -0
  36. data/lib/walrus/grammar/parslet_omission.rb +57 -0
  37. data/lib/walrus/grammar/parslet_repetition.rb +97 -0
  38. data/lib/walrus/grammar/parslet_repetition_default.rb +58 -0
  39. data/lib/walrus/grammar/parslet_sequence.rb +202 -0
  40. data/lib/walrus/grammar/predicate.rb +57 -0
  41. data/lib/walrus/grammar/proc_parslet.rb +52 -0
  42. data/lib/walrus/grammar/regexp_parslet.rb +73 -0
  43. data/lib/walrus/grammar/skipped_substring_exception.rb +36 -0
  44. data/lib/walrus/grammar/string_enumerator.rb +45 -0
  45. data/lib/walrus/grammar/string_parslet.rb +75 -0
  46. data/lib/walrus/grammar/string_result.rb +24 -0
  47. data/lib/walrus/grammar/symbol_parslet.rb +63 -0
  48. data/lib/walrus/grammar.rb +170 -0
  49. data/lib/walrus/no_parameter_marker.rb +19 -0
  50. data/lib/walrus/parser.rb +420 -0
  51. data/lib/walrus/runner.rb +356 -0
  52. data/lib/walrus/template.rb +75 -0
  53. data/lib/walrus/walrus_grammar/assignment_expression.rb +24 -0
  54. data/lib/walrus/walrus_grammar/block_directive.rb +28 -0
  55. data/lib/walrus/walrus_grammar/comment.rb +24 -0
  56. data/lib/walrus/walrus_grammar/def_directive.rb +64 -0
  57. data/lib/walrus/walrus_grammar/echo_directive.rb +44 -0
  58. data/lib/walrus/walrus_grammar/escape_sequence.rb +24 -0
  59. data/lib/walrus/walrus_grammar/import_directive.rb +44 -0
  60. data/lib/walrus/walrus_grammar/include_directive.rb +27 -0
  61. data/lib/walrus/walrus_grammar/instance_variable.rb +24 -0
  62. data/lib/walrus/walrus_grammar/literal.rb +24 -0
  63. data/lib/walrus/walrus_grammar/message_expression.rb +25 -0
  64. data/lib/walrus/walrus_grammar/multiline_comment.rb +54 -0
  65. data/lib/walrus/walrus_grammar/placeholder.rb +40 -0
  66. data/lib/walrus/walrus_grammar/raw_directive.rb +42 -0
  67. data/lib/walrus/walrus_grammar/raw_text.rb +45 -0
  68. data/lib/walrus/walrus_grammar/ruby_directive.rb +29 -0
  69. data/lib/walrus/walrus_grammar/ruby_expression.rb +31 -0
  70. data/lib/walrus/walrus_grammar/set_directive.rb +24 -0
  71. data/lib/walrus/walrus_grammar/silent_directive.rb +44 -0
  72. data/lib/walrus/walrus_grammar/slurp_directive.rb +25 -0
  73. data/lib/walrus/walrus_grammar/super_directive.rb +27 -0
  74. data/lib/walrus.rb +64 -0
  75. data/spec/acceptance/acceptance_spec.rb +97 -0
  76. data/spec/acceptance/block/basic_block.expected +1 -0
  77. data/spec/acceptance/block/basic_block.tmpl +3 -0
  78. data/spec/acceptance/block/nested_blocks.expected +5 -0
  79. data/spec/acceptance/block/nested_blocks.tmpl +11 -0
  80. data/spec/acceptance/comments/comments_and_text.expected +3 -0
  81. data/spec/acceptance/comments/comments_and_text.tmpl +6 -0
  82. data/spec/acceptance/comments/single_comment.expected +0 -0
  83. data/spec/acceptance/comments/single_comment.tmpl +1 -0
  84. data/spec/acceptance/def/alternative_def_calling_conventions.expected +3 -0
  85. data/spec/acceptance/def/alternative_def_calling_conventions.tmpl +18 -0
  86. data/spec/acceptance/def/basic_def_block_no_output.expected +0 -0
  87. data/spec/acceptance/def/basic_def_block_no_output.tmpl +17 -0
  88. data/spec/acceptance/def/defs_can_be_called_multiple_times.expected +3 -0
  89. data/spec/acceptance/def/defs_can_be_called_multiple_times.tmpl +6 -0
  90. data/spec/acceptance/def/defs_can_be_dynamic.expected +4 -0
  91. data/spec/acceptance/def/defs_can_be_dynamic.tmpl +12 -0
  92. data/spec/acceptance/echo/echo_directive_with_numeric_literal.expected +1 -0
  93. data/spec/acceptance/echo/echo_directive_with_numeric_literal.tmpl +1 -0
  94. data/spec/acceptance/echo/echo_expression_list.expected +1 -0
  95. data/spec/acceptance/echo/echo_expression_list.tmpl +1 -0
  96. data/spec/acceptance/echo/echo_short_notation.expected +1 -0
  97. data/spec/acceptance/echo/echo_short_notation.tmpl +1 -0
  98. data/spec/acceptance/echo/echo_simple_expression.expected +1 -0
  99. data/spec/acceptance/echo/echo_simple_expression.tmpl +1 -0
  100. data/spec/acceptance/echo/echo_single_quoted_string_literal.expected +1 -0
  101. data/spec/acceptance/echo/echo_single_quoted_string_literal.tmpl +1 -0
  102. data/spec/acceptance/echo/multiple_echo_statements.expected +1 -0
  103. data/spec/acceptance/echo/multiple_echo_statements.tmpl +2 -0
  104. data/spec/acceptance/includes/basic_included_file.txt +1 -0
  105. data/spec/acceptance/includes/basic_includer.complex +3 -0
  106. data/spec/acceptance/includes/basic_includer.expected +3 -0
  107. data/spec/acceptance/includes/basic_includer.rb +38 -0
  108. data/spec/acceptance/includes/complicated_included_file.txt +3 -0
  109. data/spec/acceptance/includes/complicated_includer.complex +3 -0
  110. data/spec/acceptance/includes/complicated_includer.expected +3 -0
  111. data/spec/acceptance/includes/complicated_includer.rb +41 -0
  112. data/spec/acceptance/includes/nested_include_1.txt +3 -0
  113. data/spec/acceptance/includes/nested_include_2.txt +1 -0
  114. data/spec/acceptance/includes/nested_includer.complex +3 -0
  115. data/spec/acceptance/includes/nested_includer.expected +4 -0
  116. data/spec/acceptance/includes/nested_includer.rb +41 -0
  117. data/spec/acceptance/inheritance/basic_child.complex +10 -0
  118. data/spec/acceptance/inheritance/basic_child.expected +9 -0
  119. data/spec/acceptance/inheritance/basic_child.rb +54 -0
  120. data/spec/acceptance/inheritance/basic_parent.complex +5 -0
  121. data/spec/acceptance/inheritance/basic_parent.expected +3 -0
  122. data/spec/acceptance/inheritance/basic_parent.rb +41 -0
  123. data/spec/acceptance/inheritance/importing_child.complex +8 -0
  124. data/spec/acceptance/inheritance/importing_child.expected +7 -0
  125. data/spec/acceptance/inheritance/importing_child.rb +46 -0
  126. data/spec/acceptance/inheritance/subdirectory/importing_child_in_subdirectory.complex +8 -0
  127. data/spec/acceptance/inheritance/subdirectory/importing_child_in_subdirectory.expected +7 -0
  128. data/spec/acceptance/inheritance/subdirectory/importing_child_in_subdirectory.rb +44 -0
  129. data/spec/acceptance/multiline_comments/multiline_comment_with_directives_inside.expected +0 -0
  130. data/spec/acceptance/multiline_comments/multiline_comment_with_directives_inside.tmpl +15 -0
  131. data/spec/acceptance/multiline_comments/simple_multiline_comment.expected +2 -0
  132. data/spec/acceptance/multiline_comments/simple_multiline_comment.tmpl +4 -0
  133. data/spec/acceptance/raw/complicated_raw_example.expected +57 -0
  134. data/spec/acceptance/raw/complicated_raw_example.tmpl +79 -0
  135. data/spec/acceptance/raw-text/UTF_8.expected +12 -0
  136. data/spec/acceptance/raw-text/UTF_8.tmpl +12 -0
  137. data/spec/acceptance/raw-text/empty_file.expected +0 -0
  138. data/spec/acceptance/raw-text/empty_file.tmpl +0 -0
  139. data/spec/acceptance/raw-text/multi_line.expected +4 -0
  140. data/spec/acceptance/raw-text/multi_line.tmpl +4 -0
  141. data/spec/acceptance/raw-text/single_line.expected +1 -0
  142. data/spec/acceptance/raw-text/single_line.tmpl +1 -0
  143. data/spec/acceptance/raw-text/single_line_whitespace.expected +1 -0
  144. data/spec/acceptance/raw-text/single_line_whitespace.tmpl +1 -0
  145. data/spec/acceptance/ruby/ruby_directive_is_just_like_silent.expected +1 -0
  146. data/spec/acceptance/ruby/ruby_directive_is_just_like_silent.tmpl +4 -0
  147. data/spec/acceptance/ruby/ruby_directive_using_here_doc.expected +1 -0
  148. data/spec/acceptance/ruby/ruby_directive_using_here_doc.tmpl +4 -0
  149. data/spec/acceptance/ruby/ruby_directive_using_here_doc_alt_syntax.expected +1 -0
  150. data/spec/acceptance/ruby/ruby_directive_using_here_doc_alt_syntax.tmpl +4 -0
  151. data/spec/acceptance/ruby/ruby_directive_with_accumulate.expected +1 -0
  152. data/spec/acceptance/ruby/ruby_directive_with_accumulate.tmpl +4 -0
  153. data/spec/acceptance/ruby/ruby_directive_with_accumulate_and_block.expected +1 -0
  154. data/spec/acceptance/ruby/ruby_directive_with_accumulate_and_block.tmpl +6 -0
  155. data/spec/acceptance/set/unused_set.expected +0 -0
  156. data/spec/acceptance/set/unused_set.tmpl +1 -0
  157. data/spec/acceptance/set/used_set.expected +1 -0
  158. data/spec/acceptance/set/used_set.tmpl +2 -0
  159. data/spec/acceptance/silent/silent_and_echo_combined.expected +1 -0
  160. data/spec/acceptance/silent/silent_and_echo_combined.tmpl +2 -0
  161. data/spec/acceptance/silent/silent_short_notation.expected +1 -0
  162. data/spec/acceptance/silent/silent_short_notation.tmpl +1 -0
  163. data/spec/acceptance/silent/simple_silent_directive.expected +0 -0
  164. data/spec/acceptance/silent/simple_silent_directive.tmpl +1 -0
  165. data/spec/acceptance/slurp/basic_slurp_demo.expected +1 -0
  166. data/spec/acceptance/slurp/basic_slurp_demo.tmpl +4 -0
  167. data/spec/acceptance/super/super_with_no_effect.expected +4 -0
  168. data/spec/acceptance/super/super_with_no_effect.tmpl +5 -0
  169. data/spec/additions/module_spec.rb +126 -0
  170. data/spec/additions/string_spec.rb +99 -0
  171. data/spec/compiler_spec.rb +55 -0
  172. data/spec/grammar/additions/proc_spec.rb +25 -0
  173. data/spec/grammar/additions/regexp_spec.rb +37 -0
  174. data/spec/grammar/additions/string_spec.rb +106 -0
  175. data/spec/grammar/and_predicate_spec.rb +29 -0
  176. data/spec/grammar/continuation_wrapper_exception_spec.rb +23 -0
  177. data/spec/grammar/match_data_wrapper_spec.rb +41 -0
  178. data/spec/grammar/memoizing_cache_spec.rb +112 -0
  179. data/spec/grammar/node_spec.rb +126 -0
  180. data/spec/grammar/not_predicate_spec.rb +29 -0
  181. data/spec/grammar/parser_state_spec.rb +172 -0
  182. data/spec/grammar/parslet_choice_spec.rb +49 -0
  183. data/spec/grammar/parslet_combining_spec.rb +287 -0
  184. data/spec/grammar/parslet_merge_spec.rb +33 -0
  185. data/spec/grammar/parslet_omission_spec.rb +58 -0
  186. data/spec/grammar/parslet_repetition_spec.rb +77 -0
  187. data/spec/grammar/parslet_sequence_spec.rb +49 -0
  188. data/spec/grammar/parslet_spec.rb +23 -0
  189. data/spec/grammar/predicate_spec.rb +53 -0
  190. data/spec/grammar/proc_parslet_spec.rb +52 -0
  191. data/spec/grammar/regexp_parslet_spec.rb +347 -0
  192. data/spec/grammar/string_enumerator_spec.rb +94 -0
  193. data/spec/grammar/string_parslet_spec.rb +143 -0
  194. data/spec/grammar/symbol_parslet_spec.rb +30 -0
  195. data/spec/grammar_spec.rb +545 -0
  196. data/spec/parser_spec.rb +1418 -0
  197. data/spec/spec_helper.rb +34 -0
  198. data/spec/walrus_grammar/comment_spec.rb +39 -0
  199. data/spec/walrus_grammar/echo_directive_spec.rb +63 -0
  200. data/spec/walrus_grammar/escape_sequence_spec.rb +85 -0
  201. data/spec/walrus_grammar/literal_spec.rb +41 -0
  202. data/spec/walrus_grammar/message_expression_spec.rb +37 -0
  203. data/spec/walrus_grammar/multiline_comment_spec.rb +58 -0
  204. data/spec/walrus_grammar/placeholder_spec.rb +48 -0
  205. data/spec/walrus_grammar/raw_directive_spec.rb +81 -0
  206. data/spec/walrus_grammar/raw_text_spec.rb +65 -0
  207. data/spec/walrus_grammar/silent_directive_spec.rb +34 -0
  208. metadata +291 -0
@@ -0,0 +1,6 @@
1
+ This file contains comments ## like this one!
2
+ which should not appear in the template output...
3
+ ## This line should be completely missing from the output
4
+ ## and this one two, because the comments are the first
5
+ ## (and only) thing on the lines
6
+ In the final output, this should be the third line...
File without changes
@@ -0,0 +1 @@
1
+ ## This template contains only a comment; the output file should be empty.
@@ -0,0 +1,3 @@
1
+ This is block 1. It will be injected using the #silent directive.
2
+ This is block 2. It will be injected using the #ruby directive.
3
+ This is block 3. It will be referenced using a placeholder.
@@ -0,0 +1,18 @@
1
+ ## This example shows some alternative ways of causing #def content to appear in the output
2
+ ## (by default #def content is not automatically injected into the output)
3
+ #def block1
4
+ This is block 1. It will be injected using the \#silent directive.
5
+ #end
6
+ #def block2
7
+ This is block 2. It will be injected using the \#ruby directive.
8
+ #end
9
+ #def block3
10
+ This is block 3. It will be referenced using a placeholder.
11
+ #end
12
+ ## no need to call "accumulate" here because the block already does that.
13
+ #silent block1
14
+ #ruby
15
+ # no need to call "accumulate" here because the block already does that.
16
+ block2
17
+ #end
18
+ $block3
@@ -0,0 +1,17 @@
1
+ #def body
2
+ The key distinction between the \#block and \#def directives is that
3
+ the former automatically produces output in the template whereas the
4
+ latter only produces output if explicitly caused to do so (via a
5
+ placeholder).
6
+
7
+ Basically, a \#def directive defines a chunk of material that can be
8
+ used in a template or overridden or customized in an inheriting
9
+ template. The chunk is defined but no output is included by default.
10
+
11
+ A \#block directive, on the other hand, both defines a chunk and
12
+ automatically emits its contents in the template at the point it was
13
+ defined.
14
+
15
+ As such, this sample file will produce no output, although it will
16
+ cause a method to be added to the compiled version of the template.
17
+ #end
@@ -0,0 +1,3 @@
1
+ The body will appear multiple times...
2
+ The body will appear multiple times...
3
+ The body will appear multiple times...
@@ -0,0 +1,6 @@
1
+ #def body
2
+ The body will appear multiple times...
3
+ #end
4
+ #silent body
5
+ #silent body
6
+ #silent body
@@ -0,0 +1,12 @@
1
+ #def counter
2
+ #ruby
3
+ @counter ||= 0 # initialize counter
4
+ @counter += 1 # increment counter
5
+ #end
6
+ #end
7
+ ## Note how in the first three cases below I use an explicit end-of-directive marker;
8
+ ## this is to ensure that Walrus "sees" (and emits) a newline after each number.
9
+ #echo counter#
10
+ #echo counter#
11
+ #echo counter#
12
+ #echo counter
@@ -0,0 +1 @@
1
+ It doesn't get much simpler than this...
@@ -0,0 +1 @@
1
+ #echo "It doesn't get much simpler than this"; "..."
@@ -0,0 +1 @@
1
+ #= 42 #
@@ -0,0 +1 @@
1
+ It doesn't get much simpler than this
@@ -0,0 +1 @@
1
+ #echo "It doesn't get much simpler than this"
@@ -0,0 +1 @@
1
+ #echo 'Hello, world!'
@@ -0,0 +1,2 @@
1
+ #echo 'foo'
2
+ #echo "bar"
@@ -0,0 +1 @@
1
+ Paragraph 2
@@ -0,0 +1,3 @@
1
+ Paragraph 1
2
+ #include 'basic_included_file.txt'
3
+ Paragraph 3
@@ -0,0 +1,3 @@
1
+ Paragraph 1
2
+ Paragraph 2
3
+ Paragraph 3
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env ruby
2
+ # Generated Fri Apr 13 16:10:49 +0200 2007 by Walrus version 0.1
3
+
4
+ begin
5
+ require 'rubygems'
6
+ rescue LoadError
7
+ # installing Walrus via RubyGems is recommended
8
+ # otherwise Walrus must be installed in the RUBYLIB load path
9
+ end
10
+
11
+ require 'walrus/document'
12
+
13
+ module Walrus
14
+
15
+ class WalrusGrammar
16
+
17
+ class BasicIncluder < Document
18
+
19
+ def template_body
20
+
21
+ accumulate('Paragraph 1' + "\n") # RawText
22
+ # Include (start): basic_included_file.txt:
23
+ accumulate('Paragraph 2' + "\n") # RawText
24
+ accumulate('Paragraph 3') # RawText
25
+
26
+ end
27
+
28
+
29
+ if __FILE__ == $0 # when run from the command line the default action is to call 'run'
30
+ new.run
31
+ end
32
+
33
+ end # BasicIncluder
34
+
35
+ end # WalrusGrammar
36
+
37
+ end # Walrus
38
+
@@ -0,0 +1,3 @@
1
+ This is the included file.
2
+ ## It features comments which won't appear in the final output.
3
+ #silent @my_ivar = 'hello, world!'
@@ -0,0 +1,3 @@
1
+ This example features an include file which itself contains a variety of directives.
2
+ #include 'complicated_included_file.txt'
3
+ Final paragraph, referencing an instance variable defined in the included file: #= @my_ivar #
@@ -0,0 +1,3 @@
1
+ This example features an include file which itself contains a variety of directives.
2
+ This is the included file.
3
+ Final paragraph, referencing an instance variable defined in the included file: hello, world!
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env ruby
2
+ # Generated Fri Apr 13 16:10:50 +0200 2007 by Walrus version 0.1
3
+
4
+ begin
5
+ require 'rubygems'
6
+ rescue LoadError
7
+ # installing Walrus via RubyGems is recommended
8
+ # otherwise Walrus must be installed in the RUBYLIB load path
9
+ end
10
+
11
+ require 'walrus/document'
12
+
13
+ module Walrus
14
+
15
+ class WalrusGrammar
16
+
17
+ class ComplicatedIncluder < Document
18
+
19
+ def template_body
20
+
21
+ accumulate('This example features an include file which itself contains a variety of directives.' + "\n") # RawText
22
+ # Include (start): complicated_included_file.txt:
23
+ accumulate('This is the included file.' + "\n") # RawText
24
+ # Comment: It features comments which won't appear in the final output.
25
+ instance_eval { @my_ivar='hello, world!' } # Silent directive
26
+ accumulate('Final paragraph, referencing an instance variable defined in the included file: ') # RawText
27
+ accumulate(instance_eval { @my_ivar }) # Echo directive
28
+
29
+ end
30
+
31
+
32
+ if __FILE__ == $0 # when run from the command line the default action is to call 'run'
33
+ new.run
34
+ end
35
+
36
+ end # ComplicatedIncluder
37
+
38
+ end # WalrusGrammar
39
+
40
+ end # Walrus
41
+
@@ -0,0 +1,3 @@
1
+ Paragraph 2
2
+ ## This next include will add "Paragraph 3":
3
+ #include 'nested_include_2.txt'
@@ -0,0 +1 @@
1
+ Paragraph 3
@@ -0,0 +1,3 @@
1
+ Paragraph 1
2
+ #include 'nested_include_1.txt'
3
+ Paragraph 4
@@ -0,0 +1,4 @@
1
+ Paragraph 1
2
+ Paragraph 2
3
+ Paragraph 3
4
+ Paragraph 4
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env ruby
2
+ # Generated Fri Apr 13 16:10:50 +0200 2007 by Walrus version 0.1
3
+
4
+ begin
5
+ require 'rubygems'
6
+ rescue LoadError
7
+ # installing Walrus via RubyGems is recommended
8
+ # otherwise Walrus must be installed in the RUBYLIB load path
9
+ end
10
+
11
+ require 'walrus/document'
12
+
13
+ module Walrus
14
+
15
+ class WalrusGrammar
16
+
17
+ class NestedIncluder < Document
18
+
19
+ def template_body
20
+
21
+ accumulate('Paragraph 1' + "\n") # RawText
22
+ # Include (start): nested_include_1.txt:
23
+ accumulate('Paragraph 2' + "\n") # RawText
24
+ # Comment: This next include will add "Paragraph 3":
25
+ # Include (start): nested_include_2.txt:
26
+ accumulate('Paragraph 3' + "\n") # RawText
27
+ accumulate('Paragraph 4') # RawText
28
+
29
+ end
30
+
31
+
32
+ if __FILE__ == $0 # when run from the command line the default action is to call 'run'
33
+ new.run
34
+ end
35
+
36
+ end # NestedIncluder
37
+
38
+ end # WalrusGrammar
39
+
40
+ end # Walrus
41
+
@@ -0,0 +1,10 @@
1
+ #extends 'basic_parent'
2
+ #def footer
3
+ This is the overridden footer. Note that in the overridden version of the footer
4
+ I'm using a \#def block rather than a \#block like in the parent template. The
5
+ reason for this is that \#block calls automatically in-line their contents at
6
+ the point where they are declared.
7
+
8
+ Given that this template \#extends the parent, the parent will *already* be
9
+ in-lining the footer, so there is no need to in-line it again.
10
+ #end
@@ -0,0 +1,9 @@
1
+ This is the base template which subclasses will inherit.
2
+
3
+ This is the overridden footer. Note that in the overridden version of the footer
4
+ I'm using a #def block rather than a #block like in the parent template. The
5
+ reason for this is that #block calls automatically in-line their contents at
6
+ the point where they are declared.
7
+
8
+ Given that this template #extends the parent, the parent will *already* be
9
+ in-lining the footer, so there is no need to in-line it again.
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env ruby
2
+ # Generated Fri Apr 13 16:10:51 +0200 2007 by Walrus version 0.1
3
+
4
+ begin
5
+ require 'rubygems'
6
+ rescue LoadError
7
+ # installing Walrus via RubyGems is recommended
8
+ # otherwise Walrus must be installed in the RUBYLIB load path
9
+ end
10
+
11
+ require 'walrus/document'
12
+ require File.join(File.dirname(__FILE__), 'basic_parent').to_s
13
+
14
+ module Walrus
15
+
16
+ class WalrusGrammar
17
+
18
+ class BasicChild < BasicParent
19
+
20
+ def template_body
21
+
22
+ super # (invoked automatically due to Extends directive)
23
+
24
+ end
25
+
26
+ def footer
27
+ accumulate('This is the overridden footer. Note that in the overridden version of the footer' + "\n") # RawText
28
+ accumulate('I\'m using a ') # RawText (continued)
29
+ accumulate("#") # EscapeSequence
30
+ accumulate('def block rather than a ') # RawText
31
+ accumulate("#") # EscapeSequence
32
+ accumulate('block like in the parent template. The' + "\n") # RawText
33
+ accumulate('reason for this is that ') # RawText (continued)
34
+ accumulate("#") # EscapeSequence
35
+ accumulate('block calls automatically in-line their contents at' + "\n") # RawText
36
+ accumulate('the point where they are declared.' + "\n") # RawText (continued)
37
+ accumulate('' + "\n") # RawText (continued)
38
+ accumulate('Given that this template ') # RawText (continued)
39
+ accumulate("#") # EscapeSequence
40
+ accumulate('extends the parent, the parent will *already* be' + "\n") # RawText
41
+ accumulate('in-lining the footer, so there is no need to in-line it again.' + "\n") # RawText (continued)
42
+ end
43
+
44
+
45
+ if __FILE__ == $0 # when run from the command line the default action is to call 'run'
46
+ new.run
47
+ end
48
+
49
+ end # BasicChild
50
+
51
+ end # WalrusGrammar
52
+
53
+ end # Walrus
54
+
@@ -0,0 +1,5 @@
1
+ This is the base template which subclasses will inherit.
2
+
3
+ #block footer
4
+ This is the footer for the base template.
5
+ #end
@@ -0,0 +1,3 @@
1
+ This is the base template which subclasses will inherit.
2
+
3
+ This is the footer for the base template.
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env ruby
2
+ # Generated Fri Apr 13 16:10:51 +0200 2007 by Walrus version 0.1
3
+
4
+ begin
5
+ require 'rubygems'
6
+ rescue LoadError
7
+ # installing Walrus via RubyGems is recommended
8
+ # otherwise Walrus must be installed in the RUBYLIB load path
9
+ end
10
+
11
+ require 'walrus/document'
12
+
13
+ module Walrus
14
+
15
+ class WalrusGrammar
16
+
17
+ class BasicParent < Document
18
+
19
+ def template_body
20
+
21
+ accumulate('This is the base template which subclasses will inherit.' + "\n") # RawText
22
+ accumulate('' + "\n") # RawText (continued)
23
+ lookup_and_accumulate_placeholder(:footer)
24
+
25
+ end
26
+
27
+ def footer
28
+ accumulate('This is the footer for the base template.' + "\n") # RawText
29
+ end
30
+
31
+
32
+ if __FILE__ == $0 # when run from the command line the default action is to call 'run'
33
+ new.run
34
+ end
35
+
36
+ end # BasicParent
37
+
38
+ end # WalrusGrammar
39
+
40
+ end # Walrus
41
+
@@ -0,0 +1,8 @@
1
+ #import 'basic_parent'
2
+ This time we use an \#import directive rather than an \#extends.
3
+
4
+ This means that we have access to all of the methods defined in the parent,
5
+ but the main "template_body" is not explicitly called.
6
+
7
+ Here we'll call in the parent's footer:
8
+ $footer
@@ -0,0 +1,7 @@
1
+ This time we use an #import directive rather than an #extends.
2
+
3
+ This means that we have access to all of the methods defined in the parent,
4
+ but the main "template_body" is not explicitly called.
5
+
6
+ Here we'll call in the parent's footer:
7
+ This is the footer for the base template.
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env ruby
2
+ # Generated Fri Apr 13 16:10:52 +0200 2007 by Walrus version 0.1
3
+
4
+ begin
5
+ require 'rubygems'
6
+ rescue LoadError
7
+ # installing Walrus via RubyGems is recommended
8
+ # otherwise Walrus must be installed in the RUBYLIB load path
9
+ end
10
+
11
+ require 'walrus/document'
12
+ require File.join(File.dirname(__FILE__), 'basic_parent').to_s
13
+
14
+ module Walrus
15
+
16
+ class WalrusGrammar
17
+
18
+ class ImportingChild < BasicParent
19
+
20
+ def template_body
21
+
22
+ accumulate('This time we use an ') # RawText
23
+ accumulate("#") # EscapeSequence
24
+ accumulate('import directive rather than an ') # RawText
25
+ accumulate("#") # EscapeSequence
26
+ accumulate('extends.' + "\n") # RawText
27
+ accumulate('' + "\n") # RawText (continued)
28
+ accumulate('This means that we have access to all of the methods defined in the parent,' + "\n") # RawText (continued)
29
+ accumulate('but the main "template_body" is not explicitly called.' + "\n") # RawText (continued)
30
+ accumulate('' + "\n") # RawText (continued)
31
+ accumulate('Here we\'ll call in the parent\'s footer:' + "\n") # RawText (continued)
32
+ lookup_and_accumulate_placeholder(:footer)
33
+
34
+ end
35
+
36
+
37
+ if __FILE__ == $0 # when run from the command line the default action is to call 'run'
38
+ new.run
39
+ end
40
+
41
+ end # ImportingChild
42
+
43
+ end # WalrusGrammar
44
+
45
+ end # Walrus
46
+
@@ -0,0 +1,8 @@
1
+ #import '../basic_parent'
2
+ We have to use a different form of the \#import directive when working
3
+ within a subdirectory. Instead of providing a class name we pass a
4
+ quoted string literal with relative path information. In this way Walrus
5
+ knows where to find the parent template.
6
+
7
+ Here we'll call in the parent's footer:
8
+ $footer
@@ -0,0 +1,7 @@
1
+ We have to use a different form of the #import directive when working
2
+ within a subdirectory. Instead of providing a class name we pass a
3
+ quoted string literal with relative path information. In this way Walrus
4
+ knows where to find the parent template.
5
+
6
+ Here we'll call in the parent's footer:
7
+ This is the footer for the base template.
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env ruby
2
+ # Generated Fri Apr 13 16:10:52 +0200 2007 by Walrus version 0.1
3
+
4
+ begin
5
+ require 'rubygems'
6
+ rescue LoadError
7
+ # installing Walrus via RubyGems is recommended
8
+ # otherwise Walrus must be installed in the RUBYLIB load path
9
+ end
10
+
11
+ require 'walrus/document'
12
+ require File.join(File.dirname(__FILE__), '..', 'basic_parent').to_s
13
+
14
+ module Walrus
15
+
16
+ class WalrusGrammar
17
+
18
+ class ImportingChildInSubdirectory < BasicParent
19
+
20
+ def template_body
21
+
22
+ accumulate('We have to use a different form of the ') # RawText
23
+ accumulate("#") # EscapeSequence
24
+ accumulate('import directive when working' + "\n") # RawText
25
+ accumulate('within a subdirectory. Instead of providing a class name we pass a' + "\n") # RawText (continued)
26
+ accumulate('quoted string literal with relative path information. In this way Walrus' + "\n") # RawText (continued)
27
+ accumulate('knows where to find the parent template.' + "\n") # RawText (continued)
28
+ accumulate('' + "\n") # RawText (continued)
29
+ accumulate('Here we\'ll call in the parent\'s footer:' + "\n") # RawText (continued)
30
+ lookup_and_accumulate_placeholder(:footer)
31
+
32
+ end
33
+
34
+
35
+ if __FILE__ == $0 # when run from the command line the default action is to call 'run'
36
+ new.run
37
+ end
38
+
39
+ end # ImportingChildInSubdirectory
40
+
41
+ end # WalrusGrammar
42
+
43
+ end # Walrus
44
+
@@ -0,0 +1,15 @@
1
+ #*
2
+
3
+ Another multiline comment
4
+
5
+ Note that I can use anything I want inside comments:
6
+
7
+ * Tabs
8
+ * Non-existent #directives
9
+ * Real directives like #raw, #set, #super, #def and #import
10
+ * Placeholders: $hello("world")
11
+ * Escape sequences: \n\r
12
+ * Nested comments: ## here is a single-line one
13
+ * Nested comments: #* here is a multi-line one *#
14
+
15
+ *#
@@ -0,0 +1,2 @@
1
+ Text before the comment...
2
+ Text after the comment.
@@ -0,0 +1,4 @@
1
+ Text before the comment... #* This
2
+ is a multiline
3
+ comment *#
4
+ Text after the comment.
@@ -0,0 +1,57 @@
1
+ This example demonstrates a number of different uses of the #raw directive.
2
+ In this paragraph if I want to use characters that have a special meaning for
3
+ Walrus then I have to escape them (example, a $placeholder, a #directive, an
4
+ \$ escape sequence).
5
+
6
+ But this paragraph is different, it is inside a #raw block.
7
+ I can do anything at all in the #raw block without having to escape it.
8
+ For example, use Walrus directives:
9
+ #super, #set a = b
10
+ Use placeholders:
11
+ $a, $b, $c
12
+ Use backslashes:
13
+ \n, \t, \m, \n, \o
14
+
15
+ This paragraph is another example where the closing marker is not
16
+ on a new line of it's own...
17
+ This is an example where I use an explicit directive-closing marker (#) so that
18
+ I can start my #raw content on the same line as the opening directive. I can do the
19
+ same trick with the closing directive so that my text can continue on on the same
20
+ line... See?
21
+
22
+ This paragraph uses a "here document". That means I can include a literal #end directive
23
+ in it without it causing the block to come to an end. Here we see the block continuing
24
+ and I can still use $placeholders and #directives without them having any special meaning.
25
+ The end marker (in this case "HERE") must be the first and last thing on the line in order
26
+ for it to be detected. All other uses of the end marker go through literally with no
27
+ special meaning.
28
+
29
+ There is no way to include a literal end directive in a #raw block without the help of
30
+ a "here document". You can't escape the end directive for example, because the escape
31
+ character (\) has no special meaning in a #raw block. Notice that if I try it it won't
32
+ work:\
33
+ I am now outside the #raw block because the #end directive was interpreted as an end marker
34
+ despite my attempt to escape it.
35
+
36
+ This is an example of an alternative "here document" syntax. The hyphen means that you can
37
+ precede the end marker with whitespace. Note that if the marker (in this case "THERE") is
38
+ preceded by non-whitespace characters on the same line then it has no special meaning: THERE
39
+ Likewise, if it is followed by such characters then it has no meaning either....
40
+ THERE... we keep going because "THERE" wasn't the last thing on the line.
41
+
42
+ Trailing whitespace is acceptable after the end marker, but it is not included in the output.
43
+
44
+ The same is true when using the alternative syntax.
45
+
46
+ In fact, trailing whitespace is acceptable when first opening the here document too, but it
47
+ is ignored
48
+
49
+ THe same is true for the alternate syntax.
50
+
51
+ Note that when using the alternative "here document" syntax the optional whitespace before the
52
+ end marker truly is optional; that is, the end marker can be the first thing on the line if
53
+ you want it to. (Although if that's the case you may as well use the first syntax.)
54
+
55
+ In this example I am going to use some multi-byte characters:
56
+ €áéíóú
57
+ àèìòù