render_component 1.0.0 → 3.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile CHANGED
@@ -1,4 +1,8 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- # Specify your gem's dependencies in foo.gemspec
4
- gemspec
3
+ group :development do
4
+ gem "shoulda", ">= 0"
5
+ gem "bundler", "~> 1.0.0"
6
+ gem "jeweler", "~> 1.5.2"
7
+ gem "rcov", ">= 0"
8
+ end
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 vhochstein
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile CHANGED
@@ -1,22 +1,60 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
1
10
  require 'rake'
11
+
12
+ require 'jeweler'
13
+ require './lib/render_component/version.rb'
14
+
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "render_component"
18
+ gem.version = RenderComponent::Version::STRING
19
+ gem.homepage = "http://github.com/vhochstein/render_component"
20
+ gem.license = "MIT"
21
+ gem.summary = %Q{render actions in other controllers for their rendered response}
22
+ gem.description = %Q{Components allow you to call other actions for their rendered response while executing another action}
23
+ gem.email = "david@loudthinking.com"
24
+ gem.authors = ["David Heinemeier Hansson"]
25
+ gem.add_runtime_dependency 'railties', '~>3.0.0'
26
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
27
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
28
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
29
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
30
+ end
31
+ Jeweler::RubygemsDotOrgTasks.new
32
+
33
+
2
34
  require 'rake/testtask'
3
- require 'rake/rdoctask'
4
-
5
- desc 'Default: run unit tests.'
6
- task :default => :test
7
-
8
35
  desc 'Test the components plugin.'
9
36
  Rake::TestTask.new(:test) do |t|
10
37
  t.libs << 'lib'
11
38
  t.pattern = 'test/**/*_test.rb'
12
39
  t.verbose = true
13
40
  end
14
-
41
+
42
+ require 'rcov/rcovtask'
43
+ Rcov::RcovTask.new do |test|
44
+ test.libs << 'test'
45
+ test.pattern = 'test/**/test_*.rb'
46
+ test.verbose = true
47
+ end
48
+
49
+ task :default => :test
50
+
51
+ require 'rake/rdoctask'
52
+
15
53
  desc 'Generate documentation for the components plugin.'
16
54
  Rake::RDocTask.new(:rdoc) do |rdoc|
55
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
17
56
  rdoc.rdoc_dir = 'rdoc'
18
- rdoc.title = 'Components'
19
- rdoc.options << '--line-numbers' << '--inline-source'
20
- rdoc.rdoc_files.include('README')
57
+ rdoc.title = "render_component #{version}"
58
+ rdoc.rdoc_files.include('README*')
21
59
  rdoc.rdoc_files.include('lib/**/*.rb')
22
- end
60
+ end
data/init.rb CHANGED
@@ -1,3 +1,2 @@
1
- require 'components'
2
- require 'action_dispatch/middleware/flash'
3
- ActionController::Base.send :include, Components
1
+ RENDER_COMPONENT_INSTALLED = :plugin
2
+ require 'render_component'
@@ -1 +1,4 @@
1
- require 'components'
1
+ require 'render_component/components'
2
+ require 'action_controller'
3
+ require 'action_dispatch/middleware/flash'
4
+ ActionController::Base.send :include, RenderComponent::Components
@@ -1,38 +1,39 @@
1
- module Components
2
- def self.included(base) #:nodoc:
3
- base.class_eval do
4
- include InstanceMethods
5
- extend ClassMethods
6
- ActionView::Base.send(:include, HelperMethods)
7
-
8
- # If this controller was instantiated to process a component request,
9
- # +parent_controller+ points to the instantiator of this controller.
10
- attr_accessor :parent_controller
11
-
12
- alias_method_chain :session, :render_component
13
- alias_method_chain :flash, :render_component
14
- alias_method :component_request?, :parent_controller
1
+ module RenderComponent
2
+ module Components
3
+ def self.included(base) #:nodoc:
4
+ base.class_eval do
5
+ include InstanceMethods
6
+ extend ClassMethods
7
+ helper HelperMethods
8
+
9
+ # If this controller was instantiated to process a component request,
10
+ # +parent_controller+ points to the instantiator of this controller.
11
+ attr_accessor :parent_controller
12
+
13
+ alias_method_chain :session, :render_component
14
+ alias_method_chain :flash, :render_component
15
+ alias_method :component_request?, :parent_controller
16
+ end
15
17
  end
16
- end
17
18
 
