wlang 0.8.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. data/LICENCE.rdoc +25 -0
  2. data/README.rdoc +111 -0
  3. data/bin/wlang +24 -0
  4. data/doc/specification/about.rdoc +61 -0
  5. data/doc/specification/dialects.wtpl +0 -0
  6. data/doc/specification/examples.rb +3 -0
  7. data/doc/specification/glossary.wtpl +14 -0
  8. data/doc/specification/hosting.rdoc +0 -0
  9. data/doc/specification/overview.rdoc +116 -0
  10. data/doc/specification/rulesets.wtpl +87 -0
  11. data/doc/specification/specification.css +52 -0
  12. data/doc/specification/specification.html +1361 -0
  13. data/doc/specification/specification.js +8 -0
  14. data/doc/specification/specification.wtpl +41 -0
  15. data/doc/specification/specification.yml +430 -0
  16. data/doc/specification/symbols.wtpl +16 -0
  17. data/lib/wlang.rb +186 -0
  18. data/lib/wlang/basic_object.rb +19 -0
  19. data/lib/wlang/dialect.rb +230 -0
  20. data/lib/wlang/dialect_dsl.rb +136 -0
  21. data/lib/wlang/dialect_loader.rb +69 -0
  22. data/lib/wlang/dialects/coderay_dialect.rb +35 -0
  23. data/lib/wlang/dialects/plain_text_dialect.rb +75 -0
  24. data/lib/wlang/dialects/rdoc_dialect.rb +33 -0
  25. data/lib/wlang/dialects/ruby_dialect.rb +35 -0
  26. data/lib/wlang/dialects/sql_dialect.rb +38 -0
  27. data/lib/wlang/dialects/standard_dialects.rb +113 -0
  28. data/lib/wlang/dialects/xhtml_dialect.rb +40 -0
  29. data/lib/wlang/encoder.rb +66 -0
  30. data/lib/wlang/encoder_set.rb +117 -0
  31. data/lib/wlang/errors.rb +37 -0
  32. data/lib/wlang/intelligent_buffer.rb +94 -0
  33. data/lib/wlang/parser.rb +251 -0
  34. data/lib/wlang/parser_context.rb +146 -0
  35. data/lib/wlang/ruby_extensions.rb +21 -0
  36. data/lib/wlang/rule.rb +66 -0
  37. data/lib/wlang/rule_set.rb +93 -0
  38. data/lib/wlang/rulesets/basic_ruleset.rb +75 -0
  39. data/lib/wlang/rulesets/buffering_ruleset.rb +103 -0
  40. data/lib/wlang/rulesets/context_ruleset.rb +115 -0
  41. data/lib/wlang/rulesets/encoding_ruleset.rb +73 -0
  42. data/lib/wlang/rulesets/imperative_ruleset.rb +132 -0
  43. data/lib/wlang/rulesets/ruleset_utils.rb +296 -0
  44. data/lib/wlang/template.rb +79 -0
  45. data/lib/wlang/wlang_command.rb +54 -0
  46. data/lib/wlang/wlang_command_options.rb +158 -0
  47. data/test/sandbox.rb +1 -0
  48. data/test/test_all.rb +8 -0
  49. data/test/wlang/anagram_bugs_test.rb +111 -0
  50. data/test/wlang/basic_ruleset_test.rb +52 -0
  51. data/test/wlang/buffering_ruleset_test.rb +102 -0
  52. data/test/wlang/buffering_template1.wtpl +1 -0
  53. data/test/wlang/buffering_template2.wtpl +1 -0
  54. data/test/wlang/buffering_template3.wtpl +1 -0
  55. data/test/wlang/buffering_template4.wtpl +1 -0
  56. data/test/wlang/buffering_template5.wtpl +1 -0
  57. data/test/wlang/context_ruleset_test.rb +32 -0
  58. data/test/wlang/data.rb +3 -0
  59. data/test/wlang/encoder_set_test.rb +42 -0
  60. data/test/wlang/imperative_ruleset_test.rb +107 -0
  61. data/test/wlang/intelligent_buffer_test.rb +194 -0
  62. data/test/wlang/othersymbols_test.rb +16 -0
  63. data/test/wlang/parser_context_test.rb +29 -0
  64. data/test/wlang/parser_test.rb +89 -0
  65. data/test/wlang/plain_text_dialect_test.rb +21 -0
  66. data/test/wlang/ruby_dialect_test.rb +100 -0
  67. data/test/wlang/ruby_expected.rb +3 -0
  68. data/test/wlang/ruby_template.wrb +3 -0
  69. data/test/wlang/ruleset_utils_test.rb +245 -0
  70. data/test/wlang/specification_examples_test.rb +52 -0
  71. data/test/wlang/test_utils.rb +25 -0
  72. data/test/wlang/wlang_test.rb +80 -0
  73. metadata +136 -0
