markaby 0.8.1 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,61 +1,94 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
2
 
3
3
  class MarkabyTest < Test::Unit::TestCase
4
+ include TestHelpers
5
+
4
6
  def teardown
5
7
  Markaby::Builder.restore_defaults!
6
8
  end
7
9
 
8
10
  def test_simple
9
11
  assert_equal "<hr/>", mab { hr }
10
- assert_equal "<hr/><br/>", mab { hr; br }
11
- assert_equal "<p>foo</p>", mab { p 'foo' }
12
- assert_equal "<p>foo</p>", mab { p { 'foo' } }
13
- end
14
-
15
- def test_classes_and_ids
16
- assert_equal %{<div class="one"></div>}, mab { div.one '' }
17
- assert_equal %{<div class="one two"></div>}, mab { div.one.two '' }
18
- assert_equal %{<div id="three"></div>}, mab { div.three! '' }
19
- assert_equal %{<hr class="hidden"/>}, mab { hr.hidden }
20
-
21
- out = mab { input.foo :id => 'bar' }
22
- out.should match("<input.*class=\"foo\".*/>")
23
- out.should match("<input.*name=\"bar\".*/>")
12
+ assert_equal "<hr/><br/>", mab {
13
+ hr
14
+ br
15
+ }
16
+ assert_equal "<p>foo</p>", mab { p "foo" }
17
+ assert_equal "<p>foo</p>", mab { p { "foo" } }
24
18
  end
25
19
 
26
20
  def test_escaping
27
- assert_equal "<h1>Apples &amp; Oranges</h1>", mab { h1 'Apples & Oranges' }
28
- assert_equal "<h1>Apples & Oranges</h1>", mab { h1 { 'Apples & Oranges' } }
29
- assert_equal "<h1 class=\"fruits&amp;floots\">Apples</h1>", mab { h1 'Apples', :class => 'fruits&floots' }
21
+ assert_equal "<h1>Apples &amp; Oranges</h1>", mab { h1 "Apples & Oranges" }
22
+ assert_equal "<h1>Apples & Oranges</h1>", mab { h1 { "Apples & Oranges" } }
23
+ assert_equal "<h1 class=\"fruits&amp;floots\">Apples</h1>", mab { h1 "Apples", class: "fruits&floots" }
30
24
  end
31
25
 
32
26
  def test_capture
33
27
  builder = Markaby::Builder.new
34
28
  assert builder.to_s.empty?
35
- assert_equal "<h1>TEST</h1>", builder.capture { h1 'TEST' }
29
+ assert_equal "<h1>TEST</h1>", builder.capture { h1 "TEST" }
36
30
  assert builder.to_s.empty?
37
- assert mab { capture { h1 'hello world' }; nil }.empty?
38
- assert_equal mab { div { h1 'TEST' } }, mab { div { capture { h1 'TEST' } } }
31
+ assert mab {
32
+ capture { h1 "hello world" }
33
+ nil
34
+ }.empty?
35
+ assert_equal mab { div { h1 "TEST" } }, mab { div { capture { h1 "TEST" } } }
39
36
  end
40
37
 
41
38
  def test_ivars
42
39
  html = "<div><h1>Steve</h1><div><h2>Gerald</h2></div><h3>Gerald</h3></div>"
43
- assert_equal html, mab { div { @name = 'Steve'; h1 @name; div { @name = 'Gerald'; h2 @name }; h3 @name } }
44
- assert_equal html, mab { div { @name = 'Steve'; h1 @name; self << capture { div { @name = 'Gerald'; h2 @name } }; h3 @name } }
45
- assert_equal html, mab(:name => 'Steve') { div { h1 @name; self << capture { div { @name = 'Gerald'; h2 @name } }; h3 @name } }
40
+ assert_equal html, mab {
41
+ div {
42
+ @name = "Steve"
43
+ h1 @name
44
+ div {
45
+ @name = "Gerald"
46
+ h2 @name
47
+ }
48
+ h3 @name
49
+ }
50
+ }
51
+ assert_equal html, mab {
52
+ div {
53
+ @name = "Steve"
54
+ h1 @name
55
+ self << capture {
56
+ div {
57
+ @name = "Gerald"
58
+ h2 @name
59
+ }
60
+ }
61
+ h3 @name
62
+ }
63
+ }
64
+ assert_equal html, mab(name: "Steve") {
65
+ div {
66
+ h1 @name
67
+ self << capture {
68
+ div {
69
+ @name = "Gerald"
70
+ h2 @name
71
+ }
72
+ }
73
+ h3 @name
74
+ }
75
+ }
46
76
  end