18
- module ClassMethods
19
- # Track parent controller to identify component requests
20
- def process_with_components(request, action, parent_controller = nil) #:nodoc:
21
- controller = new
22
- controller.parent_controller = parent_controller
23
- controller.dispatch(action, request)
19
+ module ClassMethods
20
+ # Track parent controller to identify component requests
21
+ def process_with_components(request, action, parent_controller = nil) #:nodoc:
22
+ controller = new
23
+ controller.parent_controller = parent_controller
24
+ controller.dispatch(action, request)
25
+ end
24
26
  end
25
- end
26
27
 
27
- module HelperMethods
28
- def render_component(options)
29
- controller.send(:render_component_into_view, options)
28
+ module HelperMethods
29
+ def render_component(options)
30
+ controller.send(:render_component_into_view, options)
31
+ end
30
32
  end
31
- end
32
33
 
33
- module InstanceMethods
34
-
35
- protected
34
+ module InstanceMethods
35
+
36
+ protected
36
37
  # Renders the component specified as the response for the current method
37
38
  def render_component(options) #:doc:
38
39
  component_logging(options) do
@@ -44,7 +45,7 @@ module Components
44
45
  end
45
46
  end
46
47
  end
47
-
48
+
48
49
  # Returns the component response as a string
49
50
  def render_component_into_view(options) #:doc:
50
51
  component_logging(options) do
