merb-parts 0.9.2 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +7 -5
- data/lib/merb-parts/part_controller.rb +3 -1
- data/spec/fixtures/controllers/main.rb +29 -0
- data/spec/fixtures/parts/todo_part.rb +26 -0
- data/spec/fixtures/parts/views/layout/todo_part.html.erb +3 -0
- data/spec/fixtures/parts/views/layout/todo_part.xml.erb +3 -0
- data/spec/fixtures/parts/views/todo_part/formatted_output.html.erb +1 -0
- data/spec/fixtures/parts/views/todo_part/formatted_output.js.erb +1 -0
- data/spec/fixtures/parts/views/todo_part/formatted_output.xml.erb +1 -0
- data/spec/fixtures/parts/views/todo_part/list.html.erb +3 -0
- data/spec/fixtures/parts/views/todo_part/part_with_params.html.erb +3 -0
- data/spec/fixtures/views/main/part_within_view.html.erb +1 -0
- data/spec/merb-parts_spec.rb +71 -0
- data/spec/spec_helper.rb +12 -0
- metadata +23 -3
data/Rakefile
CHANGED
@@ -4,7 +4,7 @@ require "spec/rake/spectask"
|
|
4
4
|
|
5
5
|
PLUGIN = "merb-parts"
|
6
6
|
NAME = "merb-parts"
|
7
|
-
VERSION = "0.9.
|
7
|
+
VERSION = "0.9.3"
|
8
8
|
AUTHOR = "Hassox"
|
9
9
|
EMAIL = ""
|
10
10
|
HOMEPAGE = "http://merb-plugins.rubyforge.org/merb-parts/"
|
@@ -21,25 +21,27 @@ spec = Gem::Specification.new do |s|
|
|
21
21
|
s.author = AUTHOR
|
22
22
|
s.email = EMAIL
|
23
23
|
s.homepage = HOMEPAGE
|
24
|
-
s.add_dependency('merb-core', '>= 0.9.
|
24
|
+
s.add_dependency('merb-core', '>= 0.9.3')
|
25
25
|
s.require_path = 'lib'
|
26
26
|
s.autorequire = PLUGIN
|
27
|
-
s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,
|
27
|
+
s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,spec}/**/*")
|
28
28
|
end
|
29
29
|
|
30
30
|
Rake::GemPackageTask.new(spec) do |pkg|
|
31
31
|
pkg.gem_spec = spec
|
32
32
|
end
|
33
33
|
|
34
|
+
install_home = ENV['GEM_HOME'] ? "-i #{ENV['GEM_HOME']}" : ""
|
35
|
+
|
34
36
|
task :install => [:package] do
|
35
|
-
sh %{sudo gem install pkg/#{NAME}-#{VERSION} --no-update-sources}
|
37
|
+
sh %{sudo gem install #{install_home} pkg/#{NAME}-#{VERSION} --no-update-sources}
|
36
38
|
end
|
37
39
|
|
38
40
|
namespace :jruby do
|
39
41
|
|
40
42
|
desc "Run :package and install the resulting .gem with jruby"
|
41
43
|
task :install => :package do
|
42
|
-
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}
|
43
45
|
end
|
44
46
|
|
45
47
|
end
|
@@ -68,8 +68,10 @@ module Merb
|
|
68
68
|
end
|
69
69
|
|
70
70
|
# Send any methods that are missing back up to the web controller
|
71
|
+
# Patched to set partial locals on the web controller
|
71
72
|
def method_missing(sym, *args, &blk)
|
73
|
+
@web_controller.instance_variable_set(:@_merb_partial_locals, @_merb_partial_locals)
|
72
74
|
@web_controller.send(sym, *args, &blk)
|
73
|
-
end
|
75
|
+
end
|
74
76
|
end
|
75
77
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class Main < Merb::Controller
|
2
|
+
self._template_root = File.dirname(__FILE__) / ".." / "views"
|
3
|
+
|
4
|
+
def index
|
5
|
+
part TodoPart => :list
|
6
|
+
end
|
7
|
+
|
8
|
+
def index2
|
9
|
+
part TodoPart => :one
|
10
|
+
end
|
11
|
+
|
12
|
+
def index3
|
13
|
+
part(TodoPart => :one) + part(TodoPart => :list)
|
14
|
+
end
|
15
|
+
|
16
|
+
def index4
|
17
|
+
provides :xml, :js
|
18
|
+
part(TodoPart => :formatted_output)
|
19
|
+
end
|
20
|
+
|
21
|
+
def part_with_params
|
22
|
+
part(TodoPart => :part_with_params, :my_param => "my_value")
|
23
|
+
end
|
24
|
+
|
25
|
+
def part_within_view
|
26
|
+
render
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class TodoPart < Merb::PartController
|
2
|
+
self._template_root = File.expand_path(File.join(File.dirname(__FILE__), "views"))
|
3
|
+
|
4
|
+
before :load_todos
|
5
|
+
|
6
|
+
def list
|
7
|
+
render
|
8
|
+
end
|
9
|
+
|
10
|
+
def one
|
11
|
+
render :list, :layout => false
|
12
|
+
end
|
13
|
+
|
14
|
+
def load_todos
|
15
|
+
@todos = ["Do this", "Do that", 'Do the other thing']
|
16
|
+
end
|
17
|
+
|
18
|
+
def formatted_output
|
19
|
+
render
|
20
|
+
end
|
21
|
+
|
22
|
+
def part_with_params
|
23
|
+
render
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
part_html_format
|
@@ -0,0 +1 @@
|
|
1
|
+
part_js_format
|
@@ -0,0 +1 @@
|
|
1
|
+
part_xml_format
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= part TodoPart => :one %>
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe "A Merb PartController" do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
Merb::Router.prepare do |r|
|
7
|
+
r.default_routes
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should render a part template with no layout" do
|
12
|
+
controller = dispatch_to(Main, :index2)
|
13
|
+
controller.body.should ==
|
14
|
+
"TODOPART\nDo this|Do that|Do the other thing\nTODOPART"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should render a part template with it's own layout" do
|
18
|
+
controller = dispatch_to(Main, :index)
|
19
|
+
controller.body.should ==
|
20
|
+
"TODOLAYOUT\nTODOPART\nDo this|Do that|Do the other thing\nTODOPART\nTODOLAYOUT"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should render multiple parts if more then one part is passed in" do
|
24
|
+
controller = dispatch_to(Main, :index3)
|
25
|
+
controller.body.should ==
|
26
|
+
"TODOPART\nDo this|Do that|Do the other thing\nTODOPART" +
|
27
|
+
"TODOLAYOUT\nTODOPART\nDo this|Do that|Do the other thing\nTODOPART\nTODOLAYOUT"
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should render the html format by default to the controller that set it" do
|
31
|
+
controller = dispatch_to(Main, :index4)
|
32
|
+
controller.body.should match(/part_html_format/m)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should render the xml format according to the controller" do
|
36
|
+
controller = dispatch_to(Main, :index4, {:format => 'xml'} )
|
37
|
+
controller.body.should match(/part_xml_format/m)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should render the js format according to the controller" do
|
41
|
+
controller = dispatch_to(Main, :index4, :format => 'js')
|
42
|
+
controller.body.should match(/part_js_format/m)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should provide params when calling a part" do
|
46
|
+
controller = dispatch_to(Main, :part_with_params)
|
47
|
+
controller.body.should match( /my_param = my_value/)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should render from inside a view" do
|
51
|
+
controller = dispatch_to(Main, :part_within_view)
|
52
|
+
controller.body.should match( /Do this/)
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "A Merb Part Controller with urls" do
|
59
|
+
|
60
|
+
def new_url_controller(route, params = {:action => 'show', :controller => 'Test'})
|
61
|
+
@controller = dispatch_to(Main, :index)
|
62
|
+
TodoPart.new(@controller)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should use the web_controllers type if no controller is specified" do
|
66
|
+
c = new_url_controller(@default_route, :controller => "my_controller")
|
67
|
+
the_url = c.url(:action => "bar")
|
68
|
+
the_url.should == "/main/bar"
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require "merb-core"
|
3
|
+
require File.join( File.dirname(__FILE__), "..", "lib", "merb-parts" )
|
4
|
+
|
5
|
+
# Require the fixtures
|
6
|
+
Dir[File.join(File.dirname(__FILE__), "fixtures", "*/**.rb")].each{|f| require f }
|
7
|
+
|
8
|
+
Merb.start :environment => 'test'
|
9
|
+
|
10
|
+
Spec::Runner.configure do |config|
|
11
|
+
config.include Merb::Test::RequestHelper
|
12
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: merb-parts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hassox
|
@@ -9,7 +9,7 @@ autorequire: merb-parts
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
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,7 @@ dependencies:
|
|
19
19
|
requirements:
|
20
20
|
- - ">="
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: 0.9.
|
22
|
+
version: 0.9.3
|
23
23
|
version:
|
24
24
|
description: "Merb More: Merb plugin that provides Part Controllers."
|
25
25
|
email: ""
|
@@ -42,6 +42,26 @@ files:
|
|
42
42
|
- lib/merb-parts/mixins/web_controller.rb
|
43
43
|
- lib/merb-parts/part_controller.rb
|
44
44
|
- lib/merb-parts.rb
|
45
|
+
- spec/fixtures
|
46
|
+
- spec/fixtures/controllers
|
47
|
+
- spec/fixtures/controllers/main.rb
|
48
|
+
- spec/fixtures/parts
|
49
|
+
- spec/fixtures/parts/todo_part.rb
|
50
|
+
- spec/fixtures/parts/views
|
51
|
+
- spec/fixtures/parts/views/layout
|
52
|
+
- spec/fixtures/parts/views/layout/todo_part.html.erb
|
53
|
+
- spec/fixtures/parts/views/layout/todo_part.xml.erb
|
54
|
+
- spec/fixtures/parts/views/todo_part
|
55
|
+
- spec/fixtures/parts/views/todo_part/formatted_output.html.erb
|
56
|
+
- spec/fixtures/parts/views/todo_part/formatted_output.js.erb
|
57
|
+
- spec/fixtures/parts/views/todo_part/formatted_output.xml.erb
|
58
|
+
- spec/fixtures/parts/views/todo_part/list.html.erb
|
59
|
+
- spec/fixtures/parts/views/todo_part/part_with_params.html.erb
|
60
|
+
- spec/fixtures/views
|
61
|
+
- spec/fixtures/views/main
|
62
|
+
- spec/fixtures/views/main/part_within_view.html.erb
|
63
|
+
- spec/merb-parts_spec.rb
|
64
|
+
- spec/spec_helper.rb
|
45
65
|
has_rdoc: true
|
46
66
|
homepage: http://merb-plugins.rubyforge.org/merb-parts/
|
47
67
|
post_install_message:
|