undies 3.0.0.rc.3 → 3.0.0

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.
Files changed (37) hide show
  1. data/.gitignore +17 -3
  2. data/Gemfile +7 -4
  3. data/{LICENSE → LICENSE.txt} +0 -0
  4. data/README.md +107 -105
  5. data/Rakefile +1 -8
  6. data/lib/undies/api.rb +2 -1
  7. data/lib/undies/element.rb +43 -81
  8. data/lib/undies/element_node.rb +6 -5
  9. data/lib/undies/io.rb +0 -1
  10. data/lib/undies/raw.rb +15 -0
  11. data/lib/undies/source.rb +0 -8
  12. data/lib/undies/version.rb +1 -1
  13. data/lib/undies.rb +4 -2
  14. data/test/helper.rb +5 -85
  15. data/test/support/element.rb +79 -0
  16. data/test/{templates → support/templates}/content.html.rb +0 -0
  17. data/test/{templates → support/templates}/index.html.rb +0 -0
  18. data/test/{templates → support/templates}/layout.html.rb +0 -0
  19. data/test/{templates → support/templates}/test.html.rb +0 -0
  20. data/test/{element_closed_test.rb → unit/element_closed_tests.rb} +2 -6
  21. data/test/{element_node_test.rb → unit/element_node_tests.rb} +5 -11
  22. data/test/{element_open_test.rb → unit/element_open_tests.rb} +2 -5
  23. data/test/{element_test.rb → unit/element_tests.rb} +1 -2
  24. data/test/{io_test.rb → unit/io_tests.rb} +3 -8
  25. data/test/{named_source_test.rb → unit/named_source_tests.rb} +4 -5
  26. data/test/{raw_test.rb → unit/raw_tests.rb} +6 -5
  27. data/test/{root_node_test.rb → unit/root_node_tests.rb} +4 -3
  28. data/test/{source_stack_test.rb → unit/source_stack_tests.rb} +2 -3
  29. data/test/{source_test.rb → unit/source_tests.rb} +5 -6
  30. data/test/{template_builder_render_test.rb → unit/template_builder_render_tests.rb} +3 -0
  31. data/test/{template_source_render_test.rb → unit/template_source_render_tests.rb} +5 -10
  32. data/test/{template_test.rb → unit/template_tests.rb} +12 -30
  33. data/undies.gemspec +16 -18
  34. metadata +58 -111
  35. data/Gemfile.lock +0 -48
  36. data/test/fixtures/write_thing.rb +0 -21
  37. data/test/irb.rb +0 -9
data/lib/undies/io.rb CHANGED
@@ -28,7 +28,6 @@ module Undies
28
28
  "#{' '*(@level+relative_level)*@indent}"
29
29
  end
30
30
 
31
- # TODO: threaded/forked writing for performance improvement
32
31
  def <<(markup)
33
32
  @stream << markup
34
33
  end
data/lib/undies/raw.rb ADDED
@@ -0,0 +1,15 @@
1
+ module Undies
2
+
3
+ class Raw < ::String
4
+
5
+ # A Raw string is one that is impervious to String#gsub
6
+ # and returns itself when `to_s` is called. Used to circumvent
7
+ # the default html escaping of markup
8
+
9
+ def gsub(*args); self; end
10
+ def gsub!(*args); nil; end
11
+ def to_s; self; end
12
+
13
+ end
14
+
15
+ end
data/lib/undies/source.rb CHANGED
@@ -1,7 +1,5 @@
1
1
  module Undies
2
2
 
3
-
4
-
5
3
  class Source
6
4
 
7
5
  attr_reader :source, :data, :layout
@@ -72,8 +70,6 @@ module Undies
72
70
 
73
71
  end
74
72
 
75
-
76
-
77
73
  class NamedSource
78
74
 
79
75
  attr_accessor :file, :opts, :proc
@@ -123,8 +119,6 @@ module Undies
123
119
  end
124
120
  end
125
121
 
126
-
127
-
128
122
  class SourceStack < ::Array
129
123
 
130
124
  # a source stack is used to manage which sources and any deeply nested
@@ -144,6 +138,4 @@ module Undies
144
138
 
145
139
  end
146
140
 
147
-
148
-
149
141
  end
@@ -1,3 +1,3 @@
1
1
  module Undies
2
- VERSION = "3.0.0.rc.3"
2
+ VERSION = "3.0.0"
3
3
  end
data/lib/undies.rb CHANGED
@@ -1,4 +1,6 @@
1
- module Undies; end
2
-
1
+ require 'undies/version'
3
2
  require 'undies/io'
