undies 2.2.1 → 3.0.0.rc.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. data/ARCH.md +116 -0
  2. data/Gemfile +3 -0
  3. data/Gemfile.lock +20 -4
  4. data/LICENSE +22 -0
  5. data/README.md +343 -0
  6. data/Rakefile +25 -17
  7. data/bench/bench_runner.rb +132 -12
  8. data/bench/large.html.erb +9 -13
  9. data/bench/large.html.haml +11 -0
  10. data/bench/large.html.rb +8 -12
  11. data/bench/profiler +1 -1
  12. data/bench/profiler_runner.rb +2 -5
  13. data/bench/small.html.erb +9 -13
  14. data/bench/small.html.haml +11 -0
  15. data/bench/small.html.rb +8 -12
  16. data/bench/verylarge.html.erb +9 -13
  17. data/bench/verylarge.html.haml +11 -0
  18. data/bench/verylarge.html.rb +8 -12
  19. data/lib/undies/api.rb +163 -0
  20. data/lib/undies/element.rb +160 -80
  21. data/lib/undies/element_node.rb +116 -0
  22. data/lib/undies/io.rb +43 -0
  23. data/lib/undies/root_node.rb +62 -0
  24. data/lib/undies/source.rb +78 -2
  25. data/lib/undies/template.rb +17 -131
  26. data/lib/undies/version.rb +1 -1
  27. data/lib/undies.rb +3 -2
  28. data/test/element_closed_test.rb +69 -0
  29. data/test/element_node_test.rb +274 -0
  30. data/test/element_open_test.rb +101 -0
  31. data/test/element_test.rb +23 -196
  32. data/test/fixtures/write_thing.rb +4 -4
  33. data/test/helper.rb +84 -0
  34. data/test/io_test.rb +104 -0
  35. data/test/named_source_test.rb +1 -1
  36. data/test/raw_test.rb +25 -0
  37. data/test/root_node_test.rb +108 -0
  38. data/test/source_stack_test.rb +1 -1
  39. data/test/template_builder_render_test.rb +4 -9
  40. data/test/template_source_render_test.rb +16 -20
  41. data/test/template_test.rb +87 -80
  42. data/test/templates/content.html.rb +1 -1
  43. data/test/templates/test.html.rb +1 -1
  44. data/undies.gemspec +1 -0
  45. metadata +52 -23
  46. data/README.rdoc +0 -203
  47. data/lib/undies/named_source.rb +0 -54
  48. data/lib/undies/node.rb +0 -87
  49. data/lib/undies/node_stack.rb +0 -111
  50. data/lib/undies/output.rb +0 -31
  51. data/lib/undies/source_stack.rb +0 -22
  52. data/test/node_stack_test.rb +0 -109
  53. data/test/node_test.rb +0 -91
  54. data/test/output_test.rb +0 -69
