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
@@ -1,49 +0,0 @@
|
|
1
|
-
module WLang
|
2
|
-
class Scope
|
3
|
-
class SinatraScope < ObjectScope
|
4
|
-
|
5
|
-
def fetch(key, dialect = nil, unfound = nil)
|
6
|
-
find_partial(key, subject) || super
|
7
|
-
end
|
8
|
-
|
9
|
-
def inspect
|
10
|
-
"SinatraScope"
|
11
|
-
end
|
12
|
-
alias :to_s :inspect
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
def find_partial(key, app)
|
17
|
-
find_internal_partial(key, app) || find_external_partial(key, app)
|
18
|
-
end
|
19
|
-
|
20
|
-
def find_internal_partial(key, app)
|
21
|
-
return unless app.settings.templates[key]
|
22
|
-
app.send(:compile_template, :wlang, key, {}, app.settings.views)
|
23
|
-
end
|
24
|
-
|
25
|
-
def find_external_partial(key, app)
|
26
|
-
views = app.settings.views
|
27
|
-
find_files(views, key) do |file|
|
28
|
-
if engine = Tilt[file]
|
29
|
-
tpl = app.template_cache.fetch(file) do
|
30
|
-
options = if app.settings.respond_to?(:wlang)
|
31
|
-
app.settings.wlang
|
32
|
-
else
|
33
|
-
{}
|
34
|
-
end
|
35
|
-
engine.new(file.to_s, 1, options)
|
36
|
-
end
|
37
|
-
return tpl
|
38
|
-
end
|
39
|
-
end
|
40
|
-
nil
|
41
|
-
end
|
42
|
-
|
43
|
-
def find_files(folder, name, &bl)
|
44
|
-
Path(folder).glob("#{name}.*").each(&bl)
|
45
|
-
end
|
46
|
-
|
47
|
-
end # class SinatraScope
|
48
|
-
end # class Scope
|
49
|
-
end # module WLang
|
data/lib/wlang/tilt.rb
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
module Tilt
|
2
|
-
class WLangTemplate < ::Tilt::Template
|
3
|
-
|
4
|
-
class << self
|
5
|
-
|
6
|
-
def engine_initialized?
|
7
|
-
defined? ::WLang
|
8
|
-
end
|
9
|
-
|
10
|
-
def with_options(options)
|
11
|
-
Class.new(WLangTemplate).tap{|c| c.default_options = options }
|
12
|
-
end
|
13
|
-
|
14
|
-
def default_options=(options)
|
15
|
-
@default_options = options
|
16
|
-
end
|
17
|
-
|
18
|
-
def default_options
|
19
|
-
(superclass.default_options rescue {}).merge(@default_options || {})
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
def initialize_engine
|
25
|
-
require_template_library('wlang')
|
26
|
-
end
|
27
|
-
|
28
|
-
protected
|
29
|
-
|
30
|
-
def prepare
|
31
|
-
opts = self.class.default_options.merge(self.options)
|
32
|
-
opts.merge!(:path => file) if file
|
33
|
-
@engine = WLang::Template.new(data, opts)
|
34
|
-
end
|
35
|
-
|
36
|
-
def evaluate(scope, locals, &block)
|
37
|
-
args = [scope]
|
38
|
-
args << locals if locals && !(locals.respond_to?(:empty?) && locals.empty?)
|
39
|
-
args << { :yield => block } if block
|
40
|
-
@engine.render(*args)
|
41
|
-
end
|
42
|
-
|
43
|
-
end
|
44
|
-
register WLangTemplate, 'wlang'
|
45
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'rack/test'
|
3
|
-
describe 'Integration with Sinatra for partials' do
|
4
|
-
include Rack::Test::Methods
|
5
|
-
|
6
|
-
let(:app){
|
7
|
-
sinatra_app do
|
8
|
-
set :accessible, "world"
|
9
|
-
set :views, fixtures_folder/'templates'
|
10
|
-
template :internal_partial do
|
11
|
-
"Hello ${who}!"
|
12
|
-
end
|
13
|
-
helpers do
|
14
|
-
def accessible; settings.accessible; end
|
15
|
-
end
|
16
|
-
get '/external' do
|
17
|
-
wlang ">{hello}", :locals => {:who => "sinatra"}
|
18
|
-
end
|
19
|
-
get '/internal' do
|
20
|
-
wlang ">{internal_partial}", :locals => {:who => "sinatra"}
|
21
|
-
end
|
22
|
-
end
|
23
|
-
}
|
24
|
-
|
25
|
-
it 'renders external partials correcty' do
|
26
|
-
get '/external'
|
27
|
-
last_response.body.should eq("Hello sinatra!")
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'renders internal partials correcty' do
|
31
|
-
get '/internal'
|
32
|
-
last_response.body.should eq("Hello sinatra!")
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
require 'tilt'
|
2
|
-
require 'wlang/tilt'
|
3
|
-
describe 'WLang integration with tilt' do
|
4
|
-
|
5
|
-
it 'allows invoking tilt directly' do
|
6
|
-
Tilt.new(hello_path.to_s).render(:who => "world").should eq("Hello world!")
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'allows specifying the dialect' do
|
10
|
-
Tilt.new(hello_path.to_s, :dialect => Upcasing).render.should eq("Hello WHO!")
|
11
|
-
end
|
12
|
-
|
13
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
module WLang
|
3
|
-
class Scope
|
4
|
-
describe SinatraScope, 'fetch' do
|
5
|
-
|
6
|
-
let(:app){
|
7
|
-
sinatra_app do
|
8
|
-
set :accessible, "world"
|
9
|
-
set :views, fixtures_folder/'templates'
|
10
|
-
helpers do
|
11
|
-
def accessible; settings.accessible; end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
}
|
15
|
-
|
16
|
-
let(:scope){ Scope::SinatraScope.new(app) }
|
17
|
-
|
18
|
-
it 'delegates to helpers correctly' do
|
19
|
-
scope.fetch(:accessible).should eq("world")
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'returns Tilt templates on existing views' do
|
23
|
-
scope.fetch('hello', app).should be_a(Tilt::Template)
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,65 +0,0 @@
|
|
1
|
-
require 'tilt'
|
2
|
-
require 'wlang/tilt'
|
3
|
-
describe Tilt::WLangTemplate do
|
4
|
-
|
5
|
-
it 'is registered for .wlang files' do
|
6
|
-
Tilt.mappings['wlang'].should include(Tilt::WLangTemplate)
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'supports basic rendering with no scope no locals' do
|
10
|
-
template = Tilt::WLangTemplate.new{ "Hello" }
|
11
|
-
template.render.should eq("Hello")
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'supports a binding scope' do
|
15
|
-
template = Tilt::WLangTemplate.new{ "Hello ${who}" }
|
16
|
-
who = "world"
|
17
|
-
template.render(binding).should eq("Hello world")
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'supports a Hash scope' do
|
21
|
-
template = Tilt::WLangTemplate.new{ "Hello ${who}" }
|
22
|
-
scope = {:who => "world"}
|
23
|
-
template.render(scope).should eq("Hello world")
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'supports both a scope and locals' do
|
27
|
-
template = Tilt::WLangTemplate.new{ "Hello ${who} and ${who_else}" }
|
28
|
-
who = "world"
|
29
|
-
template.render(binding, :who_else => 'wlang').should eq("Hello world and wlang")
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'supports being rendered multiple times' do
|
33
|
-
template = Tilt::WLangTemplate.new{ "Hello ${i}" }
|
34
|
-
3.times{|i| template.render(binding).should eq("Hello #{i}") }
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'supports passing a block for yielding' do
|
38
|
-
template = Tilt::WLangTemplate.new{ "Hello ${yield}" }
|
39
|
-
template.render{ "world" }.should eq('Hello world')
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'supports expressions on yield' do
|
43
|
-
template = Tilt::WLangTemplate.new{ "Hello ${yield.upcase}" }
|
44
|
-
template.render{ "world" }.should eq('Hello WORLD')
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'passes :path option to the underlying template' do
|
48
|
-
tpl = Tilt::WLangTemplate.new(hello_path.to_s)
|
49
|
-
tpl = tpl.send(:prepare)
|
50
|
-
tpl.should be_a(WLang::Template)
|
51
|
-
tpl.path.should eq(hello_path.to_s)
|
52
|
-
end
|
53
|
-
|
54
|
-
it 'supports passing a dialect as options' do
|
55
|
-
template = Tilt::WLangTemplate.new(:dialect => Upcasing){ "Hello ${who}" }
|
56
|
-
template.render.should eq("Hello WHO")
|
57
|
-
end
|
58
|
-
|
59
|
-
it 'supports options through inheritance' do
|
60
|
-
tpl_class = Tilt::WLangTemplate.with_options(:dialect => Upcasing)
|
61
|
-
template = tpl_class.new{ "Hello ${who}" }
|
62
|
-
template.render.should eq("Hello WHO")
|
63
|
-
end
|
64
|
-
|
65
|
-
end
|
data/tasks/debug_mail.rake
DELETED
@@ -1,75 +0,0 @@
|
|
1
|
-
# Installs a rake task for debuging the announcement mail.
|
2
|
-
#
|
3
|
-
# This file installs the 'rake debug_mail' that flushes an announcement mail
|
4
|
-
# for your library on the standard output. It is automatically generated
|
5
|
-
# by Noe from your .noespec file, and should therefore be configured there,
|
6
|
-
# under the variables/rake_tasks/debug_mail entry, as illustrated below:
|
7
|
-
#
|
8
|
-
# variables:
|
9
|
-
# rake_tasks:
|
10
|
-
# debug_mail:
|
11
|
-
# rx_changelog_sections: /^#/
|
12
|
-
# nb_changelog_sections: 1
|
13
|
-
# ...
|
14
|
-
#
|
15
|
-
# If you have specific needs requiring manual intervention on this file,
|
16
|
-
# don't forget to set safe-override to false in your noe specification:
|
17
|
-
#
|
18
|
-
# template-info:
|
19
|
-
# manifest:
|
20
|
-
# tasks/debug_mail.rake:
|
21
|
-
# safe-override: false
|
22
|
-
#
|
23
|
-
# The mail template used can be found in debug_mail.txt. That file may be
|
24
|
-
# changed to tune the mail you want to send. If you do so, don't forget to
|
25
|
-
# add a manifest entry in your .noespec file to avoid overriding you
|
26
|
-
# changes. The mail template uses wlang, with parentheses for block
|
27
|
-
# delimiters.
|
28
|
-
#
|
29
|
-
# template-info:
|
30
|
-
# manifest:
|
31
|
-
# tasks/debug_mail.txt:
|
32
|
-
# safe-override: false
|
33
|
-
#
|
34
|
-
desc "Debug the release announcement mail"
|
35
|
-
task :debug_mail do
|
36
|
-
begin
|
37
|
-
require 'wlang'
|
38
|
-
rescue LoadError
|
39
|
-
abort "wlang is not available. Try 'gem install wlang'"
|
40
|
-
end
|
41
|
-
require 'yaml'
|
42
|
-
|
43
|
-
# Check that a .noespec file exists
|
44
|
-
noespec_file = File.expand_path('../../wlang.noespec', __FILE__)
|
45
|
-
unless File.exists?(noespec_file)
|
46
|
-
raise "Unable to find .noespec project file, sorry."
|
47
|
-
end
|
48
|
-
|
49
|
-
# Load it as well as variables and options
|
50
|
-
noespec = YAML::load(File.read(noespec_file))
|
51
|
-
vars = noespec['variables'] || {}
|
52
|
-
|
53
|
-
# Changes are taken from CHANGELOG
|
54
|
-
logs = Dir[File.expand_path("../../CHANGELOG.*", __FILE__)]
|
55
|
-
unless logs.size == 1
|
56
|
-
abort "Unable to find a changelog file"
|
57
|
-
end
|
58
|
-
|
59
|
-
# Load interesting changesets
|
60
|
-
changes, end_found = [], 0
|
61
|
-
File.readlines(logs.first).select{|line|
|
62
|
-
if line =~ /^# /
|
63
|
-
break if end_found >= 1
|
64
|
-
end_found += 1
|
65
|
-
end
|
66
|
-
changes << line
|
67
|
-
}
|
68
|
-
vars['changes'] = changes.join
|
69
|
-
|
70
|
-
# WLang template
|
71
|
-
template = File.expand_path('../debug_mail.txt', __FILE__)
|
72
|
-
|
73
|
-
# Let's go!
|
74
|
-
$stdout << WLang::file_instantiate(template, vars, "wlang/active-text")
|
75
|
-
end
|
data/tasks/debug_mail.txt
DELETED
data/tasks/spec_test.rake
DELETED
@@ -1,71 +0,0 @@
|
|
1
|
-
# Installs a rake task for for running examples written using rspec.
|
2
|
-
#
|
3
|
-
# This file installs the 'rake spec_test' (aliased as 'rake spec') as well as
|
4
|
-
# extends 'rake test' to run spec tests, if any. It is automatically generated
|
5
|
-
# by Noe from your .noespec file, and should therefore be configured there,
|
6
|
-
# under the variables/rake_tasks/spec_test entry, as illustrated below:
|
7
|
-
#
|
8
|
-
# variables:
|
9
|
-
# rake_tasks:
|
10
|
-
# spec_test:
|
11
|
-
# pattern: spec/**/*_spec.rb
|
12
|
-
# verbose: true
|
13
|
-
# rspec_opts: [--color, --backtrace]
|
14
|
-
# ...
|
15
|
-
#
|
16
|
-
# If you have specific needs requiring manual intervention on this file,
|
17
|
-
# don't forget to set safe-override to false in your noe specification:
|
18
|
-
#
|
19
|
-
# template-info:
|
20
|
-
# manifest:
|
21
|
-
# tasks/spec_test.rake:
|
22
|
-
# safe-override: false
|
23
|
-
#
|
24
|
-
# This file has been written to conform to RSpec v2.4.0. More information about
|
25
|
-
# rspec and options of the rake task defined below can be found on
|
26
|
-
# http://relishapp.com/rspec
|
27
|
-
#
|
28
|
-
begin
|
29
|
-
require "rspec/core/rake_task"
|
30
|
-
desc "Run RSpec code examples"
|
31
|
-
RSpec::Core::RakeTask.new(:spec_test) do |t|
|
32
|
-
# Glob pattern to match files.
|
33
|
-
t.pattern = "spec/**/test_*.rb"
|
34
|
-
|
35
|
-
# Whether or not to fail Rake when an error occurs (typically when
|
36
|
-
# examples fail).
|
37
|
-
t.fail_on_error = true
|
38
|
-
|
39
|
-
# A message to print to stderr when there are failures.
|
40
|
-
t.failure_message = nil
|
41
|
-
|
42
|
-
# Use verbose output. If this is set to true, the task will print the
|
43
|
-
# executed spec command to stdout.
|
44
|
-
t.verbose = true
|
45
|
-
|
46
|
-
# Use rcov for code coverage?
|
47
|
-
t.rcov = false
|
48
|
-
|
49
|
-
# Path to rcov.
|
50
|
-
t.rcov_path = "rcov"
|
51
|
-
|
52
|
-
# Command line options to pass to rcov. See 'rcov --help' about this
|
53
|
-
t.rcov_opts = []
|
54
|
-
|
55
|
-
# Command line options to pass to ruby. See 'ruby --help' about this
|
56
|
-
t.ruby_opts = []
|
57
|
-
|
58
|
-
# Path to rspec
|
59
|
-
t.rspec_path = "rspec"
|
60
|
-
|
61
|
-
# Command line options to pass to rspec. See 'rspec --help' about this
|
62
|
-
t.rspec_opts = ["--color", "--backtrace"]
|
63
|
-
end
|
64
|
-
rescue LoadError => ex
|
65
|
-
task :spec_test do
|
66
|
-
abort 'rspec is not available. In order to run spec, you must: gem install rspec'
|
67
|
-
end
|
68
|
-
ensure
|
69
|
-
task :spec => [:spec_test]
|
70
|
-
task :test => [:spec_test]
|
71
|
-
end
|
data/tasks/unit_test.rake
DELETED
@@ -1,76 +0,0 @@
|
|
1
|
-
# Installs a rake task for for running unit tests.
|
2
|
-
#
|
3
|
-
# This file installs the 'rake unit_test' and extends 'rake test' to run unit
|
4
|
-
# tests, if any. It is automatically generated by Noe from your .noespec file,
|
5
|
-
# and should therefore be configured there, under the variables/rake_tasks/unit_test
|
6
|
-
# entry, as illustrated below:
|
7
|
-
#
|
8
|
-
# variables:
|
9
|
-
# rake_tasks:
|
10
|
-
# unit_test:
|
11
|
-
# pattern: test/test*.rb
|
12
|
-
# verbose: false
|
13
|
-
# warning: false
|
14
|
-
# ...
|
15
|
-
#
|
16
|
-
# If you have specific needs requiring manual intervention on this file,
|
17
|
-
# don't forget to set safe-override to false in your noe specification:
|
18
|
-
#
|
19
|
-
# template-info:
|
20
|
-
# manifest:
|
21
|
-
# tasks/unit_test.rake:
|
22
|
-
# safe-override: false
|
23
|
-
#
|
24
|
-
# More info about the TestTask and its options can be found on
|
25
|
-
# http://rake.rubyforge.org/classes/Rake/TestTask.html
|
26
|
-
#
|
27
|
-
begin
|
28
|
-
require 'rake/testtask'
|
29
|
-
desc "Run unit tests"
|
30
|
-
Rake::TestTask.new(:unit_test) do |t|
|
31
|
-
|
32
|
-
# List of directories to added to $LOAD_PATH before running the
|
33
|
-
# tests. (default is 'lib')
|
34
|
-
t.libs = ["lib"]
|
35
|
-
|
36
|
-
# True if verbose test output desired. (default is false)
|
37
|
-
t.verbose = false
|
38
|
-
|
39
|
-
# Test options passed to the test suite. An explicit TESTOPTS=opts
|
40
|
-
# on the command line will override this. (default is NONE)
|
41
|
-
t.options = nil
|
42
|
-
|
43
|
-
# Request that the tests be run with the warning flag set.
|
44
|
-
# E.g. warning=true implies "ruby -w" used to run the tests.
|
45
|
-
t.warning = false
|
46
|
-
|
47
|
-
# Glob pattern to match test files. (default is 'test/test*.rb')
|
48
|
-
t.pattern = "test/test_*.rb"
|
49
|
-
|
50
|
-
# Style of test loader to use. Options are:
|
51
|
-
#
|
52
|
-
# * :rake -- Rake provided test loading script (default).
|
53
|
-
# * :testrb -- Ruby provided test loading script.
|
54
|
-
# * :direct -- Load tests using command line loader.
|
55
|
-
#
|
56
|
-
t.loader = :rake
|
57
|
-
|
58
|
-
# Array of commandline options to pass to ruby when running test
|
59
|
-
# loader.
|
60
|
-
t.ruby_opts = []
|
61
|
-
|
62
|
-
# Explicitly define the list of test files to be included in a
|
63
|
-
# test. +list+ is expected to be an array of file names (a
|
64
|
-
# FileList is acceptable). If both +pattern+ and +test_files+ are
|
65
|
-
# used, then the list of test files is the union of the two.
|
66
|
-
t.test_files = nil
|
67
|
-
|
68
|
-
end
|
69
|
-
rescue LoadError => ex
|
70
|
-
task :unit_test do
|
71
|
-
abort "rake/testtask does not seem available...\n #{ex.message}"
|
72
|
-
end
|
73
|
-
ensure
|
74
|
-
desc "Run all tests"
|
75
|
-
task :test => [:unit_test]
|
76
|
-
end
|