4
3
  require 'undies/template'
4
+
5
+ module Undies
6
+ end
data/test/helper.rb CHANGED
@@ -1,88 +1,8 @@
1
- # this file is automatically required in when you require 'assert' in your tests
1
+ # this file is automatically required when you run `assert`
2
+ # put any test helpers here
2
3
 
3
- # add root dir to the load path
4
+ # add the root dir to the load path
4
5
  $LOAD_PATH.unshift(File.expand_path("../..", __FILE__))
5
6
 
6
- require 'undies'
7
-
8
- module Undies
9
- module Element
10
-
11
- module CSSProxyMacro
12
-
13
- def proxy_css_methods
14
- called_from = caller.first
15
- Assert::Macro.new("have style attributes") do
16
-
17
- should "respond to any method ending in '!' as an id proxy", called_from do
18
- assert subject.respond_to?(:asdgasdg!)
19
- end
20
-
21
- should "proxy id attr with methods ending in '!'", called_from do
22
- assert_equal({
23
- :id => 'thing1'
24
- }, subject.thing1!.instance_variable_get("@attrs"))
25
- end
26
-
27
- should "proxy id attr with last method call ending in '!'", called_from do
28
- assert_equal({
29
- :id => 'thing2'
30
- }, subject.thing1!.thing2!.instance_variable_get("@attrs"))
31
- end
32
-
33
- should "set id attr to explicit if called last ", called_from do
34
- assert_equal({
35
- :id => 'thing3'
36
- }, subject.thing1!.thing2!(:id => 'thing3').instance_variable_get("@attrs"))
37
- end
38
-
39
- should "set id attr to proxy if called last", called_from do
40
- assert_equal({
41
- :id => 'thing1'
42
- }, subject.thing2!(:id => 'thing3').thing1!.instance_variable_get("@attrs"))
43
- end
44
-
45
- should "respond to any other method as a class proxy", called_from do
46
- assert_respond_to :asdgasdg, subject
47
- end
48
-
49
- should "proxy single html class attr", called_from do
50
- assert_equal({
51
- :class => 'thing'
52
- }, subject.thing.instance_variable_get("@attrs"))
53
- end
54
-
55
- should "proxy multi html class attrs", called_from do
56
- assert_equal({
57
- :class => 'list thing awesome'
58
- }, subject.list.thing.awesome.instance_variable_get("@attrs"))
59
- end
60
-
61
- should "set class attr with explicit if called last ", called_from do
62
- assert_equal({
63
- :class => 'list'
64
- }, subject.thing.awesome(:class => "list").instance_variable_get("@attrs"))
65
- end
66
-
67
- should "update class attr with proxy if called last", called_from do
68
- assert_equal({
69
- :class => 'list is good'
70
- }, subject.thing.awesome(:class => "list is").good.instance_variable_get("@attrs"))
71
- end
72
-
73
- should "proxy mixed class and id selector attrs", called_from do
74
- subject.thing1!.awesome({:class => "list is", :id => "thing2"}).good.thing3!
75
-
76
- assert_equal({
77
- :class => 'list is good',
78
- :id => "thing3"
79
- }, subject.instance_variable_get("@attrs"))
80
- end
81
-
82
- end
83
- end
84
-
85
- end
86
-
87
- end
88
- end
7
+ # require pry for debugging (`binding.pry`)
8
+ require 'pry'
@@ -0,0 +1,79 @@
1
+ require 'undies/element'
2
+
3
+ module Undies::Element
4
+ module TestHelpers
5
+
6
+ def proxy_css_methods
7
+ called_from = caller.first
8
+ Assert::Macro.new("have style attributes") do
9
+
10
+ should "respond to any method ending in '!' as an id proxy", called_from do
11
+ assert subject.respond_to?(:asdgasdg!)
12
+ end
13
+
14
+ should "proxy id attr with methods ending in '!'", called_from do
15
+ assert_equal({
16
+ :id => 'thing1'
17
+ }, subject.thing1!.instance_variable_get("@attrs"))
18
+ end
19
+
20
+ should "proxy id attr with last method call ending in '!'", called_from do
21
+ assert_equal({
22
+ :id => 'thing2'
23
+ }, subject.thing1!.thing2!.instance_variable_get("@attrs"))
24
+ end
25
+
26
+ should "set id attr to explicit if called last ", called_from do
27
+ assert_equal({
28
+ :id => 'thing3'
29
+ }, subject.thing1!.thing2!(:id => 'thing3').instance_variable_get("@attrs"))
30
+ end
31
+
32
+ should "set id attr to proxy if called last", called_from do
33
+ assert_equal({
34
+ :id => 'thing1'
35
+ }, subject.thing2!(:id => 'thing3').thing1!.instance_variable_get("@attrs"))
36
+ end
37
+
38
+ should "respond to any other method as a class proxy", called_from do
39
+ assert_respond_to :asdgasdg, subject
40
+ end
41
+
42
+ should "proxy single html class attr", called_from do
43
+ assert_equal({
44
+ :class => 'thing'
45
+ }, subject.thing.instance_variable_get("@attrs"))
46
+ end
47
+
48
+ should "proxy multi html class attrs", called_from do
49
+ assert_equal({
50
+ :class => 'list thing awesome'
51
+ }, subject.list.thing.awesome.instance_variable_get("@attrs"))
52
+ end
53
+
54
+ should "set class attr with explicit if called last ", called_from do
55
+ assert_equal({
56
+ :class => 'list'
57
+ }, subject.thing.awesome(:class => "list").instance_variable_get("@attrs"))
58
+ end
59
+
60
+ should "update class attr with proxy if called last", called_from do
61
+ assert_equal({
62
+ :class => 'list is good'
63
+ }, subject.thing.awesome(:class => "list is").good.instance_variable_get("@attrs"))
64
+ end
65
+
66
+ should "proxy mixed class and id selector attrs", called_from do
67
+ subject.thing1!.awesome({:class => "list is", :id => "thing2"}).good.thing3!
68
+
69
+ assert_equal({
70
+ :class => 'list is good',
71
+ :id => "thing3"
72
+ }, subject.instance_variable_get("@attrs"))
73
+ end
74
+
75
+ end
76
+ end
77
+
78
+ end
79
+ end
File without changes
File without changes
@@ -1,7 +1,7 @@
1
1
  require "assert"
