responders 0.7.0 → 0.8.0
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/CHANGELOG.rdoc +4 -0
- data/Gemfile +1 -3
- data/Gemfile.lock +24 -14
- data/README.rdoc +11 -1
- data/Rakefile +2 -1
- data/lib/responders/flash_responder.rb +19 -3
- data/lib/responders/version.rb +1 -1
- data/responders.gemspec +0 -1
- data/test/flash_responder_test.rb +21 -1
- data/test/locales/en.yml +6 -1
- metadata +11 -5
data/CHANGELOG.rdoc
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,38 +1,41 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
responders (0.
|
4
|
+
responders (0.8.0)
|
5
5
|
railties (~> 3.1)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: http://rubygems.org/
|
9
9
|
specs:
|
10
|
-
actionpack (3.2.
|
11
|
-
activemodel (= 3.2.
|
12
|
-
activesupport (= 3.2.
|
10
|
+
actionpack (3.2.1)
|
11
|
+
activemodel (= 3.2.1)
|
12
|
+
activesupport (= 3.2.1)
|
13
13
|
builder (~> 3.0.0)
|
14
14
|
erubis (~> 2.7.0)
|
15
|
-
journey (~> 1.0.
|
15
|
+
journey (~> 1.0.1)
|
16
16
|
rack (~> 1.4.0)
|
17
17
|
rack-cache (~> 1.1)
|
18
18
|
rack-test (~> 0.6.1)
|
19
19
|
sprockets (~> 2.1.2)
|
20
|
-
activemodel (3.2.
|
21
|
-
activesupport (= 3.2.
|
20
|
+
activemodel (3.2.1)
|
21
|
+
activesupport (= 3.2.1)
|
22
22
|
builder (~> 3.0.0)
|
23
|
-
activesupport (3.2.
|
23
|
+
activesupport (3.2.1)
|
24
24
|
i18n (~> 0.6)
|
25
25
|
multi_json (~> 1.0)
|
26
26
|
builder (3.0.0)
|
27
|
+
columnize (0.3.6)
|
27
28
|
erubis (2.7.0)
|
28
29
|
hike (1.2.1)
|
29
30
|
i18n (0.6.0)
|
30
|
-
journey (1.0.
|
31
|
+
journey (1.0.3)
|
31
32
|
json (1.6.5)
|
33
|
+
linecache (0.46)
|
34
|
+
rbx-require-relative (> 0.0.4)
|
32
35
|
metaclass (0.0.1)
|
33
|
-
mocha (0.10.
|
36
|
+
mocha (0.10.4)
|
34
37
|
metaclass (~> 0.0.1)
|
35
|
-
multi_json (1.0
|
38
|
+
multi_json (1.1.0)
|
36
39
|
rack (1.4.1)
|
37
40
|
rack-cache (1.1)
|
38
41
|
rack (>= 0.4)
|
@@ -40,16 +43,22 @@ GEM
|
|
40
43
|
rack
|
41
44
|
rack-test (0.6.1)
|
42
45
|
rack (>= 1.0)
|
43
|
-
railties (3.2.
|
44
|
-
actionpack (= 3.2.
|
45
|
-
activesupport (= 3.2.
|
46
|
+
railties (3.2.1)
|
47
|
+
actionpack (= 3.2.1)
|
48
|
+
activesupport (= 3.2.1)
|
46
49
|
rack-ssl (~> 1.3.2)
|
47
50
|
rake (>= 0.8.7)
|
48
51
|
rdoc (~> 3.4)
|
49
52
|
thor (~> 0.14.6)
|
50
53
|
rake (0.9.2.2)
|
54
|
+
rbx-require-relative (0.0.9)
|
51
55
|
rdoc (3.12)
|
52
56
|
json (~> 1.4)
|
57
|
+
ruby-debug (0.10.4)
|
58
|
+
columnize (>= 0.1)
|
59
|
+
ruby-debug-base (~> 0.10.4.0)
|
60
|
+
ruby-debug-base (0.10.4)
|
61
|
+
linecache (>= 0.3)
|
53
62
|
sprockets (2.1.2)
|
54
63
|
hike (~> 1.2)
|
55
64
|
rack (~> 1.0)
|
@@ -63,3 +72,4 @@ PLATFORMS
|
|
63
72
|
DEPENDENCIES
|
64
73
|
mocha
|
65
74
|
responders!
|
75
|
+
ruby-debug
|
data/README.rdoc
CHANGED
@@ -32,12 +32,22 @@ to be used with Rails 2.3 together with Inherited Resources, please check this b
|
|
32
32
|
This responder is activated in all non get requests. By default it will use the keys
|
33
33
|
:notice and :alert, but they can be changed in your application:
|
34
34
|
|
35
|
-
|
35
|
+
config.responders.flash_keys = [ :success, :failure ]
|
36
36
|
|
37
37
|
Or:
|
38
38
|
|
39
39
|
Responders::FlashResponder.flash_keys = [ :success, :failure ]
|
40
40
|
|
41
|
+
You can also have embedded HTML. Just create a <tt>_html</tt> scope.
|
42
|
+
|
43
|
+
flash:
|
44
|
+
actions:
|
45
|
+
create:
|
46
|
+
alert_html: "<strong>OH NOES!</strong> You did it wrong!"
|
47
|
+
posts:
|
48
|
+
create:
|
49
|
+
notice_html: "<strong>Yay!</strong> You did it!"
|
50
|
+
|
41
51
|
* HttpCacheResponder - Automatically adds Last-Modified headers to API requests. This
|
42
52
|
allows clients to easily query the server if a resource changed and if the client tries
|
43
53
|
to retrieve a resource that has not been modified, it returns not_modified status.
|
data/Rakefile
CHANGED
@@ -51,6 +51,12 @@ module Responders
|
|
51
51
|
# flash.cars.create.status
|
52
52
|
# flash.actions.create.status
|
53
53
|
#
|
54
|
+
# You can also have flash messages with embedded HTML. Just create a scope that
|
55
|
+
# ends with <tt>_html</tt> as the scopes below:
|
56
|
+
#
|
57
|
+
# flash.actions.create.notice_html
|
58
|
+
# flash.cars.create.notice_html
|
59
|
+
#
|
54
60
|
# == Options
|
55
61
|
#
|
56
62
|
# FlashResponder also accepts some options through respond_with API.
|
@@ -80,6 +86,9 @@ module Responders
|
|
80
86
|
mattr_accessor :flash_keys
|
81
87
|
@@flash_keys = [ :notice, :alert ]
|
82
88
|
|
89
|
+
mattr_reader :helper
|
90
|
+
@@helper = Object.new.extend(ActionView::Helpers::TranslationHelper)
|
91
|
+
|
83
92
|
def initialize(controller, resources, options={})
|
84
93
|
super
|
85
94
|
@flash = options.delete(:flash)
|
@@ -112,7 +121,7 @@ module Responders
|
|
112
121
|
return if controller.flash[status].present?
|
113
122
|
|
114
123
|
options = mount_i18n_options(status)
|
115
|
-
message = ::
|
124
|
+
message = Responders::FlashResponder.helper.t options[:default].shift, options
|
116
125
|
set_flash(status, message)
|
117
126
|
end
|
118
127
|
|
@@ -156,8 +165,15 @@ module Responders
|
|
156
165
|
slices = controller.controller_path.split('/')
|
157
166
|
|
158
167
|
while slices.size > 0
|
159
|
-
|
160
|
-
|
168
|
+
controller_scope = :"flash.#{slices.fill(controller.controller_name, -1).join('.')}.#{controller.action_name}.#{status}"
|
169
|
+
actions_scope = :"flash.#{slices.fill(:actions, -1).join('.')}.#{controller.action_name}.#{status}"
|
170
|
+
|
171
|
+
defaults << :"#{controller_scope}_html"
|
172
|
+
defaults << controller_scope
|
173
|
+
|
174
|
+
defaults << :"#{actions_scope}_html"
|
175
|
+
defaults << actions_scope
|
176
|
+
|
161
177
|
slices.shift
|
162
178
|
end
|
163
179
|
|
data/lib/responders/version.rb
CHANGED
data/responders.gemspec
CHANGED
@@ -16,7 +16,6 @@ Gem::Specification.new do |s|
|
|
16
16
|
|
17
17
|
s.files = `git ls-files`.split("\n")
|
18
18
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
19
|
s.require_paths = ["lib"]
|
21
20
|
|
22
21
|
s.add_dependency "railties", "~> 3.1"
|
@@ -30,10 +30,14 @@ class AddressesController < ApplicationController
|
|
30
30
|
respond_with(@resource, :notice => "Yes, notice this!", :alert => "Warning, warning!")
|
31
31
|
end
|
32
32
|
|
33
|
+
def with_html
|
34
|
+
respond_with(@resource)
|
35
|
+
end
|
36
|
+
|
33
37
|
protected
|
34
38
|
|
35
39
|
def interpolation_options
|
36
|
-
{ :reference => 'Ocean Avenue' }
|
40
|
+
{ :reference => 'Ocean Avenue', :xss => '<script>alert(1)</script>' }
|
37
41
|
end
|
38
42
|
|
39
43
|
def set_resource
|
@@ -134,6 +138,22 @@ class FlashResponderTest < ActionController::TestCase
|
|
134
138
|
assert_equal "Warning, warning!", flash[:alert]
|
135
139
|
end
|
136
140
|
|
141
|
+
def test_sets_html_using_controller_scope
|
142
|
+
post :with_html
|
143
|
+
assert_equal "<strong>Yay!</strong> You did it!", flash[:success]
|
144
|
+
end
|
145
|
+
|
146
|
+
def test_sets_html_using_actions_scope
|
147
|
+
post :with_html, :fail => true
|
148
|
+
assert_equal "<strong>OH NOES!</strong> You did it wrong!", flash[:failure]
|
149
|
+
end
|
150
|
+
|
151
|
+
def test_escapes_html_interpolations
|
152
|
+
Responders::FlashResponder.flash_keys = [ :xss, :xss ]
|
153
|
+
post :with_html
|
154
|
+
assert_equal "<strong>Yay!</strong> <script>alert(1)</script>", flash[:xss]
|
155
|
+
end
|
156
|
+
|
137
157
|
# If we have flash.now, it's always marked as used.
|
138
158
|
def assert_flash_now(k)
|
139
159
|
assert flash.instance_variable_get(:@used).to_a.include?(k.to_sym),
|
data/test/locales/en.yml
CHANGED
@@ -5,7 +5,10 @@ en:
|
|
5
5
|
success: "Resource created with success"
|
6
6
|
failure: "Resource could not be created"
|
7
7
|
with_block:
|
8
|
-
success: "Resource with block created with success"
|
8
|
+
success: "Resource with block created with success"
|
9
|
+
with_html:
|
10
|
+
failure_html: "<strong>OH NOES!</strong> You did it wrong!"
|
11
|
+
xss_html: "<strong>Yay!</strong> %{xss}"
|
9
12
|
addresses:
|
10
13
|
update:
|
11
14
|
success: "Nice! %{resource_name} was updated with success!"
|
@@ -13,6 +16,8 @@ en:
|
|
13
16
|
destroy:
|
14
17
|
success: "Successfully deleted the address at %{reference}"
|
15
18
|
notice: "Successfully deleted the chosen address at %{reference}"
|
19
|
+
with_html:
|
20
|
+
success_html: "<strong>Yay!</strong> You did it!"
|
16
21
|
admin:
|
17
22
|
actions:
|
18
23
|
create:
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: responders
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-03-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: railties
|
16
|
-
requirement: &
|
16
|
+
requirement: &70303791369100 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '3.1'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70303791369100
|
25
25
|
description: A set of Rails 3 responders to dry up your application
|
26
26
|
email: contact@plataformatec.com.br
|
27
27
|
executables: []
|
@@ -67,15 +67,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
67
67
|
- - ! '>='
|
68
68
|
- !ruby/object:Gem::Version
|
69
69
|
version: '0'
|
70
|
+
segments:
|
71
|
+
- 0
|
72
|
+
hash: -73151246775261150
|
70
73
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
74
|
none: false
|
72
75
|
requirements:
|
73
76
|
- - ! '>='
|
74
77
|
- !ruby/object:Gem::Version
|
75
78
|
version: '0'
|
79
|
+
segments:
|
80
|
+
- 0
|
81
|
+
hash: -73151246775261150
|
76
82
|
requirements: []
|
77
83
|
rubyforge_project: responders
|
78
|
-
rubygems_version: 1.8.
|
84
|
+
rubygems_version: 1.8.11
|
79
85
|
signing_key:
|
80
86
|
specification_version: 3
|
81
87
|
summary: A set of Rails 3 responders to dry up your application
|