wlang 0.10.2 → 2.0.0.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (269) hide show
  1. data/CHANGELOG.md +3 -121
  2. data/Gemfile +23 -1
  3. data/Gemfile.lock +32 -28
  4. data/LICENCE.md +18 -21
  5. data/Manifest.txt +4 -5
  6. data/README.md +100 -174
  7. data/Rakefile +1 -13
  8. data/bin/wlang +3 -29
  9. data/lib/wlang.rb +21 -394
  10. data/lib/wlang/command.rb +94 -0
  11. data/lib/wlang/compiler.rb +78 -0
  12. data/lib/wlang/compiler/autospacing.rb +60 -0
  13. data/lib/wlang/compiler/dialect_enforcer.rb +91 -0
  14. data/lib/wlang/compiler/filter.rb +32 -0
  15. data/lib/wlang/compiler/grammar.citrus +67 -0
  16. data/lib/wlang/compiler/parser.rb +26 -0
  17. data/lib/wlang/compiler/proc_call_removal.rb +15 -0
  18. data/lib/wlang/compiler/static_merger.rb +28 -0
  19. data/lib/wlang/compiler/strconcat_flattener.rb +25 -0
  20. data/lib/wlang/compiler/to_ruby_abstraction.rb +22 -0
  21. data/lib/wlang/compiler/to_ruby_code.rb +55 -0
  22. data/lib/wlang/dialect.rb +40 -237
  23. data/lib/wlang/dialect/dispatching.rb +51 -0
  24. data/lib/wlang/dialect/evaluation.rb +30 -0
  25. data/lib/wlang/dialect/tags.rb +50 -0
  26. data/lib/wlang/dummy.rb +32 -0
  27. data/lib/wlang/html.rb +106 -0
  28. data/lib/wlang/loader.rb +6 -0
  29. data/lib/wlang/mustang.rb +90 -0
  30. data/lib/wlang/scope.rb +57 -0
  31. data/lib/wlang/scope/binding_scope.rb +18 -0
  32. data/lib/wlang/scope/object_scope.rb +25 -0
  33. data/lib/wlang/scope/proxy_scope.rb +18 -0
  34. data/lib/wlang/scope/root_scope.rb +24 -0
  35. data/lib/wlang/template.rb +16 -86
  36. data/lib/wlang/version.rb +9 -8
  37. data/spec/fixtures/dialect/foobar.rb +31 -0
  38. data/spec/fixtures/dialect/upcasing.rb +13 -0
  39. data/spec/fixtures/templates/hello.tpl +1 -0
  40. data/spec/integration/examples/1-basics.txt +65 -0
  41. data/spec/integration/examples/2-imperative.txt +51 -0
  42. data/spec/integration/examples/3-partials.txt +76 -0
  43. data/spec/integration/examples/4-recursion.txt +16 -0
  44. data/spec/integration/html/test_ampersand.rb +15 -0
  45. data/spec/integration/html/test_bang.rb +38 -0
  46. data/spec/integration/html/test_caret.rb +33 -0
  47. data/spec/integration/html/test_dollar.rb +16 -0
  48. data/spec/integration/html/test_greater.rb +23 -0
  49. data/spec/integration/html/test_modulo.rb +16 -0
  50. data/spec/integration/html/test_plus.rb +48 -0
  51. data/spec/integration/html/test_question.rb +33 -0
  52. data/spec/integration/html/test_sharp.rb +21 -0
  53. data/spec/integration/html/test_slash.rb +16 -0
  54. data/spec/integration/html/test_star.rb +37 -0
  55. data/spec/integration/test_dummy.rb +51 -0
  56. data/spec/integration/test_examples.rb +29 -0
  57. data/spec/integration/test_mustang.rb +120 -0
  58. data/spec/integration/test_readme.rb +56 -0
  59. data/spec/integration/test_upcasing.rb +22 -0
  60. data/spec/spec_helper.rb +62 -1
  61. data/spec/test_wlang.rb +101 -0
  62. data/spec/unit/compiler/autospacing/test_right_strip.rb +30 -0
  63. data/spec/unit/compiler/autospacing/test_unindent.rb +30 -0
  64. data/spec/unit/compiler/test_dialect_enforcer.rb +168 -0
  65. data/spec/unit/compiler/test_grammar.rb +207 -0
  66. data/spec/unit/compiler/test_parser.rb +69 -0
  67. data/spec/unit/compiler/test_proc_call_removal.rb +24 -0
  68. data/spec/unit/compiler/test_static_merger.rb +29 -0
  69. data/spec/unit/compiler/test_strconcat_flattener.rb +30 -0
  70. data/spec/unit/compiler/test_to_ruby_abstraction.rb +59 -0
  71. data/spec/unit/compiler/test_to_ruby_code.rb +24 -0
  72. data/spec/unit/dialect/test_compile.rb +52 -0
  73. data/spec/unit/dialect/test_dispatching.rb +19 -0
  74. data/spec/unit/dialect/test_evaluate.rb +41 -0
  75. data/spec/unit/dialect/test_render.rb +33 -0
  76. data/spec/unit/dialect/test_tags.rb +32 -0
  77. data/spec/unit/dialect/test_with_scope.rb +18 -0
  78. data/spec/unit/scope/test_binding_scope.rb +27 -0
  79. data/spec/unit/scope/test_coerce.rb +22 -0
  80. data/spec/unit/scope/test_object_scope.rb +38 -0
  81. data/spec/unit/scope/test_proxy_scope.rb +22 -0
  82. data/spec/unit/scope/test_root_scope.rb +22 -0
  83. data/spec/unit/test_assumptions.rb +29 -0
  84. data/spec/unit/test_scope.rb +57 -0
  85. data/tasks/debug_mail.rake +42 -45
  86. data/tasks/gem.rake +22 -17
  87. data/tasks/spec_test.rake +9 -17
  88. data/tasks/unit_test.rake +11 -12
  89. data/tasks/yard.rake +13 -13
  90. data/wlang.gemspec +36 -32
  91. data/wlang.noespec +27 -35
  92. metadata +268 -451
  93. data/doc/specification/about.rdoc +0 -61
  94. data/doc/specification/analytics.wtpl +0 -13
  95. data/doc/specification/dialect.wtpl +0 -14
  96. data/doc/specification/dialects.wtpl +0 -3
  97. data/doc/specification/examples.rb +0 -3
  98. data/doc/specification/glossary.wtpl +0 -14
  99. data/doc/specification/hosting.rdoc +0 -0
  100. data/doc/specification/overview.rdoc +0 -116
  101. data/doc/specification/rulesets.wtpl +0 -87
  102. data/doc/specification/specification.css +0 -53
  103. data/doc/specification/specification.html +0 -1690
  104. data/doc/specification/specification.js +0 -8
  105. data/doc/specification/specification.wtpl +0 -42
  106. data/doc/specification/specification.yml +0 -432
  107. data/doc/specification/symbols.wtpl +0 -16
  108. data/lib/wlang/dialect_dsl.rb +0 -141
  109. data/lib/wlang/dialect_loader.rb +0 -74
  110. data/lib/wlang/dialects/bluecloth_dialect.rb +0 -16
  111. data/lib/wlang/dialects/coderay_dialect.rb +0 -45
  112. data/lib/wlang/dialects/hosted_dialect.rb +0 -50
  113. data/lib/wlang/dialects/plain_text_dialect.rb +0 -69
  114. data/lib/wlang/dialects/rdoc_dialect.rb +0 -33
  115. data/lib/wlang/dialects/redcloth_dialect.rb +0 -16
  116. data/lib/wlang/dialects/ruby_dialect.rb +0 -118
  117. data/lib/wlang/dialects/sql_dialect.rb +0 -38
  118. data/lib/wlang/dialects/standard_dialects.rb +0 -181
  119. data/lib/wlang/dialects/xhtml_dialect.rb +0 -63
  120. data/lib/wlang/dialects/yaml_dialect.rb +0 -30
  121. data/lib/wlang/encoder.rb +0 -62
  122. data/lib/wlang/encoder_set.rb +0 -122
  123. data/lib/wlang/errors.rb +0 -80
  124. data/lib/wlang/ext/hash_methodize.rb +0 -13
  125. data/lib/wlang/ext/string.rb +0 -44
  126. data/lib/wlang/hash_scope.rb +0 -89
  127. data/lib/wlang/hosted_language.rb +0 -146
  128. data/lib/wlang/intelligent_buffer.rb +0 -94
  129. data/lib/wlang/parser.rb +0 -332
  130. data/lib/wlang/parser_state.rb +0 -94
  131. data/lib/wlang/rule.rb +0 -66
  132. data/lib/wlang/rule_set.rb +0 -106
  133. data/lib/wlang/rulesets/basic_ruleset.rb +0 -83
  134. data/lib/wlang/rulesets/buffering_ruleset.rb +0 -115
  135. data/lib/wlang/rulesets/context_ruleset.rb +0 -111
  136. data/lib/wlang/rulesets/encoding_ruleset.rb +0 -73
  137. data/lib/wlang/rulesets/imperative_ruleset.rb +0 -132
  138. data/lib/wlang/rulesets/ruleset_utils.rb +0 -317
  139. data/lib/wlang/wlang_command.rb +0 -51
  140. data/lib/wlang/wlang_command_options.rb +0 -163
  141. data/spec/basic_object.spec +0 -40
  142. data/spec/coderay_dialect.spec +0 -8
  143. data/spec/dialect/apply_post_transform.spec +0 -16
  144. data/spec/global_extensions.rb +0 -2
  145. data/spec/hash_scope.spec +0 -76
  146. data/spec/redcloth_dialect.spec +0 -24
  147. data/spec/test_all.rb +0 -8
  148. data/spec/wlang.spec +0 -53
  149. data/spec/wlang_spec.rb +0 -8
  150. data/spec/xhtml_dialect.spec +0 -22
  151. data/tasks/genspec.rake +0 -5
  152. data/test/blackbox/basic/execution_1.exp +0 -1
  153. data/test/blackbox/basic/execution_1.tpl +0 -1
  154. data/test/blackbox/basic/execution_2.exp +0 -1
  155. data/test/blackbox/basic/execution_2.tpl +0 -1
  156. data/test/blackbox/basic/execution_3.exp +0 -1
  157. data/test/blackbox/basic/execution_3.tpl +0 -1
  158. data/test/blackbox/basic/execution_4.exp +0 -1
  159. data/test/blackbox/basic/execution_4.tpl +0 -1
  160. data/test/blackbox/basic/inclusion_1.exp +0 -1
  161. data/test/blackbox/basic/inclusion_1.tpl +0 -1
  162. data/test/blackbox/basic/inclusion_2.exp +0 -1
  163. data/test/blackbox/basic/inclusion_2.tpl +0 -1
  164. data/test/blackbox/basic/injection_1.exp +0 -1
  165. data/test/blackbox/basic/injection_1.tpl +0 -1
  166. data/test/blackbox/basic/injection_2.exp +0 -1
  167. data/test/blackbox/basic/injection_2.tpl +0 -1
  168. data/test/blackbox/basic/modulation_1.exp +0 -1
  169. data/test/blackbox/basic/modulation_1.tpl +0 -1
  170. data/test/blackbox/basic/modulation_2.exp +0 -1
  171. data/test/blackbox/basic/modulation_2.tpl +0 -1
  172. data/test/blackbox/basic/recursive_app_1.exp +0 -1
  173. data/test/blackbox/basic/recursive_app_1.tpl +0 -1
  174. data/test/blackbox/basic/recursive_app_2.exp +0 -1
  175. data/test/blackbox/basic/recursive_app_2.tpl +0 -1
  176. data/test/blackbox/buffering/data_1.rb +0 -1
  177. data/test/blackbox/buffering/data_assignment_1.exp +0 -1
  178. data/test/blackbox/buffering/data_assignment_1.tpl +0 -1
  179. data/test/blackbox/buffering/data_assignment_2.exp +0 -1
  180. data/test/blackbox/buffering/data_assignment_2.tpl +0 -1
  181. data/test/blackbox/buffering/data_assignment_3.exp +0 -1
  182. data/test/blackbox/buffering/data_assignment_3.tpl +0 -1
  183. data/test/blackbox/buffering/data_assignment_4.exp +0 -1
  184. data/test/blackbox/buffering/data_assignment_4.tpl +0 -1
  185. data/test/blackbox/buffering/input_1.exp +0 -1
  186. data/test/blackbox/buffering/input_1.tpl +0 -1
  187. data/test/blackbox/buffering/input_2.exp +0 -1
  188. data/test/blackbox/buffering/input_2.tpl +0 -1
  189. data/test/blackbox/buffering/input_3.exp +0 -1
  190. data/test/blackbox/buffering/input_3.tpl +0 -1
  191. data/test/blackbox/buffering/input_inclusion.exp +0 -1
  192. data/test/blackbox/buffering/input_inclusion.tpl +0 -1
  193. data/test/blackbox/buffering/input_inclusion_1.exp +0 -0
  194. data/test/blackbox/buffering/input_inclusion_1.tpl +0 -1
  195. data/test/blackbox/buffering/input_inclusion_2.exp +0 -1
  196. data/test/blackbox/buffering/input_inclusion_2.tpl +0 -1
  197. data/test/blackbox/buffering/input_inclusion_3.exp +0 -1
  198. data/test/blackbox/buffering/input_inclusion_3.tpl +0 -1
  199. data/test/blackbox/buffering/input_inclusion_4.exp +0 -0
  200. data/test/blackbox/buffering/input_inclusion_4.tpl +0 -1
  201. data/test/blackbox/buffering/input_inclusion_5.exp +0 -1
  202. data/test/blackbox/buffering/input_inclusion_5.tpl +0 -1
  203. data/test/blackbox/buffering/input_inclusion_6.exp +0 -1
  204. data/test/blackbox/buffering/input_inclusion_6.tpl +0 -1
  205. data/test/blackbox/buffering/input_inclusion_7.exp +0 -0
  206. data/test/blackbox/buffering/input_inclusion_7.tpl +0 -1
  207. data/test/blackbox/buffering/text_1.txt +0 -1
  208. data/test/blackbox/buffering/wlang.txt +0 -1
  209. data/test/blackbox/context/assignment_1.exp +0 -1
  210. data/test/blackbox/context/assignment_1.tpl +0 -1
  211. data/test/blackbox/context/assignment_2.exp +0 -1
  212. data/test/blackbox/context/assignment_2.tpl +0 -1
  213. data/test/blackbox/context/assignment_3.exp +0 -2
  214. data/test/blackbox/context/assignment_3.tpl +0 -2
  215. data/test/blackbox/context/assignment_4.exp +0 -1
  216. data/test/blackbox/context/assignment_4.tpl +0 -1
  217. data/test/blackbox/context/block_assignment_1.exp +0 -1
  218. data/test/blackbox/context/block_assignment_1.tpl +0 -1
  219. data/test/blackbox/context/block_assignment_2.exp +0 -1
  220. data/test/blackbox/context/block_assignment_2.tpl +0 -1
  221. data/test/blackbox/context/modulo_assignment_1.exp +0 -1
  222. data/test/blackbox/context/modulo_assignment_1.tpl +0 -1
  223. data/test/blackbox/context/modulo_assignment_2.exp +0 -1
  224. data/test/blackbox/context/modulo_assignment_2.tpl +0 -1
  225. data/test/blackbox/data_1.rb +0 -1
  226. data/test/blackbox/postblock/hello.exp +0 -1
  227. data/test/blackbox/postblock/hello.pre +0 -1
  228. data/test/blackbox/postblock/hello.tpl +0 -1
  229. data/test/blackbox/postblock/hello_input_inclusion.exp +0 -1
  230. data/test/blackbox/postblock/hello_input_inclusion.tpl +0 -1
  231. data/test/blackbox/postblock/hello_to_authors.exp +0 -1
  232. data/test/blackbox/postblock/hello_to_authors.tpl +0 -1
  233. data/test/blackbox/poststring/hello.exp +0 -1
  234. data/test/blackbox/poststring/hello.tpl +0 -1
  235. data/test/blackbox/test_all.rb +0 -70
  236. data/test/standard_dialects/ruby/data.rb +0 -7
  237. data/test/standard_dialects/ruby/inclusion.exp +0 -6
  238. data/test/standard_dialects/ruby/inclusion.tpl +0 -6
  239. data/test/standard_dialects/test_all.rb +0 -29
  240. data/test/standard_dialects/yaml/assumptions_test.rb +0 -13
  241. data/test/standard_dialects/yaml/data.rb +0 -3
  242. data/test/standard_dialects/yaml/inclusion_1.exp +0 -7
  243. data/test/standard_dialects/yaml/inclusion_1.tpl +0 -2
  244. data/test/standard_dialects/yaml/inclusion_2.exp +0 -5
  245. data/test/standard_dialects/yaml/inclusion_2.tpl +0 -3
  246. data/test/unit/test_all.rb +0 -9
  247. data/test/unit/wlang/anagram_bugs_test.rb +0 -111
  248. data/test/unit/wlang/basic_ruleset_test.rb +0 -52
  249. data/test/unit/wlang/buffering_ruleset_test.rb +0 -102
  250. data/test/unit/wlang/buffering_template1.wtpl +0 -1
  251. data/test/unit/wlang/buffering_template2.wtpl +0 -1
  252. data/test/unit/wlang/buffering_template3.wtpl +0 -1
  253. data/test/unit/wlang/buffering_template4.wtpl +0 -1
  254. data/test/unit/wlang/buffering_template5.wtpl +0 -1
  255. data/test/unit/wlang/context_ruleset_test.rb +0 -32
  256. data/test/unit/wlang/data.rb +0 -3
  257. data/test/unit/wlang/encoder_set_test.rb +0 -42
  258. data/test/unit/wlang/imperative_ruleset_test.rb +0 -107
  259. data/test/unit/wlang/intelligent_buffer_test.rb +0 -194
  260. data/test/unit/wlang/othersymbols_test.rb +0 -16
  261. data/test/unit/wlang/parser_test.rb +0 -88
  262. data/test/unit/wlang/plain_text_dialect_test.rb +0 -21
  263. data/test/unit/wlang/ruby_dialect_test.rb +0 -100
  264. data/test/unit/wlang/ruby_expected.rb +0 -3
  265. data/test/unit/wlang/ruby_template.wrb +0 -3
  266. data/test/unit/wlang/ruleset_utils_test.rb +0 -245
  267. data/test/unit/wlang/specification_examples_test.rb +0 -54
  268. data/test/unit/wlang/test_utils.rb +0 -25
  269. data/test/unit/wlang/wlang_test.rb +0 -80
