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
data/lib/wlang/wlang_command.rb
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
require 'wlang'
|
|
2
|
-
require 'wlang/wlang_command_options'
|
|
3
|
-
require 'wlang/dialects/standard_dialects'
|
|
4
|
-
module WLang
|
|
5
|
-
|
|
6
|
-
#
|
|
7
|
-
# Provides the _wlang_ commandline tool. See 'wlang --help' for documentation.
|
|
8
|
-
#
|
|
9
|
-
class WLangCommand
|
|
10
|
-
|
|
11
|
-
# Creates a commandline instance.
|
|
12
|
-
def initialize()
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
# Run _wlang_ commandline on specific arguments
|
|
16
|
-
def run(args)
|
|
17
|
-
# parse the options
|
|
18
|
-
options = Options.new.parse(args)
|
|
19
|
-
|
|
20
|
-
# get output buffer
|
|
21
|
-
buffer = STDOUT
|
|
22
|
-
if options.output_file
|
|
23
|
-
buffer = File.new(options.output_file, "w")
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
source = File.read(options.template_file)
|
|
27
|
-
dialect = options.template_dialect
|
|
28
|
-
braces = options.template_brace
|
|
29
|
-
context = options.context_object
|
|
30
|
-
context = {options.context_name => context} unless options.context_name.nil?
|
|
31
|
-
template = WLang::file_template(options.template_file, options.template_dialect, braces)
|
|
32
|
-
|
|
33
|
-
if options.verbosity>1
|
|
34
|
-
puts "Instantiating #{options.template_file}"
|
|
35
|
-
puts "Using dialect #{dialect}"
|
|
36
|
-
puts "Block delimiters are " << Template::BLOCK_SYMBOLS[braces].inspect
|
|
37
|
-
puts "Context is " << context.inspect
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
buffer << template.instantiate(context || {})
|
|
41
|
-
|
|
42
|
-
# Flush and close if needed
|
|
43
|
-
if File===buffer
|
|
44
|
-
buffer.flush
|
|
45
|
-
buffer.close
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
end # class WLang
|
|
50
|
-
|
|
51
|
-
end # module WLang
|
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
require 'optparse'
|
|
2
|
-
module WLang
|
|
3
|
-
class WLangCommand
|
|
4
|
-
|
|
5
|
-
#
|
|
6
|
-
# Options of the _wlang_ commandline
|
|
7
|
-
#
|
|
8
|
-
class Options
|
|
9
|
-
|
|
10
|
-
# Source template file
|
|
11
|
-
attr_reader :template_file
|
|
12
|
-
|
|
13
|
-
# Template dialect
|
|
14
|
-
attr_reader :template_dialect
|
|
15
|
-
|
|
16
|
-
# Which brace kind used in template (:braces, :brackes, :parentheses)
|
|
17
|
-
attr_reader :template_brace
|
|
18
|
-
|
|
19
|
-
# Context file
|
|
20
|
-
attr_reader :context_file
|
|
21
|
-
|
|
22
|
-
# Context object
|
|
23
|
-
attr_reader :context_object
|
|
24
|
-
|
|
25
|
-
# Context kind [:yaml, :ruby, :dsl]
|
|
26
|
-
attr_reader :context_kind
|
|
27
|
-
|
|
28
|
-
# Name of the context
|
|
29
|
-
attr_reader :context_name
|
|
30
|
-
|
|
31
|
-
# Output file
|
|
32
|
-
attr_reader :output_file
|
|
33
|
-
|
|
34
|
-
# Verbose mode?
|
|
35
|
-
attr_reader :verbosity
|
|
36
|
-
|
|
37
|
-
# Initializes the options with default values
|
|
38
|
-
def initialize
|
|
39
|
-
@verbosity = 0
|
|
40
|
-
@template_brace = :braces
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
#
|
|
44
|
-
# Parses commandline options provided as an array of Strings.
|
|
45
|
-
#
|
|
46
|
-
def parse(argv)
|
|
47
|
-
opts = OptionParser.new do |opt|
|
|
48
|
-
opt.program_name = File.basename $0
|
|
49
|
-
opt.version = WLang::VERSION
|
|
50
|
-
opt.release = nil
|
|
51
|
-
opt.summary_indent = ' ' * 4
|
|
52
|
-
banner = <<-EOF
|
|
53
|
-
# Usage #{opt.program_name} [options] template context-file
|
|
54
|
-
|
|
55
|
-
# Template is parsed as a wlang dialect (based on its extension by default) and
|
|
56
|
-
# instantiated through a given context file.
|
|
57
|
-
EOF
|
|
58
|
-
opt.banner = banner.gsub(/[ \t]+# /, "")
|
|
59
|
-
|
|
60
|
-
opt.separator nil
|
|
61
|
-
opt.separator "Options:"
|
|
62
|
-
|
|
63
|
-
opt.on("-d", "--dialect=DIALECT",
|
|
64
|
-
"Interpret source template as a given wlang dialect") do |value|
|
|
65
|
-
@template_dialect = value
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
opt.on("-m", "--methodize",
|
|
69
|
-
"Use methodization of hashes?") do |value|
|
|
70
|
-
Kernel.load('wlang/ext/hash_methodize.rb')
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
opt.on("-o", "--output=OUTPUT",
|
|
74
|
-
"Flush instantiation result in output file") do |value|
|
|
75
|
-
@output_file = value
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
opt.on("--brace=BRACE", ["brace", "parenthesis", "bracket"],
|
|
79
|
-
"Block delimiters used by the template file (braces, brackets, parentheses)") do |value|
|
|
80
|
-
# handle template brace
|
|
81
|
-
case value
|
|
82
|
-
when "brace", "braces", "{"
|
|
83
|
-
@template_brace = :braces
|
|
84
|
-
when "brackets", "bracket", "["
|
|
85
|
-
@template_brace = :brackets
|
|
86
|
-
when "parentheses", "parenthesis", "("
|
|
87
|
-
@template_brace = :parentheses
|
|
88
|
-
else
|
|
89
|
-
raise "Unknown brace kind #{brace}"
|
|
90
|
-
end
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
opt.on("--context-name=NAME",
|
|
94
|
-
"Name of the context object") do |value|
|
|
95
|
-
@context_name = value
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
opt.on("--context-kind=KIND", ["yaml", "ruby", "dsl"],
|
|
99
|
-
"Kind of context object (yaml, ruby, dsl)") do |value|
|
|
100
|
-
@context_kind = '.' + value
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
opt.on("--verbose", "-v",
|
|
104
|
-
"Display extra progress as we parse.") do |value|
|
|
105
|
-
@verbosity = 2
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
# No argument, shows at tail. This will print an options summary.
|
|
109
|
-
# Try it and see!
|
|
110
|
-
opt.on_tail("-h", "--help", "Show this message") do
|
|
111
|
-
puts opts
|
|
112
|
-
exit
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
# Another typical switch to print the version.
|
|
116
|
-
opt.on_tail("--version", "Show version") do
|
|
117
|
-
puts "wlang version " << WLang::VERSION << " (c) University of Louvain, Bernard & Louis Lambeau"
|
|
118
|
-
exit
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
opt.separator nil
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
# handle arguments
|
|
125
|
-
rest = opts.parse!(argv)
|
|
126
|
-
if rest.length<1 or rest.length>2
|
|
127
|
-
puts opts
|
|
128
|
-
exit
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
# handle template file
|
|
132
|
-
@template_file = File.expand_path(rest[0])
|
|
133
|
-
raise("File '#{@template_file}' not readable")\
|
|
134
|
-
unless File.file?(@template_file) and File.readable?(@template_file)
|
|
135
|
-
|
|
136
|
-
# handle context file
|
|
137
|
-
if rest.length==2
|
|
138
|
-
@context_file = rest[1]
|
|
139
|
-
raise("File '#{@context_file}' not readable")\
|
|
140
|
-
unless File.file?(@context_file) and File.readable?(@context_file)
|
|
141
|
-
end
|
|
142
|
-
|
|
143
|
-
# handle template dialect
|
|
144
|
-
unless @template_dialect
|
|
145
|
-
extname = File.extname(@template_file)
|
|
146
|
-
@template_dialect = WLang::FILE_EXTENSIONS[extname]
|
|
147
|
-
raise("No known dialect for file extension '#{extname}'\n"\
|
|
148
|
-
"Known extensions are: " << WLang::FILE_EXTENSIONS.keys.join(", "))\
|
|
149
|
-
if @template_dialect.nil?
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
# handle context object
|
|
153
|
-
if @context_file
|
|
154
|
-
@context_object = WLang::load_data(@context_file, @context_kind)
|
|
155
|
-
end
|
|
156
|
-
|
|
157
|
-
return self
|
|
158
|
-
end
|
|
159
|
-
|
|
160
|
-
end # class Options
|
|
161
|
-
|
|
162
|
-
end # class WLangCommand
|
|
163
|
-
end # module WLang
|
data/spec/basic_object.spec
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
require File.expand_path('../spec_helper', __FILE__)
|
|
2
|
-
describe "WLang's version of BasicObject" do
|
|
3
|
-
|
|
4
|
-
class A
|
|
5
|
-
# Methods that we keep
|
|
6
|
-
KEPT_METHODS = ["__send__", "__id__", "instance_eval", "initialize",
|
|
7
|
-
"object_id", "nil?", "singleton_method_added", "__clean_scope__",
|
|
8
|
-
"singleton_method_undefined"]
|
|
9
|
-
|
|
10
|
-
def self.__clean_scope__
|
|
11
|
-
# Removes all methods that are not needed to the class
|
|
12
|
-
(instance_methods + private_instance_methods).each do |m|
|
|
13
|
-
undef_method(m.to_s.to_sym) unless KEPT_METHODS.include?(m.to_s)
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
__clean_scope__
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
it "should not have kernel methods except certain" do
|
|
20
|
-
[:puts, :to_s, :hash].each do |sym|
|
|
21
|
-
begin
|
|
22
|
-
A.new.instance_eval{ __send__(sym, []) }
|
|
23
|
-
"Not pass here".should == ""
|
|
24
|
-
rescue NoMethodError
|
|
25
|
-
true.should == true
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
it "should not gain methods when requiring gems" do
|
|
31
|
-
Kernel.load(File.join(File.dirname(__FILE__),"global_extensions.rb"))
|
|
32
|
-
begin
|
|
33
|
-
A.new.__clean_scope__.instance_eval{ hello_world }
|
|
34
|
-
"Not pass here".should == ""
|
|
35
|
-
rescue NoMethodError
|
|
36
|
-
true.should == true
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
end
|
data/spec/coderay_dialect.spec
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
describe "WLang::Dialect#post_transform" do
|
|
2
|
-
|
|
3
|
-
let(:dialect){ WLang::Dialect.new("test", nil) }
|
|
4
|
-
subject{ dialect.apply_post_transform("hello") }
|
|
5
|
-
|
|
6
|
-
context "when a string has been installed" do
|
|
7
|
-
before{ dialect.post_transformer = "plain-text/upcase" }
|
|
8
|
-
it{ should == "HELLO" }
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
context "when a a has been installed" do
|
|
12
|
-
before{ dialect.post_transformer = lambda{|txt| "yes!#{txt}"} }
|
|
13
|
-
it{ should == "yes!hello" }
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
end
|
data/spec/global_extensions.rb
DELETED
data/spec/hash_scope.spec
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
require File.expand_path('../spec_helper', __FILE__)
|
|
2
|
-
require 'wlang/hash_scope'
|
|
3
|
-
|
|
4
|
-
describe ::WLang::HashScope do
|
|
5
|
-
|
|
6
|
-
# Builds a new scope instance, with an optional parent and
|
|
7
|
-
# initial hash
|
|
8
|
-
def newscope(pairing = nil, parent = nil)
|
|
9
|
-
::WLang::HashScope.new(pairing, parent)
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
it "should act as a basic hash at first glance" do
|
|
13
|
-
scope = newscope
|
|
14
|
-
scope.has_key?(:hello).should be_false
|
|
15
|
-
scope[:hello] = "world"
|
|
16
|
-
scope.has_key?(:hello).should be_true
|
|
17
|
-
scope[:hello].should == "world"
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
it "should support a parent" do
|
|
21
|
-
parent = newscope(:hello => "world", :mine => false)
|
|
22
|
-
child = newscope({:mine => true}, parent)
|
|
23
|
-
|
|
24
|
-
child.has_key?(:mine).should be_true
|
|
25
|
-
child.has_key?(:hello).should be_true
|
|
26
|
-
child[:mine].should be_true
|
|
27
|
-
child[:hello].should == "world"
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
it "should never touch its parent" do
|
|
31
|
-
parent = newscope(:hello => "world")
|
|
32
|
-
child = newscope(nil, parent)
|
|
33
|
-
child[:hello].should == "world"
|
|
34
|
-
child[:hello] = "none"
|
|
35
|
-
child[:hello].should == "none"
|
|
36
|
-
parent[:hello].should == "world"
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
it "should support branching easily" do
|
|
40
|
-
parent = newscope(:hello => "world")
|
|
41
|
-
parent.branch do |scope|
|
|
42
|
-
scope[:who] = "blambeau"
|
|
43
|
-
scope[:who].should == "blambeau"
|
|
44
|
-
scope[:hello].should == "world"
|
|
45
|
-
scope[:hello] = "none"
|
|
46
|
-
end
|
|
47
|
-
parent.has_key?(:who).should be_false
|
|
48
|
-
parent[:hello].should == "world"
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
it "should allow push/pop kind of branching" do
|
|
52
|
-
scope = newscope(:hello => "world")
|
|
53
|
-
scope = scope.branch
|
|
54
|
-
scope[:hello].should == "world"
|
|
55
|
-
scope[:hello] = "none"
|
|
56
|
-
scope[:hello].should == "none"
|
|
57
|
-
scope = scope.parent
|
|
58
|
-
scope[:hello].should == "world"
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
it "should respect scoping hierarchy" do
|
|
62
|
-
scope = newscope(:hello => "world")
|
|
63
|
-
child = newscope({}, scope)
|
|
64
|
-
child2 = newscope({}, child)
|
|
65
|
-
|
|
66
|
-
scope.parent.should be_nil
|
|
67
|
-
scope.root.should == scope
|
|
68
|
-
|
|
69
|
-
child.parent.should == scope
|
|
70
|
-
child.root.should == scope
|
|
71
|
-
|
|
72
|
-
child2.parent.should == child
|
|
73
|
-
child2.root.should == scope
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
end
|
data/spec/redcloth_dialect.spec
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
require File.expand_path('../spec_helper', __FILE__)
|
|
2
|
-
describe("WLang should support redcloth encoder") do
|
|
3
|
-
|
|
4
|
-
it("should support basic redcloth encoding") {
|
|
5
|
-
expected = "<h1>This is a title</h1>"
|
|
6
|
-
WLang::encode("h1. This is a title", "redcloth/xhtml").should == expected
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
it("should not perturbate template variables with global variables") {
|
|
10
|
-
# RedCloth installs a t global method (which becomes a private method
|
|
11
|
-
# of Object) which was perturbating the HostedLanguage::DSL class.
|
|
12
|
-
# This test acts as a non-regression one.
|
|
13
|
-
require 'rubygems'
|
|
14
|
-
require 'RedCloth'
|
|
15
|
-
"${t}".wlang(:t => 'wlang').should == 'wlang'
|
|
16
|
-
begin
|
|
17
|
-
"${t}".wlang()
|
|
18
|
-
true.should == false
|
|
19
|
-
rescue ::WLang::UndefinedVariableError
|
|
20
|
-
true.should == true
|
|
21
|
-
end
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
end
|
data/spec/test_all.rb
DELETED
data/spec/wlang.spec
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
require File.expand_path('../spec_helper', __FILE__)
|
|
2
|
-
describe ::WLang do
|
|
3
|
-
|
|
4
|
-
it("should allow easy use of encoders") {
|
|
5
|
-
WLang::encode('&', 'xhtml/entities-encoding').should == '&'
|
|
6
|
-
WLang::encode("O'Neil", 'ruby/single-quoting').should == "O\\'Neil"
|
|
7
|
-
WLang::encode('O"Neil', 'ruby/double-quoting').should == 'O\\"Neil'
|
|
8
|
-
WLang::encode("O'Neil", 'sql/single-quoting').should == "O\\'Neil"
|
|
9
|
-
WLang::encode("O'Neil", 'sql/sybase/single-quoting').should == "O''Neil"
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
it "should allow easy upper camel casing" do
|
|
13
|
-
WLang::encode('hello_world', 'plain-text/camel-case').should == "HelloWorld"
|
|
14
|
-
WLang::encode('hello_world', 'plain-text/camel').should == "HelloWorld"
|
|
15
|
-
WLang::encode('hello_world', 'plain-text/upper-camel').should == "HelloWorld"
|
|
16
|
-
WLang::encode('this is another example', 'plain-text/camel-case').should == "ThisIsAnotherExample"
|
|
17
|
-
WLang::encode("this is yet \n another example", 'plain-text/camel-case').should == "ThisIsYetAnotherExample"
|
|
18
|
-
|
|
19
|
-
WLang::encode('hello_world', 'plain-text/lower-camel').should == "helloWorld"
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
it "should allow easy ruby method casing" do
|
|
23
|
-
WLang::encode('helloWorld', 'ruby/method-case').should == "hello_world"
|
|
24
|
-
WLang::encode('HelloWorld', 'ruby/method-case').should == "hello_world"
|
|
25
|
-
WLang::encode('hello world', 'ruby/method-case').should == "hello_world"
|
|
26
|
-
WLang::encode('Hello123World', 'ruby/method-case').should == "hello123_world"
|
|
27
|
-
WLang::encode('HelloWorld_123', 'ruby/method-case').should == "hello_world_123"
|
|
28
|
-
WLang::encode('123_HelloWorld', 'ruby/method-case').should == "_123_hello_world"
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
it "should have correct examples in README.rdoc" do
|
|
32
|
-
expected = "Hello world!"
|
|
33
|
-
"Hello ${who}!".wlang(:who => 'world').should == expected
|
|
34
|
-
|
|
35
|
-
expected = "Hello cruel & world!"
|
|
36
|
-
"Hello ${who}!".wlang({:who => 'cruel & world'}, 'wlang/xhtml').should == expected
|
|
37
|
-
|
|
38
|
-
expected = "Hello blambeau, llambeau"
|
|
39
|
-
"Hello *{authors as a}{${a}}{, }".wlang(:authors => ['blambeau', 'llambeau']).should == expected
|
|
40
|
-
|
|
41
|
-
expected = "INSERT INTO people VALUES ('O\\'Neil')"
|
|
42
|
-
"INSERT INTO people VALUES ('{who}')".wlang({:who => "O'Neil"}, 'wlang/sql')
|
|
43
|
-
|
|
44
|
-
expected = "Hello wlang!"
|
|
45
|
-
tpl = "Hello $(${varname})!".wlang(:varname => 'who')
|
|
46
|
-
tpl.wlang({:who => 'wlang'}, 'wlang/active-string', :parentheses).should == expected
|
|
47
|
-
|
|
48
|
-
context = {:varname => 'who', :who => 'wlang'}
|
|
49
|
-
expected = "Hello wlang!"
|
|
50
|
-
"Hello ${${varname}}!".wlang(context).should == expected
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
end
|