2
- require 'undies/io'
3
2
  require "undies/element"
4
3
 
4
+ require 'test/support/element'
5
5
 
6
6
  module Undies::Element
7
7
 
@@ -25,16 +25,12 @@ module Undies::Element
25
25
 
26
26
  end
27
27
 
28
-
29
-
30
28
  class ClosedCSSProxyTests < ClosedBasicTests
31
- extend CSSProxyMacro
29
+ extend TestHelpers
32
30
 
33
31
  should proxy_css_methods
34
32
  end
35
33
 
36
-
37
-
38
34
  class ClosedSerializeTests < ClosedBasicTests
39
35
 
40
36
  should "serialize with no attrs" do
@@ -1,12 +1,12 @@
1
1
  require "assert"
2
- require 'undies/io'
3
2
  require 'undies/element_node'
4
- require 'undies/element'
5
3
 
4
+ require 'undies/io'
5
+ require 'undies/element'
6
6
 
7
7
  class Undies::ElementNode
8
8
 
9
- class BasicTests < Assert::Context
9
+ class UnitTests < Assert::Context
10
10
  desc 'an element node'
11
11
  before do
12
12
  # io test with :pp 1 so we can test newline insertion
@@ -41,9 +41,7 @@ class Undies::ElementNode
41
41
 
42
42
  end
43
43
 
44
-
45
-
46
- class AddContentTests < BasicTests
44
+ class AddContentTests < UnitTests
47
45
  desc "adding content"
48
46
  before do
49
47
  @text1 = "some raw markup"
@@ -122,8 +120,6 @@ class Undies::ElementNode
122
120
 
123
121
  end
124
122
 
125
-
126
-
127
123
  class AddContentStartTagNotWrittenTests < AddContentTests
128
124
  desc "(the start tag has not been written)"
129
125
  before do
@@ -208,9 +204,7 @@ class Undies::ElementNode
208
204
 
209
205
  end
210
206
 
211
-
212
-
213
- class SerializeTests < BasicTests
207
+ class SerializeTests < UnitTests
214
208
 
215
209
  should "serialize nested elements with pp and only honor the last build block" do
216
210
  io = Undies::IO.new(@out = "", :pp => 1, :level => 0)
@@ -1,6 +1,7 @@
1
1
  require "assert"
2
2
  require "undies/element"
3
3
 
4
+ require 'test/support/element'
4
5
 
5
6
  module Undies::Element
6
7
 
@@ -32,16 +33,12 @@ module Undies::Element
32
33
 
33
34
  end
34
35
 
35
-
36
-
37
36
  class OpenCSSProxyTests < OpenBasicTests
38
- extend CSSProxyMacro
37
+ extend TestHelpers
39
38
 
