markaby 0.5 → 0.6.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. data/.gitignore +4 -0
  2. data/CHANGELOG.rdoc +79 -0
  3. data/Markaby.gemspec +103 -0
  4. data/{README → README.rdoc} +14 -6
  5. data/Rakefile +71 -14
  6. data/VERSION +1 -0
  7. data/garlic.rb +29 -0
  8. data/init.rb +6 -0
  9. data/lib/markaby.rb +4 -9
  10. data/lib/markaby/builder.rb +156 -143
  11. data/lib/markaby/builder_tags.rb +64 -0
  12. data/lib/markaby/cssproxy.rb +36 -34
  13. data/lib/markaby/kernel_method.rb +7 -0
  14. data/lib/markaby/rails.rb +64 -39
  15. data/lib/markaby/rails/current.rb +46 -0
  16. data/lib/markaby/rails/deprecated.rb +124 -0
  17. data/lib/markaby/rails/rails_builder.rb +50 -0
  18. data/lib/markaby/tags.rb +158 -130
  19. data/lib/markaby/tilt.rb +21 -0
  20. data/spec/markaby/builder_spec.rb +118 -0
  21. data/spec/markaby/css_proxy_spec.rb +47 -0
  22. data/spec/markaby/fragment_spec.rb +10 -0
  23. data/spec/markaby/markaby_other_static.mab +1 -0
  24. data/spec/markaby/markaby_spec.rb +232 -0
  25. data/spec/markaby/rails/spec_helper.rb +21 -0
  26. data/spec/markaby/rails/views/markaby/_a_partial.mab +3 -0
  27. data/spec/markaby/rails/views/markaby/_partial_child_with_locals.mab +1 -0
  28. data/spec/markaby/rails/views/markaby/access_to_helpers.mab +1 -0
  29. data/spec/markaby/rails/views/markaby/broken.mab +7 -0
  30. data/spec/markaby/rails/views/markaby/correct_template_values.mab +5 -0
  31. data/spec/markaby/rails/views/markaby/form_for.mab +2 -0
  32. data/spec/markaby/rails/views/markaby/form_for_with_fields.mab +3 -0
  33. data/spec/markaby/rails/views/markaby/form_for_with_multiple_fields.mab +4 -0
  34. data/spec/markaby/rails/views/markaby/no_values_passed.mab +3 -0
  35. data/spec/markaby/rails/views/markaby/partial_parent.mab +1 -0
  36. data/spec/markaby/rails/views/markaby/partial_parent_with_locals.mab +7 -0
  37. data/spec/markaby/rails/views/markaby/render_erb_without_explicit_render_call.erb +1 -0
  38. data/spec/markaby/rails/views/markaby/render_explicit_but_empty_markaby_layout.mab +0 -0
  39. data/spec/markaby/rails/views/markaby/render_mab_without_explicit_render_call.mab +3 -0
  40. data/spec/markaby/rails/views/markaby/render_with_ivar.mab +3 -0
  41. data/spec/markaby/rails/views/markaby/renders_erb.rhtml +1 -0
  42. data/spec/markaby/rails_spec.rb +249 -0
  43. data/spec/markaby/rails_version_spec.rb +37 -0
  44. data/spec/markaby/tilt/erb.erb +1 -0
  45. data/spec/markaby/tilt/locals.mab +1 -0
  46. data/spec/markaby/tilt/markaby.mab +1 -0
  47. data/spec/markaby/tilt/markaby_other_static.mab +1 -0
  48. data/spec/markaby/tilt/render_twice.mab +1 -0
  49. data/spec/markaby/tilt/scope.mab +1 -0
  50. data/spec/markaby/tilt/yielding.mab +2 -0
  51. data/spec/markaby/tilt_spec.rb +86 -0
  52. data/spec/spec.opts +2 -0
  53. data/spec/spec_helper.rb +39 -0
  54. metadata +132 -52
  55. data/lib/markaby/metaid.rb +0 -16
  56. data/lib/markaby/template.rb +0 -12
  57. data/setup.rb +0 -1551
  58. data/test/test_markaby.rb +0 -109
  59. data/tools/rakehelp.rb +0 -106
