parlement 0.6 → 0.7
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/CHANGES +13 -0
- data/README +51 -38
- data/app/controllers/account_controller.rb +65 -37
- data/app/controllers/application.rb +1 -1
- data/app/controllers/elt_controller.rb +1 -0
- data/app/models/elt.rb +25 -14
- data/app/models/mail.rb +36 -35
- data/app/models/mail_notify.rb +23 -0
- data/app/views/account/_login.rhtml +1 -1
- data/app/views/account/_show.rhtml +22 -5
- data/app/views/elt/_elt.rhtml +44 -47
- data/app/views/elt/_listByDate.rhtml +7 -7
- data/app/views/elt/show.rhtml +3 -3
- data/app/views/layouts/top.rhtml +1 -0
- data/app/views/person/show.rhtml +5 -0
- data/config/environment.rb +1 -1
- data/db/ROOT/parlement/Parlement_fr.txt +46 -0
- data/db/ROOT/parlement/news/Version_06.txt +25 -0
- data/db/ROOT/parlement/news/Version_07.txt +12 -0
- data/db/ROOT/parlement/test.txt +14 -5
- data/db/ROOT/parlement.txt +2 -0
- data/db/development_structure.sql +119 -44
- data/db/migrate/004_people_image.rb +9 -0
- data/lib/data_import.rb +9 -13
- data/public/javascripts/mybehaviour.js +41 -0
- data/test/fixtures/img.png +0 -0
- data/test/fixtures/mail/avatar +249 -0
- data/test/fixtures/people.yml +1 -1
- data/test/functional/account_controller_test.rb +108 -56
- data/test/functional/elt_controller_test.rb +6 -6
- data/test/unit/elt_test.rb +1 -1
- data/test/unit/mail_test.rb +17 -0
- data/vendor/plugins/engines/CHANGELOG +91 -53
- data/vendor/plugins/engines/README +1 -1
- data/vendor/plugins/engines/generators/engine/templates/init_engine.erb +6 -4
- data/vendor/plugins/engines/generators/engine/templates/test/test_helper.erb +5 -1
- data/vendor/plugins/engines/init.rb +8 -3
- data/vendor/plugins/engines/lib/engines/action_mailer_extensions.rb +6 -5
- data/vendor/plugins/engines/lib/engines/action_view_extensions.rb +10 -6
- data/vendor/plugins/engines/lib/engines/active_record_extensions.rb +3 -1
- data/vendor/plugins/engines/lib/engines/dependencies_extensions.rb +27 -16
- data/vendor/plugins/engines/lib/engines/routing_extensions.rb +28 -0
- data/vendor/plugins/engines/lib/engines/testing_extensions.rb +6 -2
- data/vendor/plugins/engines/lib/engines.rb +77 -12
- data/vendor/plugins/engines/tasks/deprecated_engines.rake +7 -0
- data/vendor/plugins/engines/tasks/engines.rake +25 -10
- data/vendor/plugins/login_engine/CHANGELOG +8 -0
- data/vendor/plugins/login_engine/README +2 -2
- data/vendor/plugins/login_engine/app/controllers/user_controller.rb +4 -1
- data/vendor/plugins/login_engine/app/views/user/forgot_password.rhtml +1 -1
- data/vendor/plugins/login_engine/init_engine.rb +6 -5
- data/vendor/plugins/login_engine/lib/login_engine/authenticated_user.rb +1 -1
- data/vendor/plugins/output_compression/CHANGELOG +0 -0
- data/vendor/plugins/output_compression/MIT-LICENSE +20 -0
- data/vendor/plugins/output_compression/README +4 -4
- data/vendor/plugins/output_compression/init.rb +1 -2
- data/vendor/plugins/output_compression/lib/output_compression.rb +84 -66
- data/vendor/plugins/output_compression/{Rakefile → rakefile} +22 -22
- data/vendor/plugins/output_compression/test/output_test.rb +11 -0
- data/vendor/plugins/output_compression/test/test_controller.rb +3 -0
- data/vendor/plugins/output_compression/test/test_helper.rb +14 -0
- data/vendor/plugins/responds_to_parent/MIT-LICENSE +20 -0
- data/vendor/plugins/responds_to_parent/README +42 -0
- data/vendor/plugins/responds_to_parent/Rakefile +22 -0
- data/vendor/plugins/responds_to_parent/init.rb +1 -0
- data/vendor/plugins/responds_to_parent/lib/responds_to_parent.rb +45 -0
- data/vendor/plugins/responds_to_parent/test/responds_to_parent_test.rb +115 -0
- metadata +33 -16
- data/vendor/plugins/login_engine/tasks/tasks.rake +0 -4
- data/vendor/plugins/output_compression/tasks/output_compression_tasks.rake +0 -4
- data/vendor/plugins/output_compression/test/output_compression_test.rb +0 -8
- /data/db/ROOT/parlement/news/{release0.1.txt → Version_01.txt} +0 -0
- /data/db/ROOT/parlement/news/{release0.2.txt → Version_02.txt} +0 -0
- /data/db/ROOT/parlement/news/{release0.3.txt → Version_03.txt} +0 -0
- /data/db/ROOT/parlement/news/{release0.4.txt → Version_04.txt} +0 -0
- /data/db/ROOT/parlement/news/{release0.5.txt → Version_05.txt} +0 -0
@@ -1,12 +1,45 @@
|
|
1
1
|
require 'logger'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
# We need to know the version of Rails that we are running before we
|
4
|
+
# can override any of the dependency stuff, since Rails' own behaviour
|
5
|
+
# has changed over the various releases. We need to explicily make sure
|
6
|
+
# that the Rails::VERSION constant is loaded, because such things could
|
7
|
+
# not automatically be achieved prior to 1.1, and the location of the
|
8
|
+
# file moved in 1.1.1!
|
9
|
+
def load_rails_version
|
10
|
+
# At this point, we can't even rely on RAILS_ROOT existing, so we have to figure
|
11
|
+
# the path to RAILS_ROOT/vendor/rails manually
|
12
|
+
rails_base = File.expand_path(
|
13
|
+
File.join(File.dirname(__FILE__), # RAILS_ROOT/vendor/plugins/engines/lib
|
14
|
+
'..', # RAILS_ROOT/vendor/plugins/engines
|
15
|
+
'..', # RAILS_ROOT/vendor/plugins
|
16
|
+
'..', # RAILS_ROOT/vendor
|
17
|
+
'rails', 'railties', 'lib')) # RAILS_ROOT/vendor/rails/railties/lib
|
18
|
+
begin
|
19
|
+
load File.join(rails_base, 'rails', 'version.rb')
|
20
|
+
#puts 'loaded 1.1.1+ from vendor: ' + File.join(rails_base, 'rails', 'version.rb')
|
21
|
+
rescue MissingSourceFile # this means they DON'T have Rails 1.1.1 or later installed in vendor
|
22
|
+
begin
|
23
|
+
load File.join(rails_base, 'rails_version.rb')
|
24
|
+
#puts 'loaded 1.1.0- from vendor: ' + File.join(rails_base, 'rails_version.rb')
|
25
|
+
rescue MissingSourceFile # this means they DON'T have Rails 1.1.0 or previous installed in vendor
|
26
|
+
begin
|
27
|
+
# try and load version information for Rails 1.1.1 or later from the $LOAD_PATH
|
28
|
+
require 'rails/version'
|
29
|
+
#puts 'required 1.1.1+ from load path'
|
30
|
+
rescue LoadError
|
31
|
+
# try and load version information for Rails 1.1.0 or previous from the $LOAD_PATH
|
32
|
+
require 'rails_version'
|
33
|
+
#puts 'required 1.1.0- from load path'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
8
37
|
end
|
9
38
|
|
39
|
+
# Actually perform the load
|
40
|
+
load_rails_version
|
41
|
+
#puts "Detected Rails version: #{Rails::VERSION::STRING}"
|
42
|
+
|
10
43
|
require 'engines/ruby_extensions'
|
11
44
|
# ... further files are required at the bottom of this file
|
12
45
|
|
@@ -18,6 +51,15 @@ module Engines
|
|
18
51
|
def version
|
19
52
|
"#{Version::Major}.#{Version::Minor}.#{Version::Release}"
|
20
53
|
end
|
54
|
+
|
55
|
+
# For holding the rails configuration object
|
56
|
+
attr_accessor :rails_config
|
57
|
+
|
58
|
+
# A flag to stop searching for views in the application
|
59
|
+
attr_accessor :disable_app_views_loading
|
60
|
+
|
61
|
+
# A flag to stop code being mixed in from the application
|
62
|
+
attr_accessor :disable_app_code_mixing
|
21
63
|
end
|
22
64
|
|
23
65
|
# The DummyLogger is a class which might pass through to a real Logger
|
@@ -108,7 +150,7 @@ module Engines
|
|
108
150
|
Engines.log.debug "considering plugins: #{plugins.inspect}"
|
109
151
|
plugins.each { |plugin|
|
110
152
|
engine_name = File.basename(plugin)
|
111
|
-
if File.exist?(File.join(plugin, "init_engine.rb")) || # if the directory contains
|
153
|
+
if File.exist?(File.join(plugin, "init_engine.rb")) || # if the directory contains init_engine.rb
|
112
154
|
(engine_name =~ /_engine$/) || # or it engines in '_engines'
|
113
155
|
(engine_name =~ /_bundle$/) # or even ends in '_bundle'
|
114
156
|
|
@@ -118,6 +160,12 @@ module Engines
|
|
118
160
|
}
|
119
161
|
end
|
120
162
|
|
163
|
+
# Initialize the routing controller paths.
|
164
|
+
def initialize_routing
|
165
|
+
# See lib/engines/routing_extensions.rb for more information.
|
166
|
+
ActionController::Routing.controller_paths = Engines.rails_config.controller_paths
|
167
|
+
end
|
168
|
+
|
121
169
|
def start_engine(engine_name, options={})
|
122
170
|
|
123
171
|
# Create a new Engine and put this engine at the front of the ActiveEngines list
|
@@ -137,6 +185,9 @@ module Engines
|
|
137
185
|
if Rails::VERSION::STRING =~ /^1.0/ && !Engines.config(:edge)
|
138
186
|
Controllers.add_path(engine_controllers) if File.exist?(engine_controllers)
|
139
187
|
Controllers.add_path(engine_components) if File.exist?(engine_components)
|
188
|
+
else
|
189
|
+
ActionController::Routing.controller_paths << engine_controllers
|
190
|
+
ActionController::Routing.controller_paths << engine_components
|
140
191
|
end
|
141
192
|
|
142
193
|
# copy the files unless indicated otherwise
|
@@ -169,12 +220,13 @@ module Engines
|
|
169
220
|
end
|
170
221
|
|
171
222
|
# Add ALL paths under the engine root to the load path
|
172
|
-
app_dirs =
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
File.
|
223
|
+
app_dirs = %w(controllers helpers models).collect { |d|
|
224
|
+
File.join(engine.root, 'app', d)
|
225
|
+
}
|
226
|
+
other_dirs = %w(components lib).collect { |d|
|
227
|
+
File.join(engine.root, d)
|
177
228
|
}
|
229
|
+
load_paths = (app_dirs + other_dirs).select { |d| File.directory?(d) }
|
178
230
|
|
179
231
|
# Remove other engines from the $LOAD_PATH by matching against the engine.root values
|
180
232
|
# in ActiveEngines. Store the removed engines in the order they came off.
|
@@ -244,6 +296,16 @@ EOS
|
|
244
296
|
def active
|
245
297
|
ActiveEngines
|
246
298
|
end
|
299
|
+
|
300
|
+
# Pass a block to perform an operation on each engine. You may pass an argument
|
301
|
+
# to determine the order:
|
302
|
+
#
|
303
|
+
# * :load_order - in the order they were loaded (i.e. lower precidence engines first).
|
304
|
+
# * :precidence_order - highest precidence order (i.e. last loaded) first
|
305
|
+
def each(ordering=:precidence_order, &block)
|
306
|
+
engines = (ordering == :load_order) ? active.reverse : active
|
307
|
+
engines.each { |e| yield e }
|
308
|
+
end
|
247
309
|
end
|
248
310
|
end
|
249
311
|
|
@@ -395,8 +457,11 @@ end
|
|
395
457
|
|
396
458
|
# These files must be required after the Engines module has been defined.
|
397
459
|
require 'engines/dependencies_extensions'
|
460
|
+
require 'engines/routing_extensions'
|
398
461
|
require 'engines/action_view_extensions'
|
399
462
|
require 'engines/action_mailer_extensions'
|
400
|
-
require 'engines/testing_extensions'
|
401
463
|
require 'engines/migration_extensions'
|
402
464
|
require 'engines/active_record_extensions'
|
465
|
+
|
466
|
+
# only load the testing extensions if we are in the test environment
|
467
|
+
require 'engines/testing_extensions' if %w(test).include?(RAILS_ENV)
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# Old-style engines rake tasks.
|
2
|
+
# NOTE: THESE ARE DEPRICATED! PLEASE USE THE NEW STYLE!
|
3
|
+
|
4
|
+
task :engine_info => "engines:info"
|
5
|
+
task :engine_migrate => "db:migrate:engines"
|
6
|
+
task :enginedoc => "doc:engines"
|
7
|
+
task :load_plugin_fixtures => "db:fixtures:engines:load"
|
@@ -33,7 +33,7 @@ namespace :engines do
|
|
33
33
|
puts "Details: #{e.info}"
|
34
34
|
else
|
35
35
|
puts "Engines plugin: #{Engines.version}"
|
36
|
-
Engines.
|
36
|
+
Engines.each do |e|
|
37
37
|
puts "#{e.name}: #{e.version}"
|
38
38
|
end
|
39
39
|
end
|
@@ -147,15 +147,30 @@ namespace :test do
|
|
147
147
|
# NOTE: we're using the Rails 1.0 non-namespaced task here, just to maintain
|
148
148
|
# compatibility with Rails 1.0
|
149
149
|
# TODO: make this work with Engines.config(:root)
|
150
|
-
|
150
|
+
|
151
|
+
namespace :engines do
|
152
|
+
Engines::RakeTasks.all_engines.each do |engine_name|
|
153
|
+
desc "Run the engine tests for '#{engine_name}'"
|
154
|
+
Rake::TestTask.new(engine_name => :prepare_test_database) do |t|
|
155
|
+
t.libs << 'test'
|
156
|
+
t.pattern = "vendor/plugins/#{engine_name}/test/**/*_test.rb"
|
157
|
+
t.verbose = true
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
Rake::TestTask.new(:engines => [:warn_about_multiple_engines_testing, :prepare_test_database]) do |t|
|
151
163
|
t.libs << "test"
|
152
|
-
|
153
|
-
|
154
|
-
t.pattern = "vendor/plugins/#{ENV['ENGINE']}/test/**/*_test.rb"
|
155
|
-
else
|
156
|
-
t.pattern = 'vendor/plugins/**/test/**/*_test.rb'
|
157
|
-
end
|
158
|
-
|
164
|
+
engines = ENV['ENGINE'] || '**'
|
165
|
+
t.pattern = "vendor/plugins/#{engines}/test/**/*_test.rb"
|
159
166
|
t.verbose = true
|
160
|
-
end
|
167
|
+
end
|
168
|
+
|
169
|
+
task :warn_about_multiple_engines_testing do
|
170
|
+
puts %{-~============== A Moste Polite Warninge ==================~-
|
171
|
+
You may experience issues testing multiple engines at once.
|
172
|
+
Please test engines individual for the moment.
|
173
|
+
-~===============( ... as you were ... )===================~-
|
174
|
+
}
|
175
|
+
end
|
161
176
|
end
|
@@ -1,3 +1,11 @@
|
|
1
|
+
= v1.0.2
|
2
|
+
* Added version
|
3
|
+
* Removed errant requires no longer needed (murray.steele@gmail.com, Ticket #156, Ticket #157, Ticket #158)
|
4
|
+
# Removed documentation/rake tasks that refer the schema.rb (Ticket #155)
|
5
|
+
# Verified cannot be assigned via URL parameters. If more security is required, users should override the signup action itself (Ticket #169)
|
6
|
+
# Minor view/flash message cleanup
|
7
|
+
# Authentication by token now respects primary key prefixes (Ticket #140)
|
8
|
+
|
1
9
|
= v1.0.1
|
2
10
|
* Added CHANGELOG
|
3
11
|
* Changed wording for when password forgotten to 'reset', rather than 'retrieve'. (snowblink@gmail.com)
|
@@ -99,7 +99,7 @@ You'll need to configure it properly so that email can be sent. One of the easie
|
|
99
99
|
|
100
100
|
=== Create the DB schema
|
101
101
|
|
102
|
-
After you have done the modifications the the ApplicationController and its helper, you can import the user model into the database.
|
102
|
+
After you have done the modifications the the ApplicationController and its helper, you can import the user model into the database. Migration information in login_engine/db/migrate/.
|
103
103
|
|
104
104
|
You *MUST* check that these files aren't going to interfere with anything in your application.
|
105
105
|
|
@@ -114,7 +114,7 @@ You can change the table name used by adding
|
|
114
114
|
|
115
115
|
...to the LoginEngine configuration in <tt>environment.rb</tt>. Then run from the root of your project:
|
116
116
|
|
117
|
-
rake
|
117
|
+
rake db:migrate:engines ENGINE=login
|
118
118
|
|
119
119
|
to import the schema into your database.
|
120
120
|
|
@@ -34,6 +34,7 @@ class UserController < ApplicationController
|
|
34
34
|
def signup
|
35
35
|
return if generate_blank
|
36
36
|
params[:user].delete('form')
|
37
|
+
params[:user].delete('verified') # you CANNOT pass this as part of the request
|
37
38
|
@user = User.new(params[:user])
|
38
39
|
begin
|
39
40
|
User.transaction(@user) do
|
@@ -44,10 +45,12 @@ class UserController < ApplicationController
|
|
44
45
|
if @user.save
|
45
46
|
key = @user.generate_security_token
|
46
47
|
url = url_for(:action => 'home', :user_id => @user.id, :key => key)
|
47
|
-
flash[:notice] = 'Signup successful!
|
48
|
+
flash[:notice] = 'Signup successful!'
|
48
49
|
if LoginEngine.config(:use_email_notification) and LoginEngine.config(:confirm_account)
|
49
50
|
UserNotify.deliver_signup(@user, params[:user][:password], url)
|
50
51
|
flash[:notice] << ' Please check your registered email account to verify your account registration and continue with the login.'
|
52
|
+
else
|
53
|
+
flash[:notice] << ' Please log in.'
|
51
54
|
end
|
52
55
|
redirect_to :action => 'login'
|
53
56
|
end
|
@@ -10,7 +10,7 @@
|
|
10
10
|
<label>Email Address:</label> <%= text_field("user", "email", "size" => 30) %>
|
11
11
|
|
12
12
|
<div class="button-bar">
|
13
|
-
<%= submit_tag '
|
13
|
+
<%= submit_tag 'Reset Password' %>
|
14
14
|
<%= link_to 'Cancel', :action => 'login' %>
|
15
15
|
</div>
|
16
16
|
<%= end_form_tag %>
|
@@ -2,9 +2,10 @@
|
|
2
2
|
|
3
3
|
require 'login_engine'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
module LoginEngine::Version
|
6
|
+
Major = 1
|
7
|
+
Minor = 0
|
8
|
+
Release = 2
|
9
|
+
end
|
8
10
|
|
9
|
-
|
10
|
-
#ApplicationHelper.send(:include, LoginEngine)
|
11
|
+
Engines.current.version = LoginEngine::Version
|
@@ -46,7 +46,7 @@ module LoginEngine
|
|
46
46
|
def authenticate_by_token(id, token)
|
47
47
|
# Allow logins for deleted accounts, but only via this method (and
|
48
48
|
# not the regular authenticate call)
|
49
|
-
u = find(:first, :conditions => ["
|
49
|
+
u = find(:first, :conditions => ["#{User.primary_key} = ? AND security_token = ?", id, token])
|
50
50
|
return nil if u.nil? or u.token_expired?
|
51
51
|
return nil if false == u.update_expiry
|
52
52
|
u
|
File without changes
|
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2005-2006 Tom Fakes
|
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.
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
Contributors:
|
2
|
+
Tom Fakes - Initial simple implementation, plugin implementation
|
3
|
+
Dan Kubb - Handle multiple encodings, correct response headers
|
4
|
+
Sebastian - Handle component requests
|
@@ -1,2 +1 @@
|
|
1
|
-
|
2
|
-
require 'output_compression'
|
1
|
+
require 'output_compression'
|
@@ -1,66 +1,84 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
#
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
response.
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
1
|
+
#
|
2
|
+
# Contributors:
|
3
|
+
# Tom Fakes - Initial simple implementation, plugin implementation
|
4
|
+
# Dan Kubb - Handle multiple encodings, correct response headers
|
5
|
+
# Sebastian - Handle component requests
|
6
|
+
#
|
7
|
+
begin
|
8
|
+
require 'stringio'
|
9
|
+
require 'zlib'
|
10
|
+
COMPRESSION_DISABLED = false
|
11
|
+
rescue
|
12
|
+
COMPRESSION_DISABLED = true
|
13
|
+
RAILS_DEFAULT_LOGGER.info "Output Compression not available: " + $!
|
14
|
+
end
|
15
|
+
|
16
|
+
class OutputCompressionFilter
|
17
|
+
|
18
|
+
def self.filter(controller)
|
19
|
+
return if COMPRESSION_DISABLED ||
|
20
|
+
controller.response.headers['Content-Encoding'] ||
|
21
|
+
controller.request.env['HTTP_ACCEPT_ENCODING'].nil? ||
|
22
|
+
controller.request.is_component_request?
|
23
|
+
begin
|
24
|
+
controller.request.env['HTTP_ACCEPT_ENCODING'].split(/\s*,\s*/).each do |encoding|
|
25
|
+
# TODO: use "q" values to determine user agent encoding preferences
|
26
|
+
case encoding
|
27
|
+
when /\Agzip\b/
|
28
|
+
StringIO.open('', 'w') do |strio|
|
29
|
+
begin
|
30
|
+
gz = Zlib::GzipWriter.new(strio)
|
31
|
+
gz.write(controller.response.body)
|
32
|
+
controller.response.body = strio.string
|
33
|
+
ensure
|
34
|
+
gz.close if gz
|
35
|
+
end
|
36
|
+
end
|
37
|
+
when /\Adeflate\b/
|
38
|
+
controller.response.body = Zlib::Deflate.deflate(controller.response.body, Zlib::BEST_COMPRESSION)
|
39
|
+
when /\Aidentity\b/
|
40
|
+
# do nothing for identity
|
41
|
+
else
|
42
|
+
next # the encoding is not supported, try the next one
|
43
|
+
end
|
44
|
+
controller.logger.info "Response body was encoded with #{encoding}"
|
45
|
+
controller.response.headers['Content-Encoding'] = encoding
|
46
|
+
break # the encoding is supported, stop
|
47
|
+
end
|
48
|
+
end
|
49
|
+
controller.response.headers['Content-Length'] = controller.response.body.length
|
50
|
+
if controller.response.headers['Vary'] != '*'
|
51
|
+
controller.response.headers['Vary'] =
|
52
|
+
controller.response.headers['Vary'].to_s.split(',').push('Accept-Encoding').uniq.join(',')
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
# Handle component requests by not compressing the output from a component
|
59
|
+
module ActionController
|
60
|
+
# These methods are available in both the production and test Request objects.
|
61
|
+
class AbstractRequest
|
62
|
+
def is_component_request=(val) #:nodoc:
|
63
|
+
@is_component_request = val
|
64
|
+
end
|
65
|
+
|
66
|
+
# Returns true when the request corresponds to a render_component call
|
67
|
+
def is_component_request?
|
68
|
+
@is_component_request
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
# Mark the request as being a Component request
|
74
|
+
module ActionController
|
75
|
+
module Components
|
76
|
+
protected
|
77
|
+
def request_for_component(options)
|
78
|
+
request_for_component = original_request_for_component(options)
|
79
|
+
request_for_component.is_component_request = true
|
80
|
+
return request_for_component
|
81
|
+
end
|
82
|
+
alias :original_request_for_component :request_for_component
|
83
|
+
end
|
84
|
+
end
|
@@ -1,22 +1,22 @@
|
|
1
|
-
require 'rake'
|
2
|
-
require 'rake/testtask'
|
3
|
-
require 'rake/rdoctask'
|
4
|
-
|
5
|
-
desc 'Default: run unit tests.'
|
6
|
-
task :default => :test
|
7
|
-
|
8
|
-
desc 'Test the
|
9
|
-
Rake::TestTask.new(:test) do |t|
|
10
|
-
t.libs << 'lib'
|
11
|
-
t.pattern = 'test/**/*_test.rb'
|
12
|
-
t.verbose = true
|
13
|
-
end
|
14
|
-
|
15
|
-
desc 'Generate documentation for the
|
16
|
-
Rake::RDocTask.new(:rdoc) do |rdoc|
|
17
|
-
rdoc.rdoc_dir = 'rdoc'
|
18
|
-
rdoc.title = '
|
19
|
-
rdoc.options << '--line-numbers --inline-source'
|
20
|
-
rdoc.rdoc_files.include('README')
|
21
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
22
|
-
end
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
|
5
|
+
desc 'Default: run unit tests.'
|
6
|
+
task :default => :test
|
7
|
+
|
8
|
+
desc 'Test the Output Compression plugin.'
|
9
|
+
Rake::TestTask.new(:test) do |t|
|
10
|
+
t.libs << 'lib'
|
11
|
+
t.pattern = 'test/**/*_test.rb'
|
12
|
+
t.verbose = true
|
13
|
+
end
|
14
|
+
|
15
|
+
desc 'Generate documentation for the Output Compression plugin.'
|
16
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
17
|
+
rdoc.rdoc_dir = 'rdoc'
|
18
|
+
rdoc.title = 'Output Compression'
|
19
|
+
rdoc.options << '--line-numbers --inline-source'
|
20
|
+
rdoc.rdoc_files.include('README')
|
21
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
22
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'test/unit'
|
5
|
+
require 'action_controller'
|
6
|
+
require "#{File.dirname(__FILE__)}/../init"
|
7
|
+
|
8
|
+
ActionController::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
|
9
|
+
ActionController::Base.logger.level = Logger::DEBUG
|
10
|
+
|
11
|
+
require "#{File.dirname(__FILE__)}/test_controller"
|
12
|
+
|
13
|
+
class Test::Unit::TestCase #:nodoc:
|
14
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2006 Sean Treadway
|
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.
|
@@ -0,0 +1,42 @@
|
|
1
|
+
RespondsToParent
|
2
|
+
================
|
3
|
+
|
4
|
+
Adds responds_to_parent to your controller to respond to the parent document of your page.
|
5
|
+
Make Ajaxy file uploads by posting the form to a hidden iframe, and respond with
|
6
|
+
RJS to the parent window.
|
7
|
+
|
8
|
+
Example
|
9
|
+
=======
|
10
|
+
|
11
|
+
Controller:
|
12
|
+
|
13
|
+
class Test < ActionController::Base
|
14
|
+
def main
|
15
|
+
end
|
16
|
+
|
17
|
+
def form_action
|
18
|
+
# Do stuff with params[:uploaded_file]
|
19
|
+
|
20
|
+
responds_to_parent do
|
21
|
+
render :update do |page|
|
22
|
+
page << "alert($('stuff').innerHTML)"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
main.rhtml:
|
29
|
+
|
30
|
+
<html>
|
31
|
+
<body>
|
32
|
+
<div id="stuff">Here is some stuff</div>
|
33
|
+
|
34
|
+
<form target="frame" action="form_action">
|
35
|
+
<input type="file" name="uploaded_file"/>
|
36
|
+
<input type="submit"/>
|
37
|
+
</form>
|
38
|
+
|
39
|
+
<iframe id='frame' name="frame"></iframe>
|
40
|
+
</body>
|
41
|
+
</html>
|
42
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
|
5
|
+
desc 'Default: run unit tests.'
|
6
|
+
task :default => :test
|
7
|
+
|
8
|
+
desc 'Test the responds_to_parent plugin.'
|
9
|
+
Rake::TestTask.new(:test) do |t|
|
10
|
+
t.libs << 'lib'
|
11
|
+
t.pattern = 'test/**/*_test.rb'
|
12
|
+
t.verbose = true
|
13
|
+
end
|
14
|
+
|
15
|
+
desc 'Generate documentation for the responds_to_parent plugin.'
|
16
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
17
|
+
rdoc.rdoc_dir = 'rdoc'
|
18
|
+
rdoc.title = 'RespondsToParent'
|
19
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
20
|
+
rdoc.rdoc_files.include('README')
|
21
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
22
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
ActionController::Base.send :include, RespondsToParent
|