Markaby 0.6.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. data/.gitignore +4 -0
  2. data/CHANGELOG.rdoc +43 -0
  3. data/Markaby.gemspec +100 -0
  4. data/README.rdoc +262 -0
  5. data/Rakefile +48 -0
  6. data/VERSION +1 -0
  7. data/garlic.rb +29 -0
  8. data/init.rb +6 -0
  9. data/lib/markaby/builder.rb +275 -0
  10. data/lib/markaby/builder_tags.rb +64 -0
  11. data/lib/markaby/cssproxy.rb +55 -0
  12. data/lib/markaby/kernel_method.rb +7 -0
  13. data/lib/markaby/rails/current.rb +41 -0
  14. data/lib/markaby/rails/deprecated.rb +122 -0
  15. data/lib/markaby/rails.rb +68 -0
  16. data/lib/markaby/tags.rb +193 -0
  17. data/lib/markaby/tilt.rb +21 -0
  18. data/lib/markaby.rb +30 -0
  19. data/spec/markaby/builder_spec.rb +40 -0
  20. data/spec/markaby/css_proxy_spec.rb +44 -0
  21. data/spec/markaby/fragment_spec.rb +7 -0
  22. data/spec/markaby/markaby_other_static.mab +1 -0
  23. data/spec/markaby/markaby_spec.rb +207 -0
  24. data/spec/markaby/rails/spec_helper.rb +20 -0
  25. data/spec/markaby/rails/views/markaby/_a_partial.mab +3 -0
  26. data/spec/markaby/rails/views/markaby/_partial_child_with_locals.mab +1 -0
  27. data/spec/markaby/rails/views/markaby/access_to_helpers.mab +1 -0
  28. data/spec/markaby/rails/views/markaby/broken.mab +7 -0
  29. data/spec/markaby/rails/views/markaby/correct_template_values.mab +5 -0
  30. data/spec/markaby/rails/views/markaby/no_values_passed.mab +3 -0
  31. data/spec/markaby/rails/views/markaby/partial_parent.mab +1 -0
  32. data/spec/markaby/rails/views/markaby/partial_parent_with_locals.mab +7 -0
  33. data/spec/markaby/rails/views/markaby/render_erb_without_explicit_render_call.erb +1 -0
  34. data/spec/markaby/rails/views/markaby/render_explicit_but_empty_markaby_layout.mab +0 -0
  35. data/spec/markaby/rails/views/markaby/render_mab_without_explicit_render_call.mab +3 -0
  36. data/spec/markaby/rails/views/markaby/render_with_ivar.mab +3 -0
  37. data/spec/markaby/rails/views/markaby/renders_erb.rhtml +1 -0
  38. data/spec/markaby/rails_spec.rb +190 -0
  39. data/spec/markaby/rails_version_spec.rb +37 -0
  40. data/spec/markaby/tilt/erb.erb +1 -0
  41. data/spec/markaby/tilt/locals.mab +1 -0
  42. data/spec/markaby/tilt/markaby.mab +1 -0
  43. data/spec/markaby/tilt/markaby_other_static.mab +1 -0
  44. data/spec/markaby/tilt/render_twice.mab +1 -0
  45. data/spec/markaby/tilt/scope.mab +1 -0
  46. data/spec/markaby/tilt/yielding.mab +2 -0
  47. data/spec/markaby/tilt_spec.rb +86 -0
  48. data/spec/markaby/xml_markup_spec.rb +9 -0
  49. data/spec/spec.opts +2 -0
  50. data/spec/spec_helper.rb +39 -0
  51. metadata +126 -0