data/test/node_test.rb DELETED
@@ -1,91 +0,0 @@
1
- require "assert"
2
-
3
- require "undies/output"
4
- require "undies/node"
5
-
6
- class Undies::Node
7
-
8
- class BasicTests < Assert::Context
9
- desc 'a node'
10
- before do
11
- @output = Undies::Output.new(StringIO.new(@out = ""))
12
- @n = Undies::Node.new("a text node here")
13
- end
14
- subject { @n }
15
-
16
- should have_class_methods :start_tag, :end_tag, :set_start_tag, :set_end_tag
17
- should have_class_methods :builds, :add_build
18
- should have_class_methods :children, :set_children
19
- should have_class_methods :attrs, :merge_attrs
20
- should have_class_methods :node_name, :content, :mode, :prefix
21
-
22
- should "have no start/end tags" do
23
- assert_empty subject.class.start_tag(subject)
24
- assert_empty subject.class.end_tag(subject)
25
- end
26
-
27
- should "have content" do
28
- assert_equal "a text node here", subject.class.content(subject)
29
- end
30
-
31
- should "have no builds" do
32
- assert_empty subject.class.builds(subject)
33
- end
34
-
35
- should "be :inline mode by default" do
36
- assert_equal :inline, subject.class.mode(subject)
37
- end
38
-
39
- should "have no prefix if :inline mode" do
40
- assert_empty subject.class.prefix(subject, 'start_tag', 2, 2)
41
- assert_empty subject.class.prefix(subject, 'end_tag', 1, 2)
42
- end
43
-
44
- should "have a pp prefix if not :inline mode" do
45
- node = Undies::Node.new("a non inline node", :partial)
46
- assert_equal "\n ", node.class.prefix(node, 'start_tag', 2, 2)
47
- assert_equal "\n ", node.class.prefix(node, 'end_tag', 2, 2)
48
- assert_equal "\n ", node.class.prefix(node, 'start_tag', 1, 2)
49
- assert_equal "\n", node.class.prefix(node, 'end_tag', 1, 2)
50
- assert_equal "", node.class.prefix(node, 'start_tag', 0, 2)
51
- assert_equal "\n", node.class.prefix(node, 'end_tag', 0, 2)
52
- end
53
-
54
- should "have no children by default" do
55
- assert_equal false, subject.class.children(subject)
56
- end
57
-
58
- should "have no attrs by default" do
59
- assert_empty subject.class.attrs(subject)
60
- end
61
-
62
- should "have no name by default" do
63
- assert_empty subject.class.node_name(subject)
64
- end
65
-
66
- should "add a build if given a block" do
67
- subject.class.add_build(subject, Proc.new {})
68
- assert_equal [Proc.new {}], subject.class.builds(subject)
69
-
70
- subject.class.add_build(subject, Proc.new {})
71
- assert_equal [Proc.new {}, Proc.new {}], subject.class.builds(subject)
72
- end
73
-
74
- should "set children if given a value" do
75
- subject.class.set_children(subject, true)
76
- assert_equal true, subject.class.children(subject)
77
- end
78
-
79
- should "merge attrs if given an attrs hash" do
80
- attrs_hash = {:same => 'value', :new => 'a new value'}
81
- subject.class.merge_attrs(subject, attrs_hash)
82
- assert_equal attrs_hash, subject.class.attrs(subject)
83
-
84
- attrs_hash = {:same => 'new same', :new => 'a new value'}
85
- subject.class.merge_attrs(subject, attrs_hash)
86
- assert_equal attrs_hash, subject.class.attrs(subject)
87
- end
88
-
89
- end
90
-
91
- end
data/test/output_test.rb DELETED
@@ -1,69 +0,0 @@
1
- require "assert"
2
-
3
- require 'stringio'
4
- require 'undies/node'
5
- require 'undies/element'
6
- require 'undies/node_stack'
7
- require 'test/fixtures/write_thing'
8
-
9
- require "undies/output"
10
-
11
- class Undies::Output
12
-
13
- class BasicTests < Assert::Context
14
- desc 'render data'
15
- before do
16
- @io = StringIO.new(@out = "")
17
- @output = Undies::Output.new(@io)
18
- end
19
- subject { @output }
20
-
21
- should have_readers :io, :pp
22
- should have_writer :options
23
- should have_accessor :pp_level
24
- should have_instance_method :write
25
-
26
- should "know its stream" do
27
- assert_same @io, subject.io
28
- end
29
-
30
- should "default to no pretty printing" do
31
- assert_equal 0, subject.pp
32
- end
33
-
34
- should "default to pretty printing level 0" do
35
- assert_equal 0, subject.pp_level
36
- end
37
-
38
- end
39
-
40
- class PrettyPrintTests < BasicTests
41
- desc "when pretty printing"
42
- before do
43
- subject.options = {:pp => 2}
44
- end
45
-
46
- should "know its pp indent amount" do
47
- assert_equal 2, subject.pp
48
- end
49
-
50
- should "start pp at level 0 by default" do
51
- assert_equal 0, subject.pp_level
52
- end
53
-
54
- should "pretty print stream data" do
55
- subject.write(WriteThing.new, :hi, 0)
56
- assert_equal "hi", @out
57
-
58
- subject.pp_level +=1
59
- subject.write(WriteThing.new, :hello, 0)
60
- assert_equal "hi\n hello", @out
61
-
62
- subject.pp_level -= 1
63
- subject.write(WriteThing.new, :hithere, 0)
64
- assert_equal "hi\n hellohithere", @out
65
- end
66
-
67
- end
68
-
69
- end