merb-builder 0.9.2 → 0.9.3

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.
data/Rakefile CHANGED
@@ -3,7 +3,7 @@ require 'rake/gempackagetask'
3
3
 
4
4
  PLUGIN = "merb-builder"
5
5
  NAME = "merb-builder"
6
- VERSION = "0.9.2"
6
+ VERSION = "0.9.3"
7
7
  AUTHOR = "Jonathan Younger"
8
8
  EMAIL = "jonathan@daikini.com"
9
9
  HOMEPAGE = "http://merb-plugins.rubyforge.org/merb-builder/"
@@ -20,25 +20,28 @@ spec = Gem::Specification.new do |s|
20
20
  s.author = AUTHOR
21
21
  s.email = EMAIL
22
22
  s.homepage = HOMEPAGE
23
- s.add_dependency('merb-core', '>= 0.9.2')
23
+ s.add_dependency('merb-core', '>= 0.9.3')
24
+ s.add_dependency('builder', '>= 2.0.0')
24
25
  s.require_path = 'lib'
25
26
  s.autorequire = PLUGIN
26
- s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,specs}/**/*")
27
+ s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,spec}/**/*")
27
28
  end
28
29
 
29
30
  Rake::GemPackageTask.new(spec) do |pkg|
30
31
  pkg.gem_spec = spec
31
32
  end
32
33
 
34
+ install_home = ENV['GEM_HOME'] ? "-i #{ENV['GEM_HOME']}" : ""
35
+
33
36
  task :install => [:package] do