@@ -0,0 +1,190 @@
1
+ require File.join(File.dirname(__FILE__), 'rails', 'spec_helper')
2
+
3
+ if RUNNING_RAILS
4
+ class NonSpecificTestController < ActionController::Base
5
+ VIEW_PATH = File.expand_path(File.join(File.dirname(__FILE__), 'rails', 'views'))
6
+
7
+ around_filter :catch_exceptions
8
+
9
+ attr_reader :last_exception
10
+
11
+ def catch_exceptions
12
+ yield
13
+ rescue Exception => @last_exception
14
+ raise @last_exception
15
+ end
16
+ end
17
+
18
+ if Markaby::Rails.deprecated_rails_version?
19
+ class ActionController::TestCase < Test::Unit::TestCase; end
20
+
21
+ class TestController < NonSpecificTestController
22
+ self.template_root = VIEW_PATH
23
+ end
24
+ else
25
+ class TestController < NonSpecificTestController
26
+ append_view_path(VIEW_PATH)
27
+ end
28
+ end
29
+
30
+ class MarkabyController < TestController
31
+ def renders_nothing
32
+ render :text => ""
33
+ end
34
+
35
+ def renders_erb_with_explicit_template
36
+ render :template => "markaby/renders_erb"
37
+ end
38
+
39
+ def render_inline_content
40
+ mab_content = mab do
41
+ ul do
42
+ li "Scott"
43
+ end
44
+ end
45
+
46
+ render :inline => mab_content
47
+ end
48
+
49
+ def render_explicit_but_empty_markaby_layout
50
+ render :template => "markaby/render_explicit_but_empty_markaby_layout.mab"
51
+ end
52
+
53
+ def no_values_passed
54
+ render :template => "markaby/no_values_passed"
55
+ end
56
+
57
+ def correct_template_values
58
+ render :template => "markaby/correct_template_values"
59
+ end
60
+
61
+ def render_erb_without_explicit_render_call
62
+ end
63
+
64
+ def render_mab_without_explicit_render_call
65
+ end
66
+
67
+ def render_with_ivar
68
+ @user = "smtlaissezfaire"
69
+ render :template => "markaby/render_with_ivar"
70
+ end
71
+
72
+ def access_to_helpers
73
+ render :template => "markaby/access_to_helpers"
74
+ end
75
+
76
+ def renders_partial
77
+ render :template => "markaby/partial_parent"
78
+ end
79
+
80
+ def renders_partial_with_locals
81
+ render :template => "markaby/partial_parent_with_locals"
82
+ end
83
+
84
+ def render_which_raises_error
85
+ render :template => "markaby/broken"
86
+ end
87
+ end
88
+
89
+ class MarkabyOnRailsTest < ActionController::TestCase
90
+ def setup
91
+ Markaby::Builder.restore_defaults!
92
+
93
+ @request = ActionController::TestRequest.new
94
+ @response = ActionController::TestResponse.new
95
+ @controller = MarkabyController.new
96
+ end
97
+
98
+ def test_renders_nothing
99
+ get :renders_nothing
100
+ assert_response :success
101
+ end
102
+
103
+ def test_renders_erb_with_explicit_template
104
+ get :renders_erb_with_explicit_template
105
+ assert_response :success
106
+ # TODO: - fix this test environment issue so that assert_template works
107
+ # correctly in these tests
108
+ # assert_template "renders_erb.erb"
109
+ end
110
+
111
+ def test_renders_explicit_but_empty_markaby_layout
112
+ get :render_explicit_but_empty_markaby_layout
113
+ assert_response :success
114
+
115
+ assert_equal "", @response.body
116
+ # TODO:
117
+ # assert_template "markaby/render_explicit_but_empty_markaby_layout"
118
+ end
119
+
120
+ def test_renders_inline_markaby_content
121
+ get :render_inline_content
122
+ assert_response :success
123
+ assert_equal "<ul><li>Scott</li></ul>", @response.body
124
+ end
125
+
126
+ def test_renders_mab_template_with_no_values_passed
127
+ get :no_values_passed
128
+ assert_response :success
129
+ assert_equal "<ul><li>Scott</li></ul>", @response.body
130
+ end
131
+
132
+ def test_renders_mab_template_with_correct_values
133
+ get :correct_template_values
134
+ assert_response :success
135
+
136
+ assert_equal "<ul><li>smt</li><li>joho</li><li>spox</li></ul>", @response.body
137
+ end
138
+
139
+ def test_renders_without_explicit_render_call
140
+ get :render_mab_without_explicit_render_call
141
+ assert_response :success
142
+
143
+ assert_equal @response.body, "<ul><li>smtlaissezfaire</li></ul>"
144
+ end
145
+
146
+ def test_renders_with_ivar
147
+ get :render_with_ivar
148
+ assert_response :success
149
+
150
+ assert_equal "<ul><li>smtlaissezfaire</li></ul>", @response.body
151
+ end
152
+
153
+ def test_access_to_helpers
154
+ get :access_to_helpers
155
+ assert_response :success
156
+
157
+ assert_equal '<a href="/foo">bar</a>', @response.body
158
+ end
159
+
160
+ def test_renders_partial_from_template
161
+ get :renders_partial
162
+ assert_response :success
163
+
164
+ assert_equal "<ul><li>smtlaissezfaire</li></ul>", @response.body
165
+ end
166
+
167
+ def test_renders_partial_with_locals
168
+ get :renders_partial_with_locals
169
+ assert_response :success
170
+
171
+ assert_equal "<ul><li>smtlaissezfaire</li></ul>", @response.body
172
+ end
173
+
174
+ def test_raises_error_when_template_raises_error
175
+ get :render_which_raises_error
176
+
177
+ assert_response :error
178
+
179
+ assert_equal ActionView::TemplateError, @controller.last_exception.class
180
+ assert %r(undefined local variable or method `supercalifragilisticexpialidocious' for #<Markaby::.*Builder.*) =~
181
+ @controller.last_exception.message.to_s
182
+ end
183
+ end
184
+
185
+ describe "rails version" do
186
+ it "should support the current rails version" do
187
+ Markaby::Rails::SUPPORTED_RAILS_VERSIONS.should include(::Rails::VERSION::STRING)
188
+ end
189
+ end
190
+ end
@@ -0,0 +1,37 @@
1
+ require File.join(File.dirname(__FILE__), 'rails', 'spec_helper')
2
+
3
+ unless RUNNING_RAILS
4
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
5
+
6
+ describe "when rails is loaded, but is not a supported version" do
7
+ module MockRails
8
+ module VERSION
9
+ STRING = "0.0.0"
10
+ end
11
+ end
12
+
13
+ def install_mock_rails
14
+ Object.const_set(:Rails, MockRails)
15
+ end
16
+
17
+ def remove_mock_rails
18
+ Object.class_eval do
19
+ remove_const(:Rails)
20
+ end
21
+ end
22
+
23
+ before do
24
+ install_mock_rails
25
+ end
26
+
27
+ after do
28
+ remove_mock_rails
29
+ end
30
+
31
+ it "should raise" do
32
+ lambda {
33
+ ::Markaby::Rails.load
34
+ }.should raise_error(LoadError, "Cannot load markaby under rails version 0.0.0. See Markaby::Rails::SUPPORTED_RAILS_VERSIONS for exactly that, or redefine this constant.")
35
+ end
36
+ end
37
+ end
@@ -0,0 +1 @@
1
+ hello from erb!
@@ -0,0 +1 @@
1
+ li foo
@@ -0,0 +1 @@
1
+ text "hello from markaby!"
@@ -0,0 +1 @@
1
+ text "_why?"
@@ -0,0 +1 @@
1
+ text "foo"
@@ -0,0 +1 @@
1
+ li foo
@@ -0,0 +1,2 @@
1
+ text("Hey ")
2
+ yield
@@ -0,0 +1,86 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+ require 'markaby/tilt'
3
+ require 'erb'
4
+
5
+ module Markaby
6
+ describe Tilt, "templates" do
7
+ before do
8
+ @block = lambda do |t|
9
+ File.read(File.dirname(__FILE__) + "/#{t.file}")
10
+ end
11
+ end
12
+
13
+ it "should have the constant ::Tilt::Markaby after registration" do
14
+ lambda {
15
+ ::Tilt::MarkabyTemplate
16
+ }.should_not raise_error
17
+ end
18
+
19
+ it "should be able to render an erb template" do
20
+ tilt = ::Tilt::ERBTemplate.new("tilt/erb.erb", &@block)
21
+ tilt.render.should == "hello from erb!"
22
+ end
23
+
24
+ it "should be able to render a markaby template with static html" do
25
+ tilt = ::Tilt::MarkabyTemplate.new("tilt/markaby.mab", &@block)
26
+ tilt.render.should == "hello from markaby!"
27
+ end
28
+
29
+ it "should use the contents of the template" do
30
+ tilt = ::Tilt::MarkabyTemplate.new("tilt/markaby_other_static.mab", &@block)
31
+ tilt.render.should == "_why?"
32
+ end
33
+
34
+ it "should render from a string (given as data)" do
35
+ tilt = ::Tilt::MarkabyTemplate.new { "html do; end" }
36
+ tilt.render.should == "<html></html>"
37
+ end
38
+
39
+ it "should evaluate a block in the scope given" do
40
+ pending do
41
+ scope = mock 'scope object', :foo => "bar"
42
+
43
+ tilt = ::Tilt::MarkabyTemplate.new { li foo }
44
+ tilt.render(scope).should == "<li>bar</li>"
45
+ end
46
+ end
47
+
48
+ it "should evaluate a template file in the scope given" do
49
+ scope = mock 'scope object', :foo => "bar"
50
+
51
+ tilt = ::Tilt::MarkabyTemplate.new("tilt/scope.mab", &@block)
52
+ tilt.render(scope).should == "<li>bar</li>"
53
+ end
54
+
55
+ it "should pass locals to the template" do
56
+ tilt = ::Tilt::MarkabyTemplate.new("tilt/locals.mab", &@block)
57
+ tilt.render(Object.new, { :foo => "bar" }).should == "<li>bar</li>"
58
+ end
59
+
60
+ it "should yield to the block given" do
61
+ pending do
62
+ tilt = ::Tilt::MarkabyTemplate.new("tilt/yielding.mab", &@block)
63
+ output = tilt.render(Object.new, {}) do
64
+ text("Joe")
65
+ end
66
+
67
+ output.should == "Hey Joe"
68
+ end
69
+ end
70
+
71
+ it "should be able to render two templates in a row" do
72
+ tilt = ::Tilt::MarkabyTemplate.new("tilt/render_twice.mab", &@block)
73
+
74
+ tilt.render.should == "foo"
75
+ tilt.render.should == "foo"
76
+ end
77
+
78
+ it "should retrieve a Tilt::MarkabyTemplate when calling Tilt['hello.mab']" do
79
+ ::Tilt['hello.mab'].should == Markaby::Tilt::Template
80
+ end
81
+
82
+ it "should return a new instance of the implementation class (when calling Tilt.new)" do
83
+ ::Tilt.new("hello.mab").should be_a_kind_of(Markaby::Tilt::Template)
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,9 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
3
+ module Markaby
4
+ describe XmlMarkup do
5
+ it "should have method_missing as private" do
6
+ XmlMarkup.private_instance_methods.should include("method_missing")
7
+ end
8
+ end
9
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --backtrace
@@ -0,0 +1,39 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'spec'
4
+ require 'spec/interop/test'
5
+
6
+ $:.unshift File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
7
+
8
+ require 'markaby'
9
+ require 'markaby/kernel_method'
10
+ require 'markaby/rails'
11
+
12
+ module MarkabyTestHelpers
13
+ def link_to(obj)
14
+ %{<a href="">#{obj}</a>}
15
+ end
16
+ def pluralize(string)
17
+ string + "s"
18
+ end
19
+ module_function :link_to, :pluralize
20
+ end
21
+
22
+ module TestHelpers
23
+ def assert_exception(exclass, exmsg, *mab_args, &block)
24
+ begin
25
+ mab(*mab_args, &block)
26
+ rescue Exception => e
27
+ assert_equal exclass, e.class
28
+ assert_match /#{exmsg}/, e.message
29
+ end
30
+ end
31
+ end
32
+
33
+ module Test
34
+ module Unit
35
+ class TestCase
36
+ include TestHelpers
37
+ end
38
+ end
39
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: Markaby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.3
5
+ platform: ruby
6
+ authors:
7
+ - _why
8
+ - Tim Fletcher
9
+ - John Barton
10
+ - spox
11
+ - smtlaissezfaire
12
+ autorequire:
13
+ bindir: bin
14
+ cert_chain: []
15
+
16
+ date: 2009-10-10 00:00:00 -04:00
17
+ default_executable:
18
+ dependencies:
19
+ - !ruby/object:Gem::Dependency
20
+ name: builder
21
+ type: :runtime
22
+ version_requirement:
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: 2.0.0
28
+ version:
29
+ description: Tim Fletcher and _why's ruby driven HTML templating system
30
+ email: jrbarton@gmail.com
31
+ executables: []
32
+
33
+ extensions: []
34
+
35
+ extra_rdoc_files:
36
+ - README.rdoc
37
+ files:
38
+ - .gitignore
39
+ - CHANGELOG.rdoc
40
+ - Markaby.gemspec
41
+ - README.rdoc
42
+ - Rakefile
43
+ - VERSION
44
+ - garlic.rb
45
+ - init.rb
46
+ - lib/markaby.rb
47
+ - lib/markaby/builder.rb
48
+ - lib/markaby/builder_tags.rb
49
+ - lib/markaby/cssproxy.rb
50
+ - lib/markaby/kernel_method.rb
51
+ - lib/markaby/rails.rb
52
+ - lib/markaby/rails/current.rb
53
+ - lib/markaby/rails/deprecated.rb
54
+ - lib/markaby/tags.rb
55
+ - lib/markaby/tilt.rb
56
+ - spec/markaby/builder_spec.rb
57
+ - spec/markaby/css_proxy_spec.rb
58
+ - spec/markaby/fragment_spec.rb
59
+ - spec/markaby/markaby_other_static.mab
60
+ - spec/markaby/markaby_spec.rb
61
+ - spec/markaby/rails/spec_helper.rb
62
+ - spec/markaby/rails/views/markaby/_a_partial.mab
63
+ - spec/markaby/rails/views/markaby/_partial_child_with_locals.mab
64
+ - spec/markaby/rails/views/markaby/access_to_helpers.mab
65
+ - spec/markaby/rails/views/markaby/broken.mab
66
+ - spec/markaby/rails/views/markaby/correct_template_values.mab
67
+ - spec/markaby/rails/views/markaby/no_values_passed.mab
68
+ - spec/markaby/rails/views/markaby/partial_parent.mab
69
+ - spec/markaby/rails/views/markaby/partial_parent_with_locals.mab
70
+ - spec/markaby/rails/views/markaby/render_erb_without_explicit_render_call.erb
71
+ - spec/markaby/rails/views/markaby/render_explicit_but_empty_markaby_layout.mab
72
+ - spec/markaby/rails/views/markaby/render_mab_without_explicit_render_call.mab
73
+ - spec/markaby/rails/views/markaby/render_with_ivar.mab
74
+ - spec/markaby/rails/views/markaby/renders_erb.rhtml
75
+ - spec/markaby/rails_spec.rb
76
+ - spec/markaby/rails_version_spec.rb
77
+ - spec/markaby/tilt/erb.erb
78
+ - spec/markaby/tilt/locals.mab
79
+ - spec/markaby/tilt/markaby.mab
80
+ - spec/markaby/tilt/markaby_other_static.mab
81
+ - spec/markaby/tilt/render_twice.mab
82
+ - spec/markaby/tilt/scope.mab
83
+ - spec/markaby/tilt/yielding.mab
84
+ - spec/markaby/tilt_spec.rb
85
+ - spec/markaby/xml_markup_spec.rb
86
+ - spec/spec.opts
87
+ - spec/spec_helper.rb
88
+ has_rdoc: true
89
+ homepage: http://joho.github.com/markaby/
90
+ licenses: []
91
+
92
+ post_install_message:
93
+ rdoc_options:
94
+ - --charset=UTF-8
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: "0"
102
+ version:
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: "0"
108
+ version:
109
+ requirements: []
110
+
111
+ rubyforge_project:
112
+ rubygems_version: 1.3.5
113
+ signing_key:
114
+ specification_version: 3
115
+ summary: Markup as Ruby, write HTML in your native Ruby tongue
116
+ test_files:
117
+ - spec/markaby/builder_spec.rb
118
+ - spec/markaby/css_proxy_spec.rb
119
+ - spec/markaby/fragment_spec.rb
120
+ - spec/markaby/markaby_spec.rb
121
+ - spec/markaby/rails/spec_helper.rb
122
+ - spec/markaby/rails_spec.rb
123
+ - spec/markaby/rails_version_spec.rb
124
+ - spec/markaby/tilt_spec.rb
125
+ - spec/markaby/xml_markup_spec.rb
126
+ - spec/spec_helper.rb