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.
- 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
@@ -1,16 +0,0 @@
|
|
1
|
-
<table class="symbols">
|
2
|
-
<tr>
|
3
|
-
<th class="name">name</th>
|
4
|
-
<th class="symbol">symbol</th>
|
5
|
-
<th class="meaning">meaning</th>
|
6
|
-
<th class="remark">remark</th>
|
7
|
-
</tr>
|
8
|
-
*{spec.symbols as s}{
|
9
|
-
<tr>
|
10
|
-
<td><em>${s.name}</em></td>
|
11
|
-
<td>${s.symbol}</td>
|
12
|
-
<td>${s.meaning}</td>
|
13
|
-
<td>${s.remark}</td>
|
14
|
-
</tr>
|
15
|
-
}
|
16
|
-
</table>
|
data/lib/wlang/dialect_dsl.rb
DELETED
@@ -1,141 +0,0 @@
|
|
1
|
-
module WLang
|
2
|
-
class Dialect
|
3
|
-
|
4
|
-
#
|
5
|
-
# Installs the Domain Specific Language allowing to create new dialects easily.
|
6
|
-
# Below is a self-explaining example on how to use it.
|
7
|
-
#
|
8
|
-
# #
|
9
|
-
# # Starts a new _wlang_ dialect that will have children.
|
10
|
-
# #
|
11
|
-
# WLang::dialect("wlang") do
|
12
|
-
#
|
13
|
-
# #
|
14
|
-
# # Starts a _wlang/xhtml_ dialect that will be attached to .wtpl and .whtml
|
15
|
-
# # file extensions.
|
16
|
-
# #
|
17
|
-
# dialect("xhtml", ".wtpl", ".whtm") do
|
18
|
-
#
|
19
|
-
# # If your dialect needs external gems or files, use ruby_require instead
|
20
|
-
# # of built-in require: it will allow avoiding all users to have required
|
21
|
-
# # dependencies for dialects they don't use.
|
22
|
-
# ruby_require "somegem", "wlang/rulesets/basic_ruleset", "wlang/dialects/coderay_dialect" do
|
23
|
-
#
|
24
|
-
# # RuleSet defined as Ruby modules can be installed using _rules_.
|
25
|
-
# # Here: we automatically add the standard Basic ruleset to our dialect.
|
26
|
-
# rules WLang::RuleSet::Basic
|
27
|
-
#
|
28
|
-
# # You can also install inline rules if they are not designed to be
|
29
|
-
# # reusable by others.
|
30
|
-
# # Here, we add a #{...} rule that replaces all spaces by '#' symbols
|
31
|
-
# # For rule implementation, see Rule class.
|
32
|
-
# rule "#" do |parser, offset|
|
33
|
-
# text, reached = parser.parse(offset)
|
34
|
-
# text = text.gsub(/\s/, '#')
|
35
|
-
# [text, reached]
|
36
|
-
# end
|
37
|
-
#
|
38
|
-
# # Encoders can be installed the same way(s)
|
39
|
-
# # Here: we install all coderay encoders defined in a module
|
40
|
-
# encoders WLang::EncoderSet::CodeRay
|
41
|
-
#
|
42
|
-
# # And inline encoders can be installed as well
|
43
|
-
# # Encoder below will be allowed as ^{wlang/xhtml/upcase}{...} for example
|
44
|
-
# encoder 'upcase' do |src, options|
|
45
|
-
# src.upcase
|
46
|
-
# end
|
47
|
-
#
|
48
|
-
# end # ruby_require
|
49
|
-
#
|
50
|
-
# end # wlang/xhtml dialect
|
51
|
-
#
|
52
|
-
# end # wlang dialect
|
53
|
-
#
|
54
|
-
class DSL
|
55
|
-
|
56
|
-
# Initializes dsl with a real dialect instance
|
57
|
-
def initialize(dialect)
|
58
|
-
raise(ArgumentError, "Dialect expected") unless WLang::Dialect===dialect
|
59
|
-
@dialect = dialect
|
60
|
-
end
|
61
|
-
|
62
|
-
#
|
63
|
-
# Handles dialect dependencies: all _src_ dependencies will be correctly loaded
|
64
|
-
# at dialect building time (dialect are lazy loaded to avoid having all users
|
65
|
-
# to have all dependencies of standard dialects).
|
66
|
-
#
|
67
|
-
# This method should always be used instead of _require_. It takes a block that
|
68
|
-
# will be executed at building-time. Any code with dependency usage should be
|
69
|
-
# part of the block !
|
70
|
-
#
|
71
|
-
def ruby_require(*src) end
|
72
|
-
|
73
|
-
#
|
74
|
-
# Starts definition of a sub-dialect of the current one. _name_ is not allowed
|
75
|
-
# to be a qualified name. _extensions_ allows wlang to automatically infer
|
76
|
-
# dialects used by template files. A block is expected and should contain
|
77
|
-
# sub-dialect installation.
|
78
|
-
#
|
79
|
-
def dialect(name, *extensions, &block)
|
80
|
-
child = WLang::Dialect.new(name, @dialect, &block)
|
81
|
-
extensions.each do |ext|
|
82
|
-
ext = ('.' << ext) unless ext[0,1]=='.'
|
83
|
-
WLang::FILE_EXTENSIONS[ext] = child.qualified_name
|
84
|
-
end
|
85
|
-
@dialect.add_child_dialect(name, child)
|
86
|
-
end
|
87
|
-
|
88
|
-
#
|
89
|
-
# Sets a transformer to use at end of generation time.
|
90
|
-
#
|
91
|
-
def post_transform(transformer = nil, &block) end
|
92
|
-
|
93
|
-
#
|
94
|
-
# Adds a dialect encoder under _name_. Encoder's code is provided by the block.
|
95
|
-
# This block should always take <tt>|src, options|</tt> arguments: _src_ is
|
96
|
-
# the string to encode, _options_ is a Hash instance containing additional
|
97
|
-
# encoding options.
|
98
|
-
#
|
99
|
-
def encoder(name, &block) end
|
100
|
-
|
101
|
-
#
|
102
|
-
# Adds reusable encoders defined in a Ruby module. _mod_ must be a Module instance.
|
103
|
-
# If _pairs_ is ommitted (nil), all encoders of the module are added, under their
|
104
|
-
# standard names (see DEFAULT_ENCODERS under WLang::EncoderSet::XHtml for example).
|
105
|
-
# Otherwise, _pairs_ is expected to be a Hash providing a mapping between encoder
|
106
|
-
# names and _mod_ methods (whose names are given by ruby symbols).
|
107
|
-
#
|
108
|
-
def encoders(mod, pairs=nil) end
|
109
|
-
|
110
|
-
#
|
111
|
-
# Maps an inline rule with some tag symbols. _symbol_ must be ASCII symbols
|
112
|
-
# allowed by the wlang specification. The rule implementation is provided by
|
113
|
-
# the block. see Rule class about rule implementation.
|
114
|
-
#
|
115
|
-
def rule(symbol, &block) end
|
116
|
-
|
117
|
-
#
|
118
|
-
# Adds reusable rules defined in a Ruby module. _mod_ must be a Module instance.
|
119
|
-
# If _pairs_ is ommitted (nil), all rules of the module are added, under their
|
120
|
-
# standard tag symbols (see DEFAULT_RULESET under WLang::RuleSet::Basic for example).
|
121
|
-
# Otherwise, _pairs_ is expected to be a Hash providing a mapping between tag
|
122
|
-
# symbols and _mod_ methods (whose names are given by ruby symbols).
|
123
|
-
#
|
124
|
-
def rules(mod, pairs=nil) end
|
125
|
-
|
126
|
-
#
|
127
|
-
# Request wlang to associate _args_ files extensions with this dialect. File
|
128
|
-
# extensions may also be installed at construction (see dialect).
|
129
|
-
#
|
130
|
-
def extensions(*args)
|
131
|
-
args.each do |ext|
|
132
|
-
ext = ('.' << ext) unless ext[0,1]=='.'
|
133
|
-
WLang::FILE_EXTENSIONS[ext] = @dialect.qualified_name
|
134
|
-
end
|
135
|
-
end
|
136
|
-
alias :extension :extensions
|
137
|
-
|
138
|
-
end # class DSL
|
139
|
-
|
140
|
-
end
|
141
|
-
end
|
data/lib/wlang/dialect_loader.rb
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
module WLang
|
2
|
-
class Dialect
|
3
|
-
|
4
|
-
#
|
5
|
-
# Implements the same API as WLang::Dialect::DSL but used for effective loading.
|
6
|
-
# This class exists because of the lazy loading design pattern implemented by
|
7
|
-
# wlang on dialects. It does not convey any user-centric information.
|
8
|
-
#
|
9
|
-
class Loader
|
10
|
-
|
11
|
-
# Initializes dsl with a real dialect instance
|
12
|
-
def initialize(dialect)
|
13
|
-
@dialect = dialect
|
14
|
-
end
|
15
|
-
|
16
|
-
# See WLang::Dialect::DSL#ruby_require
|
17
|
-
def ruby_require(*src)
|
18
|
-
src.each do |s|
|
19
|
-
begin
|
20
|
-
require "rubygems" unless "wlang"==s[0,5]
|
21
|
-
rescue LoadError => ex
|
22
|
-
STDERR.puts "= Error, wlang depends on 'rubygems'\n"\
|
23
|
-
"= Please install it (methods differs from system, in debian : 'apt-get install rubygems')\n"\
|
24
|
-
"= Exception raised : '#{ex.message}'"
|
25
|
-
exit -1
|
26
|
-
end
|
27
|
-
begin
|
28
|
-
require s
|
29
|
-
rescue LoadError => ex
|
30
|
-
STDERR.puts "= Error in dialect '#{@dialect}'\n"\
|
31
|
-
"= This dialect depends on gem or file '#{s}' (try: 'gem install #{s}')\n"\
|
32
|
-
"= Exception raised : '#{ex.message}'"
|
33
|
-
exit -1
|
34
|
-
end
|
35
|
-
end
|
36
|
-
yield if block_given?
|
37
|
-
end
|
38
|
-
|
39
|
-
# See WLang::Dialect::DSL#dialect
|
40
|
-
def dialect(name, *extensions, &block) end
|
41
|
-
|
42
|
-
# See WLang::Dialect::DSL::post_transformer
|
43
|
-
def post_transform(transformer = nil, &block)
|
44
|
-
@dialect.post_transformer = (transformer || block)
|
45
|
-
end
|
46
|
-
|
47
|
-
# See WLang::Dialect::DSL#encoder
|
48
|
-
def encoder(name, &block)
|
49
|
-
@dialect.add_encoder(name, &block)
|
50
|
-
end
|
51
|
-
|
52
|
-
# See WLang::Dialect::DSL#encoders
|
53
|
-
def encoders(mod, pairs=nil)
|
54
|
-
@dialect.add_encoders(mod, pairs)
|
55
|
-
end
|
56
|
-
|
57
|
-
# See WLang::Dialect::DSL#rule
|
58
|
-
def rule(symbol, &block)
|
59
|
-
@dialect.add_rule(symbol, &block)
|
60
|
-
end
|
61
|
-
|
62
|
-
# See WLang::Dialect::DSL#rules
|
63
|
-
def rules(mod, pairs=nil)
|
64
|
-
@dialect.add_rules(mod, pairs)
|
65
|
-
end
|
66
|
-
|
67
|
-
# See WLang::Dialect::DSL#extensions
|
68
|
-
def extensions(*args) end
|
69
|
-
alias :extension :extensions
|
70
|
-
|
71
|
-
end # class Loader
|
72
|
-
|
73
|
-
end
|
74
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
module WLang
|
3
|
-
class EncoderSet
|
4
|
-
module BlueClothEncoders
|
5
|
-
|
6
|
-
# Default encoders
|
7
|
-
DEFAULT_ENCODERS = {"xhtml" => :xhtml_encoding}
|
8
|
-
|
9
|
-
# RDoc encoding
|
10
|
-
def self.xhtml_encoding(src, options)
|
11
|
-
BlueCloth.new(src).to_html
|
12
|
-
end
|
13
|
-
|
14
|
-
end # BlueClothEncoders
|
15
|
-
end # module EncoderSet
|
16
|
-
end # module WLang
|
@@ -1,45 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'coderay'
|
3
|
-
module WLang
|
4
|
-
class EncoderSet
|
5
|
-
|
6
|
-
#
|
7
|
-
# Allows coderay highlighter to be used as encoder. When using standard dialects,
|
8
|
-
# these encoders are installed under <tt>xhtml/coderay/ruby</tt>,
|
9
|
-
# <tt>xhtml/coderay/html</tt>, etc. qualified names.
|
10
|
-
#
|
11
|
-
# Available languages are: java, ruby, html, yaml.
|
12
|
-
#
|
13
|
-
module CodeRayEncoderSet
|
14
|
-
|
15
|
-
# Coderay recognized formats
|
16
|
-
RECOGNIZED = ["java", "ruby", "html", "yaml", "sql", "css", "javascript", "json", "php", "xml"]
|
17
|
-
|
18
|
-
# Default encoders
|
19
|
-
DEFAULT_ENCODERS = {}
|
20
|
-
RECOGNIZED.each{|f| DEFAULT_ENCODERS[f] = f.to_sym}
|
21
|
-
|
22
|
-
# Upcase encoding
|
23
|
-
def self.coderay(src, options)
|
24
|
-
/([a-z]+)$/ =~ options['_encoder_']
|
25
|
-
encoder = $1.to_sym
|
26
|
-
tokens = CodeRay.scan src, encoder
|
27
|
-
highlighted = tokens.html({
|
28
|
-
:wrap => :div,
|
29
|
-
:css => :class}
|
30
|
-
)
|
31
|
-
return highlighted
|
32
|
-
end
|
33
|
-
|
34
|
-
RECOGNIZED.each{|f|
|
35
|
-
module_eval <<-EOF
|
36
|
-
def self.#{f}(src, options)
|
37
|
-
WLang::EncoderSet::CodeRayEncoderSet.coderay(src, options.merge('_encoder_' => #{f.inspect}))
|
38
|
-
end
|
39
|
-
EOF
|
40
|
-
}
|
41
|
-
|
42
|
-
end # module CodeRay
|
43
|
-
|
44
|
-
end
|
45
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
module WLang
|
2
|
-
class EncoderSet
|
3
|
-
|
4
|
-
# Encoders for ruby
|
5
|
-
module Hosted
|
6
|
-
|
7
|
-
# Default encoders
|
8
|
-
DEFAULT_ENCODERS = {"main-encoding" => :main_encoding,
|
9
|
-
"single-quoting" => :single_quoting,
|
10
|
-
"double-quoting" => :double_quoting,
|
11
|
-
"regex-escaping" => :regex_escaping,
|
12
|
-
"method-case" => :method_case}
|
13
|
-
|
14
|
-
# No-op encoding here
|
15
|
-
def self.main_encoding(src, options); src; end
|
16
|
-
|
17
|
-
# Single-quoting encoding
|
18
|
-
def self.single_quoting(src, options); src.gsub(/([^\\])'/,%q{\1\\\'}); end
|
19
|
-
|
20
|
-
# Double-quoting encoding
|
21
|
-
def self.double_quoting(src, options); src.gsub('"','\"'); end
|
22
|
-
|
23
|
-
# Regexp-escaping encoding
|
24
|
-
def self.regex_escaping(src, options); Regexp.escape(src); end
|
25
|
-
|
26
|
-
# Converts any source to a typical ruby method name
|
27
|
-
def self.method_case(src, options)
|
28
|
-
src.strip.gsub(/[^a-zA-Z0-9\s]/," ").
|
29
|
-
gsub(/([A-Z])/){ " " + $1.downcase}.
|
30
|
-
strip.
|
31
|
-
gsub(/^([^a-z])/){ "_" + $1 }.
|
32
|
-
gsub(/\s+/){"_"}
|
33
|
-
end
|
34
|
-
|
35
|
-
|
36
|
-
end # module Hosted
|
37
|
-
|
38
|
-
end
|
39
|
-
class RuleSet
|
40
|
-
|
41
|
-
# Defines rulset of the wlang/ruby dialect
|
42
|
-
module Hosted
|
43
|
-
|
44
|
-
# Default mapping between tag symbols and methods
|
45
|
-
DEFAULT_RULESET = {}
|
46
|
-
|
47
|
-
end # module Hosted
|
48
|
-
|
49
|
-
end # class RuleSet
|
50
|
-
end # module WLang
|
@@ -1,69 +0,0 @@
|
|
1
|
-
module WLang
|
2
|
-
class EncoderSet
|
3
|
-
|
4
|
-
# Defines encoders of the plain-text dialect
|
5
|
-
module PlainText
|
6
|
-
|
7
|
-
# Default encoders
|
8
|
-
DEFAULT_ENCODERS = {"upcase" => :upcase,
|
9
|
-
"downcase" => :downcase,
|
10
|
-
"capitalize" => :capitalize,
|
11
|
-
"camel" => :camel_case,
|
12
|
-
"camel-case" => :camel_case,
|
13
|
-
"upper-camel" => :camel_case,
|
14
|
-
"lower-camel" => :lower_camel_case}
|
15
|
-
|
16
|
-
# Upcase encoding
|
17
|
-
def self.upcase(src, options); src.upcase; end
|
18
|
-
|
19
|
-
# Downcase encoding
|
20
|
-
def self.downcase(src, options); src.downcase; end
|
21
|
-
|
22
|
-
# Capitalize encoding
|
23
|
-
def self.capitalize(src, options); src.capitalize; end
|
24
|
-
|
25
|
-
# Converts a string as CamelCase
|
26
|
-
def self.camel_case(src, options)
|
27
|
-
src.gsub!(/[^a-zA-Z\s]/," ")
|
28
|
-
src = " " + src.split.join(" ")
|
29
|
-
src.gsub!(/ (.)/) { $1.upcase }
|
30
|
-
end
|
31
|
-
|
32
|
-
# Converts a string to lower camelCase
|
33
|
-
def self.lower_camel_case(src, options)
|
34
|
-
camel_case(src, options).gsub(/^([A-Z])/){ $1.downcase }
|
35
|
-
end
|
36
|
-
|
37
|
-
end # module PlainText
|
38
|
-
|
39
|
-
end
|
40
|
-
class RuleSet
|
41
|
-
|
42
|
-
# Defines rulset of the plain-text dialect
|
43
|
-
module PlainText
|
44
|
-
|
45
|
-
# Default mapping between tag symbols and methods
|
46
|
-
DEFAULT_RULESET = {'+' => :upcase, '-' => :downcase}
|
47
|
-
|
48
|
-
# Upcase rule as <tt>+{wlang/hosted}</tt>
|
49
|
-
def self.upcase(parser, offset)
|
50
|
-
expression, reached = parser.parse(offset, "wlang/hosted")
|
51
|
-
value = parser.evaluate(expression)
|
52
|
-
value = value.nil? ? "" : value.to_s
|
53
|
-
result = WLang::EncoderSet::PlainText.upcase(value)
|
54
|
-
[result, reached]
|
55
|
-
end
|
56
|
-
|
57
|
-
# Downcase rule as <tt>-{wlang/hosted}</tt>
|
58
|
-
def self.downcase(parser, offset)
|
59
|
-
expression, reached = parser.parse(offset, "wlang/hosted")
|
60
|
-
value = parser.evaluate(expression)
|
61
|
-
value = value.nil? ? "" : value.to_s
|
62
|
-
result = EncoderSet::PlainText.downcase(value)
|
63
|
-
[result, reached]
|
64
|
-
end
|
65
|
-
|
66
|
-
end # module PlainText
|
67
|
-
|
68
|
-
end
|
69
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'rdoc/markup/to_html'
|
3
|
-
module WLang
|
4
|
-
class EncoderSet
|
5
|
-
|
6
|
-
# Provides the rdoc encoder
|
7
|
-
module RDocEncoders
|
8
|
-
|
9
|
-
# Default encoders
|
10
|
-
DEFAULT_ENCODERS = {"html" => :rdoc_encoding, "div" => :rdoc_encoding, "nop" => :nop_encoding}
|
11
|
-
|
12
|
-
# RDoc encoding
|
13
|
-
def self.rdoc_encoding(src, options);
|
14
|
-
encoder = RDoc::Markup::ToHtml.new
|
15
|
-
if options['_template_'] and options['_template_'].source_file
|
16
|
-
encoder.instance_eval do
|
17
|
-
@from_path = File.dirname(options['_template_'].source_file)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
encoder.convert(src)
|
21
|
-
end
|
22
|
-
|
23
|
-
# RDoc encoding, removing enclosing <tt><p>...</p></tt>
|
24
|
-
def self.nop_encoding(src, options);
|
25
|
-
rdoc = RDoc::Markup::ToHtml.new.convert(src)
|
26
|
-
rdoc = $1 if /^\s*<p>\s*(.*?)\s+<\/p>\s*$/m =~ rdoc
|
27
|
-
rdoc
|
28
|
-
end
|
29
|
-
|
30
|
-
end # RDoc
|
31
|
-
|
32
|
-
end
|
33
|
-
end
|