47
77
 
48
78
  def test_ivars_without_at_symbol
49
- assert_equal "<h1>Hello World</h1>", mab { @message = 'Hello World'; h1 message }
79
+ assert_equal "<h1>Hello World</h1>", mab {
80
+ @message = "Hello World"
81
+ h1 message
82
+ }
50
83
  end
51
84
 
52
- def spec_helpers
53
- Markaby::Builder.ignored_helpers.clear
54
- assert_equal %{squirrels}, mab({}, MarkabyTestHelpers) { pluralize('squirrel') }
55
- assert_equal %{<a href="">edit</a>}, mab({}, MarkabyTestHelpers) { link_to('edit') }
56
- assert mab({}, MarkabyTestHelpers) { @output_helpers = false; link_to('edit'); nil }.empty?
57
- Markaby::Builder.ignore_helpers :pluralize
58
- assert_exception(NoMethodError, "undefined method `pluralize'", {}, MarkabyTestHelpers) { pluralize('squirrel') }
85
+ def test_helpers
86
+ assert_equal %(squirrels), mab({}, MarkabyTestHelpers) { pluralize("squirrel") }
87
+ assert_equal %(<a href="">edit</a>), mab({}, MarkabyTestHelpers) { link_to("edit") }
88
+ assert mab({}, MarkabyTestHelpers) {
89
+ link_to("edit")
90
+ nil
91
+ }.empty?
59
92
  end
60
93
 
61
94
  def test_uses_helper_instance_variable
@@ -66,111 +99,66 @@ class MarkabyTest < Test::Unit::TestCase
66
99
  builder = Markaby::Builder.new({}, helper)
67
100
  assert_equal :ivar_value, builder.some_ivar
68
101
  end
69
- end
70
-
71
- describe Markaby do
72
- it "can assign helpers after instantiation" do
73
- helper = double 'helper', :foo => :bar
74
-
75
- builder = Markaby::Builder.new
76
- builder.helper = helper
77
- builder.foo.should == :bar
78
- end
79
-
80
- it "should be able to set a local" do
81
- builder = Markaby::Builder.new
82
- builder.locals = { :foo => "bar" }
83
- builder.foo.should == "bar"
84
- end
85
-
86
- it "should be able to set a different local value" do
87
- builder = Markaby::Builder.new
88
- builder.locals = { :foo => "baz" }
89
- builder.foo.should == "baz"
90
- end
91
-
92
- it "should assign the correct key" do
93
- builder = Markaby::Builder.new
94
- builder.locals = { :key => :value }
95
- builder.key.should == :value
96
- end
97
-
98
- it "should be able to assign multiple locals" do
99
- builder = Markaby::Builder.new
100
-
101
- builder.locals = { :one => "two", :three => "four" }
102
-
103
- builder.one.should == "two"
104
- builder.three.should == "four"
105
- end
106
102
 
107
103
  def test_builder_bang_methods
108
104
  assert_equal "<?xml version=\"1.0\" encoding=\"UTF-8\"?>", mab { instruct! }
109
105
  end
110
106
 
