wlang 0.10.2 → 2.0.0.beta
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 +3 -121
- data/Gemfile +23 -1
- data/Gemfile.lock +32 -28
- data/LICENCE.md +18 -21
- data/Manifest.txt +4 -5
- data/README.md +100 -174
- data/Rakefile +1 -13
- data/bin/wlang +3 -29
- data/lib/wlang.rb +21 -394
- data/lib/wlang/command.rb +94 -0
- data/lib/wlang/compiler.rb +78 -0
- data/lib/wlang/compiler/autospacing.rb +60 -0
- data/lib/wlang/compiler/dialect_enforcer.rb +91 -0
- data/lib/wlang/compiler/filter.rb +32 -0
- data/lib/wlang/compiler/grammar.citrus +67 -0
- data/lib/wlang/compiler/parser.rb +26 -0
- data/lib/wlang/compiler/proc_call_removal.rb +15 -0
- data/lib/wlang/compiler/static_merger.rb +28 -0
- data/lib/wlang/compiler/strconcat_flattener.rb +25 -0
- data/lib/wlang/compiler/to_ruby_abstraction.rb +22 -0
- data/lib/wlang/compiler/to_ruby_code.rb +55 -0
- data/lib/wlang/dialect.rb +40 -237
- data/lib/wlang/dialect/dispatching.rb +51 -0
- data/lib/wlang/dialect/evaluation.rb +30 -0
- data/lib/wlang/dialect/tags.rb +50 -0
- data/lib/wlang/dummy.rb +32 -0
- data/lib/wlang/html.rb +106 -0
- data/lib/wlang/loader.rb +6 -0
- data/lib/wlang/mustang.rb +90 -0
- data/lib/wlang/scope.rb +57 -0
- data/lib/wlang/scope/binding_scope.rb +18 -0
- data/lib/wlang/scope/object_scope.rb +25 -0
- data/lib/wlang/scope/proxy_scope.rb +18 -0
- data/lib/wlang/scope/root_scope.rb +24 -0
- data/lib/wlang/template.rb +16 -86
- data/lib/wlang/version.rb +9 -8
- data/spec/fixtures/dialect/foobar.rb +31 -0
- data/spec/fixtures/dialect/upcasing.rb +13 -0
- data/spec/fixtures/templates/hello.tpl +1 -0
- data/spec/integration/examples/1-basics.txt +65 -0
- data/spec/integration/examples/2-imperative.txt +51 -0
- data/spec/integration/examples/3-partials.txt +76 -0
- data/spec/integration/examples/4-recursion.txt +16 -0
- data/spec/integration/html/test_ampersand.rb +15 -0
- data/spec/integration/html/test_bang.rb +38 -0
- data/spec/integration/html/test_caret.rb +33 -0
- data/spec/integration/html/test_dollar.rb +16 -0
- data/spec/integration/html/test_greater.rb +23 -0
- data/spec/integration/html/test_modulo.rb +16 -0
- data/spec/integration/html/test_plus.rb +48 -0
- data/spec/integration/html/test_question.rb +33 -0
- data/spec/integration/html/test_sharp.rb +21 -0
- data/spec/integration/html/test_slash.rb +16 -0
- data/spec/integration/html/test_star.rb +37 -0
- data/spec/integration/test_dummy.rb +51 -0
- data/spec/integration/test_examples.rb +29 -0
- data/spec/integration/test_mustang.rb +120 -0
- data/spec/integration/test_readme.rb +56 -0
- data/spec/integration/test_upcasing.rb +22 -0
- data/spec/spec_helper.rb +62 -1
- data/spec/test_wlang.rb +101 -0
- data/spec/unit/compiler/autospacing/test_right_strip.rb +30 -0
- data/spec/unit/compiler/autospacing/test_unindent.rb +30 -0
- data/spec/unit/compiler/test_dialect_enforcer.rb +168 -0
- data/spec/unit/compiler/test_grammar.rb +207 -0
- data/spec/unit/compiler/test_parser.rb +69 -0
- data/spec/unit/compiler/test_proc_call_removal.rb +24 -0
- data/spec/unit/compiler/test_static_merger.rb +29 -0
- data/spec/unit/compiler/test_strconcat_flattener.rb +30 -0
- data/spec/unit/compiler/test_to_ruby_abstraction.rb +59 -0
- data/spec/unit/compiler/test_to_ruby_code.rb +24 -0
- data/spec/unit/dialect/test_compile.rb +52 -0
- data/spec/unit/dialect/test_dispatching.rb +19 -0
- data/spec/unit/dialect/test_evaluate.rb +41 -0
- data/spec/unit/dialect/test_render.rb +33 -0
- data/spec/unit/dialect/test_tags.rb +32 -0
- data/spec/unit/dialect/test_with_scope.rb +18 -0
- data/spec/unit/scope/test_binding_scope.rb +27 -0
- data/spec/unit/scope/test_coerce.rb +22 -0
- data/spec/unit/scope/test_object_scope.rb +38 -0
- data/spec/unit/scope/test_proxy_scope.rb +22 -0
- data/spec/unit/scope/test_root_scope.rb +22 -0
- data/spec/unit/test_assumptions.rb +29 -0
- data/spec/unit/test_scope.rb +57 -0
- data/tasks/debug_mail.rake +42 -45
- data/tasks/gem.rake +22 -17
- data/tasks/spec_test.rake +9 -17
- data/tasks/unit_test.rake +11 -12
- data/tasks/yard.rake +13 -13
- data/wlang.gemspec +36 -32
- data/wlang.noespec +27 -35
- metadata +268 -451
- data/doc/specification/about.rdoc +0 -61
- data/doc/specification/analytics.wtpl +0 -13
- data/doc/specification/dialect.wtpl +0 -14
- data/doc/specification/dialects.wtpl +0 -3
- data/doc/specification/examples.rb +0 -3
- data/doc/specification/glossary.wtpl +0 -14
- data/doc/specification/hosting.rdoc +0 -0
- data/doc/specification/overview.rdoc +0 -116
- data/doc/specification/rulesets.wtpl +0 -87
- data/doc/specification/specification.css +0 -53
- data/doc/specification/specification.html +0 -1690
- data/doc/specification/specification.js +0 -8
- data/doc/specification/specification.wtpl +0 -42
- data/doc/specification/specification.yml +0 -432
- data/doc/specification/symbols.wtpl +0 -16
- data/lib/wlang/dialect_dsl.rb +0 -141
- data/lib/wlang/dialect_loader.rb +0 -74
- data/lib/wlang/dialects/bluecloth_dialect.rb +0 -16
- data/lib/wlang/dialects/coderay_dialect.rb +0 -45
- data/lib/wlang/dialects/hosted_dialect.rb +0 -50
- data/lib/wlang/dialects/plain_text_dialect.rb +0 -69
- data/lib/wlang/dialects/rdoc_dialect.rb +0 -33
- data/lib/wlang/dialects/redcloth_dialect.rb +0 -16
- data/lib/wlang/dialects/ruby_dialect.rb +0 -118
- data/lib/wlang/dialects/sql_dialect.rb +0 -38
- data/lib/wlang/dialects/standard_dialects.rb +0 -181
- data/lib/wlang/dialects/xhtml_dialect.rb +0 -63
- data/lib/wlang/dialects/yaml_dialect.rb +0 -30
- data/lib/wlang/encoder.rb +0 -62
- data/lib/wlang/encoder_set.rb +0 -122
- data/lib/wlang/errors.rb +0 -80
- data/lib/wlang/ext/hash_methodize.rb +0 -13
- data/lib/wlang/ext/string.rb +0 -44
- data/lib/wlang/hash_scope.rb +0 -89
- data/lib/wlang/hosted_language.rb +0 -146
- data/lib/wlang/intelligent_buffer.rb +0 -94
- data/lib/wlang/parser.rb +0 -332
- data/lib/wlang/parser_state.rb +0 -94
- data/lib/wlang/rule.rb +0 -66
- data/lib/wlang/rule_set.rb +0 -106
- data/lib/wlang/rulesets/basic_ruleset.rb +0 -83
- data/lib/wlang/rulesets/buffering_ruleset.rb +0 -115
- data/lib/wlang/rulesets/context_ruleset.rb +0 -111
- data/lib/wlang/rulesets/encoding_ruleset.rb +0 -73
- data/lib/wlang/rulesets/imperative_ruleset.rb +0 -132
- data/lib/wlang/rulesets/ruleset_utils.rb +0 -317
- data/lib/wlang/wlang_command.rb +0 -51
- data/lib/wlang/wlang_command_options.rb +0 -163
- data/spec/basic_object.spec +0 -40
- data/spec/coderay_dialect.spec +0 -8
- data/spec/dialect/apply_post_transform.spec +0 -16
- data/spec/global_extensions.rb +0 -2
- data/spec/hash_scope.spec +0 -76
- data/spec/redcloth_dialect.spec +0 -24
- data/spec/test_all.rb +0 -8
- data/spec/wlang.spec +0 -53
- data/spec/wlang_spec.rb +0 -8
- data/spec/xhtml_dialect.spec +0 -22
- data/tasks/genspec.rake +0 -5
- data/test/blackbox/basic/execution_1.exp +0 -1
- data/test/blackbox/basic/execution_1.tpl +0 -1
- data/test/blackbox/basic/execution_2.exp +0 -1
- data/test/blackbox/basic/execution_2.tpl +0 -1
- data/test/blackbox/basic/execution_3.exp +0 -1
- data/test/blackbox/basic/execution_3.tpl +0 -1
- data/test/blackbox/basic/execution_4.exp +0 -1
- data/test/blackbox/basic/execution_4.tpl +0 -1
- data/test/blackbox/basic/inclusion_1.exp +0 -1
- data/test/blackbox/basic/inclusion_1.tpl +0 -1
- data/test/blackbox/basic/inclusion_2.exp +0 -1
- data/test/blackbox/basic/inclusion_2.tpl +0 -1
- data/test/blackbox/basic/injection_1.exp +0 -1
- data/test/blackbox/basic/injection_1.tpl +0 -1
- data/test/blackbox/basic/injection_2.exp +0 -1
- data/test/blackbox/basic/injection_2.tpl +0 -1
- data/test/blackbox/basic/modulation_1.exp +0 -1
- data/test/blackbox/basic/modulation_1.tpl +0 -1
- data/test/blackbox/basic/modulation_2.exp +0 -1
- data/test/blackbox/basic/modulation_2.tpl +0 -1
- data/test/blackbox/basic/recursive_app_1.exp +0 -1
- data/test/blackbox/basic/recursive_app_1.tpl +0 -1
- data/test/blackbox/basic/recursive_app_2.exp +0 -1
- data/test/blackbox/basic/recursive_app_2.tpl +0 -1
- data/test/blackbox/buffering/data_1.rb +0 -1
- data/test/blackbox/buffering/data_assignment_1.exp +0 -1
- data/test/blackbox/buffering/data_assignment_1.tpl +0 -1
- data/test/blackbox/buffering/data_assignment_2.exp +0 -1
- data/test/blackbox/buffering/data_assignment_2.tpl +0 -1
- data/test/blackbox/buffering/data_assignment_3.exp +0 -1
- data/test/blackbox/buffering/data_assignment_3.tpl +0 -1
- data/test/blackbox/buffering/data_assignment_4.exp +0 -1
- data/test/blackbox/buffering/data_assignment_4.tpl +0 -1
- data/test/blackbox/buffering/input_1.exp +0 -1
- data/test/blackbox/buffering/input_1.tpl +0 -1
- data/test/blackbox/buffering/input_2.exp +0 -1
- data/test/blackbox/buffering/input_2.tpl +0 -1
- data/test/blackbox/buffering/input_3.exp +0 -1
- data/test/blackbox/buffering/input_3.tpl +0 -1
- data/test/blackbox/buffering/input_inclusion.exp +0 -1
- data/test/blackbox/buffering/input_inclusion.tpl +0 -1
- data/test/blackbox/buffering/input_inclusion_1.exp +0 -0
- data/test/blackbox/buffering/input_inclusion_1.tpl +0 -1
- data/test/blackbox/buffering/input_inclusion_2.exp +0 -1
- data/test/blackbox/buffering/input_inclusion_2.tpl +0 -1
- data/test/blackbox/buffering/input_inclusion_3.exp +0 -1
- data/test/blackbox/buffering/input_inclusion_3.tpl +0 -1
- data/test/blackbox/buffering/input_inclusion_4.exp +0 -0
- data/test/blackbox/buffering/input_inclusion_4.tpl +0 -1
- data/test/blackbox/buffering/input_inclusion_5.exp +0 -1
- data/test/blackbox/buffering/input_inclusion_5.tpl +0 -1
- data/test/blackbox/buffering/input_inclusion_6.exp +0 -1
- data/test/blackbox/buffering/input_inclusion_6.tpl +0 -1
- data/test/blackbox/buffering/input_inclusion_7.exp +0 -0
- data/test/blackbox/buffering/input_inclusion_7.tpl +0 -1
- data/test/blackbox/buffering/text_1.txt +0 -1
- data/test/blackbox/buffering/wlang.txt +0 -1
- data/test/blackbox/context/assignment_1.exp +0 -1
- data/test/blackbox/context/assignment_1.tpl +0 -1
- data/test/blackbox/context/assignment_2.exp +0 -1
- data/test/blackbox/context/assignment_2.tpl +0 -1
- data/test/blackbox/context/assignment_3.exp +0 -2
- data/test/blackbox/context/assignment_3.tpl +0 -2
- data/test/blackbox/context/assignment_4.exp +0 -1
- data/test/blackbox/context/assignment_4.tpl +0 -1
- data/test/blackbox/context/block_assignment_1.exp +0 -1
- data/test/blackbox/context/block_assignment_1.tpl +0 -1
- data/test/blackbox/context/block_assignment_2.exp +0 -1
- data/test/blackbox/context/block_assignment_2.tpl +0 -1
- data/test/blackbox/context/modulo_assignment_1.exp +0 -1
- data/test/blackbox/context/modulo_assignment_1.tpl +0 -1
- data/test/blackbox/context/modulo_assignment_2.exp +0 -1
- data/test/blackbox/context/modulo_assignment_2.tpl +0 -1
- data/test/blackbox/data_1.rb +0 -1
- data/test/blackbox/postblock/hello.exp +0 -1
- data/test/blackbox/postblock/hello.pre +0 -1
- data/test/blackbox/postblock/hello.tpl +0 -1
- data/test/blackbox/postblock/hello_input_inclusion.exp +0 -1
- data/test/blackbox/postblock/hello_input_inclusion.tpl +0 -1
- data/test/blackbox/postblock/hello_to_authors.exp +0 -1
- data/test/blackbox/postblock/hello_to_authors.tpl +0 -1
- data/test/blackbox/poststring/hello.exp +0 -1
- data/test/blackbox/poststring/hello.tpl +0 -1
- data/test/blackbox/test_all.rb +0 -70
- data/test/standard_dialects/ruby/data.rb +0 -7
- data/test/standard_dialects/ruby/inclusion.exp +0 -6
- data/test/standard_dialects/ruby/inclusion.tpl +0 -6
- data/test/standard_dialects/test_all.rb +0 -29
- data/test/standard_dialects/yaml/assumptions_test.rb +0 -13
- data/test/standard_dialects/yaml/data.rb +0 -3
- data/test/standard_dialects/yaml/inclusion_1.exp +0 -7
- data/test/standard_dialects/yaml/inclusion_1.tpl +0 -2
- data/test/standard_dialects/yaml/inclusion_2.exp +0 -5
- data/test/standard_dialects/yaml/inclusion_2.tpl +0 -3
- data/test/unit/test_all.rb +0 -9
- data/test/unit/wlang/anagram_bugs_test.rb +0 -111
- data/test/unit/wlang/basic_ruleset_test.rb +0 -52
- data/test/unit/wlang/buffering_ruleset_test.rb +0 -102
- data/test/unit/wlang/buffering_template1.wtpl +0 -1
- data/test/unit/wlang/buffering_template2.wtpl +0 -1
- data/test/unit/wlang/buffering_template3.wtpl +0 -1
- data/test/unit/wlang/buffering_template4.wtpl +0 -1
- data/test/unit/wlang/buffering_template5.wtpl +0 -1
- data/test/unit/wlang/context_ruleset_test.rb +0 -32
- data/test/unit/wlang/data.rb +0 -3
- data/test/unit/wlang/encoder_set_test.rb +0 -42
- data/test/unit/wlang/imperative_ruleset_test.rb +0 -107
- data/test/unit/wlang/intelligent_buffer_test.rb +0 -194
- data/test/unit/wlang/othersymbols_test.rb +0 -16
- data/test/unit/wlang/parser_test.rb +0 -88
- data/test/unit/wlang/plain_text_dialect_test.rb +0 -21
- data/test/unit/wlang/ruby_dialect_test.rb +0 -100
- data/test/unit/wlang/ruby_expected.rb +0 -3
- data/test/unit/wlang/ruby_template.wrb +0 -3
- data/test/unit/wlang/ruleset_utils_test.rb +0 -245
- data/test/unit/wlang/specification_examples_test.rb +0 -54
- data/test/unit/wlang/test_utils.rb +0 -25
- data/test/unit/wlang/wlang_test.rb +0 -80
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'wlang/html'
|
|
3
|
+
module WLang
|
|
4
|
+
describe Html, "^{...}" do
|
|
5
|
+
|
|
6
|
+
def render(tpl, scope = {})
|
|
7
|
+
Html.render(tpl, scope, "")
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
[false, nil].each do |test|
|
|
11
|
+
context "when #{test.inspect}" do
|
|
12
|
+
it 'renders the then block' do
|
|
13
|
+
render("^{test}{hello}", binding).should eq("hello")
|
|
14
|
+
end
|
|
15
|
+
it 'does not render the else block' do
|
|
16
|
+
render("^{test}{hello}{otherwise}", binding).should eq("hello")
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
[true, "Something", []].each do |test|
|
|
22
|
+
context "when #{test.inspect}" do
|
|
23
|
+
it 'do not render the then block' do
|
|
24
|
+
render("^{test}{hello}", binding).should eq("")
|
|
25
|
+
end
|
|
26
|
+
it 'renders the else block if present' do
|
|
27
|
+
render("^{test}{hello}{otherwise}", binding).should eq("otherwise")
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'wlang/html'
|
|
3
|
+
module WLang
|
|
4
|
+
describe Html, "${...}" do
|
|
5
|
+
|
|
6
|
+
def render(tpl, scope = {})
|
|
7
|
+
Html.render(tpl, scope, "")
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it 'escapes html' do
|
|
11
|
+
hello = "<script>"
|
|
12
|
+
render("${hello}", binding).should eq("<script>")
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'wlang/html'
|
|
3
|
+
module WLang
|
|
4
|
+
describe Html, ">{...}" do
|
|
5
|
+
|
|
6
|
+
def render(tpl, scope = {})
|
|
7
|
+
Html.render(tpl, scope, "")
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it 'renders a Template object by default' do
|
|
11
|
+
who = "World"
|
|
12
|
+
partial = Html.compile("${who}")
|
|
13
|
+
render("Hello >{partial}", binding).should eq("Hello World")
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it 'compiles a String to a Template' do
|
|
17
|
+
who = "World"
|
|
18
|
+
partial = "${who}"
|
|
19
|
+
render("Hello >{partial}", binding).should eq("Hello World")
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'wlang/html'
|
|
3
|
+
module WLang
|
|
4
|
+
describe Html, "%{...}" do
|
|
5
|
+
|
|
6
|
+
def render(tpl, scope = {})
|
|
7
|
+
Html.render(tpl, scope, "")
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it 'disables wlang inside the block' do
|
|
11
|
+
who = "World"
|
|
12
|
+
render("%{Hello ${who}!}", binding).should eq("Hello ${who}!")
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'wlang/html'
|
|
3
|
+
module WLang
|
|
4
|
+
describe Html, "+{...}" do
|
|
5
|
+
|
|
6
|
+
ToHtml = Struct.new(:to_html)
|
|
7
|
+
ToS = Struct.new(:to_s)
|
|
8
|
+
|
|
9
|
+
def render(tpl, scope = {})
|
|
10
|
+
Html.render(tpl, scope, "")
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
context "on an aribitraty object" do
|
|
14
|
+
it 'invokes to_html if it exists' do
|
|
15
|
+
hello = ToHtml.new("<h1>World</h1>")
|
|
16
|
+
render("+{hello}", binding).should eq("<h1>World</h1>")
|
|
17
|
+
end
|
|
18
|
+
it 'invokes to_s if to_html does not exists' do
|
|
19
|
+
hello = ToS.new("World")
|
|
20
|
+
render("+{hello}", binding).should eq("World")
|
|
21
|
+
end
|
|
22
|
+
it 'invokes to_s on the result of to_html' do
|
|
23
|
+
hello = ToHtml.new(ToS.new("<h1>World</h1>"))
|
|
24
|
+
render("+{hello}", binding).should eq("<h1>World</h1>")
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
context "on a Template" do
|
|
29
|
+
it 'renders as a partial' do
|
|
30
|
+
who = "World"
|
|
31
|
+
hello = Html.compile("Hello +{who}")
|
|
32
|
+
render("+{hello}!", binding).should eq("Hello World!")
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
context "on a Proc" do
|
|
37
|
+
it 'calls it if of arity 0' do
|
|
38
|
+
hello = Proc.new{ "World" }
|
|
39
|
+
render("+{hello}!", binding).should eq("World!")
|
|
40
|
+
end
|
|
41
|
+
it 'it invokes to_html on the result' do
|
|
42
|
+
hello = Proc.new{ ToHtml.new("World") }
|
|
43
|
+
render("+{hello}!", binding).should eq("World!")
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'wlang/html'
|
|
3
|
+
module WLang
|
|
4
|
+
describe Html, "?{...}" do
|
|
5
|
+
|
|
6
|
+
def render(tpl, scope = {})
|
|
7
|
+
Html.render(tpl, scope, "")
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
[true, "Something", []].each do |test|
|
|
11
|
+
context "when #{test.inspect}" do
|
|
12
|
+
it 'renders the then block' do
|
|
13
|
+
render("?{test}{hello}", binding).should eq("hello")
|
|
14
|
+
end
|
|
15
|
+
it 'does not render the else block' do
|
|
16
|
+
render("?{test}{hello}{otherwise}", binding).should eq("hello")
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
[false, nil].each do |test|
|
|
22
|
+
context "when #{test.inspect}" do
|
|
23
|
+
it 'do not render the then block' do
|
|
24
|
+
render("?{test}{hello}", binding).should eq("")
|
|
25
|
+
end
|
|
26
|
+
it 'renders the else block if present' do
|
|
27
|
+
render("?{test}{hello}{otherwise}", binding).should eq("otherwise")
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'wlang/html'
|
|
3
|
+
module WLang
|
|
4
|
+
describe Html, '#{...}' do
|
|
5
|
+
|
|
6
|
+
def render(tpl, scope = {})
|
|
7
|
+
Html.render(tpl, scope, "")
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it 'updates the current scope' do
|
|
11
|
+
scope = {:who => "World"}
|
|
12
|
+
render('Hello #{scope}{${who}}', binding).should eq("Hello World")
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it 'does not follows empty arrays' do
|
|
16
|
+
scope = []
|
|
17
|
+
render('Hello #{scope}{${who}}', binding).should eq("Hello ")
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'wlang/html'
|
|
3
|
+
module WLang
|
|
4
|
+
describe Html, '/{...}' do
|
|
5
|
+
|
|
6
|
+
def render(tpl, scope = {})
|
|
7
|
+
Html.render(tpl, scope, "")
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it 'does not render anything' do
|
|
11
|
+
scope = {:who => "World"}
|
|
12
|
+
render('Hello /{ a comment } World!', binding).should eq("Hello World!")
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'wlang/html'
|
|
3
|
+
module WLang
|
|
4
|
+
describe Html, "*{...}" do
|
|
5
|
+
|
|
6
|
+
def render(tpl, scope = {})
|
|
7
|
+
Html.render(tpl, scope, "")
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
let(:numbers){ [1, 2, 3] }
|
|
11
|
+
|
|
12
|
+
it 'renders the main block for each element' do
|
|
13
|
+
render("*{numbers}{+{self}}", binding).should eq("123")
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it 'renders the between block if present' do
|
|
17
|
+
render("*{numbers}{+{self}}{,}", binding).should eq("1,2,3")
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it 'preserves spacing in the third block' do
|
|
21
|
+
pending{
|
|
22
|
+
render("*{numbers}{+{self}}{, }", binding).should eq("1, 2, 3")
|
|
23
|
+
}
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it 'renders nothing on empty collections' do
|
|
27
|
+
empty = []
|
|
28
|
+
render("*{empty}{+{self}}", binding).should eq("")
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it 'supports any enumerable' do
|
|
32
|
+
elms = (1..5)
|
|
33
|
+
render("*{elms}{+{self}}{,}", binding).should eq("1,2,3,4,5")
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'wlang/dummy'
|
|
3
|
+
module WLang
|
|
4
|
+
describe Dummy do
|
|
5
|
+
|
|
6
|
+
def dummy(tpl, scope = {})
|
|
7
|
+
Dummy.render(tpl, scope)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it 'returns the string when no tag at all' do
|
|
11
|
+
dummy("Hello world!").should eq("Hello world!")
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it 'does not evaluate tags' do
|
|
15
|
+
dummy("Hello ${who}!").should eq("Hello ${who}!")
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it 'does not eat other blocks either' do
|
|
19
|
+
dummy("Hello ${who}{ and more}!").should eq("Hello ${who}{ and more}!")
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it 'keep single braces in peace' do
|
|
23
|
+
dummy("Hello {who}!").should eq("Hello {who}!")
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
context "documentation" do
|
|
27
|
+
let(:d){
|
|
28
|
+
dialect do
|
|
29
|
+
def dollar(buf, fn)
|
|
30
|
+
buf << evaluate(fn)
|
|
31
|
+
end
|
|
32
|
+
def no_wlang(buf, fn)
|
|
33
|
+
buf << render(fn)
|
|
34
|
+
end
|
|
35
|
+
tag '$', :dollar
|
|
36
|
+
tag '%', [WLang::Dummy], :no_wlang
|
|
37
|
+
end
|
|
38
|
+
}
|
|
39
|
+
let(:tpl){%q{
|
|
40
|
+
Hello ${who}! This is wlang, a templating language which comes with
|
|
41
|
+
special tags such as %{${who}, +{who}, *{authors}{...}, etc.}
|
|
42
|
+
}.gsub(/^\s*/m,"").strip}
|
|
43
|
+
let(:expected){%q{
|
|
44
|
+
Hello world! This is wlang, a templating language which comes with
|
|
45
|
+
special tags such as ${who}, +{who}, *{authors}{...}, etc.
|
|
46
|
+
}.gsub(/^\s*/m,"").strip}
|
|
47
|
+
specify{ d.render(tpl, :who => "world").should eq(expected) }
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
end # describe Dummy
|
|
51
|
+
end # module WLang
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'wlang/command'
|
|
3
|
+
module WLang
|
|
4
|
+
describe "The examples", :hash_ordering => true do
|
|
5
|
+
|
|
6
|
+
(root_folder/:examples).glob("**/*.*").each do |ex_file|
|
|
7
|
+
next if ex_file.basename.to_s == "README.md"
|
|
8
|
+
describe "the example file #{ex_file}" do
|
|
9
|
+
|
|
10
|
+
let(:command) do
|
|
11
|
+
cmd = WLang::Command.new
|
|
12
|
+
def cmd.with_output(&proc); proc.call(""); end
|
|
13
|
+
cmd
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
let(:expected) do
|
|
17
|
+
Path.dir/:examples/ex_file.basename.sub_ext(".txt")
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it 'is instantiated as expected with autospacing' do
|
|
21
|
+
got = command.run ["--auto-spacing", ex_file]
|
|
22
|
+
got.should eq(expected.read)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'wlang/mustang'
|
|
3
|
+
module WLang
|
|
4
|
+
describe Mustang do
|
|
5
|
+
|
|
6
|
+
def m(tpl, scope = {}, buffer = "")
|
|
7
|
+
Mustang.render(tpl, scope, buffer)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
context '+{...} mimicing {{{ ... }}}' do
|
|
11
|
+
it "renders nothing on nil" do
|
|
12
|
+
m('Hello +{who}', :who => nil).should eq("Hello ")
|
|
13
|
+
end
|
|
14
|
+
it "renders nothing on unknown" do
|
|
15
|
+
m('Hello +{who}', {}).should eq("Hello ")
|
|
16
|
+
end
|
|
17
|
+
it "renders the variable if known" do
|
|
18
|
+
m('Hello +{who}', :who => "World").should eq("Hello World")
|
|
19
|
+
end
|
|
20
|
+
it "calls to_s on such variable" do
|
|
21
|
+
m('Hello +{who}', :who => 12).should eq("Hello 12")
|
|
22
|
+
end
|
|
23
|
+
it "does not escape html" do
|
|
24
|
+
m('Hello +{who}', :who => "<script>").should eq("Hello <script>")
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
context "${...} mimicing {{ ... }}" do
|
|
29
|
+
it "renders nothing on nil" do
|
|
30
|
+
m('Hello ${who}', :who => nil).should eq("Hello ")
|
|
31
|
+
end
|
|
32
|
+
it "renders nothing on unknown" do
|
|
33
|
+
m('Hello ${who}', {}).should eq("Hello ")
|
|
34
|
+
end
|
|
35
|
+
it "renders the variable if known" do
|
|
36
|
+
m('Hello ${who}', :who => "World").should eq("Hello World")
|
|
37
|
+
end
|
|
38
|
+
it "calls to_s on such variable" do
|
|
39
|
+
m('Hello ${who}', :who => 12).should eq("Hello 12")
|
|
40
|
+
end
|
|
41
|
+
it "does escape html" do
|
|
42
|
+
m('Hello ${who}', :who => "<script>").should eq("Hello <script>")
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
context '#{..1..}{..2..} mimicing {{#..1..}}..2..{{/..1..}} ' do
|
|
47
|
+
it 'skips the section on false' do
|
|
48
|
+
m('Hello #{present}{World}', :present => false).should eq("Hello ")
|
|
49
|
+
end
|
|
50
|
+
it 'skips the section on nil' do
|
|
51
|
+
m('Hello #{present}{World}', :present => nil).should eq("Hello ")
|
|
52
|
+
end
|
|
53
|
+
it 'skips the section on missing' do
|
|
54
|
+
m('Hello #{present}{World}').should eq("Hello ")
|
|
55
|
+
end
|
|
56
|
+
it 'skips the section on empty lists' do
|
|
57
|
+
m('Hello #{present}{World}', :present => []).should eq("Hello ")
|
|
58
|
+
end
|
|
59
|
+
it 'iterates on non-empty lists' do
|
|
60
|
+
repo = [{:name => "resque"},{:name => "hub"},{:name => "rip"}]
|
|
61
|
+
m('Hello #{repo}{<b>${name}</b>}', :repo => repo).should eq("Hello <b>resque</b><b>hub</b><b>rip</b>")
|
|
62
|
+
end
|
|
63
|
+
it 'iterates on ranges' do
|
|
64
|
+
m('Hello #{range}{.}', :range => 1..10).should eq("Hello ..........")
|
|
65
|
+
end
|
|
66
|
+
it 'passes the block to a lambda' do
|
|
67
|
+
wrapped = lambda{|fn| "<b>#{fn.call}</b>"}
|
|
68
|
+
scope = {:wrapped => wrapped, :name => "World"}
|
|
69
|
+
m('#{wrapped}{Hello ${name}}', scope).should eq("<b>Hello World</b>")
|
|
70
|
+
end
|
|
71
|
+
it 'use a Hash a a new scope' do
|
|
72
|
+
m('Hello #{person}{${name}}', :person => {:name => "World"}).should eq("Hello World")
|
|
73
|
+
end
|
|
74
|
+
it 'use a Struct a a new scope' do
|
|
75
|
+
person = Struct.new(:name).new("World")
|
|
76
|
+
m('Hello #{person}{${name}}', :person => person).should eq("Hello World")
|
|
77
|
+
end
|
|
78
|
+
it 'outputs frequently when iterating' do
|
|
79
|
+
m('#{range}{.}', {:range => 1..10}, []).should eq(Array.new(10, '.'))
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
context "^{..1..}{..2..} mimicing {{^..1..}}..2..{{/..1..}}" do
|
|
84
|
+
it 'renders the section on false' do
|
|
85
|
+
m('Hello ^{missing}{World}', :missing => false).should eq("Hello World")
|
|
86
|
+
end
|
|
87
|
+
it 'renders the section on nil' do
|
|
88
|
+
m('Hello ^{missing}{World}', :missing => nil).should eq("Hello World")
|
|
89
|
+
end
|
|
90
|
+
it 'renders the section on missing' do
|
|
91
|
+
m('Hello ^{missing}{World}').should eq("Hello World")
|
|
92
|
+
end
|
|
93
|
+
it 'renders the section on empty lists' do
|
|
94
|
+
m('Hello ^{missing}{World}', :missing => []).should eq("Hello World")
|
|
95
|
+
end
|
|
96
|
+
it 'does not iterate lists' do
|
|
97
|
+
repo = [{:name => "resque"},{:name => "hub"},{:name => "rip"}]
|
|
98
|
+
m('Hello ^{repo}{<b>${name}</b>}', :repo => repo).should eq("Hello ")
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
context "!{...} mimicing {{!...}}" do
|
|
103
|
+
it 'skips the section altogether' do
|
|
104
|
+
m('Hello !{this is a comment} world').should eq("Hello world")
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
context '>{...} mimicing {{>...}}' do
|
|
109
|
+
it 'renders the partial' do
|
|
110
|
+
scope = {:who => "<b>${name}</b>", :name => "World"}
|
|
111
|
+
m("Hello >{who}", scope).should eq("Hello <b>World</b>")
|
|
112
|
+
end
|
|
113
|
+
it 'supports a pre-compiled partial' do
|
|
114
|
+
scope = {:who => Mustang.compile("<b>${name}</b>"), :name => "World"}
|
|
115
|
+
m("Hello >{who}", scope).should eq("Hello <b>World</b>")
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
end # describe Mustang
|
|
120
|
+
end # module WLang
|