40
39
  should proxy_css_methods
41
40
  end
42
41
 
43
-
44
-
45
42
  class OpenSerializeTests < OpenBasicTests
46
43
 
47
44
  should "serialize with no attrs, content, or build" do
@@ -1,8 +1,6 @@
1
1
  require "assert"
2
- require 'undies/io'
3
2
  require "undies/element"
4
3
 
5
-
6
4
  module Undies::Element
7
5
 
8
6
  class ElementBasicTests < Assert::Context
@@ -75,6 +73,7 @@ module Undies::Element
75
73
  assert_included 'id="test_2"', attrs
76
74
  assert_included 'nested_something="is_awesome"', attrs
77
75
  end
76
+
78
77
  end
79
78
 
80
79
  end
@@ -3,7 +3,7 @@ require "undies/io"
3
3
 
4
4
  class Undies::IO
5
5
 
6
- class BasicTests < Assert::Context
6
+ class UnitTests < Assert::Context
7
7
  desc 'render data'
8
8
  before do
9
9
  @io = Undies::IO.new(@out = "")
@@ -43,9 +43,7 @@ class Undies::IO
43
43
 
44
44
  end
45
45
 
46
-
47
-
48
- class PrettyPrintTests < BasicTests
46
+ class PrettyPrintTests < UnitTests
49
47
  desc "when pretty printing"
50
48
  before do
51
49
  subject.options = {:pp => 2, :level => 1}
@@ -70,9 +68,7 @@ class Undies::IO
70
68
 
71
69
  end
72
70
 
73
-
74
-
75
- class NodeStackTests < BasicTests
71
+ class NodeStackTests < UnitTests
76
72
 
77
73
  should "push to, pop from, and refer to the current thing on the stack" do
78
74
  subject.push("lala")
@@ -98,7 +94,6 @@ class Undies::IO
98
94
  assert_not_empty subject
99
95
  end
100
96
 
101
-
102
97
  end
103
98
 
104
99
  end
@@ -1,13 +1,12 @@
1
1
  require "assert"
2
-
3
2
  require "undies/source"
4
3
 
5
4
  class Undies::NamedSource
6
5
 
7
- class BasicTests < Assert::Context
6
+ class UnitTests < Assert::Context
8
7
  desc 'a named source'
9
8
  before do
10
- @content_file = File.expand_path('test/templates/content.html.rb')
9
+ @content_file = File.expand_path('test/support/templates/content.html.rb')
11
10
  @content_file_data = File.read(@content_file)
12
11
  @content_file_nsource = Undies::NamedSource.new(@content_file)
13
12
  @content_file_source = Undies::Source.new(@content_file)
@@ -24,7 +23,7 @@ class Undies::NamedSource
24
23
 
25
24
  end
26
25
 
27
- class AccessorTests < BasicTests
26
+ class AccessorTests < UnitTests
28
27
  before do
29
28
  subject.file = @content_file
30
29
  subject.opts = {:layout => :another}
@@ -53,7 +52,7 @@ class Undies::NamedSource
53
52
 
54
53
  end
55
54
 
56
- class UndiesTests < BasicTests
55
+ class UndiesTests < UnitTests
57
56
  before do
58
57
  Undies.named_sources.clear
59
58
  end
@@ -1,13 +1,14 @@
1
1
  require 'assert'
2
+ require 'undies/raw'
3
+
2
4
  require 'undies/template'
3
- require 'undies/element'
4
5
 
5
- module Undies
6
+ class Undies::Raw
6
7
 
7
- class RawTests < Assert::Context
8
+ class UnitTests < Assert::Context
8
9
  desc 'the Raw class'
9
10
  before do
10
- @rs = Raw.new "ab&<>'\"/yz"
11
+ @rs = Undies::Raw.new "ab&<>'\"/yz"
11
12
  end
12
13
  subject { @rs }
13
14
 
@@ -17,7 +18,7 @@ module Undies
17
18
 
18
19
  should "ignore any gsubbing" do
19
20
  assert_equal subject.to_s, subject.gsub('ab', '__').gsub('yz', '--')
20
- assert_equal subject.to_s, Template.escape_html(subject)
21
+ assert_equal subject.to_s, Undies::Template.escape_html(subject)
21
22
  end
22
23
 
23
24
  end
@@ -1,12 +1,13 @@
1
1
  require "assert"
2
+ require "undies/root_node"
3
+
2
4
  require 'undies/io'
3
- require 'undies/element_node'
4
5
  require 'undies/element'
5
- require "undies/root_node"
6
+ require 'undies/element_node'
6
7
 
