cutaneous 0.1.4 → 0.1.5
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 +4 -4
- data/cutaneous.gemspec +2 -2
- data/lib/cutaneous/engine.rb +8 -0
- data/lib/cutaneous/lexer.rb +10 -0
- data/lib/cutaneous/loader.rb +4 -0
- data/lib/cutaneous/template.rb +4 -0
- data/lib/cutaneous.rb +1 -1
- data/test/fixtures/statements1.html.cut +1 -1
- data/test/fixtures/statements2.html.cut +1 -1
- data/test/test_core.rb +83 -46
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9969ba7375a7a48961d9643edce1886e87d17881
|
4
|
+
data.tar.gz: 815bce78af65ee6ff6625ccc1666d5a758d6d74e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0a18c961d9fcd217ec41a819cbeb8710995bb77dd53cae261ec87b34d470db7246ef1e25c07fb227e26587b487ce04d3e4cb76980b7168a434b8072a0a63adf
|
7
|
+
data.tar.gz: d0f055699ba068ad627b6dc3a71aea6b721ebc892e2ea3297d73a33630679ef3704a3034f1b9b427a37dc58c89e7b97d6c9d8cb106e2e137ccd2509fb4067224
|
data/cutaneous.gemspec
CHANGED
@@ -14,8 +14,8 @@ Gem::Specification.new do |s|
|
|
14
14
|
## If your rubyforge_project name is different, then edit it and comment out
|
15
15
|
## the sub! line in the Rakefile
|
16
16
|
s.name = 'cutaneous'
|
17
|
-
s.version = '0.1.
|
18
|
-
s.date = '2013-08-
|
17
|
+
s.version = '0.1.5'
|
18
|
+
s.date = '2013-08-22'
|
19
19
|
s.rubyforge_project = 'cutaneous'
|
20
20
|
|
21
21
|
## Make sure your summary is short. The description may be as long
|
data/lib/cutaneous/engine.rb
CHANGED
@@ -39,6 +39,14 @@ module Cutaneous
|
|
39
39
|
file_loader(format).exists?(root, relative_path)
|
40
40
|
end
|
41
41
|
|
42
|
+
def convert(template, to_syntax, format = default_format)
|
43
|
+
file_loader(format).convert(template, to_syntax)
|
44
|
+
end
|
45
|
+
|
46
|
+
def convert_string(template_string, to_syntax, format = default_format)
|
47
|
+
string_loader(format).convert(template_string, to_syntax)
|
48
|
+
end
|
49
|
+
|
42
50
|
protected
|
43
51
|
|
44
52
|
def file_loader_instance(format)
|
data/lib/cutaneous/lexer.rb
CHANGED
@@ -14,6 +14,16 @@ module Cutaneous
|
|
14
14
|
@tokens ||= parse
|
15
15
|
end
|
16
16
|
|
17
|
+
def convert(to_syntax)
|
18
|
+
template = ""
|
19
|
+
tags = to_syntax.tags
|
20
|
+
tokens.each do |token|
|
21
|
+
open, close = tags[token[0]]
|
22
|
+
template << open.to_s << token[1] << close.to_s
|
23
|
+
end
|
24
|
+
template
|
25
|
+
end
|
26
|
+
|
17
27
|
# def script
|
18
28
|
# @script ||= compile
|
19
29
|
# end
|
data/lib/cutaneous/loader.rb
CHANGED
@@ -14,6 +14,10 @@ module Cutaneous
|
|
14
14
|
template(template).render(context)
|
15
15
|
end
|
16
16
|
|
17
|
+
def convert(template, to_syntax)
|
18
|
+
template(template).convert(to_syntax)
|
19
|
+
end
|
20
|
+
|
17
21
|
def template(template)
|
18
22
|
return proc_template(template) if template.is_a?(Proc)
|
19
23
|
template_path = path(template)
|
data/lib/cutaneous/template.rb
CHANGED
@@ -15,6 +15,10 @@ module Cutaneous
|
|
15
15
|
context.instance_eval(&template_proc)
|
16
16
|
end
|
17
17
|
|
18
|
+
def convert(to_syntax)
|
19
|
+
lexer.convert(to_syntax)
|
20
|
+
end
|
21
|
+
|
18
22
|
def template_proc
|
19
23
|
@template_proc ||= eval(template_proc_src, nil, path || "(cutaneous)").tap do |proc|
|
20
24
|
@lexer = nil # release any memory used by the lexer, we don't need it anymore
|
data/lib/cutaneous.rb
CHANGED
data/test/test_core.rb
CHANGED
@@ -1,62 +1,99 @@
|
|
1
1
|
require File.expand_path('../helper', __FILE__)
|
2
2
|
|
3
|
-
describe "
|
3
|
+
describe "Parsers" do
|
4
4
|
let(:template_root) { File.expand_path("../fixtures", __FILE__) }
|
5
|
-
|
6
|
-
|
7
|
-
it "will parse & execute a simple template with expressions" do
|
8
|
-
context = ContextHash(right: "right", code: "<tag/>")
|
9
|
-
result = subject.render("expressions1", context)
|
10
|
-
result.must_equal "This is right <tag/>\n"
|
5
|
+
def read_template(template)
|
6
|
+
File.read(File.join(template_root, template))
|
11
7
|
end
|
12
8
|
|
13
|
-
|
14
|
-
context = ContextHash(right: "right")
|
15
|
-
result = subject.render("statements1", context)
|
16
|
-
result.must_equal "\nThis is right 0\n\nThis is right 1\n\nThis is right 2\n\n"
|
17
|
-
end
|
9
|
+
describe "First pass parser" do
|
18
10
|
|
19
|
-
|
20
|
-
context = ContextHash(right: "right")
|
21
|
-
result = subject.render("comments1", context)
|
22
|
-
result.must_equal "\n"
|
23
|
-
end
|
11
|
+
subject { Cutaneous::Engine.new(template_root, Cutaneous::FirstPassSyntax, "html") }
|
24
12
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
end
|
31
|
-
end
|
13
|
+
it "will parse & execute a simple template with expressions" do
|
14
|
+
context = ContextHash(right: "right", code: "<tag/>")
|
15
|
+
result = subject.render("expressions1", context)
|
16
|
+
result.must_equal "This is right <tag/>\n"
|
17
|
+
end
|
32
18
|
|
33
|
-
|
34
|
-
|
35
|
-
|
19
|
+
it "will parse & execute a simple template with statements" do
|
20
|
+
context = ContextHash(right: "right")
|
21
|
+
result = subject.render("statements1", context)
|
22
|
+
result.must_equal "\nThis is right 0\n\nThis is right 1\n\nThis is right 2\n\n"
|
23
|
+
end
|
36
24
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
25
|
+
it "will parse & execute a simple template with comments" do
|
26
|
+
context = ContextHash(right: "right")
|
27
|
+
result = subject.render("comments1", context)
|
28
|
+
result.must_equal "\n"
|
29
|
+
end
|
42
30
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
31
|
+
it "will remove whitespace after tags with a closing '-'" do
|
32
|
+
context = ContextHash(right: "right")
|
33
|
+
result = subject.render("whitespace1", context)
|
34
|
+
expected = ["aa", "here 0", "here 1", "here 2\n", "ac\n", "ad\n", "ae\n", "af\n", "ag\n"].join("\n")
|
35
|
+
result.must_equal expected
|
36
|
+
end
|
48
37
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
38
|
+
it "can convert a template to another syntax" do
|
39
|
+
result = subject.convert('statements1', Cutaneous::SecondPassSyntax)
|
40
|
+
result.must_equal read_template('statements2.html.cut')
|
41
|
+
end
|
42
|
+
|
43
|
+
it "can convert a template string to another syntax" do
|
44
|
+
result = subject.convert_string(read_template('statements1.html.cut'), Cutaneous::SecondPassSyntax)
|
45
|
+
result.must_equal read_template('statements2.html.cut')
|
46
|
+
end
|
47
|
+
|
48
|
+
it "can convert a template proc to another syntax" do
|
49
|
+
result = subject.convert(proc { read_template('statements1.html.cut') }, Cutaneous::SecondPassSyntax)
|
50
|
+
result.must_equal read_template('statements2.html.cut')
|
51
|
+
end
|
53
52
|
end
|
54
53
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
54
|
+
describe "Second pass parser" do
|
55
|
+
let(:template_root) { File.expand_path("../fixtures", __FILE__) }
|
56
|
+
subject { Cutaneous::Engine.new(template_root, Cutaneous::SecondPassSyntax, "html") }
|
57
|
+
|
58
|
+
it "will parse & execute a simple template with expressions" do
|
59
|
+
context = ContextHash(right: "right", code: "<tag/>")
|
60
|
+
result = subject.render("expressions2", context)
|
61
|
+
result.must_equal "This is right <tag/> <tag/>\n"
|
62
|
+
end
|
63
|
+
|
64
|
+
it "will parse & execute a simple template with statements" do
|
65
|
+
context = ContextHash(right: "right")
|
66
|
+
result = subject.render("statements2", context)
|
67
|
+
result.must_equal "\nThis is right 0\n\nThis is right 1\n\nThis is right 2\n\n"
|
68
|
+
end
|
69
|
+
|
70
|
+
it "will parse & execute a simple template with comments" do
|
71
|
+
context = ContextHash(right: "right")
|
72
|
+
result = subject.render("comments2", context)
|
73
|
+
result.must_equal "\n"
|
74
|
+
end
|
75
|
+
|
76
|
+
it "will remove whitespace after tags with a closing '-'" do
|
77
|
+
context = ContextHash(right: "right")
|
78
|
+
result = subject.render("whitespace2", context)
|
79
|
+
expected = ["here 0", "here 1", "here 2\n"].join("\n")
|
80
|
+
result.must_equal expected
|
81
|
+
end
|
82
|
+
|
83
|
+
it "can convert a template to another syntax" do
|
84
|
+
result = subject.convert('statements2', Cutaneous::FirstPassSyntax)
|
85
|
+
result.must_equal read_template('statements1.html.cut')
|
86
|
+
end
|
87
|
+
|
88
|
+
it "can convert a template string to another syntax" do
|
89
|
+
result = subject.convert_string(read_template('statements2.html.cut'), Cutaneous::FirstPassSyntax)
|
90
|
+
result.must_equal read_template('statements1.html.cut')
|
91
|
+
end
|
92
|
+
|
93
|
+
it "can convert a template proc to another syntax" do
|
94
|
+
result = subject.convert(proc { read_template('statements2.html.cut') }, Cutaneous::FirstPassSyntax)
|
95
|
+
result.must_equal read_template('statements1.html.cut')
|
96
|
+
end
|
60
97
|
end
|
61
98
|
end
|
62
99
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cutaneous
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Garry Hill
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-08-
|
11
|
+
date: 2013-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Cutaneous is the Ruby templating language designed for use with Spontaneous
|
14
14
|
CMS. It has a simple syntax but powerful features such as Djano style template inheritance
|
@@ -86,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
86
|
version: '0'
|
87
87
|
requirements: []
|
88
88
|
rubyforge_project: cutaneous
|
89
|
-
rubygems_version: 2.0.
|
89
|
+
rubygems_version: 2.0.0
|
90
90
|
signing_key:
|
91
91
|
specification_version: 2
|
92
92
|
summary: A Ruby templating language with Django style template inheritance
|