@@ -0,0 +1,52 @@
1
+ require 'test/unit/testcase'
2
+ require 'wlang'
3
+ require 'wlang/dialects/standard_dialects'
4
+ require "yaml"
5
+
6
+ # Tests the example given in the specification
7
+ class WLang::SpecificationExamplesTest < Test::Unit::TestCase
8
+
9
+ # Tests all examples in the specification
10
+ def test_all_examples
11
+ context = {"name" => "O'Neil",
12
+ "author" => "blambeau",
13
+ "authors" => ["blambeau", "llambeau", "ancailliau"]}
14
+ spec_file = File.join(File.dirname(__FILE__),"../../doc/specification/specification.yml")
15
+ spec = YAML.load(File.open(spec_file))
16
+ spec["rulesets"].each do |ruleset|
17
+ next if ruleset["examples"].nil?
18
+ ruleset["examples"].each do |example|
19
+ dialect, expr, expected = example
20
+ dialect = "wlang/ruby" if dialect=="wlang/*"
21
+ #puts "assuming #{dialect} on #{expr}, gives #{expected}"
22
+ assert_equal(expected, WLang::instantiate(expr, context.dup, dialect))
23
+ end
24
+ end
25
+ end
26
+
27
+ # Tests that what is said is valid.
28
+ def test_what_is_said_in_specification
29
+ WLang::dialect("specification") do
30
+ rules WLang::RuleSet::Basic
31
+ rules WLang::RuleSet::Imperative
32
+ end
33
+ tests = [
34
+ ["*{authors as who}{${who}}{, }", "blambeau, llambeau, ancailliau"],
35
+ ["*{authors as who}{${who}} {, }", "blambeaullambeauancailliau {, }"],
36
+ ["*{authors as who} {${who}}{, }", nil]
37
+ ]
38
+ context = {"authors" => ["blambeau", "llambeau", "ancailliau"]}
39
+
40
+ tests.each do |test|
41
+ template, expected = test
42
+ if expected.nil?
43
+ assert_raise WLang::ParseError do
44
+ assert_equal(expected, template.wlang(context, "specification"))
45
+ end
46
+ else
47
+ assert_equal(expected, template.wlang(context, "specification"))
48
+ end
49
+ end
50
+ end
51
+
52
+ end
@@ -0,0 +1,25 @@
1
+ require 'wlang/template'
2
+
3
+ #
4
+ # Provides some test utilities
5
+ #
6
+ module WLang::TestUtils
7
+
8
+ # Returns a relative file
9
+ def relative_file(name, from=__FILE__)
10
+ File.join(File.dirname(from), name)
11
+ end
12
+
13
+ # Returns a relative file
14
+ def read_relative_file(name, from=__FILE__)
15
+ File.read(File.join(File.dirname(from), name))
16
+ end
17
+
18
+ # Factors a template and fakes its source-file as from
19
+ def relative_template(src, dialect, from=__FILE__)
20
+ template = WLang::Template.new(src, dialect)
21
+ template.source_file = from
22
+ template
23
+ end
24
+
25
+ end
@@ -0,0 +1,80 @@
1
+ require 'test/unit/testcase'
2
+ require 'wlang'
3
+ require 'wlang/dialects/standard_dialects'
4
+
5
+ module WLang
6
+
7
+ class WLangTest < Test::Unit::TestCase
8
+
9
+ # Tests that dialects are recognized
10
+ def test_dialect
11
+ assert_not_nil(WLang::dialect("plain-text"))
12
+ assert_not_nil(WLang::dialect("wlang"))
13
+ assert_not_nil(WLang::dialect("wlang/dummy"))
14
+ assert_not_nil(WLang::dialect("wlang/active-string"))
15
+ assert_not_nil(WLang::dialect("wlang/ruby"))
16
+ assert_not_nil(WLang::dialect("wlang/xhtml"))
17
+ assert_nil(WLang::dialect("wlang/plain-tet"))
18
+ assert_equal(true, WLang::dialect("wlang/dummy").send(:is_built?))
19
+ assert_equal(true, WLang::dialect("wlang/xhtml").send(:is_built?))
20
+ end
21
+
22
+ # Tests that encoders are recognized
23
+ def test_encoder
24
+ assert_not_nil(WLang::encoder("plain-text/upcase"))
25
+ assert_not_nil(WLang::encoder("plain-text/downcase"))
26
+ assert_not_nil(WLang::encoder("plain-text/capitalize"))
27
+ assert_nil(WLang::encoder("plain-text/capize"))
28
+ end
29
+
30
+ # Tests the regular expression for dialect names
31
+ def test_dialect_name_regexp
32
+ assert_not_nil(WLang::QUALIFIED_DIALECT_NAME_REGEXP =~ "wlang")
33
+ assert_not_nil(WLang::QUALIFIED_DIALECT_NAME_REGEXP =~ "wlang/plain-text")
34
+ assert_not_nil(WLang::QUALIFIED_DIALECT_NAME_REGEXP =~ "wlang/xhtml")
35
+ assert_not_nil(WLang::QUALIFIED_DIALECT_NAME_REGEXP =~ "wlang/sql")
36
+ assert_not_nil(WLang::QUALIFIED_DIALECT_NAME_REGEXP =~ "wlang/sql/sybase")
37
+ assert_nil(WLang::QUALIFIED_DIALECT_NAME_REGEXP =~ "WLang")
38
+ assert_nil(WLang::QUALIFIED_DIALECT_NAME_REGEXP =~ "WLang/sql")
39
+ assert_nil(WLang::QUALIFIED_DIALECT_NAME_REGEXP =~ "wlang/sql/ sybase")
40
+ end
41
+
42
+ # Tests some classical uses of dialect names
43
+ def test_dialect_name_classical_use
44
+ assert_equal(1, "wlang".split('/').length)
45
+ assert_equal(["wlang"], "wlang".split('/'))
46
+ assert_equal("wlang", "wlang".split('/')[0])
47
+ assert_equal(3, "wlang/sql/sybase".split('/').length)
48
+ assert_equal(["wlang","sql","sybase"], "wlang/sql/sybase".split('/'))
49
+ assert_equal(["sql","sybase"], "wlang/sql/sybase".split('/')[1..-1])
50
+ end
51
+
52
+ # Tests contribution on the String class
53
+ def test_wlang_on_string
54
+ expected = "HELLO blambeau !!"
55
+ result = "^{plain-text/upcase}{hello} ${name} !!".wlang("name" => "blambeau")
56
+ assert_equal(expected, result);
57
+ end
58
+
59
+ # Tests that parsing something with %{wlang/dummy}{...} does not interpret
60
+ # anything.
61
+ def test_wlang_dummy_does_not_interpret_anything
62
+ template = "${name}"
63
+ assert_equal("${name}", WLang::instantiate(template, nil, "wlang/dummy"))
64
+
65
+ template = "%{wlang/dummy}{${name}}"
66
+ assert_equal("${name}", WLang::instantiate(template, nil, "wlang/xhtml"))
67
+
68
+ # assert_raise do
69
+ # template = "!{raise('raised')}"
70
+ # WLang::instantiate(template, nil, "wlang/xhtml")
71
+ # end
72
+ assert_nothing_raised do
73
+ template = "%{wlang/dummy}{!{raise 'Not raised'}}"
74
+ WLang::instantiate(template, nil, "wlang/xhtml")
75
+ end
76
+ end
77
+
78
+ end # class WLangTest
79
+
80
+ end # module WLang
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wlang
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.8.4
5
+ platform: ruby
6
+ authors:
7
+ - Bernard Lambeau
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-01-14 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Simple and powerful code generator and template engine.
17
+ email: blambeau@gmail.com
18
+ executables:
19
+ - wlang
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.rdoc
24
+ - LICENCE.rdoc
25
+ files:
26
+ - lib/wlang
27
+ - lib/wlang/basic_object.rb
28
+ - lib/wlang/dialect.rb
29
+ - lib/wlang/dialect_dsl.rb
30
+ - lib/wlang/dialect_loader.rb
31
+ - lib/wlang/dialects
32
+ - lib/wlang/dialects/coderay_dialect.rb
33
+ - lib/wlang/dialects/plain_text_dialect.rb
34
+ - lib/wlang/dialects/rdoc_dialect.rb
35
+ - lib/wlang/dialects/ruby_dialect.rb
36
+ - lib/wlang/dialects/sql_dialect.rb
37
+ - lib/wlang/dialects/standard_dialects.rb
38
+ - lib/wlang/dialects/xhtml_dialect.rb
39
+ - lib/wlang/encoder.rb
40
+ - lib/wlang/encoder_set.rb
41
+ - lib/wlang/errors.rb
42
+ - lib/wlang/intelligent_buffer.rb
43
+ - lib/wlang/parser.rb
44
+ - lib/wlang/parser_context.rb
45
+ - lib/wlang/ruby_extensions.rb
46
+ - lib/wlang/rule.rb
47
+ - lib/wlang/rule_set.rb
48
+ - lib/wlang/rulesets
49
+ - lib/wlang/rulesets/basic_ruleset.rb
50
+ - lib/wlang/rulesets/buffering_ruleset.rb
51
+ - lib/wlang/rulesets/context_ruleset.rb
52
+ - lib/wlang/rulesets/encoding_ruleset.rb
53
+ - lib/wlang/rulesets/imperative_ruleset.rb
54
+ - lib/wlang/rulesets/ruleset_utils.rb
55
+ - lib/wlang/template.rb
56
+ - lib/wlang/wlang_command.rb
57
+ - lib/wlang/wlang_command_options.rb
58
+ - lib/wlang.rb
59
+ - test/sandbox.rb
60
+ - test/test_all.rb
61
+ - test/wlang
62
+ - test/wlang/anagram_bugs_test.rb
63
+ - test/wlang/basic_ruleset_test.rb
64
+ - test/wlang/buffering_ruleset_output
65
+ - test/wlang/buffering_ruleset_output/subdir
66
+ - test/wlang/buffering_ruleset_output/subdir/subdir
67
+ - test/wlang/buffering_ruleset_test.rb
68
+ - test/wlang/buffering_template1.wtpl
69
+ - test/wlang/buffering_template2.wtpl
70
+ - test/wlang/buffering_template3.wtpl
71
+ - test/wlang/buffering_template4.wtpl
72
+ - test/wlang/buffering_template5.wtpl
73
+ - test/wlang/context_ruleset_test.rb
74
+ - test/wlang/data.rb
75
+ - test/wlang/encoder_set_test.rb
76
+ - test/wlang/imperative_ruleset_test.rb
77
+ - test/wlang/intelligent_buffer_test.rb
78
+ - test/wlang/othersymbols_test.rb
79
+ - test/wlang/parser_context_test.rb
80
+ - test/wlang/parser_test.rb
81
+ - test/wlang/plain_text_dialect_test.rb
82
+ - test/wlang/ruby_dialect_test.rb
83
+ - test/wlang/ruby_expected.rb
84
+ - test/wlang/ruby_template.wrb
85
+ - test/wlang/ruleset_utils_test.rb
86
+ - test/wlang/specification_examples_test.rb
87
+ - test/wlang/test_utils.rb
88
+ - test/wlang/wlang_test.rb
89
+ - bin/wlang
90
+ - doc/specification/about.rdoc
91
+ - doc/specification/dialects.wtpl
92
+ - doc/specification/examples.rb
93
+ - doc/specification/glossary.wtpl
94
+ - doc/specification/hosting.rdoc
95
+ - doc/specification/overview.rdoc
96
+ - doc/specification/rulesets.wtpl
97
+ - doc/specification/specification.css
98
+ - doc/specification/specification.html
99
+ - doc/specification/specification.js
100
+ - doc/specification/specification.wtpl
101
+ - doc/specification/specification.yml
102
+ - doc/specification/symbols.wtpl
103
+ - README.rdoc
104
+ - LICENCE.rdoc
105
+ has_rdoc: true
106
+ homepage: http://blambeau.github.com/wlang/
107
+ post_install_message:
108
+ rdoc_options:
109
+ - --title
110
+ - WLang - Code generator and Template engine
111
+ - --main
112
+ - README.rdoc
113
+ - --line-numbers
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: "0"
121
+ version:
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: "0"
127
+ version:
128
+ requirements: []
129
+
130
+ rubyforge_project:
131
+ rubygems_version: 1.3.1
132
+ signing_key:
133
+ specification_version: 2
134
+ summary: WLang code generator
135
+ test_files: []
136
+