@@ -1,123 +1,5 @@
1
- # Version 0.10.2 / 2011-02-25
1
+ # 2.0.0 / FIX ME
2
2
 
3
- * Bug fixes
3
+ * Enhancements
4
4
 
5
- * Fixed a bug that led to applying dialect post-transformation too many times in multi
6
- block syntaxes. Post-transformation rules related strategies are now:
7
- - Parser#instantiate now takes an optional boolean argument to set/unset dialect
8
- post transformation (defaults to true, for backward compatibility).
9
- - Invoking Template.instantiate always invoke Parser#instantiate(true)
10
- - Buffering's <<+{...} always apply post-transformation as well
11
- - Otherwise, post-transformation is only applied when the dialect explicitely changes
12
- when invoking Parser#parse and Parser#parse_block
13
-
14
- * Other enhancements
15
-
16
- * Added a bluecloth/xhtml dialect and encoder.
17
-
18
- # Version 0.10.1 / 2011-01-17
19
-
20
- * Bug fixes
21
-
22
- * Fixed a bug when using multi-block syntaxes with another delimiter than braces.
23
-
24
- * Other enhancements
25
-
26
- * WLang source code follows the ruby.noe template that comes bundled with Noe
27
-
28
- # Version 0.10.0 / 2011-01-14
29
-
30
- * New features
31
-
32
- * Introduced a wlang/hosted language which parses blocks as actually described in the specification
33
- * Introduced a semantics +{...} in wlang/ruby that prints literals.
34
- * wlang/ruby now includes the Buffering ruleset
35
- * Introduced a wlang/active-text dialect which includes Basic, Imperative, Buffering and Context rulesets.
36
- * Introduced a wlang/yaml dialect with special inclusion +{...} operator
37
-
38
- * Broken features and APIs
39
-
40
- * Due to the wlang/ruby <-> wlang/hosted changes and the fact that wlang/ruby now includes the
41
- Buffering ruleset, users that generate ruby (a few) may have broken templates and should probably
42
- be pessimist and require wlang 0.9.x
43
- * For the same reason, users that make complex wlang meta-constructions ala +{+{...}} could observe
44
- problems due to the change of +{...} in wlang/ruby. The wlang/hosted dialect is introduced to limit
45
- such problems, but not encountering them is not guaranteed.
46
-
47
- * Other enhancements
48
-
49
- * Moved to rspec 2.4.0
50
- * Moved from rdoc to yard for generating the documentation
51
- * README, CHANGELOG and LICENCE are now in Mardown instead of rdoc
52
-
53
- # Version 0.9.2
54
-
55
- * New features (by order of importance)
56
-
57
- * Implements main transformer on dialects
58
- * Makes coderay encoders available without options using a bit of meta programming
59
- * System-local absolute paths (i.e. starting with '/') are recognized by buffer rulesets
60
-
61
- # Version 0.9.1
62
-
63
- * Bug fixes
64
-
65
- * #307, about HashScope.has_key? which returned nil instead of false in some situations
66
-
67
- * Broken features and APIs (by order of importance)
68
-
69
- * HostedLanguage::DSL is strictly private and should be reopened. Methods added to this class
70
- will never be available in templates. Use HostedLanguage.variable_missing instead.
71
- * ::WLang::BasicObject has been removed. HostedLanguage::DSL implements its own strategy, which
72
- is spec tested in test/spec/basic_object.spec
73
-
74
- * New features (by order of importance)
75
-
76
- * WLang does not requires the rdoc gem by default
77
- * A new encoder redcloth/xhtml allows using Textile markups easily
78
- * The wlang/xhtml dialect provides a tag helper for links @{...}{...}
79
- * The parser class returns friendly messages when a rule is ill-implemented
80
-
81
- # Version 0.9.0
82
-
83
- * Broken features and APIs (by order of importance)
84
-
85
- * Major broken API in WLang.instantiate and WLang.file_instantiate which do not allow passing
86
- buffers anymore
87
- * Hash are not methodized by default anymore (major broken feature with 0.8.x versions)
88
- * Expressions 'a la' PHP w@w (sections/.../.../id) are not supported anymore
89
- * The default hosted language raises a WLang::UndefinedVariableError when a variable cannot be
90
- found in the current template scope (0.8.x versions returned nil in this case)
91
- * Template.initialize does not take a default context anymore
92
- * WLang::Parser.context_xxx do not exist anymore. Use branch(...) instead
93
- * WLang::Parser::Context removed, and WLang::HashScope introduced
94
- * WLang::Parser instance variables are all made protected
95
-
96
- * New features (by order of importance)
97
-
98
- * WLang::HostingLanguage introduced, with a default one for Ruby. The hosting language
99
- is the way to provide a main scope, accessible to all templates at once.
100
- * WLang::HostingLanguage is not sensitive to the difference between symbol keys and strings
101
- * Buffering and Context rulesets now branch the current parser instead of creating a new one
102
- * WLang::Error and subclasses propose a backtrace information
103
- * WLang::Parser refactored to encapsulate the whole state in another class (WLang::Parser::State)
104
- * WLang facade has been made much more robust as it now checks all its arguments.
105
- * WLang::dialect may now be used to ensure dialect instances from both Dialect args and qualified names.
106
- * Introduction of WLang.template and WLang.file_template
107
- * plain-text dialect proposes new camel-based encoders
108
- * wlang/active-string dialect has the imperative rule set included
109
- * sql dialect has been added
110
- * ruby dialect proposes a method-case encoder
111
-
112
- # Version 0.8.5
113
-
114
- * Enhances error messages a lot
115
- * Some bug fixes for ruby 0.8.7
116
-
117
- # Version 0.8.4
118
-
119
- * Migration from svn.chefbe.net to github.com
120
-
121
- # Version 0.8.0
122
-
123
- * First public version
5
+ * Birthday!
data/Gemfile CHANGED
@@ -1,2 +1,24 @@
1
1
  source 'http://rubygems.org'
