tight-engine 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/tight-engine/defer.rb +12 -7
- data/lib/tight-engine/version.rb +1 -1
- data/test/helper.rb +15 -0
- data/test/test_defer.rb +65 -0
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a7c72ad41e773091a87b4257678b4e48e1cd055
|
4
|
+
data.tar.gz: 2cd27ab7a61123d1fcab734509020852f82138c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 758b33c34d40baf909cb4d3fb92a84656b7e9d1007c2e985f1dd23614edb9c78df44abab527064261c3fdbbd8ef4441dc1d8309942b9fe0d8e564dd93d50e7ea
|
7
|
+
data.tar.gz: 6c9b265399026b068af2473b2c5d55489675535c1d93574301a3381d474e44eb5279e43f2bb1c1ba1972b7aaf0a790805253a0f1732bb3f546fc771ffc0528c8
|
data/lib/tight-engine/defer.rb
CHANGED
@@ -5,23 +5,28 @@ module Tight
|
|
5
5
|
@placeholders ||= {}
|
6
6
|
end
|
7
7
|
|
8
|
-
def defer_element(
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
def defer_element(name, args, opts)
|
9
|
+
if settings.respond_to?(:deferred_elements) && settings.deferred_elements.include?(name)
|
10
|
+
placeholders[name] = [ name, args, opts ]
|
11
|
+
"%{placeholder[:#{name}]}"
|
12
|
+
else
|
13
|
+
process_element(name, args, opts)
|
14
|
+
end
|
12
15
|
end
|
13
16
|
|
14
17
|
def process_deferred_elements( text )
|
15
18
|
text.to_str.gsub /(\s*)\%\{placeholder\[\:([^\]]+)\]\}/ do
|
16
19
|
if deferred = placeholders[$2]
|
17
|
-
output = process_element
|
20
|
+
output = process_element(*deferred)
|
18
21
|
if engine.pretty?
|
19
|
-
|
22
|
+
# $/ is magic for CR/LF/CRLF
|
23
|
+
indent = $/ + $1
|
24
|
+
$1 + output.gsub(/\r|\n|\r\n/, indent) + indent
|
20
25
|
else
|
21
26
|
output
|
22
27
|
end
|
23
28
|
else
|
24
|
-
|
29
|
+
"#{$1}%{placeholder[:#{$2}]}"
|
25
30
|
end
|
26
31
|
end
|
27
32
|
end
|
data/lib/tight-engine/version.rb
CHANGED
data/test/helper.rb
ADDED
data/test/test_defer.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'tight-engine/defer'
|
3
|
+
|
4
|
+
describe Tight::Engine::Defer do
|
5
|
+
include Tight::Engine::Defer
|
6
|
+
|
7
|
+
def process_element(*args)
|
8
|
+
"block test\n" + args.inspect + @iteration
|
9
|
+
end
|
10
|
+
|
11
|
+
def args
|
12
|
+
['Block', [1, 3], :false => true]
|
13
|
+
end
|
14
|
+
|
15
|
+
before do
|
16
|
+
@iteration = '1'
|
17
|
+
settings.clear
|
18
|
+
placeholders.clear
|
19
|
+
engine.clear
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should have no initial placeholders' do
|
23
|
+
assert_equal({}, placeholders)
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should defer elements set to be deferred' do
|
27
|
+
settings[:deferred_elements] = ['Block']
|
28
|
+
|
29
|
+
text = defer_element(*args)
|
30
|
+
|
31
|
+
assert_equal({'Block' => args}, placeholders)
|
32
|
+
assert_equal "%{placeholder[:Block]}", text
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should process deferred elements' do
|
36
|
+
settings[:deferred_elements] = ['Block']
|
37
|
+
|
38
|
+
text = defer_element(*args)
|
39
|
+
@iteration = '2'
|
40
|
+
result = process_deferred_elements('before' + text + 'after')
|
41
|
+
|
42
|
+
assert_equal("beforeblock test\n" + args.inspect + '2after', result)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should not defer any elements by default and process them right away' do
|
46
|
+
text = defer_element(*args)
|
47
|
+
@iteration = '2'
|
48
|
+
result = process_deferred_elements('before' + text + 'after')
|
49
|
+
|
50
|
+
assert_equal({}, placeholders)
|
51
|
+
assert_equal("block test\n" + args.inspect + '1', text)
|
52
|
+
assert_equal("beforeblock test\n" + args.inspect + '1after', result)
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should be able to be pretty' do
|
56
|
+
settings[:deferred_elements] = ['Block']
|
57
|
+
engine[:pretty?] = true
|
58
|
+
|
59
|
+
text = defer_element(*args)
|
60
|
+
@iteration = '2'
|
61
|
+
result = process_deferred_elements(' ' + text)
|
62
|
+
|
63
|
+
assert_equal(" block test\n " + args.inspect + "2\n ", result)
|
64
|
+
end
|
65
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tight-engine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Igor Bochkariov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -87,6 +87,8 @@ files:
|
|
87
87
|
- lib/tight-engine/url.rb
|
88
88
|
- lib/tight-engine/utils.rb
|
89
89
|
- lib/tight-engine/version.rb
|
90
|
+
- test/helper.rb
|
91
|
+
- test/test_defer.rb
|
90
92
|
- tight-engine.gemspec
|
91
93
|
homepage: https://github.com/ujifgc/tight-engine
|
92
94
|
licenses:
|
@@ -112,5 +114,7 @@ rubygems_version: 2.2.2
|
|
112
114
|
signing_key:
|
113
115
|
specification_version: 4
|
114
116
|
summary: A tight engine for a swift content management system
|
115
|
-
test_files:
|
117
|
+
test_files:
|
118
|
+
- test/helper.rb
|
119
|
+
- test/test_defer.rb
|
116
120
|
has_rdoc:
|