wlang 0.9.2 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +96 -0
- data/{LICENCE.rdoc → LICENCE.md} +2 -2
- data/README.md +176 -0
- data/bin/wlang +1 -0
- data/doc/specification/dialects.wtpl +1 -1
- data/doc/specification/specification.html +1237 -1001
- data/doc/specification/specification.yml +12 -10
- data/lib/wlang.rb +2 -2
- data/lib/wlang/dialects/coderay_dialect.rb +1 -0
- data/lib/wlang/dialects/hosted_dialect.rb +50 -0
- data/lib/wlang/dialects/plain_text_dialect.rb +2 -2
- data/lib/wlang/dialects/ruby_dialect.rb +74 -5
- data/lib/wlang/dialects/standard_dialects.rb +41 -0
- data/lib/wlang/dialects/yaml_dialect.rb +30 -0
- data/lib/wlang/encoder.rb +0 -4
- data/lib/wlang/ext/string.rb +7 -2
- data/lib/wlang/parser.rb +1 -1
- data/lib/wlang/rulesets/basic_ruleset.rb +1 -1
- data/lib/wlang/rulesets/context_ruleset.rb +3 -3
- data/lib/wlang/rulesets/encoding_ruleset.rb +3 -3
- data/lib/wlang/rulesets/imperative_ruleset.rb +2 -2
- data/test/spec/test_all.rb +1 -1
- data/test/standard_dialects/ruby/data.rb +7 -0
- data/test/standard_dialects/ruby/inclusion.exp +6 -0
- data/test/standard_dialects/ruby/inclusion.tpl +6 -0
- data/test/standard_dialects/test_all.rb +29 -0
- data/test/standard_dialects/yaml/assumptions_test.rb +13 -0
- data/test/standard_dialects/yaml/data.rb +3 -0
- data/test/standard_dialects/yaml/inclusion_1.exp +7 -0
- data/test/standard_dialects/yaml/inclusion_1.tpl +2 -0
- data/test/standard_dialects/yaml/inclusion_2.exp +5 -0
- data/test/standard_dialects/yaml/inclusion_2.tpl +3 -0
- data/test/unit/wlang/ruby_dialect_test.rb +1 -1
- metadata +23 -11
- data/CHANGELOG.rdoc +0 -73
- data/README.rdoc +0 -165
data/test/spec/test_all.rb
CHANGED
@@ -0,0 +1,29 @@
|
|
1
|
+
here = File.dirname(__FILE__)
|
2
|
+
$LOAD_PATH.unshift(File.join(here, '..', '..', 'lib'))
|
3
|
+
require 'wlang'
|
4
|
+
require 'test/unit'
|
5
|
+
module WLang
|
6
|
+
class StandardDialectsTest < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def test_standard_dialects
|
9
|
+
Dir["#{File.dirname(__FILE__)}/*"].each do |folder|
|
10
|
+
dialect_name = File.basename(folder)
|
11
|
+
Dir["#{folder}/*.tpl"].each do |template_file|
|
12
|
+
begin
|
13
|
+
basename = File.basename(template_file, ".tpl")
|
14
|
+
expected = File.read(File.join(folder, "#{basename}.exp"))
|
15
|
+
template = WLang::file_template(template_file, "wlang/#{dialect_name}")
|
16
|
+
assert_equal(expected, template.instantiate, "Standard dialect test failed wlang/#{basename}")
|
17
|
+
rescue WLang::Error => ex
|
18
|
+
puts "Standard dialect test failed: #{template_file}\n#{ex.message}"
|
19
|
+
puts ex.wlang_backtrace.join("\n")
|
20
|
+
rescue Exception => ex
|
21
|
+
puts "Standard dialect test failed: #{template_file}\n#{ex.message}"
|
22
|
+
puts ex.backtrace.join("\n")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end # class StandardDialectsTest
|
29
|
+
end # module WLang
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'yaml'
|
3
|
+
module WLang
|
4
|
+
class YAMLAssumptionTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_it_supports_quotes_as_expected
|
7
|
+
text = "---\nauthor:\n \"Bernard Lambeau\"\n"
|
8
|
+
x = YAML::load(text)
|
9
|
+
assert_equal({'author' => "Bernard Lambeau"}, x)
|
10
|
+
end
|
11
|
+
|
12
|
+
end # class YAMLAssumptionTest
|
13
|
+
end # module WLang
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wlang
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 55
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 10
|
9
|
+
- 0
|
10
|
+
version: 0.10.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Bernard Lambeau
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2011-01-15 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -26,14 +26,15 @@ executables:
|
|
26
26
|
extensions: []
|
27
27
|
|
28
28
|
extra_rdoc_files:
|
29
|
-
- README.
|
30
|
-
- LICENCE.
|
31
|
-
- CHANGELOG.
|
29
|
+
- README.md
|
30
|
+
- LICENCE.md
|
31
|
+
- CHANGELOG.md
|
32
32
|
files:
|
33
33
|
- lib/wlang/dialect.rb
|
34
34
|
- lib/wlang/dialect_dsl.rb
|
35
35
|
- lib/wlang/dialect_loader.rb
|
36
36
|
- lib/wlang/dialects/coderay_dialect.rb
|
37
|
+
- lib/wlang/dialects/hosted_dialect.rb
|
37
38
|
- lib/wlang/dialects/plain_text_dialect.rb
|
38
39
|
- lib/wlang/dialects/rdoc_dialect.rb
|
39
40
|
- lib/wlang/dialects/redcloth_dialect.rb
|
@@ -41,6 +42,7 @@ files:
|
|
41
42
|
- lib/wlang/dialects/sql_dialect.rb
|
42
43
|
- lib/wlang/dialects/standard_dialects.rb
|
43
44
|
- lib/wlang/dialects/xhtml_dialect.rb
|
45
|
+
- lib/wlang/dialects/yaml_dialect.rb
|
44
46
|
- lib/wlang/encoder.rb
|
45
47
|
- lib/wlang/encoder_set.rb
|
46
48
|
- lib/wlang/errors.rb
|
@@ -154,6 +156,16 @@ files:
|
|
154
156
|
- test/spec/test_all.rb
|
155
157
|
- test/spec/wlang.spec
|
156
158
|
- test/spec/xhtml_dialect.spec
|
159
|
+
- test/standard_dialects/ruby/data.rb
|
160
|
+
- test/standard_dialects/ruby/inclusion.exp
|
161
|
+
- test/standard_dialects/ruby/inclusion.tpl
|
162
|
+
- test/standard_dialects/test_all.rb
|
163
|
+
- test/standard_dialects/yaml/assumptions_test.rb
|
164
|
+
- test/standard_dialects/yaml/data.rb
|
165
|
+
- test/standard_dialects/yaml/inclusion_1.exp
|
166
|
+
- test/standard_dialects/yaml/inclusion_1.tpl
|
167
|
+
- test/standard_dialects/yaml/inclusion_2.exp
|
168
|
+
- test/standard_dialects/yaml/inclusion_2.tpl
|
157
169
|
- test/unit/test_all.rb
|
158
170
|
- test/unit/wlang/anagram_bugs_test.rb
|
159
171
|
- test/unit/wlang/basic_ruleset_test.rb
|
@@ -193,9 +205,9 @@ files:
|
|
193
205
|
- doc/specification/specification.wtpl
|
194
206
|
- doc/specification/specification.yml
|
195
207
|
- doc/specification/symbols.wtpl
|
196
|
-
- README.
|
197
|
-
- LICENCE.
|
198
|
-
- CHANGELOG.
|
208
|
+
- README.md
|
209
|
+
- LICENCE.md
|
210
|
+
- CHANGELOG.md
|
199
211
|
has_rdoc: true
|
200
212
|
homepage: http://blambeau.github.com/wlang/
|
201
213
|
licenses: []
|
data/CHANGELOG.rdoc
DELETED
@@ -1,73 +0,0 @@
|
|
1
|
-
== Changelog
|
2
|
-
|
3
|
-
=== Version 0.9.2
|
4
|
-
|
5
|
-
==== New features (by order of importance)
|
6
|
-
|
7
|
-
- Implements main transformer on dialects
|
8
|
-
- Makes coderay encoders available without options using a bit of meta programming
|
9
|
-
- System-local absolute paths (i.e. starting with '/') are recognized by buffer rulesets
|
10
|
-
|
11
|
-
=== Version 0.9.1
|
12
|
-
|
13
|
-
==== Bug fixes
|
14
|
-
|
15
|
-
- #307, about HashScope.has_key? which returned nil instead of false in some situations
|
16
|
-
|
17
|
-
==== Broken features and APIs (by order of importance)
|
18
|
-
|
19
|
-
- HostedLanguage::DSL is strictly private and should be reopened. Methods added to this class
|
20
|
-
will never be available in templates. Use HostedLanguage.variable_missing instead.
|
21
|
-
- ::WLang::BasicObject has been removed. HostedLanguage::DSL implements its own strategy, which
|
22
|
-
is spec tested in test/spec/basic_object.spec
|
23
|
-
|
24
|
-
==== New features (by order of importance)
|
25
|
-
|
26
|
-
- WLang does not requires the rdoc gem by default
|
27
|
-
- A new encoder redcloth/xhtml allows using Textile markups easily
|
28
|
-
- The wlang/xhtml dialect provides a tag helper for links @{...}{...}
|
29
|
-
- The parser class returns friendly messages when a rule is ill-implemented
|
30
|
-
|
31
|
-
=== Version 0.9.0
|
32
|
-
|
33
|
-
==== Broken features and APIs (by order of importance)
|
34
|
-
|
35
|
-
- Major broken API in WLang.instantiate and WLang.file_instantiate which do not allow passing
|
36
|
-
buffers anymore
|
37
|
-
- Hash are not methodized by default anymore (major broken feature with 0.8.x versions)
|
38
|
-
- Expressions 'a la' PHP w@w (sections/.../.../id) are not supported anymore
|
39
|
-
- The default hosted language raises a WLang::UndefinedVariableError when a variable cannot be
|
40
|
-
found in the current template scope (0.8.x versions returned nil in this case)
|
41
|
-
- Template.initialize does not take a default context anymore
|
42
|
-
- WLang::Parser.context_xxx do not exist anymore. Use branch(...) instead
|
43
|
-
- WLang::Parser::Context removed, and WLang::HashScope introduced
|
44
|
-
- WLang::Parser instance variables are all made protected
|
45
|
-
|
46
|
-
==== New features (by order of importance)
|
47
|
-
|
48
|
-
- WLang::HostingLanguage introduced, with a default one for Ruby. The hosting language
|
49
|
-
is the way to provide a main scope, accessible to all templates at once.
|
50
|
-
- WLang::HostingLanguage is not sensitive to the difference between symbol keys and strings
|
51
|
-
- Buffering and Context rulesets now branch the current parser instead of creating a new one
|
52
|
-
- WLang::Error and subclasses propose a backtrace information
|
53
|
-
- WLang::Parser refactored to encapsulate the whole state in another class (WLang::Parser::State)
|
54
|
-
- WLang facade has been made much more robust as it now checks all its arguments.
|
55
|
-
- WLang::dialect may now be used to ensure dialect instances from both Dialect args and qualified names.
|
56
|
-
- Introduction of WLang.template and WLang.file_template
|
57
|
-
- plain-text dialect proposes new camel-based encoders
|
58
|
-
- wlang/active-string dialect has the imperative rule set included
|
59
|
-
- sql dialect has been added
|
60
|
-
- ruby dialect proposes a method-case encoder
|
61
|
-
|
62
|
-
=== Version 0.8.5
|
63
|
-
|
64
|
-
- Enhances error messages a lot
|
65
|
-
- Some bug fixes for ruby 0.8.7
|
66
|
-
|
67
|
-
=== Version 0.8.4
|
68
|
-
|
69
|
-
- Migration from svn.chefbe.net to github.com
|
70
|
-
|
71
|
-
=== Version 0.8.0
|
72
|
-
|
73
|
-
- First public version
|
data/README.rdoc
DELETED
@@ -1,165 +0,0 @@
|
|
1
|
-
= What is _wlang_ ?
|
2
|
-
|
3
|
-
_wlang_ is a simple, powerful, robust and secure <b>code generation</b>/<b>templating engine</b>
|
4
|
-
(at least, authors hope so ;-) Motivation for it can be found at http://www.revision-zero.org/wlang.
|
5
|
-
It's main aim is to help you creating web pages, sql queries, ruby code (that is, generating code in
|
6
|
-
general) without having to worry too much about html entities encoding, sql back quoting, string
|
7
|
-
escaping and the like. WLang proposes a generic engine that you can extend to fit your needs. It also
|
8
|
-
proposes standard instantiations of this engine for common tasks such as creating SQL queries,
|
9
|
-
instantiating web pages, etc.
|
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') # &
|
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 & 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
|
-
[dialect] Basically, <em>dialect</em> is used as a synonym for (programming) <em>language</em>.
|
129
|
-
However _wlang_ uses a tree of dialects, allowing specializations: <tt>sql/sybase</tt>
|
130
|
-
for example is the qualified name of a sub-dialect 'sybase' of the 'sql' dialect.
|
131
|
-
Dialects come with associated _encoders_. Abstraction implemented by WLang::Dialect.
|
132
|
-
[wlang dialect] When we talk about a <em>wlang dialect</em>, we are actually refering to some
|
133
|
-
specialization of the wlang tag-based grammar: <tt>wlang/xhtml</tt> for example
|
134
|
-
is the templating language _wlang_ proposes to generate xhtml pages. An
|
135
|
-
example of source code in that dialect has been shown before.
|
136
|
-
In addition to its encoders a <em>wlang dialect</em> comes with its sets of _tags_
|
137
|
-
and associated _rules_. Abstraction implemented by WLang::Dialect as well as
|
138
|
-
WLang::EncoderSet and WLang::RuleSet.
|
139
|
-
[encoder set] Reusable set of <em>encoders</em>, attached to a dialect. Abstraction
|
140
|
-
implemented by WLang::EncoderSet.
|
141
|
-
[encoder] Text transformation (algorithm) applying some encoding conventions of a portion
|
142
|
-
of a the target language generated by a dialect. HTML entities-encoding, SQL's back-quoting
|
143
|
-
are examples of encoders. Encoders are accessible through their qualified name:
|
144
|
-
xhtml/entities-encoding and sql/back-quoting in the examples. Abstraction implemented by
|
145
|
-
WLang::Encoder.
|
146
|
-
[ruleset] Reusable set of <em>tags</em> associated to <em>rule</em>s. Abstraction
|
147
|
-
implemented by WLang::RuleSet.
|
148
|
-
[wlang tag] Special tags in the template, starting with wlang symbols and a number of wlang
|
149
|
-
blocks. A tag is associated with a wlang rule. Examples: <tt>${...}</tt> is a
|
150
|
-
tag with only one block, while <tt>?{...}{...}{...}</tt> is another tag but with
|
151
|
-
three blocks.
|
152
|
-
[rule] Transformation semantics of a given <em>tag</em>. When wlang instantiates a
|
153
|
-
template it simply replaces <em>wlang tags</em> by some <em>replacement value</em>
|
154
|
-
(which is always a string). This value is computed by the rule attached to
|
155
|
-
the tag. Rule definition explicitly describes the number of blocks it expects, in which dialect they
|
156
|
-
are parsed and instantiated and the way the replacement value is computed.
|
157
|
-
Example: <tt>^{wlang/active-string}{...}</tt> (also known as 'encoding')
|
158
|
-
instantiates #1, looking for an encoder qualified name. Instantiates #2 in
|
159
|
-
the current dialect. Encode #2's instantiation using encoder found in (#1)
|
160
|
-
[context] Some rules allow code to be executed in the <em>hosting language</em> (the
|
161
|
-
definition explicitly announce it by putting <tt>wlang/hosted</tt> in the corresponding
|
162
|
-
block). When doing so, this code is in fact executed in a given context that
|
163
|
-
provides the execution semantics. Abstraction implemented in WLang::Parser::Context.
|
164
|
-
[hosting language] language (or framework) that executes wlang. In this case, it will be
|
165
|
-
<tt>ruby</tt>.
|