2
- gemspec :name => "wlang"
2
+
3
+ group :runtime do
4
+ gem "citrus", "~> 2.4.1"
5
+ gem "temple", "~> 0.4.0"
6
+ gem "backports", "~> 2.6.1", :platforms => ["ruby_18", "mri_18", "mingw_18", 'jruby']
7
+ gem "quickl", "~> 0.4.3"
8
+ gem "awesome_print", "~> 1.0.2"
9
+ end
10
+
11
+ group :profiling do
12
+ gem "ruby-prof", "~> 0.11.2"
13
+ gem "mustache", "~> 0.99.4"
14
+ #gem "viiite", :git => "git://github.com/blambeau/viiite.git"
15
+ end
16
+
17
+ group :development do
18
+ gem "rake", "~> 0.9.2"
19
+ gem "bundler", "~> 1.0"
20
+ gem "rspec", "~> 2.10.0"
21
+ gem "epath", "~> 0.1.0"
22
+ gem "yard", "~> 0.8.1"
23
+ gem "bluecloth", "~> 2.2.0"
24
+ end
@@ -1,37 +1,41 @@
1
- PATH
2
- remote: .
3
- specs:
4
- wlang (0.10.2)
5
-
6
1
  GEM
7
2
  remote: http://rubygems.org/