@@ -53,15 +54,15 @@ module Components
53
54
  if redirected =~ %r{://}
54
55
  location = URI.parse(redirected)
55
56
  redirected = location.query ? "#{location.path}?#{location.query}" : location.path
56
- end
57
+ end
57
58
  render_component_into_view(Rails.application.routes.recognize_path(redirected, { :method => nil }))
58
59
  else
59
60
  response.body.html_safe
60
61
  end
61
62
  end
62
63
  end
63
-
64
-
64
+
65
+
65
66
  def flash_with_render_component(refresh = false) #:nodoc:
66
67
  if @component_flash.nil? || refresh
67
68
  @component_flash =
@@ -73,7 +74,7 @@ module Components
73
74
  end
74
75
  @component_flash
75
76
  end
76
-
77
+
77
78
  def session_with_render_component
78
79
  #if defined?(@parent_controller)
79
80
  if component_request?
@@ -82,14 +83,14 @@ module Components
82
83
  @_request.session
83
84
  end
84
85
  end
85
-
86
+
86
87
  private
87
88
  def component_response(options, reuse_response)
88
89
  klass = component_class(options)
89
90
  component_request = request_for_component(klass.controller_path, options)
90
91
  # needed ???
91
92
  #if reuse_response
92
- #component_request.env["action_controller.instance"].instance_variable_set :@_response, request.env["action_controller.instance"].instance_variable_get(:@_response)
93
+ #component_request.env["action_controller.instance"].instance_variable_set :@_response, request.env["action_controller.instance"].instance_variable_get(:@_response)
93
94
  #end
94
95
  klass.process_with_components(component_request, options[:action], self)
95
96
  end
@@ -110,17 +111,27 @@ module Components
110
111
  if options.is_a? Hash
111
112
  old_style_params = options.delete(:params)
112
113
  options.merge!(old_style_params) unless old_style_params.nil?
113
-
114
+
114
115
  request_params = options.symbolize_keys
115
116
  request_env = {}
116
-
117
+
117
118
  request.env.select {|key, value| key == key.upcase || key == 'rack.input'}.each {|item| request_env[item[0]] = item[1]}
118
-
119
+
119
120
  request_env['REQUEST_URI'] = url_for(options)
120
121
  request_env["PATH_INFO"] = url_for(options.merge(:only_path => true))
121
- request_env["action_dispatch.request.symbolized_path_parameters"] = request_params
122
+ request_env["action_dispatch.request.symbolized_path_parameters"] = request_params
122
123
  request_env["action_dispatch.request.parameters"] = request_params.with_indifferent_access
123
- ActionDispatch::Request.new(request_env)
124
+ request_env["warden"] = request.env["warden"] if (request.env.has_key?("warden"))
125
+ component_request = ActionDispatch::Request.new(request_env)
126
+
127
+ # its an internal request request forgery protection has to be disabled
128
+ # because otherwise forgery detection might raise an error
129
+ component_request.instance_eval do
130
+ def forgery_whitelisted?
131
+ true
132
+ end
133
+ end
134
+ component_request
124
135
  else
125
136
  request
126
137
  end
@@ -137,4 +148,5 @@ module Components
137
148
  end
138
149
  end
139
150
  end
151
+ end
140
152
  end
@@ -0,0 +1,9 @@
1
+ module RenderComponent
2
+ module Version
3
+ MAJOR = 3
4
+ MINOR = 0
5
+ PATCH = 4
6
+
7
+ STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
+ end
9
+ end
@@ -1,19 +1,68 @@
1
- $:.push File.expand_path("../lib", __FILE__)
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
2
5
 
3
6
  Gem::Specification.new do |s|
4
- s.name = "render_component"
5
- s.version = "1.0.0"
6
- s.platform = Gem::Platform::RUBY
7
- s.authors = ["David Heinemeier Hansson"]
8
- s.email = ["david@loudthinking.com"]
9
- s.homepage = "https://rubygems.org/gems/render_component"
10
- s.summary = %q{Rails plugin to render other actions for their rendered response}
11
- s.description = %q{Components allow you to call other actions for their rendered response while executing another action}
7
+ s.name = %q{render_component}
8
+ s.version = "3.0.3"
12
9
 
13
- s.files = `git ls-files`.split("\n")
14
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["David Heinemeier Hansson"]
12
+ s.date = %q{2011-02-01}
13
+ s.description = %q{Components allow you to call other actions for their rendered response while executing another action}
14
+ s.email = %q{david@loudthinking.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "LICENSE.txt",
23
+ "README",
24
+ "Rakefile",
25
+ "init.rb",
26
+ "lib/render_component.rb",
27
+ "lib/render_component/components.rb",
28
+ "lib/render_component/version.rb",
29
+ "render_component.gemspec",
30
+ "test/abstract_unit.rb",
31
+ "test/components_test.rb"
32
+ ]
33
+ s.homepage = %q{http://github.com/vhochstein/render_component}
34
+ s.licenses = ["MIT"]
16
35
  s.require_paths = ["lib"]
36
+ s.rubygems_version = %q{1.3.7}
37
+ s.summary = %q{render actions in other controllers for their rendered response}
38
+ s.test_files = [
39
+ "test/abstract_unit.rb",
40
+ "test/components_test.rb"
41
+ ]
17
42
 
18
- s.add_dependency('railties', '~>3.0.0')
43
+ if s.respond_to? :specification_version then
44
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
45
+ s.specification_version = 3
46
+
47
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
48
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
49
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
50
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
51
+ s.add_development_dependency(%q<rcov>, [">= 0"])
52
+ s.add_runtime_dependency(%q<railties>, ["~> 3.0.0"])
53
+ else
54
+ s.add_dependency(%q<shoulda>, [">= 0"])
55
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
56
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
57
+ s.add_dependency(%q<rcov>, [">= 0"])
58
+ s.add_dependency(%q<railties>, ["~> 3.0.0"])
59
+ end
60
+ else
61
+ s.add_dependency(%q<shoulda>, [">= 0"])
62
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
63
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
64
+ s.add_dependency(%q<rcov>, [">= 0"])
65
+ s.add_dependency(%q<railties>, ["~> 3.0.0"])
66
+ end
19
67
  end
68
+
@@ -8,7 +8,7 @@ class CallersController < ActionController::Base
8
8
  def calling_from_controller_with_params
9
9
  render_component(:controller => "callees", :action => "being_called", :params => { "name" => "David" })
10
10
  end
11
-
11
+
12
12
  def calling_from_controller_with_session
13
13
  session['name'] = 'Bernd'
14
14
  render_component(:controller => "callees", :action => "being_called")
@@ -49,6 +49,9 @@ class CallersController < ActionController::Base
49
49
  def rescue_action(e) raise end
50
50
  end
51
51
 
52
+ class ChildCallersController < CallersController
53
+ end
54
+
52
55
  class CalleesController < ActionController::Base
53
56
  def being_called
54
57
  render :text => "#{params[:name] || session[:name] || "Lady"} of the House, speaking"
@@ -75,14 +78,15 @@ class CalleesController < ActionController::Base
75
78
  end
76
79
 
77
80
  class ComponentsTest < ActionController::IntegrationTest #ActionController::TestCase
78
-
81
+
79
82
  def setup
80
- @routes.draw do
83
+ @routes.draw do
81
84
  match 'callers/:action', :to => 'callers'
85
+ match 'child_callers/:action', :to => 'child_callers'
82
86
  match 'callees/:action', :to => 'callees'
83
87
  end
84
88
  end
85
-
89
+
86
90
  def test_calling_from_controller
87
91
  get '/callers/calling_from_controller'
88
92
  assert_equal "Lady of the House, speaking", @response.body
@@ -97,7 +101,7 @@ class ComponentsTest < ActionController::IntegrationTest #ActionController::Test
97
101
  get '/callers/calling_from_controller_with_different_status_code'
98
102
  assert_equal 500, @response.response_code
99
103
  end
100
-
104
+
101
105
  def test_calling_from_template
102
106
  get '/callers/calling_from_template'
103
107
  assert_equal "Ring, ring: Lady of the House, speaking", @response.body
@@ -140,14 +144,16 @@ class ComponentsTest < ActionController::IntegrationTest #ActionController::Test
140
144
 
141
145
  assert_equal "Lady of the House, speaking", @response.body
142
146
  end
143
-
147
+
144
148
  def test_calling_from_controller_with_session
145
149
  get '/callers/calling_from_controller_with_session'
146
150
  assert_equal "Bernd of the House, speaking", @response.body
147
151
  end
148
-
149
-
150
152
 
153
+ def test_child_calling_from_template
154
+ get '/child_callers/calling_from_template'
155
+ assert_equal "Ring, ring: Lady of the House, speaking", @response.body
156
+ end
151
157
 
152
158
  protected
153
159
  def etag_for(text)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: render_component
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
- - 1
7
+ - 3
8
8
  - 0
9
- - 0
10
- version: 1.0.0
9
+ - 4
10
+ version: 3.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - David Heinemeier Hansson
@@ -15,13 +15,73 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-16 00:00:00 -05:00
18
+ date: 2011-02-01 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- name: railties
23
22
  prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
23
+ name: shoulda
24
+ version_requirements: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ requirement: *id001
34
+ type: :development
35
+ - !ruby/object:Gem::Dependency
36
+ prerelease: false
37
+ name: bundler
38
+ version_requirements: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ hash: 23
44
+ segments:
45
+ - 1
46
+ - 0
47
+ - 0
48
+ version: 1.0.0
49
+ requirement: *id002
50
+ type: :development
51
+ - !ruby/object:Gem::Dependency
52
+ prerelease: false
53
+ name: jeweler
54
+ version_requirements: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ~>
58
+ - !ruby/object:Gem::Version
59
+ hash: 7
60
+ segments:
61
+ - 1
62
+ - 5
63
+ - 2
64
+ version: 1.5.2
65
+ requirement: *id003
66
+ type: :development
67
+ - !ruby/object:Gem::Dependency
68
+ prerelease: false
69
+ name: rcov
70
+ version_requirements: &id004 !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ hash: 3
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ requirement: *id004
80
+ type: :development
81
+ - !ruby/object:Gem::Dependency
82
+ prerelease: false
83
+ name: railties
84
+ version_requirements: &id005 !ruby/object:Gem::Requirement
25
85
  none: false
26
86
  requirements:
27
87
  - - ~>
@@ -32,31 +92,34 @@ dependencies:
32
92
  - 0
33
93
  - 0
34
94
  version: 3.0.0
95
+ requirement: *id005
35
96
  type: :runtime
36
- version_requirements: *id001
37
97
  description: Components allow you to call other actions for their rendered response while executing another action
38
- email:
39
- - david@loudthinking.com
98
+ email: david@loudthinking.com
40
99
  executables: []
41
100
 
42
101
  extensions: []
43
102
 
44
- extra_rdoc_files: []
45
-
103
+ extra_rdoc_files:
104
+ - LICENSE.txt
105
+ - README
46
106
  files:
107
+ - .document
47
108
  - Gemfile
109
+ - LICENSE.txt
48
110
  - README
49
111
  - Rakefile
50
112
  - init.rb
51
- - lib/components.rb
52
113
  - lib/render_component.rb
114
+ - lib/render_component/components.rb
115
+ - lib/render_component/version.rb
53
116
  - render_component.gemspec
54
117
  - test/abstract_unit.rb
55
118
  - test/components_test.rb
56
119
  has_rdoc: true
57
- homepage: https://rubygems.org/gems/render_component
58
- licenses: []
59
-
120
+ homepage: http://github.com/vhochstein/render_component
121
+ licenses:
122
+ - MIT
60
123
  post_install_message:
61
124
  rdoc_options: []
62
125
 
@@ -86,7 +149,7 @@ rubyforge_project:
86
149
  rubygems_version: 1.3.7
87
150
  signing_key:
88
151
  specification_version: 3
89
- summary: Rails plugin to render other actions for their rendered response
152
+ summary: render actions in other controllers for their rendered response
90
153
  test_files:
91
154
  - test/abstract_unit.rb
92
155
  - test/components_test.rb