111
- it "should be able to produce the correct html from a fragment" do
112
- str = ""
113
- str += "<div>"
114
- str += "<h1>Monkeys</h1>"
115
- str += "<h2>Giraffes <small>Miniature</small> and <strong>Large</strong></h2>"
116
- str += "<h3>Donkeys</h3>"
117
- str += "<h4>Parakeet <b><i>Innocent IV</i></b> in Classic Chartreuse</h4>"
118
- str += "</div>"
119
-
120
- generated = mab {
121
- div {
122
- h1 "Monkeys"
123
- h2 {
124
- "Giraffes #{small('Miniature')} and #{strong 'Large'}"
107
+ def test_fragments
108
+ assert_equal %(<div><h1>Monkeys</h1><h2>Giraffes <strong>Miniature</strong></h2><h3>Donkeys</h3></div>),
109
+ mab {
110
+ div {
111
+ h1 "Monkeys"
112
+ h2 { "Giraffes #{strong "Miniature"}" }
113
+ h3 "Donkeys"
125
114
  }
126
- h3 "Donkeys"
127
- h4 { "Parakeet #{b { i 'Innocent IV' }} in Classic Chartreuse" }
128
115
  }
129
- }
130
116
 
131
- generated.should == str
132
- end
133
-
134
- def test_fragments
135
- assert_equal %{<div><h1>Monkeys</h1><h2>Giraffes <strong>Miniature</strong></h2><h3>Donkeys</h3></div>},
136
- mab { div { h1 "Monkeys"; h2 { "Giraffes #{strong 'Miniature' }" }; h3 "Donkeys" } }
137
-
138
- assert_equal %{<div><h1>Monkeys</h1><h2>Giraffes <small>Miniature</small> and <strong>Large</strong></h2><h3>Donkeys</h3><h4>Parakeet <strong>Large</strong> as well...</h4></div>},
139
- mab { div { @a = small 'Miniature'; @b = strong 'Large'; h1 "Monkeys"; h2 { "Giraffes #{@a} and #{@b}" }; h3 "Donkeys"; h4 { "Parakeet #{@b} as well..." } } }
117
+ assert_equal %(<div><h1>Monkeys</h1><h2>Giraffes <small>Miniature</small> and <strong>Large</strong></h2><h3>Donkeys</h3><h4>Parakeet <strong>Large</strong> as well...</h4></div>),
118
+ mab {
119
+ div {
120
+ @a = small "Miniature"
121
+ @b = strong "Large"
122
+ h1 "Monkeys"
123
+ h2 { "Giraffes #{@a} and #{@b}" }
124
+ h3 "Donkeys"
125
+ h4 { "Parakeet #{@b} as well..." }
126
+ }
127
+ }
140
128
  end
141
129
 
142
130
  def test_invalid_xhtml
143
131
  assert_exception(NoMethodError, "undefined method `dav'") { dav {} }
144
- assert_exception(Markaby::InvalidXhtmlError, "no attribute `styl' on div elements") { div(:styl => 'ok') {} }
132
+ assert_exception(Markaby::InvalidXhtmlError, "no attribute `styl' on div elements") { div(styl: "ok") {} }
145
133
  assert_exception(Markaby::InvalidXhtmlError, "no attribute `class' on tbody elements") { tbody.okay {} }
146
134
  end
147
135
 
148
136
  def test_full_doc_transitional
149
- doc = mab { xhtml_transitional { head { title 'OKay' } } }
137
+ doc = mab { xhtml_transitional { head { title "OKay" } } }
150
138
  assert doc =~ /^<\?xml version="1.0" encoding="UTF-8"\?>/
151
- assert doc.include?(%{"-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">})
152
- assert doc.include?(%{<title>OKay</title>})
139
+ assert doc.include?(%("-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">))
140
+ assert doc.include?(%(<title>OKay</title>))
153
141
  end
154
142
 
155
143
  def test_full_doc_strict
156
- doc = mab { xhtml_strict { head { title 'OKay' } } }
144
+ doc = mab { xhtml_strict { head { title "OKay" } } }
157
145
  assert doc =~ /^<\?xml version="1.0" encoding="UTF-8"\?>/
158
- assert doc.include?(%{"-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">})
159
- assert doc.include?(%{<title>OKay</title>})
146
+ assert doc.include?(%("-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">))
147
+ assert doc.include?(%(<title>OKay</title>))
160
148
  end
161
149
 
162
150
  def test_full_doc_frameset
163
- doc = mab { xhtml_frameset { head { title 'OKay' } } }
151
+ doc = mab { xhtml_frameset { head { title "OKay" } } }
164
152
  assert doc =~ /^<\?xml version="1.0" encoding="UTF-8"\?>/
165
- assert doc.include?(%{"-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">})
166
- assert doc.include?(%{<title>OKay</title>})
153
+ assert doc.include?(%("-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">))
154
+ assert doc.include?(%(<title>OKay</title>))
167
155
  end
168
156
 
169
157
  def test_root_attributes_can_be_changed
170
- doc = mab { xhtml_strict(:lang => 'fr') { head { title { 'Salut!' } } } }
171
- assert doc.include?(%{"-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">})
172
- assert doc.include?(%{<title>Salut!</title>})
173
- assert doc.include?(%{ lang="fr"})
158
+ doc = mab { xhtml_strict(lang: "fr") { head { title { "Salut!" } } } }
159
+ assert doc.include?(%("-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">))
160
+ assert doc.include?(%(<title>Salut!</title>))
161
+ assert doc.include?(%( lang="fr"))
174
162
  end
175
163
 
176
164
  def version_file
@@ -178,7 +166,7 @@ describe Markaby do
178
166
  end
179
167
 
180
168
  def test_markaby_should_have_correct_version
181
- assert_equal Markaby::VERSION, File.read(version_file).strip
169
+ assert_equal Markaby::VERSION, "0.9.0"
182
170
  end
183
171
 
184
172
  def test_duplicate_usage_of_same_id
@@ -210,7 +198,7 @@ describe Markaby do
210
198
  end
211
199
 
212
200
  def test_local_assigning
213
- builder = Markaby::Builder.new(:variable => :a_value)
201
+ builder = Markaby::Builder.new(variable: :a_value)
214
202
 
215
203
  assert_equal :a_value, builder.variable
216
204
  end
@@ -231,21 +219,4 @@ describe Markaby do
231
219
  builder = Markaby::Builder.new
232
220
  builder.something.should == "<something/>"
233
221
  end
234
-
235
- it "should copy instance variables from a helper object" do
236
- klass = Class.new do
237
- def initialize
238
- @hello = "hello there"
239
- end
240
- end
241
-
242
- builder = Markaby::Builder.new({}, klass.new)
243
- builder.capture { @hello }.should == "hello there"
244
- end
245
-
246
- describe Markaby::InvalidXhtmlError do
247
- it "should inherit from StandardError" do
248
- Markaby::InvalidXhtmlError.superclass.should == StandardError
249
- end
250
- end
251
222
  end
@@ -0,0 +1,29 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
3
+ # stub
4
+ module ActionView
5
+ module Template
6
+ class << self
7
+ def register_template_handler(sym, handler)
8
+ @template_handlers ||= {}
9
+ @template_handlers[sym] = handler
10
+ end
11
+
12
+ def template_handlers
13
+ @template_handlers ||= {}
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+ describe Markaby::Rails do
20
+ it "should register the template handler" do
21
+ Markaby::Rails::TemplateHandler.register!
22
+ ActionView::Template.template_handlers[:mab].should be_a_kind_of(Markaby::Rails::TemplateHandler)
23
+ end
24
+
25
+ it "should be able to pass options" do
26
+ Markaby::Rails::TemplateHandler.register!(indent: 2)
27
+ Markaby::Rails::TemplateHandler.options[:indent].should == 2
28
+ end
29
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,38 +1,37 @@
1
- require 'rspec'
1
+ require "rspec"
2
2
 
3
- $:.unshift File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ $:.unshift File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))
4
4
 