8
3
  specs:
9
- RedCloth (4.2.7)
10
- bluecloth (2.0.11)
11
- coderay (0.9.7)
12
- diff-lcs (1.1.2)
13
- rake (0.8.7)
14
- rdoc (3.5.3)
15
- rspec (2.4.0)
16
- rspec-core (~> 2.4.0)
17
- rspec-expectations (~> 2.4.0)
18
- rspec-mocks (~> 2.4.0)
19
- rspec-core (2.4.0)
20
- rspec-expectations (2.4.0)
21
- diff-lcs (~> 1.1.2)
22
- rspec-mocks (2.4.0)
23
- yard (0.6.4)
4
+ awesome_print (1.0.2)
5
+ backports (2.6.1)
6
+ bluecloth (2.2.0)
7
+ citrus (2.4.1)
8
+ diff-lcs (1.1.3)
9
+ epath (0.1.1)
10
+ mustache (0.99.4)
11
+ quickl (0.4.3)
12
+ rake (0.9.2.2)
13
+ rspec (2.10.0)
14
+ rspec-core (~> 2.10.0)
15
+ rspec-expectations (~> 2.10.0)
16
+ rspec-mocks (~> 2.10.0)
17
+ rspec-core (2.10.1)
18
+ rspec-expectations (2.10.0)
19
+ diff-lcs (~> 1.1.3)
20
+ rspec-mocks (2.10.1)
21
+ ruby-prof (0.11.2)
22
+ temple (0.4.0)
23
+ yard (0.8.1)
24
24
 
25
25
  PLATFORMS
26
26
  ruby
27
27
 
28
28
  DEPENDENCIES
29
- RedCloth
30
- bluecloth (~> 2.0.9)
29
+ awesome_print (~> 1.0.2)
30
+ backports (~> 2.6.1)
31
+ bluecloth (~> 2.2.0)
31
32
  bundler (~> 1.0)
32
- coderay
33
- rake (~> 0.8.7)
34
- rdoc
35
- rspec (~> 2.4.0)
36
- wlang!
37
- yard (~> 0.6.4)
33
+ citrus (~> 2.4.1)
34
+ epath (~> 0.1.0)
35
+ mustache (~> 0.99.4)
36
+ quickl (~> 0.4.3)
37
+ rake (~> 0.9.2)
38
+ rspec (~> 2.10.0)
39
+ ruby-prof (~> 0.11.2)
40
+ temple (~> 0.4.0)
41
+ yard (~> 0.8.1)
data/LICENCE.md CHANGED
@@ -1,25 +1,22 @@
1
- # Licence
1
+ # The MIT Licence
2
2
 
3
- The MIT License
3
+ Copyright (c) 2012 - Bernard Lambeau, Louis Lambeau
4
4
 
5
- Copyright (c) 2009-2011 Bernard & Louis Lambeau and the University of Louvain
6
- (Universite Catholique de Louvain, Louvain-la-Neuve, Belgium)
7
-
8
- Permission is hereby granted, free of charge, to any person obtaining a copy
9
- of this software and associated documentation files (the "Software"), to deal
10
- in the Software without restriction, including without limitation the rights
11
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
- copies of the Software, and to permit persons to whom the Software is
13
- furnished to do so, subject to the following conditions:
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
14
12
 
