undies 1.2.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/Gemfile +2 -1
- data/Gemfile.lock +10 -5
- data/Rakefile +2 -4
- data/bench/large.html.rb +32 -0
- data/bench/procs.rb +106 -0
- data/bench/profiler.rb +25 -0
- data/bench/small.html.rb +32 -0
- data/bench/verylarge.html.rb +32 -0
- data/lib/undies/element.rb +61 -61
- data/lib/undies/named_source.rb +54 -0
- data/lib/undies/node.rb +16 -24
- data/lib/undies/node_buffer.rb +35 -0
- data/lib/undies/output.rb +64 -0
- data/lib/undies/source.rb +58 -12
- data/lib/undies/source_stack.rb +22 -0
- data/lib/undies/template.rb +47 -134
- data/lib/undies/version.rb +1 -1
- data/lib/undies.rb +1 -11
- data/test/element_test.rb +106 -99
- data/test/helper.rb +4 -2
- data/test/irb.rb +3 -4
- data/test/named_source_test.rb +91 -0
- data/test/node_buffer_test.rb +54 -0
- data/test/node_test.rb +19 -10
- data/test/output_test.rb +116 -0
- data/test/source_stack_test.rb +48 -0
- data/test/source_test.rb +131 -27
- data/test/template_test.rb +120 -145
- data/test/templates/layout.html.rb +1 -1
- data/undies.gemspec +1 -1
- metadata +27 -23
- data/lib/undies/element_stack.rb +0 -35
- data/lib/undies/node_list.rb +0 -35
- data/lib/undies/partial.rb +0 -23
- data/lib/undies/partial_data.rb +0 -32
- data/test/element_stack_test.rb +0 -77
- data/test/fixtures/partial_template.rb +0 -6
- data/test/node_list_test.rb +0 -69
- data/test/partial_data_test.rb +0 -100
- data/test/partial_test.rb +0 -63
data/test/element_stack_test.rb
DELETED
@@ -1,77 +0,0 @@
|
|
1
|
-
require "test_belt"
|
2
|
-
|
3
|
-
require "stringio"
|
4
|
-
require "undies/element_stack"
|
5
|
-
require "undies/node"
|
6
|
-
|
7
|
-
class Undies::ElementStack
|
8
|
-
|
9
|
-
class BasicTest < Test::Unit::TestCase
|
10
|
-
include TestBelt
|
11
|
-
|
12
|
-
context 'an element stack'
|
13
|
-
before { @es = Undies::ElementStack.new }
|
14
|
-
subject { @es }
|
15
|
-
|
16
|
-
should have_instance_method :push, :pop
|
17
|
-
should have_reader :io
|
18
|
-
|
19
|
-
should "be an Array" do
|
20
|
-
assert_kind_of Array, subject
|
21
|
-
end
|
22
|
-
|
23
|
-
should "empty by default" do
|
24
|
-
assert subject.empty?
|
25
|
-
end
|
26
|
-
|
27
|
-
should "compain when trying to push non-elements" do
|
28
|
-
assert_raises ArgumentError do
|
29
|
-
subject.push Undies::Node.new
|
30
|
-
end
|
31
|
-
|
32
|
-
assert_nothing_raised do
|
33
|
-
subject << 1
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
should "initialize with a first item if one is given" do
|
38
|
-
stack = Undies::ElementStack.new(12)
|
39
|
-
assert_equal [12], stack
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
43
|
-
|
44
|
-
class StreamingTest < BasicTest
|
45
|
-
context "when streaming"
|
46
|
-
before do
|
47
|
-
@output = ""
|
48
|
-
@outstream = StringIO.new(@output)
|
49
|
-
@es = Undies::ElementStack.new(nil, @outstream)
|
50
|
-
end
|
51
|
-
|
52
|
-
should "know its stream" do
|
53
|
-
assert_same @outstream, subject.io
|
54
|
-
end
|
55
|
-
|
56
|
-
should "stream an elements start tag when that element is pushed" do
|
57
|
-
subject.push(Undies::Element.new(Undies::ElementStack.new, "div") {})
|
58
|
-
assert_equal "<div>", @output
|
59
|
-
end
|
60
|
-
|
61
|
-
should "stream an elements end tag when that element is popped" do
|
62
|
-
elem = Undies::Element.new(Undies::ElementStack.new, "div") {}
|
63
|
-
subject.push(elem)
|
64
|
-
popped_elem = subject.pop
|
65
|
-
assert_equal "<div></div>", @output
|
66
|
-
assert_same elem, popped_elem
|
67
|
-
end
|
68
|
-
|
69
|
-
should "stream an element with no content when pushed/popped" do
|
70
|
-
subject.push(Undies::Element.new(Undies::ElementStack.new, "span"))
|
71
|
-
subject.pop
|
72
|
-
assert_equal "<span />", @output
|
73
|
-
end
|
74
|
-
|
75
|
-
end
|
76
|
-
|
77
|
-
end
|
data/test/node_list_test.rb
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
require "test_belt"
|
2
|
-
require "undies/node_list"
|
3
|
-
require "undies/node"
|
4
|
-
|
5
|
-
class Undies::NodeList
|
6
|
-
|
7
|
-
class BasicTests < Test::Unit::TestCase
|
8
|
-
include TestBelt
|
9
|
-
|
10
|
-
context 'a node list'
|
11
|
-
subject { Undies::NodeList.new }
|
12
|
-
should have_instance_method :append
|
13
|
-
|
14
|
-
should "be an Array" do
|
15
|
-
assert_kind_of ::Array, subject
|
16
|
-
end
|
17
|
-
|
18
|
-
should "always init empty" do
|
19
|
-
assert_equal 0, subject.size
|
20
|
-
assert_equal 0, Undies::NodeList.new([1,2,3]).size
|
21
|
-
end
|
22
|
-
|
23
|
-
should "complain if you try to append something other than a node" do
|
24
|
-
assert_raises ArgumentError do
|
25
|
-
subject.append('hey!')
|
26
|
-
end
|
27
|
-
assert_raises ArgumentError do
|
28
|
-
subject << 'hey!'
|
29
|
-
end
|
30
|
-
assert_nothing_raised do
|
31
|
-
subject.append(Undies::Node.new('hey!'))
|
32
|
-
subject.append(Undies::NodeList.new)
|
33
|
-
subject << Undies::Node.new('hey!')
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
38
|
-
|
39
|
-
class NodeHandlingTests < BasicTests
|
40
|
-
setup do
|
41
|
-
@hey = Undies::Node.new "hey!"
|
42
|
-
@you = Undies::Node.new " you..."
|
43
|
-
@there = Undies::Node.new " there."
|
44
|
-
@node_list = Undies::NodeList.new
|
45
|
-
@node_list.append(@you)
|
46
|
-
@node_list.append(@there)
|
47
|
-
end
|
48
|
-
|
49
|
-
should "append nodes with the 'append' method" do
|
50
|
-
subject.append(@hey)
|
51
|
-
assert_equal 1, subject.size
|
52
|
-
end
|
53
|
-
|
54
|
-
should "return the node when appending" do
|
55
|
-
assert_equal @hey.object_id, subject.append(@hey).object_id
|
56
|
-
end
|
57
|
-
|
58
|
-
should "serialize to a string" do
|
59
|
-
assert_equal " you... there.", @node_list.to_s
|
60
|
-
|
61
|
-
to_serialize = Undies::NodeList.new
|
62
|
-
to_serialize.append(@hey)
|
63
|
-
to_serialize.append(@node_list)
|
64
|
-
assert_equal "hey! you... there.", to_serialize.to_s
|
65
|
-
end
|
66
|
-
|
67
|
-
end
|
68
|
-
|
69
|
-
end
|
data/test/partial_data_test.rb
DELETED
@@ -1,100 +0,0 @@
|
|
1
|
-
require "test_belt"
|
2
|
-
require "undies/partial_data"
|
3
|
-
|
4
|
-
class Undies::PartialLocals
|
5
|
-
|
6
|
-
class BasicTest < Test::Unit::TestCase
|
7
|
-
include TestBelt
|
8
|
-
|
9
|
-
context 'partial data'
|
10
|
-
subject { Undies::PartialLocals.new 'test/templates/index.html.rb' }
|
11
|
-
should have_readers :path, :name
|
12
|
-
|
13
|
-
should "be a kind of Hash" do
|
14
|
-
assert subject.kind_of?(::Hash)
|
15
|
-
end
|
16
|
-
|
17
|
-
should "complain if now path given" do
|
18
|
-
assert_raises ArgumentError do
|
19
|
-
Undies::PartialLocals.new
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
24
|
-
|
25
|
-
class NameTest < BasicTest
|
26
|
-
|
27
|
-
should "know its name given a file" do
|
28
|
-
data = Undies::PartialLocals.new('test/templates/current.html.rb')
|
29
|
-
assert_equal 'current', data.name
|
30
|
-
end
|
31
|
-
|
32
|
-
should "know its name given a file name with a leading char" do
|
33
|
-
data = Undies::PartialLocals.new('test/templates/_partial.html.rb')
|
34
|
-
assert_equal 'partial', data.name
|
35
|
-
end
|
36
|
-
|
37
|
-
should "know its name given a file name with multiple leading chars" do
|
38
|
-
data = Undies::PartialLocals.new('test/templates/__partial.html.rb')
|
39
|
-
assert_equal 'partial', data.name
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
43
|
-
|
44
|
-
class ValuesTest < BasicTest
|
45
|
-
before do
|
46
|
-
@path = 'test/templates/index.html.rb'
|
47
|
-
end
|
48
|
-
subject { Undies::PartialLocals.new(@path) }
|
49
|
-
|
50
|
-
should "not have any values by default" do
|
51
|
-
assert_equal({}, subject)
|
52
|
-
end
|
53
|
-
|
54
|
-
should "know its values" do
|
55
|
-
subject.values = {:name => 'A Name'}
|
56
|
-
assert_equal({:name => "A Name"}, subject)
|
57
|
-
end
|
58
|
-
|
59
|
-
should "complain when values not given as a hash" do
|
60
|
-
assert_raises ArgumentError do
|
61
|
-
subject.values = "some data"
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
should "force its object value to a string key" do
|
66
|
-
assert !subject.has_key?(:index)
|
67
|
-
assert !subject.has_key?('index')
|
68
|
-
subject.object = "thing"
|
69
|
-
assert !subject.has_key?(:index)
|
70
|
-
assert subject.has_key?('index')
|
71
|
-
end
|
72
|
-
|
73
|
-
should "force its name value to a string key" do
|
74
|
-
assert !subject.has_key?(:index)
|
75
|
-
assert !subject.has_key?('index')
|
76
|
-
subject.values = {:index => 'thing'}
|
77
|
-
assert !subject.has_key?(:index)
|
78
|
-
assert subject.has_key?('index')
|
79
|
-
end
|
80
|
-
|
81
|
-
should "set its values to its object" do
|
82
|
-
subject.object = "thing"
|
83
|
-
assert_equal({'index' => "thing"}, subject)
|
84
|
-
end
|
85
|
-
|
86
|
-
should "merge its object into the values" do
|
87
|
-
subject.object = "thing"
|
88
|
-
subject.values = {:color => "#FFF"}
|
89
|
-
assert_equal({'index' => "thing", :color => "#FFF"}, subject)
|
90
|
-
end
|
91
|
-
|
92
|
-
should "overwrite its object with the values if needed" do
|
93
|
-
subject.object = "thing"
|
94
|
-
subject.values = {'index' => "#FFF"}
|
95
|
-
assert_equal({'index' => "#FFF"}, subject)
|
96
|
-
end
|
97
|
-
|
98
|
-
end
|
99
|
-
|
100
|
-
end
|
data/test/partial_test.rb
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
require "test_belt"
|
2
|
-
|
3
|
-
require "stringio"
|
4
|
-
require "test/fixtures/partial_template"
|
5
|
-
|
6
|
-
class Undies::PartialTests
|
7
|
-
|
8
|
-
class BasicTest < Test::Unit::TestCase
|
9
|
-
include TestBelt
|
10
|
-
|
11
|
-
context 'partial'
|
12
|
-
before do
|
13
|
-
@path = 'test/templates/test.html.rb'
|
14
|
-
@p = TestPartial.new @path
|
15
|
-
end
|
16
|
-
subject { @p }
|
17
|
-
|
18
|
-
should "be a kind of Template" do
|
19
|
-
assert subject.kind_of?(Undies::Template)
|
20
|
-
end
|
21
|
-
|
22
|
-
should "complain if no path given" do
|
23
|
-
assert_raises ArgumentError do
|
24
|
-
TestPartial.new
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
class LocalsTest < BasicTest
|
31
|
-
before do
|
32
|
-
@path = 'test/templates/index.html.rb'
|
33
|
-
end
|
34
|
-
|
35
|
-
should "know its data" do
|
36
|
-
partial = TestPartial.new(@path, :name => 'A Name')
|
37
|
-
assert_equal("A Name", partial.name)
|
38
|
-
end
|
39
|
-
|
40
|
-
should "know its object" do
|
41
|
-
partial = TestPartial.new(@path, "thing")
|
42
|
-
assert_equal("thing", partial.index)
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
46
|
-
|
47
|
-
class StreamTest < BasicTest
|
48
|
-
context "that is streaming"
|
49
|
-
|
50
|
-
before do
|
51
|
-
@output = ""
|
52
|
-
@outstream = StringIO.new(@output)
|
53
|
-
end
|
54
|
-
|
55
|
-
|
56
|
-
should "should write to the stream as its being constructed" do
|
57
|
-
TestPartial.new @path, @outstream
|
58
|
-
assert_equal "<html><head></head><body><div>Hi</div></body></html>", @output
|
59
|
-
end
|
60
|
-
|
61
|
-
end
|
62
|
-
|
63
|
-
end
|