34
- sh %{sudo gem install pkg/#{NAME}-#{VERSION} --no-update-sources}
37
+ sh %{sudo gem install #{install_home} pkg/#{NAME}-#{VERSION} --no-update-sources}
35
38
  end
36
39
 
37
40
  namespace :jruby do
38
41
 
39
42
  desc "Run :package and install the resulting .gem with jruby"
40
43
  task :install => :package do
41
- sh %{#{SUDO} jruby -S gem install pkg/#{NAME}-#{Merb::VERSION}.gem --no-rdoc --no-ri}
44
+ sh %{#{SUDO} jruby -S gem install #{install_home} pkg/#{NAME}-#{Merb::VERSION}.gem --no-rdoc --no-ri}
42
45
  end
43
46
 
44
47
  end
@@ -28,7 +28,36 @@ module Merb::Template
28
28
  name
29
29
  end
30
30
 
31
- module Mixin; end
31
+ module Mixin
32
+ def _builder_buffer(the_binding)
33
+ @_buffer = eval("xml", the_binding, __FILE__, __LINE__)
34
+ end
35
+ # ==== Parameters
36
+ # *args:: Arguments to pass to the block.
37
+ # &block:: The template block to call.
38
+ #
39
+ # ==== Returns
40
+ # String:: The output of the block.
41
+ #
42
+ # ==== Examples
43
+ # Capture being used in a .html.erb page:
44
+ #
45
+ # @foo = capture do
46
+ # xml.instruct!
47
+ # xml.foo do
48
+ # xml.bar "baz"
49
+ # end
50
+ # xml.target!
51
+ # end
52
+ def capture_builder(*args, &block)
53
+ block.call(*args)
54
+ end
55
+
56
+ def concat_builder(string, binding)
57
+ _builder_buffer(binding) << string
58
+ end
59
+
60
+ end
32
61
  Merb::Template.register_extensions(self, %w[builder])
33
62
  end
34
63
  end
@@ -0,0 +1,56 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe "Builder" do
4
+ before(:each) do
5
+ @xml = ::Builder::XmlMarkup.new :indent => 2
6
+ @xml.instruct!
7
+ end
8
+
9
+ it "should be able to render Builder templates" do
10
+ c = dispatch_to(BuilderController, :index, :format => "xml")
11
+ @xml.hello "World"
12
+ c.body.should == @xml.target!
13
+ end
14
+
15
+ it "should be able to render partial Builder templates" do
16
+ c = dispatch_to(PartialBuilder, :index, :format => "xml")
17
+ @xml.hello "World"
18
+ c.body.should == @xml.target!
19
+ end
20
+
21
+ it "should be able to have ivars defined in both the controller and the parent template" do
22
+ c = dispatch_to(PartialIvars, :index, :format => "xml")
23
+ @xml.p "Partial Builder"
24
+ c.body.should == @xml.target!
25
+ end
26
+
27
+ it "should use the builder configuration in Merb::Config" do
28
+ c = dispatch_to(BuilderConfig, :index, :format => "xml")
29
+ xml = ::Builder::XmlMarkup.new :indent => 4
30
+ xml.instruct!
31
+ xml.foo do
32
+ xml.bar "baz"
33
+ end
34
+ c.body.should == xml.target!
35
+ end
36
+
37
+ it "should capture_builder properly" do
38
+ c = dispatch_to(CaptureBuilder, :index, :format => "xml")
39
+ xml = ::Builder::XmlMarkup.new :indent => 4
40
+ xml.instruct!
41
+ xml.comment! "I would not say such things if I were you"
42
+ xml.node 'Capture'
43
+
44
+ c.body.should == xml.target!
45
+ end
46
+
47
+ it "should concat_builder properly" do
48
+ c = dispatch_to(ConcatBuilder, :index, :format => "xml")
49
+ xml = ::Builder::XmlMarkup.new :indent => 4
50
+ xml.instruct!
51
+ xml.node 'Concat'
52
+
53
+ c.body.should == xml.target!.chomp
54
+ end
55
+
56
+ end
@@ -0,0 +1,32 @@
1
+ class BuilderController < Merb::Controller
2
+ provides :xml
3
+ self._template_root = File.dirname(__FILE__) / "views"
4
+ def index
5
+ render
6
+ end
7
+ end
8
+
9
+ class PartialBuilder < BuilderController
10
+ end
11
+
12
+ class BuilderConfig < BuilderController
13
+ end
14
+
15
+ class PartialIvars < BuilderController
16
+ def index
17
+ @var1 = "Partial"
18
+ render
19
+ end
20
+ end
21
+
22
+ class CaptureBuilder < BuilderController
23
+ end
24
+
25
+ module Merb::ConcatBuilderHelper
26
+ def concatter(&blk)
27
+ concat("<node>Concat</node>", blk.binding)
28
+ end
29
+ end
30
+
31
+ class ConcatBuilder < BuilderController
32
+ end
@@ -0,0 +1,4 @@
1
+ xml.instruct!
2
+ xml.foo do
3
+ xml.bar "baz"
4
+ end
@@ -0,0 +1,2 @@
1
+ xml.instruct!
2
+ xml.hello 'World'
@@ -0,0 +1,5 @@
1
+ xml.instruct!
2
+ @foo = capture do
3
+ xml.comment!('I would not say such things if I were you')
4
+ end
5
+ xml.node 'Capture'
@@ -0,0 +1,4 @@
1
+ xml.instruct!
2
+ concatter do
3
+ xml.comment!('I would not do that if I were you')
4
+ end
@@ -0,0 +1,2 @@
1
+ xml.instruct!
2
+ xml << partial(:partial_builder)
@@ -0,0 +1 @@
1
+ xml.p "#{@var1} #{@var2}"
@@ -0,0 +1,3 @@
1
+ @var2 = "Builder"
2
+ xml.instruct!
3
+ xml << partial(:partial_builder)
@@ -0,0 +1,14 @@
1
+ $TESTING=true
2
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
3
+ require "rubygems"
4
+ require "merb-core"
5
+ require "spec"
6
+
7
+ require "merb-builder"
8
+ require File.dirname(__FILE__) / "controllers" / "builder"
9
+
10
+ Merb.start :environment => 'test', :builder => { "indent" => 4 }
11
+
12
+ Spec::Runner.configure do |config|
13
+ config.include Merb::Test::RequestHelper
14
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: merb-builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.9.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Younger
@@ -9,7 +9,7 @@ autorequire: merb-builder
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-03-24 00:00:00 -05:00
12
+ date: 2008-05-04 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -19,7 +19,16 @@ dependencies:
19
19
  requirements:
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: 0.9.2
22
+ version: 0.9.3
23
+ version:
24
+ - !ruby/object:Gem::Dependency
25
+ name: builder
26
+ version_requirement:
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: 2.0.0
23
32
  version:
24
33
  description: Merb plugin that provides Builder support
25
34
  email: jonathan@daikini.com
@@ -39,6 +48,25 @@ files:
39
48
  - lib/merb-builder
40
49
  - lib/merb-builder/template.rb
41
50
  - lib/merb-builder.rb
51
+ - spec/builder_spec.rb
52
+ - spec/controllers
53
+ - spec/controllers/builder.rb
54
+ - spec/controllers/views
55
+ - spec/controllers/views/builder_config
56
+ - spec/controllers/views/builder_config/index.xml.builder
57
+ - spec/controllers/views/builder_controller
58
+ - spec/controllers/views/builder_controller/index.xml.builder
59
+ - spec/controllers/views/capture_builder
60
+ - spec/controllers/views/capture_builder/index.xml.builder
61
+ - spec/controllers/views/concat_builder
62
+ - spec/controllers/views/concat_builder/index.xml.builder
63
+ - spec/controllers/views/partial_builder
64
+ - spec/controllers/views/partial_builder/_partial_builder.xml.builder
65
+ - spec/controllers/views/partial_builder/index.xml.builder
66
+ - spec/controllers/views/partial_ivars
67
+ - spec/controllers/views/partial_ivars/_partial_builder.xml.builder
68
+ - spec/controllers/views/partial_ivars/index.xml.builder
69
+ - spec/spec_helper.rb
42
70
  has_rdoc: true
43
71
  homepage: http://merb-plugins.rubyforge.org/merb-builder/
44
72
  post_install_message: