wlang 2.3.1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +4 -6
- data/Gemfile +1 -21
- data/Gemfile.lock +34 -38
- data/LICENCE.md +17 -19
- data/README.md +26 -64
- data/lib/wlang.rb +0 -9
- data/lib/wlang/compiler/grammar.citrus +6 -6
- data/lib/wlang/dialect.rb +1 -1
- data/lib/wlang/loader.rb +0 -1
- data/lib/wlang/scope.rb +0 -2
- data/lib/wlang/template.rb +14 -18
- data/lib/wlang/version.rb +3 -3
- data/spec/fixtures/templates/front_matter.wlang +4 -0
- data/spec/spec_helper.rb +0 -7
- data/spec/unit/compiler/test_to_ruby_code.rb +2 -2
- data/spec/unit/scope/test_coerce.rb +0 -4
- data/spec/unit/source/test_path.rb +3 -3
- data/spec/unit/source/test_template_content.rb +1 -1
- data/spec/unit/template/test_path.rb +2 -2
- data/spec/unit/template/test_to_ruby_code.rb +1 -1
- data/spec/unit/test_assumptions.rb +1 -1
- data/tasks/test.rake +17 -0
- data/wlang.gemspec +5 -169
- metadata +114 -255
- data/lib/wlang/scope/sinatra_scope.rb +0 -49
- data/lib/wlang/tilt.rb +0 -3
- data/lib/wlang/tilt/wlang_template.rb +0 -45
- data/spec/integration/sinatra/test_partials.rb +0 -35
- data/spec/integration/tilt/test_wlang_template.rb +0 -13
- data/spec/unit/scope/sinatra_scope/test_fetch.rb +0 -28
- data/spec/unit/tilt/test_wlang_template.rb +0 -65
- data/tasks/debug_mail.rake +0 -75
- data/tasks/debug_mail.txt +0 -13
- data/tasks/spec_test.rake +0 -71
- data/tasks/unit_test.rake +0 -76
- data/tasks/yard.rake +0 -51
- data/wlang.noespec +0 -45
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c13dc41782e57a6c997a991bfd683be1e9ede7887694126d724a7436203bf4f6
|
4
|
+
data.tar.gz: 9043c388c6a3326e0b2fdd28fe2b2eef7ac88933b18c6d6434d5c38c5fee2ccc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 283d2695c3c096d80806894e376bbc18c6e170a057092ef149a625857c910ae00c9f8f3e00e8f31c655788a6ea148b3c98718bc3bad32a8caeff283609e47ced
|
7
|
+
data.tar.gz: 9e0427a186128ef78959ca01906baffe296b0730f7cb6f052883f0d3a12b0c5faf7ebc49cc917c8ec399adee03e30030d2e012fbcfa1f09db561f51cd6bff45b
|
data/CHANGELOG.md
CHANGED
@@ -1,10 +1,8 @@
|
|
1
|
-
#
|
1
|
+
# 3.0.0 / 2020-12-29
|
2
2
|
|
3
|
-
*
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
* Allowed Citrus to 3.0
|
3
|
+
* Clean project to use a standard ruby-2.7 stack
|
4
|
+
* Upgrade citrus to 3.x
|
5
|
+
* Remove support for sinatra and tilt
|
8
6
|
|
9
7
|
# 2.2.4 / 2014-07-29
|
10
8
|
|
data/Gemfile
CHANGED
@@ -1,22 +1,2 @@
|
|
1
1
|
source 'http://rubygems.org'
|
2
|
-
|
3
|
-
group :runtime do
|
4
|
-
gem "citrus", "~> 3.0"
|
5
|
-
gem "temple", "~> 0.6"
|
6
|
-
gem "quickl", "~> 0.4.3"
|
7
|
-
gem "path", "~> 1.3"
|
8
|
-
gem "backports", "~> 2.6"
|
9
|
-
end
|
10
|
-
|
11
|
-
group :extra do
|
12
|
-
gem "awesome_print", "~> 1.0.2"
|
13
|
-
end
|
14
|
-
|
15
|
-
group :development do
|
16
|
-
gem "tilt", "~> 1.3"
|
17
|
-
gem "rake", "~> 0.9.2"
|
18
|
-
gem "bundler", "~> 1.0"
|
19
|
-
gem "rspec", "~> 2.10.0"
|
20
|
-
gem "sinatra", ">= 1.4"
|
21
|
-
gem "rack-test", "~> 0.6"
|
22
|
-
end
|
2
|
+
gemspec
|
data/Gemfile.lock
CHANGED
@@ -1,46 +1,42 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
wlang (3.0.0)
|
5
|
+
citrus (~> 3.0)
|
6
|
+
path (~> 2.0)
|
7
|
+
quickl (~> 0.4.3)
|
8
|
+
temple (~> 0.6)
|
9
|
+
|
1
10
|
GEM
|
2
11
|
remote: http://rubygems.org/
|
3
12
|
specs:
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
diff-lcs (1.1.3)
|
8
|
-
path (1.3.1)
|
13
|
+
citrus (3.0.2)
|
14
|
+
diff-lcs (1.4.4)
|
15
|
+
path (2.0.1)
|
9
16
|
quickl (0.4.3)
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
rspec-
|
20
|
-
rspec-
|
21
|
-
|
22
|
-
|
23
|
-
rspec-
|
24
|
-
|
25
|
-
rack (~> 1.5, >= 1.5.2)
|
26
|
-
rack-protection (~> 1.4)
|
27
|
-
tilt (~> 1.3, >= 1.3.4)
|
28
|
-
temple (0.6.5)
|
29
|
-
tilt (1.3.7)
|
17
|
+
rake (13.0.3)
|
18
|
+
rspec (3.10.0)
|
19
|
+
rspec-core (~> 3.10.0)
|
20
|
+
rspec-expectations (~> 3.10.0)
|
21
|
+
rspec-mocks (~> 3.10.0)
|
22
|
+
rspec-core (3.10.1)
|
23
|
+
rspec-support (~> 3.10.0)
|
24
|
+
rspec-expectations (3.10.1)
|
25
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
26
|
+
rspec-support (~> 3.10.0)
|
27
|
+
rspec-mocks (3.10.1)
|
28
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
29
|
+
rspec-support (~> 3.10.0)
|
30
|
+
rspec-support (3.10.1)
|
31
|
+
temple (0.8.2)
|
30
32
|
|
31
33
|
PLATFORMS
|
32
|
-
|
34
|
+
x86_64-darwin-18
|
33
35
|
|
34
36
|
DEPENDENCIES
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
rack-test (~> 0.6)
|
42
|
-
rake (~> 0.9.2)
|
43
|
-
rspec (~> 2.10.0)
|
44
|
-
sinatra (>= 1.4)
|
45
|
-
temple (~> 0.6)
|
46
|
-
tilt (~> 1.3)
|
37
|
+
rake (~> 13.0)
|
38
|
+
rspec (~> 3.0)
|
39
|
+
wlang!
|
40
|
+
|
41
|
+
BUNDLED WITH
|
42
|
+
2.2.2
|
data/LICENCE.md
CHANGED
@@ -1,22 +1,20 @@
|
|
1
|
-
|
1
|
+
Copyright (c) 2012-2021 - Bernard Lambeau, Louis Lambeau
|
2
2
|
|
3
|
-
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
4
10
|
|
5
|
-
|
6
|
-
|
7
|
-
"Software"), to deal in the Software without restriction, including
|
8
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
the following conditions:
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,40 +1,48 @@
|
|
1
1
|
# WLang
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
WLang is a powerful code generation and templating engine, implemented on top o
|
4
|
+
[temple](https://github.com/judofyr/temple) and much inspired by the excellent
|
5
|
+
[mustache](http://mustache.github.com/).
|
6
6
|
|
7
7
|
## Links
|
8
8
|
|
9
9
|
* http://github.com/blambeau/wlang
|
10
|
-
* http://blambeau.github.com/wlang
|
11
10
|
* http://rubygems.org/gems/wlang
|
12
11
|
* http://revision-zero.org/wlang
|
13
12
|
|
14
13
|
## Features
|
15
14
|
|
16
15
|
* Tunable templating engine. You can define your own tags, and their behavior.
|
17
|
-
* Powerful logic-less HTML concretization to render web pages à la Mustache
|
16
|
+
* Powerful logic-less HTML concretization to render web pages à la Mustache
|
17
|
+
with extra.
|
18
18
|
* Compiled templates for speedy generation.
|
19
|
-
* [Tilt](https://github.com/rtomayko/tilt) and [Sinatra](https://github.com/sinatra/sinatra) integration.
|
20
19
|
|
21
|
-
WLang
|
20
|
+
WLang 3.0 also has a few remaining issues.
|
22
21
|
|
23
|
-
* It
|
24
|
-
|
22
|
+
* It has some issues with spacing; not a big issue for HTML rendering but might
|
23
|
+
prevent certain generation tasks.
|
25
24
|
|
26
25
|
## Tunable templating engine
|
27
26
|
|
28
|
-
WLang is a templating engine, written in ruby. In that, it is similar to ERB,
|
27
|
+
WLang is a templating engine, written in ruby. In that, it is similar to ERB,
|
28
|
+
Mustache and the like:
|
29
29
|
|
30
30
|
```ruby
|
31
31
|
WLang::Html.render 'Hello to ${who}!', who: 'you & the world'
|
32
32
|
# => "Hello to you & the world!"
|
33
33
|
```
|
34
34
|
|
35
|
-
To output HTML pages, WLang does not provides you with killer features or
|
35
|
+
To output HTML pages, WLang does not provides you with killer features or
|
36
|
+
extraordinary shortcus. It supports escaping, as shown above, but many other
|
37
|
+
templating engines do. For such HTML tasks, WLang does a pretty good job but
|
38
|
+
many other engines perform faster and have nicer features. See the examples
|
39
|
+
folder that documents WLang::Html.
|
36
40
|
|
37
|
-
WLang is designed to help you for other uses cases, user-defined ones in
|
41
|
+
WLang is designed to help you for other uses cases, user-defined ones in
|
42
|
+
particular, such as generating code or whatever text generation task for
|
43
|
+
which other engines quickly become inappropriate. WLang helps there because
|
44
|
+
it allows you to create your own _dialect_, that is, you can define your own
|
45
|
+
tags and their behavior. For instance,
|
38
46
|
|
39
47
|
```ruby
|
40
48
|
class Highlighter < WLang::Dialect
|
@@ -47,58 +55,12 @@ class Highlighter < WLang::Dialect
|
|
47
55
|
|
48
56
|
tag '$', :highlight
|
49
57
|
end
|
50
|
-
Highlighter.render('Hello ${who}!'
|
58
|
+
Highlighter.render('Hello ${who}!', who: 'you & the world')
|
51
59
|
# => "Hello YOU & THE WORLD !"
|
52
60
|
```
|
53
61
|
|
54
|
-
WLang already provides a few useful dialects, such as WLang::Html
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
```ruby
|
61
|
-
require 'tilt' # needed in your bundle, not a wlang dependency
|
62
|
-
require 'wlang' # loads Tilt support provided Tilt has already been required
|
63
|
-
|
64
|
-
template = Tilt.new("path/to/a/template.wlang") # suppose 'Hello ${who}!'
|
65
|
-
template.render(:who => "world")
|
66
|
-
# => Hello world!
|
67
|
-
|
68
|
-
template = Tilt.new("path/to/a/template.wlang", :dialect => Highlighter)
|
69
|
-
template.render(:who => "world")
|
70
|
-
# => Hello WORLD!
|
71
|
-
```
|
72
|
-
|
73
|
-
Please note that you should require tilt first, then wlang. Otherwise, you'll have to require `wlang/tilt` explicitely.
|
74
|
-
|
75
|
-
# Sinatra integration
|
76
|
-
|
77
|
-
WLang comes bundled with built-in support for [Sinatra](https://github.com/sinatra/sinatra) >= 1.4 (release still in progress). As usual in Sinatra, you can simply invoke wlang as follows:
|
78
|
-
|
79
|
-
get '/' do
|
80
|
-
wlang :index, :locals => { ... }
|
81
|
-
end
|
82
|
-
|
83
|
-
As wlang encourages logic-less templates, you should always use locals. However, there is specific support for layouts and partials, as the following example demonstrates:
|
84
|
-
|
85
|
-
get '/' do
|
86
|
-
wlang :index, :locals => {:who => "world"}
|
87
|
-
end
|
88
|
-
|
89
|
-
__END__
|
90
|
-
|
91
|
-
@@layout
|
92
|
-
<html>
|
93
|
-
>{yield}
|
94
|
-
</html>
|
95
|
-
|
96
|
-
@@index
|
97
|
-
Hello from a partial: >{partial}
|
98
|
-
|
99
|
-
@@partial
|
100
|
-
yeah, a partial saying hello to '${who}'!
|
101
|
-
|
102
|
-
Returned body will be (ignoring carriage returns):
|
103
|
-
|
104
|
-
<html>Hello from a partial: yeah, a partial saying hello to 'world'!</html>
|
62
|
+
WLang already provides a few useful dialects, such as WLang::Html
|
63
|
+
(inspired by Mustache but a bit more powerful in my opinion). If they don't
|
64
|
+
match your needs, it is up to you to define you own dialect for making your
|
65
|
+
generation task easy. Have a look at the implementation of WLang's ones, it's
|
66
|
+
pretty simple to get started!
|
data/lib/wlang.rb
CHANGED
@@ -27,14 +27,6 @@ module WLang
|
|
27
27
|
end
|
28
28
|
module_function :dialect
|
29
29
|
|
30
|
-
SinatraApp = proc{|arg|
|
31
|
-
defined?(Sinatra::Base) && Sinatra::Base===arg
|
32
|
-
}
|
33
|
-
|
34
|
-
TiltTemplate = proc{|arg|
|
35
|
-
defined?(Tilt::Template) && Tilt::Template===arg
|
36
|
-
}
|
37
|
-
|
38
30
|
end # module WLang
|
39
31
|
require 'wlang/compiler'
|
40
32
|
require 'wlang/source'
|
@@ -42,4 +34,3 @@ require 'wlang/template'
|
|
42
34
|
require 'wlang/dialect'
|
43
35
|
require 'wlang/scope'
|
44
36
|
require 'wlang/html'
|
45
|
-
require 'wlang/tilt' if defined?(::Tilt)
|
@@ -2,7 +2,7 @@ grammar WLang::Grammar
|
|
2
2
|
|
3
3
|
rule template
|
4
4
|
(strconcat !.){
|
5
|
-
[:template, [:fn,
|
5
|
+
[:template, [:fn, capture(:strconcat).value]]
|
6
6
|
}
|
7
7
|
end
|
8
8
|
|
@@ -29,15 +29,15 @@ grammar WLang::Grammar
|
|
29
29
|
rule block
|
30
30
|
(fn_start strconcat fn_stop){
|
31
31
|
[:strconcat,
|
32
|
-
[:static,
|
33
|
-
|
34
|
-
[:static,
|
32
|
+
[:static, capture(:fn_start).to_s],
|
33
|
+
capture(:strconcat).value,
|
34
|
+
[:static, capture(:fn_stop).to_s]]
|
35
35
|
}
|
36
36
|
end
|
37
37
|
|
38
38
|
rule wlang
|
39
39
|
(symbols functions){
|
40
|
-
[:wlang,
|
40
|
+
[:wlang, capture(:symbols).to_s] + capture(:functions).value
|
41
41
|
}
|
42
42
|
end
|
43
43
|
|
@@ -47,7 +47,7 @@ grammar WLang::Grammar
|
|
47
47
|
|
48
48
|
rule function
|
49
49
|
(fn_start strconcat fn_stop){
|
50
|
-
|
50
|
+
capture(:strconcat).value
|
51
51
|
}
|
52
52
|
end
|
53
53
|
|
data/lib/wlang/dialect.rb
CHANGED
data/lib/wlang/loader.rb
CHANGED
data/lib/wlang/scope.rb
CHANGED
@@ -17,7 +17,6 @@ module WLang
|
|
17
17
|
case arg
|
18
18
|
when Hash then ObjectScope.new(arg)
|
19
19
|
when Scope then arg
|
20
|
-
when SinatraApp then SinatraScope.new(arg)
|
21
20
|
when Binding then BindingScope.new(arg)
|
22
21
|
when Proc then ProcScope.new(arg)
|
23
22
|
else
|
@@ -103,4 +102,3 @@ require 'wlang/scope/null_scope'
|
|
103
102
|
require 'wlang/scope/object_scope'
|
104
103
|
require 'wlang/scope/binding_scope'
|
105
104
|
require 'wlang/scope/proc_scope'
|
106
|
-
require 'wlang/scope/sinatra_scope'
|
data/lib/wlang/template.rb
CHANGED
@@ -48,29 +48,25 @@ module WLang
|
|
48
48
|
scope, buffer = call_args_conventions(args)
|
49
49
|
dialect_instance.dup.render compiled, scope, buffer
|
50
50
|
end
|
51
|
-
alias :render :call
|
52
|
-
|
53
|
-
private
|
54
51
|
|
55
|
-
|
52
|
+
alias :render :call
|
56
53
|
|
57
|
-
|
58
|
-
opt = options[:yaml_front_matter]
|
59
|
-
opt.nil? or opt
|
60
|
-
end
|
54
|
+
attr_reader :source, :compiled, :dialect_instance
|
61
55
|
|
62
|
-
|
63
|
-
# Ensure a buffer as lat argument
|
64
|
-
args << '' unless args.last.respond_to?(:<<)
|
65
|
-
buffer = args.pop
|
56
|
+
private
|
66
57
|
|
67
|
-
|
68
|
-
|
58
|
+
def yaml_front_matter?
|
59
|
+
opt = options[:yaml_front_matter]
|
60
|
+
opt.nil? or opt
|
61
|
+
end
|
69
62
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
63
|
+
def call_args_conventions(args)
|
64
|
+
args << '' unless args.last.respond_to?(:<<)
|
65
|
+
buffer = args.pop
|
66
|
+
args << self.locals unless self.locals.empty?
|
67
|
+
scope = WLang::Scope.chain(args)
|
68
|
+
[scope, buffer]
|
69
|
+
end
|
74
70
|
|
75
71
|
end # class Template
|
76
72
|
end # module WLang
|
data/lib/wlang/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,9 +1,6 @@
|
|
1
1
|
require 'path'
|
2
2
|
$root_folder ||= Path.backfind('.[Rakefile]')
|
3
3
|
|
4
|
-
require 'tilt'
|
5
|
-
require 'sinatra/base'
|
6
|
-
|
7
4
|
# Require wlang
|
8
5
|
$LOAD_PATH.unshift(($root_folder/:lib).to_s)
|
9
6
|
require 'wlang'
|
@@ -56,10 +53,6 @@ module Helpers
|
|
56
53
|
end
|
57
54
|
end
|
58
55
|
|
59
|
-
def sinatra_app(&block)
|
60
|
-
Sinatra.new(Sinatra::Base, &block).new!
|
61
|
-
end
|
62
|
-
|
63
56
|
end
|
64
57
|
include Helpers
|
65
58
|
|