7
8
  class Undies::RootNode
8
9
 
9
- class BasicTests < Assert::Context
10
+ class UnitTests < Assert::Context
10
11
  desc 'a root node'
11
12
  before do
12
13
  @io = Undies::IO.new(@out = "", :pp => 1)
@@ -1,13 +1,12 @@
1
1
  require "assert"
2
-
3
2
  require "undies/source"
4
3
 
5
4
  class Undies::SourceStack
6
5
 
7
- class BasicTests < Assert::Context
6
+ class UnitTests < Assert::Context
8
7
  desc 'a source stack'
9
8
  before do
10
- @content_file = File.expand_path('test/templates/content.html.rb')
9
+ @content_file = File.expand_path('test/support/templates/content.html.rb')
11
10
  @content_file_source = Undies::Source.new(@content_file)
12
11
 
13
12
  @hi_proc = Proc.new do
@@ -1,13 +1,12 @@
1
1
  require "assert"
2
-
3
2
  require "undies/source"
4
3
 
5
4
  class Undies::Source
6
5
 
7
- class BasicTests < Assert::Context
6
+ class UnitTests < Assert::Context
8
7
  desc 'a source'
9
8
  before do
10
- @content_file = File.expand_path('test/templates/content.html.rb')
9
+ @content_file = File.expand_path('test/support/templates/content.html.rb')
11
10
  @content_file_data = File.read(@content_file)
12
11
  @content_file_source = Undies::Source.new(@content_file)
13
12
 
@@ -35,7 +34,7 @@ class Undies::Source
35
34
 
36
35
  end
37
36
 
38
- class SourceWriterTests < BasicTests
37
+ class SourceWriterTests < UnitTests
39
38
  before do
40
39
  @does_not_exist_path = '/path/does/not/exist'
41
40
  end
@@ -66,7 +65,7 @@ class Undies::Source
66
65
 
67
66
  end
68
67
 
69
- class LayoutWriterTests < BasicTests
68
+ class LayoutWriterTests < UnitTests
70
69
 
71
70
  should "write nil layout values" do
72
71
  subject.layout = nil
@@ -114,7 +113,7 @@ class Undies::Source
114
113
 
115
114
  end
116
115
 
117
- class ArgsParserTests < BasicTests
116
+ class ArgsParserTests < UnitTests
118
117
 
119
118
  should "parse block arg as proc source" do
120
119
  s = Undies::Source.new(&@hi_proc)
@@ -1,6 +1,9 @@
1
1
  require "assert"
2
2
  require "undies/template"
3
3
 
4
+ require 'undies/io'
5
+ require 'undies/source'
6
+
4
7
  class Undies::Template
5
8
 
6
9
  class BuilderRenderTests < Assert::Context
@@ -1,9 +1,10 @@
1
1
  require "assert"
2
2
  require "undies/template"
3
3
 
4
- class Undies::Template
5
-
4
+ require 'undies/io'
5
+ require 'undies/source'
6
6
 
7
+ class Undies::Template
7
8
 
8
9
  class SourceRenderTests < Assert::Context
9
10
  desc 'a template rendered using a source object'
@@ -25,8 +26,6 @@ class Undies::Template
25
26
 
26
27
  end
27
28
 
28
-
29
-
30
29
  class LayoutTests < SourceRenderTests
31
30
  setup do
32
31
  @expected_output = "<html><head></head><body><div>Hi</div></body></html>"
@@ -39,12 +38,12 @@ class Undies::Template
39
38
  }
40
39
  }
41
40
  end
42
- @layout_file = File.expand_path "test/templates/layout.html.rb"
41
+ @layout_file = File.expand_path "test/support/templates/layout.html.rb"
43
42
 
44
43
  @content_proc = Proc.new do
45
44
  _div "Hi"
46
45
  end
47
- @content_file = File.expand_path "test/templates/content.html.rb"
46
+ @content_file = File.expand_path "test/support/templates/content.html.rb"
48
47
 
49
48
  @cp_lp_source = Undies::Source.new(:layout => @layout_proc, &@content_proc)
50
49
  @cp_lf_source = Undies::Source.new(:layout => @layout_file, &@content_proc)
@@ -74,8 +73,6 @@ class Undies::Template
74
73
 
75
74
  end
76
75
 
77
-
78
-
79
76
  class PartialTests < SourceRenderTests
80
77
  desc "using partials"
81
78
 
@@ -106,6 +103,4 @@ class Undies::Template
106
103
 
107
104
  end
108
105
 
109
-
110
-
111
106
  end