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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d9af08abd886546c991e706361e0a40872e0e6ca
4
- data.tar.gz: b9e8bb833bf96cfbc027ff4f446c41b085930b1c
3
+ metadata.gz: 3a7c72ad41e773091a87b4257678b4e48e1cd055
4
+ data.tar.gz: 2cd27ab7a61123d1fcab734509020852f82138c1
5
5
  SHA512:
6
- metadata.gz: da17884b6953ce5babcb31c05a577f114c56f16ae41dde952840a849c0d6f70ea297d92c33025da579b3a491ded507a523d1d810a827cb66b3db962da1280aab
7
- data.tar.gz: 1e6484ce7ec08c592a25c9fb9575f853b8826986ca8868883ad3eab2a94d4a95d639bed33d8f7f024ef47573aa8c60b3ff649261ad85cf2120f790457c49d618
6
+ metadata.gz: 758b33c34d40baf909cb4d3fb92a84656b7e9d1007c2e985f1dd23614edb9c78df44abab527064261c3fdbbd8ef4441dc1d8309942b9fe0d8e564dd93d50e7ea
7
+ data.tar.gz: 6c9b265399026b068af2473b2c5d55489675535c1d93574301a3381d474e44eb5279e43f2bb1c1ba1972b7aaf0a790805253a0f1732bb3f546fc771ffc0528c8
@@ -5,23 +5,28 @@ module Tight
5
5
  @placeholders ||= {}
6
6
  end
7
7
 
8
- def defer_element( name, args, opts )
9
- return unless settings.deferred_elements.include?(name)
10
- placeholders[name] = [ name, args, opts ]
11
- "%{placeholder[:#{name}]}"
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 *deferred
20
+ output = process_element(*deferred)
18
21
  if engine.pretty?
19
- $1+output.gsub(/\r|\n|\r\n/, $1)+$1
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
@@ -1,5 +1,5 @@
1
1
  module Tight
2
2
  module Engine
3
- VERSION = '0.0.2'
3
+ VERSION = '0.0.3'
4
4
  end
5
5
  end
@@ -0,0 +1,15 @@
1
+ ENV['RACK_ENV'] = 'test'
2
+
3
+ require 'minitest/autorun'
4
+ require 'sinatra/base'
5
+ require 'ostruct'
6
+
7
+ class MiniTest::Spec
8
+ def settings
9
+ @settings ||= OpenStruct.new
10
+ end
11
+
12
+ def engine
13
+ @engine ||= OpenStruct.new
14
+ end
15
+ end
@@ -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.2
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-05 00:00:00.000000000 Z
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: