Markaby 0.6.3 → 0.6.5

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.
@@ -1,3 +1,34 @@
1
+ = 0.6.4
2
+
3
+ * Fixed a bug in which direct string values to Markaby::Builder wouldn't evaluate:
4
+ Markaby::Builder.new { 'foo' }.to_s #=> "foo"
5
+
6
+ * Fix critical bug with form_for, which was raising an error
7
+ * Introduce proxy object for form_for:
8
+
9
+ form_for :foo do |f|
10
+ f.text_field :bar
11
+ f.text_field :baz
12
+ end
13
+
14
+ * Remove support for rails 2.1.x series. We'll accept patches for them, if anyone cares enough.
15
+
16
+ == 0.6.2 / 0.6.3
17
+
18
+ * Add basic support for the Tilt templating engine (used with Sinatra):
19
+
20
+ require 'markaby'
21
+ require 'markaby/tilt'
22
+
23
+ == 0.6.1
24
+
25
+ * Support the following rails versions:
26
+ 1.2.2, 1.2.3, 1.2.4, 1.2.5, 1.2.6, 2.1.0, 2.1.1, 2.1.2, 2.2.0,
27
+ 2.2.1, 2.2.2, 2.2.3, 2.3.1, 2.3.2, 2.3.2.1, 2.3.3, 2.3.3.1, 2.3.4
28
+ * Only run rails tests when inside a rails plugins
29
+ * Run tests of the various versions of rails with garlic
30
+ * Start conversion to rspec. Use test/spec temporarily until conversion is done.
31
+
1
32
  = 0.6
2
33
  === 23 August, 2009
3
34
 
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{Markaby}
8
- s.version = "0.6.3"
8
+ s.version = "0.6.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["_why", "Tim Fletcher", "John Barton", "spox", "smtlaissezfaire"]
12
- s.date = %q{2009-10-10}
12
+ s.date = %q{2009-10-12}
13
13
  s.description = %q{Tim Fletcher and _why's ruby driven HTML templating system}
14
14
  s.email = %q{jrbarton@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -32,6 +32,7 @@ Gem::Specification.new do |s|
32
32
  "lib/markaby/rails.rb",
33
33
  "lib/markaby/rails/current.rb",
34
34
  "lib/markaby/rails/deprecated.rb",
35
+ "lib/markaby/rails/rails_builder.rb",
35
36
  "lib/markaby/tags.rb",
36
37
  "lib/markaby/tilt.rb",
37
38
  "spec/markaby/builder_spec.rb",
@@ -45,6 +46,9 @@ Gem::Specification.new do |s|
45
46
  "spec/markaby/rails/views/markaby/access_to_helpers.mab",
46
47
  "spec/markaby/rails/views/markaby/broken.mab",
47
48
  "spec/markaby/rails/views/markaby/correct_template_values.mab",
49
+ "spec/markaby/rails/views/markaby/form_for.mab",
50
+ "spec/markaby/rails/views/markaby/form_for_with_fields.mab",
51
+ "spec/markaby/rails/views/markaby/form_for_with_multiple_fields.mab",
48
52
  "spec/markaby/rails/views/markaby/no_values_passed.mab",
49
53
  "spec/markaby/rails/views/markaby/partial_parent.mab",
50
54
  "spec/markaby/rails/views/markaby/partial_parent_with_locals.mab",
@@ -24,8 +24,9 @@ Write Rails templates in pure Ruby. Example layout:
24
24
 
25
25
  Markaby supports many versions of rails:
26
26
 
27
- 1.2.2, 1.2.3, 1.2.4, 1.2.5, 1.2.6, 2.1.0, 2.1.1, 2.1.2, 2.2.0,
28
- 2.2.1, 2.2.2, 2.2.3, 2.3.1, 2.3.2, 2.3.2.1, 2.3.3, 2.3.3.1, 2.3.4
27
+ 1.2.2, 1.2.3, 1.2.4, 1.2.5, 1.2.6, 2.2.0,
28
+ 2.2.1, 2.2.2, 2.2.3, 2.3.1, 2.3.2, 2.3.2.1,
29
+ 2.3.3, 2.3.3.1, 2.3.4
29
30
 
30
31
  == Using Markaby as a Ruby class
31
32
 
data/Rakefile CHANGED
@@ -1,7 +1,18 @@
1
1
  require 'rake'
2
2
  require 'spec/rake/spectask'
3
3
  require 'rake/clean'
4
- require 'rake/rdoctask'
4
+
5
+ begin
6
+ require 'hanna/rdoctask'
7
+
8
+ Rake::RDocTask.new do |rdoc|
9
+ rdoc.rdoc_dir = 'doc/rdoc'
10
+ rdoc.options << '--line-numbers'
11
+ rdoc.rdoc_files.add(['README.rdoc', 'CHANGELOG.rdoc', 'lib/**/*.rb'])
12
+ end
13
+ rescue LoadError
14
+ puts "Could not load hanna-rdoc. Please install with mislav-hanna package"
15
+ end
5
16
 
6
17
  task :default => :spec
7
18
 
@@ -11,12 +22,6 @@ Spec::Rake::SpecTask.new do |t|
11
22
  t.spec_opts = ["--color"]
12
23
  end
13
24
 
14
- Rake::RDocTask.new do |rdoc|
15
- rdoc.rdoc_dir = 'doc/rdoc'
16
- rdoc.options << '--line-numbers'
17
- rdoc.rdoc_files.add(['README.rdoc', 'CHANGELOG.rdoc', 'lib/**/*.rb'])
18
- end
19
-
20
25
  begin
21
26
  require 'jeweler'
22
27
 
@@ -46,3 +51,27 @@ desc "Start a Markaby-aware IRB session"
46
51
  task :irb do
47
52
  sh 'irb -I lib -r markaby -r markaby/kernel_method'
48
53
  end
54
+
55
+ namespace :gemspec do
56
+ task :commit do
57
+ sh "git add ."
58
+ sh "git commit -m 'Update gemspec'"
59
+ end
60
+ end
61
+
62
+ namespace :release do
63
+ task :patch => [:spec, "version:bump:patch", :update_gemspec, :rerdoc, :tag_release, :build, :push_tags]
64
+
65
+ task :update_gemspec => ["gemspec:generate", "gemspec:validate", "gemspec:commit"]
66
+ task :tag_release do
67
+ require File.dirname(__FILE__) + "/lib/markaby"
68
+ version = "v#{Markaby::VERSION}"
69
+ sh "git tag #{version}"
70
+ end
71
+
72
+ task :push_tags do
73
+ sh "git push --tags"
74
+ end
75
+ end
76
+
77
+ task :release => "release:patch"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.3
1
+ 0.6.5
@@ -91,7 +91,7 @@ module Markaby
91
91
 
92
92
  @builder = XmlMarkup.new(:indent => @indent, :target => @streams.last)
93
93
 
94
- instance_eval(&block) if block
94
+ text(capture(&block)) if block
95
95
  end
96
96
 
97
97
  def helper=(helper)
@@ -132,7 +132,7 @@ module Markaby
132
132
  # stream for the builder object, running the block and passing back its stream as a string.
133
133
  #
134
134
  # >> Markaby::Builder.new.capture { h1 "TEST"; h2 "CAPTURE ME" }
135
- # => "<h1>TITLE</h1>\n<h2>CAPTURE ME</h2>\n"
135
+ # => "<h1>TEST</h1><h2>CAPTURE ME</h2>"
136
136
  #
137
137
  def capture(&block)
138
138
  @streams.push(@builder.target = [])
@@ -1,28 +1,31 @@
1
1
  module Markaby
2
2
  module Rails
3
+ UNSUPPORTED_RAILS_VERSIONS = [
4
+ "2.0.0",
5
+ "2.0.1",
6
+ "2.0.2",
7
+ "2.0.3",
8
+ "2.0.4",
9
+ "2.0.5",
10
+ "2.1.0",
11
+ "2.1.1",
12
+ "2.1.2",
13
+ "2.3.0"
14
+ ]
15
+
3
16
  DEPRECATED_RAILS_VERSIONS = [
4
17
  "1.2.2",
5
18
  "1.2.3",
6
19
  "1.2.4",
7
20
  "1.2.5",
8
- "1.2.6",
21
+ "1.2.6"
9
22
  ]
10
-
23
+
11
24
  FULLY_SUPPORTED_RAILS_VERSIONS = [
12
- # "2.0.0",
13
- # "2.0.1",
14
- # "2.0.2",
15
- # "2.0.3",
16
- # "2.0.4",
17
- # "2.0.5",
18
- "2.1.0",
19
- "2.1.1",
20
- "2.1.2",
21
25
  "2.2.0",
22
26
  "2.2.1",
23
27
  "2.2.2",
24
28
  "2.2.3",
25
- # "2.3.0",
26
29
  "2.3.1",
27
30
  "2.3.2",
28
31
  "2.3.2.1",
@@ -49,7 +52,7 @@ module Markaby
49
52
  end
50
53
 
51
54
  def check_rails_version
52
- unless SUPPORTED_RAILS_VERSIONS.include?(detected_rails_version)
55
+ if UNSUPPORTED_RAILS_VERSIONS.include?(detected_rails_version)
53
56
  error_message = "Cannot load markaby under rails version #{detected_rails_version}. "
54
57
  error_message << "See Markaby::Rails::SUPPORTED_RAILS_VERSIONS for exactly that, or redefine this constant."
55
58
  raise LoadError, error_message
@@ -1,6 +1,10 @@
1
+ require 'markaby/rails/rails_builder'
2
+
1
3
  module Markaby
2
4
  module Rails
3
5
  class TemplateHandler < ::ActionView::TemplateHandler
6
+ include ActionView::TemplateHandlers::Compilable
7
+
4
8
  def compile(template, local_assigns={})
5
9
  <<-CODE
6
10
  handler = Markaby::Rails::TemplateHandler.new
@@ -10,8 +14,9 @@ module Markaby
10
14
  end
11
15
 
12
16
  def render(template, local_assigns = (template.respond_to?(:locals) ? template.locals : {}))
13
- builder = Markaby::Builder.new(instance_variables.merge(local_assigns), @view)
14
-
17
+ builder = RailsBuilder.new(instance_variables.merge(local_assigns), @view)
18
+ @view.output_buffer = builder
19
+
15
20
  template.is_a?(Proc) ?
16
21
  builder.instance_eval(&template) :
17
22
  builder.instance_eval(template.source)
@@ -1,3 +1,5 @@
1
+ require 'markaby/rails/rails_builder'
2
+
1
3
  module ActionView # :nodoc:
2
4
  class Base # :nodoc:
3
5
  def render_template(template_extension, template, file_path = nil, local_assigns = {})
@@ -64,7 +66,7 @@ module Markaby
64
66
  end
65
67
  end
66
68
 
67
- class Builder < ::Markaby::Builder # :nodoc:
69
+ class Builder < RailsBuilder # :nodoc:
68
70
  def initialize(*args, &block)
69
71
  super *args, &block
70
72
 
@@ -0,0 +1,50 @@
1
+ module Markaby
2
+ module Rails
3
+ class RailsBuilder < Markaby::Builder
4
+ def form_for(*args, &block)
5
+ @template.form_for(*args) do |__form_for_variable|
6
+ yield(FormHelperProxy.new(self, __form_for_variable))
7
+ end
8
+ end
9
+
10
+ # This is used for the block variable given to form_for. Typically, an erb template looks as so:
11
+ #
12
+ # <% form_for :foo do |f|
13
+ # <%= f.text_field :bar %>
14
+ # <% end %>
15
+ #
16
+ # form_for adds the form tag to the input stream, and assumes that later the user will append
17
+ # the <input> tag to the input stream himself (in erb, this is done with the <%= %> tags).
18
+ #
19
+ # We could do the following in Markaby:
20
+ #
21
+ # form_for :foo do |f|
22
+ # text f.text_field(:bar)
23
+ # end
24
+ #
25
+ # But this is ugly. This is prettier:
26
+ #
27
+ # form_for :foo do |f|
28
+ # f.text_field :bar
29
+ # end
30
+ class FormHelperProxy
31
+ def initialize(builder, proxied_object)
32
+ @builder = builder
33
+ @proxied_object = proxied_object
34
+ end
35
+
36
+ def respond_to?(sym, include_private = false)
37
+ @proxied_object.respond_to?(sym, include_private) || super
38
+ end
39
+
40
+ private
41
+
42
+ def method_missing(sym, *args, &block)
43
+ result = @proxied_object.__send__(sym, *args, &block)
44
+ @builder.text(result) if result.is_a?(String)
45
+ result
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -1,40 +1,116 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
2
 
3
- class BuilderTest < Test::Unit::TestCase
4
- def setup
5
- Markaby::Builder.restore_defaults!
6
- end
3
+ module Markaby
4
+ describe Builder do
5
+ before do
6
+ Markaby::Builder.restore_defaults!
7
+ end
7
8
 
8
- def teardown
9
- Markaby::Builder.restore_defaults!
10
- end
9
+ after do
10
+ Markaby::Builder.restore_defaults!
11
+ end
11
12
 
12
- def test_method_missing_is_private
13
- assert Markaby::Builder.private_instance_methods.include?("method_missing")
14
- end
15
-
16
- # setting options
17
- def test_should_be_able_to_restore_defaults_after_setting
18
- Markaby::Builder.set :indent, 2
19
- Markaby::Builder.restore_defaults!
13
+ it "should have method missing as a private method" do
14
+ Markaby::Builder.private_instance_methods.should include("method_missing")
15
+ end
20
16
 
21
- assert_equal 0, Markaby::Builder.get(:indent)
22
- end
17
+ describe "setting options" do
18
+ it "should be able to restore defaults after setting" do
19
+ Markaby::Builder.set :indent, 2
20
+ Markaby::Builder.restore_defaults!
23
21
 
24
- def test_should_be_able_set_global_options
25
- Markaby::Builder.set :indent, 2
26
- assert_equal 2, Markaby::Builder.get(:indent)
27
- end
28
-
29
- # internal clobbering by passed in assigns
30
- def test_internal_helpers_ivar_should_not_be_overwritten_by_assigns
31
- helper = Class.new do
32
- def some_method
33
- "a value"
22
+ Markaby::Builder.get(:indent).should == 0
23
+ end
24
+
25
+ it "should be able to set global options" do
26
+ Markaby::Builder.set :indent, 2
27
+ Markaby::Builder.get(:indent).should == 2
34
28
  end
35
- end.new
29
+ end
36
30
 
37
- builder = Markaby::Builder.new({:helpers => nil}, helper)
38
- assert_equal "a value", builder.some_method
31
+ describe "hidden internal variables" do
32
+ # internal clobbering by passed in assigns
33
+ it "should not overwrite internal helpers ivar when assigning a :helpers key" do
34
+ helper = Class.new do
35
+ def some_method
36
+ "a value"
37
+ end
38
+ end.new
39
+
40
+ builder = Markaby::Builder.new({:helpers => nil}, helper)
41
+ builder.some_method.should == "a value"
42
+ end
43
+ end
44
+
45
+ describe "evaluating blocks" do
46
+ it "should evaluate a pure-string block (without requiring a call to the text method)" do
47
+ b = Builder.new do
48
+ "foo"
49
+ end
50
+
51
+ b.to_s.should == "foo"
52
+ end
53
+
54
+ it "should only evaluate the last argument in a pure-string block" do
55
+ b = Builder.new do
56
+ "foo"
57
+ "bar"
58
+ end
59
+
60
+ b.to_s.should == "bar"
61
+ end
62
+
63
+ it "should evaluate pure-strings inside an tag" do
64
+ b = Builder.new do
65
+ h1 do
66
+ "foo"
67
+ end
68
+ end
69
+
70
+ b.to_s.should == "<h1>foo</h1>"
71
+ end
72
+
73
+ it "should ignore a pure string in the block, even if comes last, if there has been any markup whatsoever" do
74
+ b = Builder.new do
75
+ h1
76
+ "foo"
77
+ end
78
+
79
+ b.to_s.should == "<h1/>"
80
+ end
81
+ end
82
+
83
+ describe "capture" do
84
+ before do
85
+ @builder = Builder.new
86
+ end
87
+
88
+ it "should return the string captured" do
89
+ out = @builder.capture do
90
+ h1 "TEST"
91
+ h2 "CAPTURE ME"
92
+ end
93
+
94
+ out.should == "<h1>TEST</h1><h2>CAPTURE ME</h2>"
95
+ end
96
+
97
+ it "should not change the output buffer" do
98
+ lambda {
99
+ @builder.capture do
100
+ h1 "FOO!"
101
+ end
102
+ }.should_not change { @builder.to_s }
103
+ end
104
+
105
+ it "should be able to capture inside a capture" do
106
+ out = @builder.capture do
107
+ capture do
108
+ h1 "foo"
109
+ end
110
+ end
111
+
112
+ out.should == "<h1>foo</h1>"
113
+ end
114
+ end
39
115
  end
40
116
  end
@@ -9,6 +9,7 @@ unless defined?(RUNNING_RAILS)
9
9
  end
10
10
 
11
11
  if RUNNING_RAILS
12
+ ENV["RAILS_ENV"] ||= "test"
12
13
  require RAILS_BOOT_FILE
13
14
  Rails::Initializer.run
14
15
  require 'action_controller/test_process'
@@ -0,0 +1,2 @@
1
+ form_for :obj do
2
+ end
@@ -0,0 +1,3 @@
1
+ form_for :foo do |f|
2
+ f.text_field :foo
3
+ end
@@ -0,0 +1,4 @@
1
+ form_for :foo do |f|
2
+ f.text_field :foo
3
+ f.text_field :baz
4
+ end
@@ -84,6 +84,34 @@ if RUNNING_RAILS
84
84
  def render_which_raises_error
85
85
  render :template => "markaby/broken"
86
86
  end
87
+
88
+ def renders_form_for
89
+ @obj = Object.new
90
+ render :template => "markaby/form_for"
91
+ end
92
+
93
+ def render_form_for_with_fields
94
+ @obj = Object.new
95
+ def @obj.foo
96
+ "bar"
97
+ end
98
+
99
+ render :template => "markaby/form_for_with_fields"
100
+ end
101
+
102
+ def render_form_for_with_multiple_fields
103
+ @obj = Object.new
104
+
105
+ def @obj.foo
106
+ "bar"
107
+ end
108
+
109
+ def @obj.baz
110
+ "quxx"
111
+ end
112
+
113
+ render :template => "markaby/form_for_with_multiple_fields"
114
+ end
87
115
  end
88
116
 
89
117
  class MarkabyOnRailsTest < ActionController::TestCase
@@ -180,6 +208,37 @@ if RUNNING_RAILS
180
208
  assert %r(undefined local variable or method `supercalifragilisticexpialidocious' for #<Markaby::.*Builder.*) =~
181
209
  @controller.last_exception.message.to_s
182
210
  end
211
+
212
+ def test_renders_form_for_properly
213
+ get :renders_form_for
214
+
215
+ assert_response :success
216
+
217
+ assert %r(<form.*></form>) =~ @response.body
218
+ end
219
+
220
+ def test_renders_form_for_with_fields_for
221
+ get :render_form_for_with_fields
222
+
223
+ assert_response :success
224
+
225
+ assert_equal "<form action=\"/markaby/render_form_for_with_fields\" method=\"post\"><input id=\"foo_foo\" name=\"foo[foo]\" size=\"30\" type=\"text\" /></form>",
226
+ @response.body
227
+ end
228
+
229
+ def test_renders_form_for_with_multiple_fields
230
+ get :render_form_for_with_multiple_fields
231
+
232
+ assert_response :success
233
+
234
+ expected_output = "<form action=\"/markaby/render_form_for_with_multiple_fields\" method=\"post\">"
235
+ expected_output << "<input id=\"foo_foo\" name=\"foo[foo]\" size=\"30\" type=\"text\" />"
236
+ expected_output << "<input id=\"foo_baz\" name=\"foo[baz]\" size=\"30\" type=\"text\" />"
237
+ expected_output << "</form>"
238
+
239
+ assert_equal expected_output,
240
+ @response.body
241
+ end
183
242
  end
184
243
 
185
244
  describe "rails version" do
@@ -6,7 +6,7 @@ unless RUNNING_RAILS
6
6
  describe "when rails is loaded, but is not a supported version" do
7
7
  module MockRails
8
8
  module VERSION
9
- STRING = "0.0.0"
9
+ STRING = ::Markaby::Rails::UNSUPPORTED_RAILS_VERSIONS.first
10
10
  end
11
11
  end
12
12
 
@@ -31,7 +31,7 @@ unless RUNNING_RAILS
31
31
  it "should raise" do
32
32
  lambda {
33
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.")
34
+ }.should raise_error(LoadError, "Cannot load markaby under rails version 2.0.0. See Markaby::Rails::SUPPORTED_RAILS_VERSIONS for exactly that, or redefine this constant.")
35
35
  end
36
36
  end
37
37
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Markaby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.3
4
+ version: 0.6.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - _why
@@ -13,7 +13,7 @@ autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
15
 
16
- date: 2009-10-10 00:00:00 -04:00
16
+ date: 2009-10-12 00:00:00 -04:00
17
17
  default_executable:
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
@@ -51,6 +51,7 @@ files:
51
51
  - lib/markaby/rails.rb
52
52
  - lib/markaby/rails/current.rb
53
53
  - lib/markaby/rails/deprecated.rb
54
+ - lib/markaby/rails/rails_builder.rb
54
55
  - lib/markaby/tags.rb
55
56
  - lib/markaby/tilt.rb
56
57
  - spec/markaby/builder_spec.rb
@@ -64,6 +65,9 @@ files:
64
65
  - spec/markaby/rails/views/markaby/access_to_helpers.mab
65
66
  - spec/markaby/rails/views/markaby/broken.mab
66
67
  - spec/markaby/rails/views/markaby/correct_template_values.mab
68
+ - spec/markaby/rails/views/markaby/form_for.mab
69
+ - spec/markaby/rails/views/markaby/form_for_with_fields.mab
70
+ - spec/markaby/rails/views/markaby/form_for_with_multiple_fields.mab
67
71
  - spec/markaby/rails/views/markaby/no_values_passed.mab
68
72
  - spec/markaby/rails/views/markaby/partial_parent.mab
69
73
  - spec/markaby/rails/views/markaby/partial_parent_with_locals.mab