5
- require 'markaby'
6
- require 'markaby/kernel_method'
5
+ require "markaby"
6
+ require "markaby/kernel_method"
7
+ require "markaby/rails"
8
+ require "test/unit"
9
+
10
+ # need to set this to true otherwise Test::Unit goes berserk + tries to run
11
+ # see https://jonleighton.name/2012/stop-test-unit-autorun/
12
+ Test::Unit.run = true
7
13
 
8
14
  module MarkabyTestHelpers
9
15
  def link_to(obj)
10
- %{<a href="">#{obj}</a>}
16
+ %(<a href="">#{obj}</a>)
11
17
  end
18
+
12
19
  def pluralize(string)
13
20
  string + "s"
14
21
  end
22
+
15
23
  module_function :link_to, :pluralize
16
24
  end
17
25
 
18
26
  module TestHelpers
19
27
  def assert_exception(exclass, exmsg, *mab_args, &block)
20
- begin
21
- mab(*mab_args, &block)
22
- rescue Exception => e
23
- assert_equal exclass, e.class
24
- assert_match /#{exmsg}/, e.message
25
- end
28
+ mab(*mab_args, &block)
29
+ rescue => e
30
+ assert_equal exclass, e.class
31
+ assert_match(/#{exmsg}/, e.message)
26
32
  end
27
33
  end
28
34
 
29
- module Test
30
- module Unit
31
- class TestCase
32
- include TestHelpers
33
- def self.it(name, &blk)
34
- define_method("test_#{name}", &blk)
35
- end
36
- end
37
- end
35
+ RSpec.configure do |c|
36
+ c.expect_with(:rspec) { |c| c.syntax = [:should, :expect] }
38
37
  end
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: markaby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Taylor
8
8
  - judofyr
9
9
  - _why
10
- autorequire:
10
+ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-09-21 00:00:00.000000000 Z
13
+ date: 2023-12-04 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: builder
@@ -30,16 +30,16 @@ dependencies:
30
30
  name: bundler
31
31
  requirement: !ruby/object:Gem::Requirement
32
32
  requirements:
33
- - - "~>"
33
+ - - ">="
34
34
  - !ruby/object:Gem::Version
35
- version: '1.3'
35
+ version: 2.2.10
36
36
  type: :development
37
37
  prerelease: false
38
38
  version_requirements: !ruby/object:Gem::Requirement
39
39
  requirements:
40
- - - "~>"
40
+ - - ">="
41
41
  - !ruby/object:Gem::Version
42
- version: '1.3'
42
+ version: 2.2.10
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: rake
45
45
  requirement: !ruby/object:Gem::Requirement
@@ -64,9 +64,11 @@ files:
64
64
  - ".gitignore"
65
65
  - ".rspec"
66
66
  - ".ruby-version"
67
+ - ".travis.yml"
67
68
  - CHANGELOG.rdoc
68
69
  - Gemfile
69
70
  - Gemfile.lock
71
+ - LICENSE
70
72
  - Markaby.gemspec
71
73
  - README.rdoc
72
74
  - Rakefile
@@ -74,21 +76,28 @@ files:
74
76
  - lib/markaby/builder.rb
75
77
  - lib/markaby/builder_tags.rb
76
78
  - lib/markaby/cssproxy.rb
79
+ - lib/markaby/html5.rb
77
80
  - lib/markaby/kernel_method.rb
78
- - lib/markaby/tags.rb
81
+ - lib/markaby/rails.rb
82
+ - lib/markaby/tagset.rb
79
83
  - lib/markaby/version.rb
84
+ - lib/markaby/xhtml_frameset.rb
85
+ - lib/markaby/xhtml_strict.rb
86
+ - lib/markaby/xhtml_transitional.rb
87
+ - lib/markaby/xml_tagset.rb
80
88
  - spec/markaby/builder_spec.rb
81
89
  - spec/markaby/css_proxy_spec.rb
82
90
  - spec/markaby/fragment_spec.rb
83
91
  - spec/markaby/html5_spec.rb
84
92
  - spec/markaby/markaby_spec.rb
85
93
  - spec/markaby/markaby_test_unit_spec.rb
94
+ - spec/markaby/rails_spec.rb
86
95
  - spec/spec_helper.rb
87
96
  homepage: ''
88
97
  licenses:
89
98
  - MIT
90
99
  metadata: {}
91
- post_install_message:
100
+ post_install_message:
92
101
  rdoc_options: []
93
102
  require_paths:
94
103
  - lib
@@ -103,16 +112,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
112
  - !ruby/object:Gem::Version
104
113
  version: '0'
105
114
  requirements: []
106
- rubyforge_project:
107
- rubygems_version: 2.6.12
108
- signing_key:
115
+ rubygems_version: 3.1.6
116
+ signing_key:
109
117
  specification_version: 4
110
118
  summary: A pure ruby based, html markup language
111
- test_files:
112
- - spec/markaby/builder_spec.rb
113
- - spec/markaby/css_proxy_spec.rb
114
- - spec/markaby/fragment_spec.rb
115
- - spec/markaby/html5_spec.rb
116
- - spec/markaby/markaby_spec.rb
117
- - spec/markaby/markaby_test_unit_spec.rb
118
- - spec/spec_helper.rb
119
+ test_files: []