responders 0.7.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,7 @@
1
+ == 0.8
2
+
3
+ * Allow embedded HTML in flash messages
4
+
1
5
  == 0.7
2
6
 
3
7
  * Support Rails 3.1 onward
data/Gemfile CHANGED
@@ -4,6 +4,4 @@ gemspec
4
4
 
5
5
  gem "mocha"
6
6
 
7
- if RUBY_VERSION < "1.9"
8
- gem "ruby-debug"
9
- end
7
+ gem "ruby-debug", :platform => :mri_18
@@ -1,38 +1,41 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- responders (0.7.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.0)
11
- activemodel (= 3.2.0)
12
- activesupport (= 3.2.0)
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.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.0)
21
- activesupport (= 3.2.0)
20
+ activemodel (3.2.1)
21
+ activesupport (= 3.2.1)
22
22
  builder (~> 3.0.0)
23
- activesupport (3.2.0)
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.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.3)
36
+ mocha (0.10.4)
34
37
  metaclass (~> 0.0.1)
35
- multi_json (1.0.4)
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.0)
44
- actionpack (= 3.2.0)
45
- activesupport (= 3.2.0)
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
@@ -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
- config.responders.flash_keys = [ :success, :failure ]
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
@@ -1,6 +1,7 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require 'rake'
3
+ require 'bundler/gem_tasks'
4
+
4
5
  require 'rake/testtask'
5
6
  require 'rdoc/task'
6
7
  require File.join(File.dirname(__FILE__), 'lib', 'responders', 'version')
@@ -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 = ::I18n.t options[:default].shift, options
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
- defaults << :"flash.#{slices.fill(controller.controller_name, -1).join('.')}.#{controller.action_name}.#{status}"
160
- defaults << :"flash.#{slices.fill(:actions, -1).join('.')}.#{controller.action_name}.#{status}"
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
 
@@ -1,3 +1,3 @@
1
1
  module Responders
2
- VERSION = "0.7.0".freeze
2
+ VERSION = "0.8.0".freeze
3
3
  end
@@ -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> &lt;script&gt;alert(1)&lt;/script&gt;", 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),
@@ -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.7.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-01-25 00:00:00.000000000 Z
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: &2151933860 !ruby/object:Gem::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: *2151933860
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.10
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