15
- The above copyright notice and this permission notice shall be included in
16
- all copies or substantial portions of the Software.
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
17
15
 
18
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
- THE SOFTWARE.
25
-
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,9 +1,10 @@
1
- bin/**/*
1
+ wlang.gemspec
2
+ wlang.noespec
3
+ .gemtest
2
4
  CHANGELOG.md
3
- doc/specification/**/*
4
- example/**/*
5
5
  Gemfile
6
6
  Gemfile.lock
7
+ bin/**/*
7
8
  lib/**/*
8
9
  LICENCE.md
9
10
  Manifest.txt
@@ -12,5 +13,3 @@ README.md
12
13
  spec/**/*
13
14
  tasks/**/*
14
15
  test/**/*
15
- wlang.gemspec
16
- wlang.noespec
data/README.md CHANGED
@@ -1,174 +1,100 @@
1
- # What is _wlang_ ?
2
-
3
- WLang is a general-purpose *code generation*/*templating engine*. It's main aim is to help you generating
4
- web pages, sql queries, ruby code (that is, generating code in general) without having to worry too much
5
- about html entities encoding, sql back quoting, string escaping and the like. WLang proposes a generic
6
- engine that you can extend to fit your needs. It also proposes standard instantiations of this engine
7
- for common tasks such as creating SQL queries, instantiating web pages, and so on.
8
-
9
- Basic concepts and usage is illustrated below. Also have a look at the [detailed specification](http://blambeau.github.com/wlang).
10
-
11
- ## A collection of typical encoders
12
-
13
- The first basic usage of WLang is to provide a collection of text encoders:
14
-
15
- WLang::encode('&', 'xhtml/entities-encoding') # &amp;
16
- WLang::encode("O'Neil", 'sql/single-quoting') # O\'Neil
17
- WLang::encode("O'Neil", 'sql/sybase/single-quoting') # O''Neil
18
- ...
19
- WLang::encode("hello world", 'plain-text/camel') # HelloWorld
20
- WLang::encode("hello world", 'plain-text/lower-camel') # helloWorld
21
- ...
22
- WLang::encode("helloWorld", 'ruby/method-case') # hello_world
23
-
24
- ## A powerful alternative to ruby string interpolation
25
-
26
- The second usage is to have shortcuts for using these encoders in typical
27
- situations:
28
-
29
- # Hello world!
30
- "Hello ${who}!".wlang(:who => 'world')
31
-
32
- # Hello cruel &amp; world!
33
- "Hello ${who}!".wlang({:who => 'cruel & world'}, 'wlang/xhtml')
34
-
35
- # Hello blambeau, llambeau
36
- "Hello *{authors as a}{${a}}{, }".wlang(:authors => ['blambeau', 'llambeau'])
37
-
38
- # INSERT INTO people VALUES ('O\'Neil')
39
- INSERT INTO people VALUES ('{who}')".wlang(:who => "O'Neil")
40
-
41
- ## A powerful templating engine
42
-
43
- But the main usage of _wlang_ is as follows (for bold words, see terminology later):
44
- you have a *template* file (written in a given _wlang_ *dialect*), you have some
45
- instantiation *context* (data provided through a Ruby Hash or a yaml file for
46
- example) and you would like to instantiate the template with that data.
47
-
48
- Example: a template.whtml as follows
49
- <html>
50
- <head>
51
- <title>${title}</title>
52
- </head>
53
- <body>
54
- <h1>Hello ${who} !</h1>
55
- </body>
56
- </html>
57
-
58
- Instantiation data is a hash containing values for _title_ and _who_. Instantiating
59
- the template is straightforward:
60
-
61
- require 'wlang'
62
- context = {"title" => "Hello world in WLang", "who" => "Alice"}
63
- STDOUT << WLang.file_instantiate("template.whtml", context)
64
-
65
- ## Behind the scene
66
-
67
- - WLang helps you avoiding SQL injection and XSS attacks through the same tags reacting differently
68
- in different contexts.
69
- - WLang understands your context (and its dialect) from the template file extension
70
- - WLang provides a rich collection of pre-defined tags and dialects
71
- - WLang allows you to create your own encoders, tags and dialects while reusing existing ones
72
- - WLang may change the current dialect during the template instantiation itself (generating
73
- html with embedded javascript is easy and natural)
74
- - WLang is able to generate wlang code without any perturabation
75
-
76
- ## Additional examples (availability of the tags may depend on the dialect)
77
-
78
- * Include text files on the fly
79
-
80
- <<{my_file.html}
81
-
82
- * Instantiate sub-templates on the fly, passing data as arguments
83
-
84
- <<+{my_sub_template.whtml using who: 'wlang'}
85
-
86
- * Load data from yaml or ruby files on the fly
87
-
88
- <<={resources.yaml as resources}{
89
- *{resources as r}{ ${r} }
90
- }
91
-
92
- * WLang instrospection (basic example)
93
-
94
- context = {:varname => 'who', :who => 'wlang'}
95
- "Hello ${${varname}}!".wlang(context) # => Hello wlang!
96
-
97
- * Generate a wlang template and instantiate it after that
98
-
99
- dialect = 'wlang/active-string'
100
- tpl = "Hello $(${varname})!" # => Hello $(${varname})
101
- tpl = tpl.wlang(:varname => 'who') # => Hello $(who)!
102
- tpl = tpl.wlang({:who => 'wlang'}, dialect, :parentheses) # => Hello wlang!
103
-
104
- ## Roadmap
105
-
106
- - For terminology and a quick overview of _wlang_ for generating code, read on.
107
- - For the current cheatsheet/specification see the file doc/specification/specification.html
108
- - If you want to learn _wlang_ quickly, see the example directory or read examples
109
- in the specification file (if you understand all examples in the specification file, then you
110
- probably master wlang.
111
- - If you want a killer example (but simple) see the way the specification.html file
112
- is generated in doc/specification directory
113
- - If you want to know which dialects are available (that is, in which target languages
114
- you can generate code), see the specification as well or read the file
115
- lib/wlang/dialects/standard_dialects.rb in the source distribution.
116
- - If you want to create your own wlang dialect, see WLang::Dialect::DSL
117
- - If you think that your own dialect is of generic purpose and well-designed, if
118
- you have any question or want to contribute join us on {github}[http://github.com/blambeau/wlang].
119
-
120
- ## Terminology
121
-
122
- _wlang_ comes with a well-defined terminology for the underlying abstractions. As
123
- the documentation uses it, you'll probably be happy to learn about the main abstractions
124
- and associated terms.
125
-
126
- _template_ : Source code respecting the wlang grammar, and attached to a given <em>wlang
127
- dialect</em>. Asbtraction implemented by WLang::Template.
128
-
129
- _dialect_ : Basically, <em>dialect</em> is used as a synonym for (programming) <em>language</em>.
130
- However _wlang_ uses a tree of dialects, allowing specializations: <tt>sql/sybase</tt>
131
- for example is the qualified name of a sub-dialect 'sybase' of the 'sql' dialect.
132
- Dialects come with associated _encoders_. Abstraction implemented by WLang::Dialect.
133
-
134
- _wlang dialect_ : When we talk about a <em>wlang dialect</em>, we are actually refering to some
135
- specialization of the wlang tag-based grammar: <tt>wlang/xhtml</tt> for example
136
- is the templating language _wlang_ proposes to generate xhtml pages. An
137
- example of source code in that dialect has been shown before.
138
- In addition to its encoders a <em>wlang dialect</em> comes with its sets of _tags_
139
- and associated _rules_. Abstraction implemented by WLang::Dialect as well as
140
- WLang::EncoderSet and WLang::RuleSet.
141
-
142
- _encoder set_ : Reusable set of <em>encoders</em>, attached to a dialect. Abstraction
143
- implemented by WLang::EncoderSet.
144
-
145
- _encoder_ : Text transformation (algorithm) applying some encoding conventions of a portion
146
- of a the target language generated by a dialect. HTML entities-encoding, SQL's back-quoting
147
- are examples of encoders. Encoders are accessible through their qualified name:
148
- xhtml/entities-encoding and sql/back-quoting in the examples. Abstraction implemented by
149
- WLang::Encoder.
150
-
151
- _ruleset_ : Reusable set of <em>tags</em> associated to <em>rule</em>s. Abstraction
152
- implemented by WLang::RuleSet.
153
-
154
- _wlang tag_ : Special tags in the template, starting with wlang symbols and a number of wlang
155
- blocks. A tag is associated with a wlang rule. Examples: <tt>${...}</tt> is a
156
- tag with only one block, while <tt>?{...}{...}{...}</tt> is another tag but with
157
- three blocks.
158
-
159
- _rule_ : Transformation semantics of a given <em>tag</em>. When wlang instantiates a
160
- template it simply replaces <em>wlang tags</em> by some <em>replacement value</em>
161
- (which is always a string). This value is computed by the rule attached to
162
- the tag. Rule definition explicitly describes the number of blocks it expects, in which dialect they
163
- are parsed and instantiated and the way the replacement value is computed.
164
- Example: <tt>^{wlang/active-string}{...}</tt> (also known as 'encoding')
165
- instantiates #1, looking for an encoder qualified name. Instantiates #2 in
166
- the current dialect. Encode #2's instantiation using encoder found in (#1)
167
-
168
- _context_ : Some rules allow code to be executed in the <em>hosting language</em> (the
169
- definition explicitly announce it by putting <tt>wlang/hosted</tt> in the corresponding
170
- block). When doing so, this code is in fact executed in a given context that
171
- provides the execution semantics. Abstraction implemented in WLang::Parser::Context.
172
-
173
- _hosting language_ : language (or framework) that executes wlang. In this case, it will be
174
- <tt>ruby</tt>.
1
+ # WLang
2
+
3
+ [![Build Status](https://secure.travis-ci.org/blambeau/wlang.png?branch=wlang2)](http://travis-ci.org/blambeau/wlang)
4
+
5
+ WLang is a powerful code generation and templating engine.
6
+
7
+ This is the README of wlang2, a fresh new implementation of the [wlang templating language concept](http://revision-zero.org/wlang), this one implemented on top of [temple](https://github.com/judofyr/temple) and much inspired by the excellent [mustache](http://mustache.github.com/). (For users of wlang 1.0 (formaly 0.10.2), this rewrite cleans most concepts as well as the abstract wlang semantics; it also uses a simple compiler architecture to gain huge perfomance gains in comparison to early wlang days).
8
+
9
+ **WLang2 is work in progress**. It does not support rubinius so far, due to an incompatibility with the Citrus parser generator. It also have some issues with spacing; not a big issue for HTML rendering but might prevent certain generation tasks.
10
+
11
+ ## Links
12
+
13
+ * http://github.com/blambeau/wlang
14
+ * http://blambeau.github.com/wlang
15
+ * http://rubygems.org/gems/wlang
16
+ * http://revision-zero.org/wlang
17
+
18
+ ## A user-defined templating engine
19
+
20
+ WLang is a templating engine, written in ruby. In that, it is similar to ERB, Mustache and the like:
21
+
22
+ ```ruby
23
+ WLang::Html.render 'Hello to ${who}!', who: 'you & the world'
24
+ # => "Hello you &amp; the world!"
25
+ ```
26
+
27
+ To output HTML pages, WLang does not provides you with killer features or extraordinary shortcus. It supports escaping, as shown above, but many other templating engines do. For such HTML tasks, WLang does a pretty good job but many other engines perform faster and have nicer features. See the examples folder that documents WLang::Html.
28
+
29
+ WLang is designed to help you for other uses cases, user-defined ones in particular, such as generating code or whatever text generation task for which other engines quickly become inappropriate. WLang helps there because it allows you to create your own _dialect_, that is, you can define your own tags and their behavior. For instance,
30
+
31
+ ```ruby
32
+ class Highlighter < WLang::Dialect
33
+
34
+ def highlight(buf, fn)
35
+ var_name = render(fn)
36
+ var_value = evaluate(var_name)
37
+ buf << var_value.to_s.upcase
38
+ end
39
+
40
+ tag '$', :highlight
41
+ end
42
+ Highlighter.render('Hello ${who}!'), who: 'you & the world'
43
+ # => "Hello YOU & THE WORLD !"
44
+ ```
45
+
46
+ WLang already provides a few useful dialects, such as WLang::Mustang (mimicing mustache) and WLang::Html (a bit more powerful in my opinion). If they don't match your needs, it is up to you to define you own dialect for making your generation task easy. Have a look at the implementation of WLang's ones, it's pretty simple to get started!
47
+
48
+ ## Abstract semantics
49
+
50
+ WLang has a powerful semantics in terms of concatenation of strings and high-order functions (i.e. functions that take other functions as parameters). Let take the following template as an example:
51
+
52
+ ```
53
+ Hello ${who} !
54
+ ```
55
+
56
+ The functional semantics of this template is as follows:
57
+
58
+ ```clojure
59
+ (fn (concat "Hello", ($ (fn "who")), " !"))
60
+ ```
61
+
62
+ That is, the compilation of this template yields a function that concatenates the
63
+ string `"Hello"` with the result of the higher-order function `($ )` (that itself takes another function as a parameter, corresponding to the sub-template in its brackets delimited blocks) and then the string `" !"`. Providing a concrete semantics to those high-order functions yields so called WLang _dialects_, as we've seen before.
64
+
65
+ Having a well-defined semantics allows wlang to properly compile your user-defined dialect and its instantiation engine so as to preserve decent performances. The WLang architecture is a typical compiler chain. This means that, provided some additional coding, you could even define your own language/syntax and reuse the compilation mechanism, provided that you preserve the semantics above.
66
+
67
+ ## Higher-order constructs
68
+
69
+ A feature that distinguishes WLang from most templating engines is the fact that higher-level constructions are permitted. In addition to tag functions that accept multiple arguments, thus multiple blocks in the source text, those blocks may be complex templates themselves.
70
+
71
+ For instance, the following behavior is perfectly implementable:
72
+
73
+ ```ruby
74
+ HighLevel.render 'Hello *{ ${collection} }{ ${self} }{ and } !',
75
+ collection: 'whos', whos: [ "you", "wlang", "world" ]
76
+ # => "Hello you and wlang and world"
77
+ ```
78
+
79
+ An implementation of `HighLevel` might be as follows:
80
+
81
+ ```ruby
82
+ class HighLevel < WLang::Dialect
83
+
84
+ def join(buf, expr, main, between)
85
+ evaluate(expr).each_with_index do |val,i|
86
+ buf << render(between, val) unless i==0
87
+ buf << render(main, val).strip
88
+ end
89
+ end
90
+
91
+ def print(buf, fn)
92
+ buf << evaluate(fn).to_s
93
+ end
94
+
95
+ tag '*', :join
96
+ tag '$', :print
97
+ end
98
+ ```
99
+
100
+ Use at your own risk, though, as it might lead to dialects that are difficult to understand and/or use and present serious injections risks! Otherwise, higher-order constructions provides you with very powerful tools.