@@ -1,109 +0,0 @@
1
- require 'test/unit'
2
- require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'markaby'))
3
-
4
- module MarkabyTestHelpers
5
- def link_to(obj)
6
- %{<a href="">#{obj}</a>}
7
- end
8
- def pluralize(string)
9
- string + "s"
10
- end
11
- module_function :link_to, :pluralize
12
- end
13
-
14
- class MarkabyTest < Test::Unit::TestCase
15
-
16
- def mab(*args, &block)
17
- Markaby::Builder.new(*args, &block).to_s
18
- end
19
-
20
- def assert_exception(exclass, exmsg, *mab_args, &block)
21
- begin
22
- mab(*mab_args, &block)
23
- rescue Exception => e
24
- assert_equal exclass, e.class
25
- assert_equal exmsg, e.message
26
- end
27
- end
28
-
29
- def test_simple
30
- assert_equal "<hr/>", mab { hr }
31
- assert_equal "<p>foo</p>", mab { p 'foo' }
32
- assert_equal "<p>foo</p>", mab { p { 'foo' } }
33
- end
34
-
35
- def test_classes_and_ids
36
- assert_equal %{<div class="one"></div>}, mab { div.one '' }
37
- assert_equal %{<div class="one two"></div>}, mab { div.one.two '' }
38
- assert_equal %{<div id="three"></div>}, mab { div.three! '' }
39
- end
40
-
41
- def test_escaping
42
- assert_equal "<h1>Apples &amp; Oranges</h1>", mab { h1 'Apples & Oranges' }
43
- assert_equal "<h1>Apples & Oranges</h1>", mab { h1 { 'Apples & Oranges' } }
44
- assert_equal "<h1 class=\"fruits&amp;floots\">Apples</h1>", mab { h1 'Apples', :class => 'fruits&floots' }
45
- end
46
-
47
- def test_capture
48
- builder = Markaby::Builder.new
49
- assert builder.to_s.empty?
50
- assert_equal "<h1>TEST</h1>", builder.capture { h1 'TEST' }
51
- assert builder.to_s.empty?
52
- assert mab { capture { h1 'hello world' }; nil }.empty?
53
- assert_equal mab { div { h1 'TEST' } }, mab { div { capture { h1 'TEST' } } }
54
- end
55
-
56
- def test_ivars
57
- html = "<div><h1>Steve</h1><div><h2>Gerald</h2></div><h3>Gerald</h3></div>"
58
- assert_equal html, mab { div { @name = 'Steve'; h1 @name; div { @name = 'Gerald'; h2 @name }; h3 @name } }
59
- assert_equal html, mab { div { @name = 'Steve'; h1 @name; self << capture { div { @name = 'Gerald'; h2 @name } }; h3 @name } }
60
- assert_equal html, mab(:name => 'Steve') { div { h1 @name; self << capture { div { @name = 'Gerald'; h2 @name } }; h3 @name } }
61
- end
62
-
63
- def test_ivars_without_at_symbol
64
- assert_equal "<h1>Hello World</h1>", mab { @message = 'Hello World'; h1 message }
65
- end
66
-
67
- def test_helpers
68
- Markaby::Builder.ignored_helpers.clear
69
- assert_equal %{squirrels}, mab({}, MarkabyTestHelpers) { pluralize('squirrel') }
70
- assert_equal %{<a href="">edit</a>}, mab({}, MarkabyTestHelpers) { link_to('edit') }
71
- assert mab({}, MarkabyTestHelpers) { @output_helpers = false; link_to('edit'); nil }.empty?
72
- Markaby::Builder.ignore_helpers :pluralize
73
- assert_exception(NoMethodError, "no such method `pluralize'", {}, MarkabyTestHelpers) { pluralize('squirrel') }
74
- end
75
-
76
- def test_builder_bang_methods
77
- assert_equal "<?xml version=\"1.0\" encoding=\"UTF-8\"?>", mab { instruct! }
78
- end
79
-
80
- def test_fragments
81
- assert_equal %{<div><h1>Monkeys</h1><h2>Giraffes <small>Miniature</small> and <strong>Large</strong></h2><h3>Donkeys</h3><h4>Parakeet <b><i>Innocent IV</i></b> in Classic Chartreuse</h4></div>},
82
- mab { div { h1 "Monkeys"; h2 { "Giraffes #{small 'Miniature' } and #{strong 'Large'}" }; h3 "Donkeys"; h4 { "Parakeet #{b { i 'Innocent IV' }} in Classic Chartreuse" } } }
83
- assert_equal %{<div><h1>Monkeys</h1><h2>Giraffes <strong>Miniature</strong></h2><h3>Donkeys</h3></div>},
84
- mab { div { h1 "Monkeys"; h2 { "Giraffes #{strong 'Miniature' }" }; h3 "Donkeys" } }
85
- 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>},
86
- mab { div { @a = small 'Miniature'; @b = strong 'Large'; h1 "Monkeys"; h2 { "Giraffes #{@a} and #{@b}" }; h3 "Donkeys"; h4 { "Parakeet #{@b} as well..." } } }
87
- end
88
-
89
- def test_invalid_xhtml
90
- assert_exception(NoMethodError, "no such method `dav'") { dav {} }
91
- assert_exception(Markaby::InvalidXhtmlError, "no attribute `styl' on div elements") { div(:styl => 'ok') {} }
92
- assert_exception(Markaby::InvalidXhtmlError, "no attribute `class' on tbody elements") { tbody.okay {} }
93
- end
94
-
95
- def test_full_doc_transitional
96
- doc = mab { instruct!; xhtml_transitional { head { title 'OKay' } } }
97
- assert doc =~ /^<\?xml version="1.0" encoding="UTF-8"\?>/
98
- assert doc.include?(%{"-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">})
99
- assert doc.include?(%{<title>OKay</title>})
100
- end
101
-
102
- def test_full_doc_strict
103
- doc = mab { xhtml_strict { head { title 'OKay' } } }
104
- assert doc =~ /^<\?xml version="1.0" encoding="UTF-8"\?>/
105
- assert doc.include?(%{"-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">})
106
- assert doc.include?(%{<title>OKay</title>})
107
- end
108
-
109
- end
@@ -1,106 +0,0 @@
1
-
2
- def make(makedir)
3
- Dir.chdir(makedir) do
4
- sh 'make'
5
- end
6
- end
7
-
8
-
9
- def extconf(dir)
10
- Dir.chdir(dir) do ruby "extconf.rb" end
11
- end
12
-
13
-
14
- def setup_tests
15
- Rake::TestTask.new do |t|
16
- t.libs << "test"
17
- t.test_files = FileList['test/test*.rb']
18
- t.verbose = true
19
- end
20
- end
21
-
22
-
23
- def setup_clean otherfiles
24
- files = ['build/*', '**/*.o', '**/*.so', '**/*.a', 'lib/*-*', '**/*.log'] + otherfiles
25
- CLEAN.include(files)
26
- end
27
-
28
-
29
- def setup_rdoc files
30
- Rake::RDocTask.new do |rdoc|
31
- rdoc.rdoc_dir = 'doc/rdoc'
32
- rdoc.options << '--line-numbers'
33
- rdoc.rdoc_files.add(files)
34
- end
35
- end
36
-
37
-
38
- def setup_extension(dir, extension)
39
- ext = "ext/#{dir}"
40
- ext_so = "#{ext}/#{extension}.#{Config::CONFIG['DLEXT']}"
41
- ext_files = FileList[
42
- "#{ext}/*.c",
43
- "#{ext}/*.h",
44
- "#{ext}/extconf.rb",
45
- "#{ext}/Makefile",
46
- "lib"
47
- ]
48
-
49
- task "lib" do
50
- directory "lib"
51
- end
52
-
53
- desc "Builds just the #{extension} extension"
54
- task extension.to_sym => ["#{ext}/Makefile", ext_so ]
55
-
56
- file "#{ext}/Makefile" => ["#{ext}/extconf.rb"] do
57
- extconf "#{ext}"
58
- end
59
-
60
- file ext_so => ext_files do
61
- make "#{ext}"
62
- cp ext_so, "lib"
63
- end
64
- end
65
-
66
-
67
- def setup_gem(pkg_name, pkg_version, author, summary, dependencies, test_file)
68
- pkg_version = pkg_version
69
- pkg_name = pkg_name
70
- pkg_file_name = "#{pkg_name}-#{pkg_version}"
71
-
72
- spec = Gem::Specification.new do |s|
73
- s.name = pkg_name
74
- s.version = pkg_version
75
- s.platform = Gem::Platform::RUBY
76
- s.author = author
77
- s.summary = summary
78
- s.test_file = test_file
79
- s.has_rdoc = true
80
- s.extra_rdoc_files = [ "README" ]
81
- dependencies.each do |dep|
82
- s.add_dependency(*dep)
83
- end
84
- s.files = %w(README Rakefile setup.rb) +
85
- Dir.glob("{bin,doc,test,lib}/**/*") +
86
- Dir.glob("ext/**/*.{h,c,rb}") +
87
- Dir.glob("examples/**/*.rb") +
88
- Dir.glob("tools/*.rb")
89
-
90
- s.require_path = "lib"
91
- s.extensions = FileList["ext/**/extconf.rb"].to_a
92
-
93
- s.bindir = "bin"
94
- end
95
-
96
- Rake::GemPackageTask.new(spec) do |p|
97
- p.gem_spec = spec
98
- p.need_tar = true
99
- end
100
-
101
- task :install do
102
- sh %{rake package}
103
- sh %{gem install pkg/#{pkg_name}-#{pkg_version}}
104
- end
105
-
106
- end