padrino-responders 0.1.2 → 0.1.3
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/Rakefile +3 -3
- data/lib/padrino-responders/default.rb +13 -17
- data/lib/padrino-responders/helpers/controller_helpers.rb +42 -0
- data/padrino-responders.gemspec +4 -4
- metadata +5 -5
data/Rakefile
CHANGED
|
@@ -6,13 +6,13 @@ begin
|
|
|
6
6
|
require 'jeweler'
|
|
7
7
|
Jeweler::Tasks.new do |gemspec|
|
|
8
8
|
gemspec.name = "padrino-responders"
|
|
9
|
-
gemspec.version = "0.1.
|
|
9
|
+
gemspec.version = "0.1.3"
|
|
10
10
|
gemspec.summary = "Simplified responders for Padrino framework"
|
|
11
11
|
gemspec.description = "This component is used to create slim controllers
|
|
12
12
|
without unnecessery and repetitive code."
|
|
13
13
|
gemspec.email = "kriss.kowalik@gmail.com"
|
|
14
|
-
gemspec.homepage = "http://github.com/
|
|
15
|
-
gemspec.authors = ["Kris Kowalik"]
|
|
14
|
+
gemspec.homepage = "http://github.com/nu7hatch/padrino-responders"
|
|
15
|
+
gemspec.authors = ["Kris 'nu7hatch' Kowalik"]
|
|
16
16
|
end
|
|
17
17
|
rescue LoadError
|
|
18
18
|
puts "Jeweler not available. Install it with: gem install jeweler"
|
|
@@ -53,11 +53,11 @@ module Padrino
|
|
|
53
53
|
#
|
|
54
54
|
module Default
|
|
55
55
|
|
|
56
|
-
def respond(object, location=nil) # :nodoc:
|
|
56
|
+
def respond(object, location=nil, kind=nil) # :nodoc:
|
|
57
57
|
if request.put?
|
|
58
|
-
default_response_for_save('edit', object, location)
|
|
58
|
+
default_response_for_save(kind || 'edit', object, location)
|
|
59
59
|
elsif request.post?
|
|
60
|
-
default_response_for_save('new', object, location)
|
|
60
|
+
default_response_for_save(kind || 'new', object, location)
|
|
61
61
|
elsif request.delete?
|
|
62
62
|
default_response_for_destroy(object, location)
|
|
63
63
|
else
|
|
@@ -125,13 +125,12 @@ module Padrino
|
|
|
125
125
|
# other formats. Otherwise we will see default form view or serialized errors.
|
|
126
126
|
#
|
|
127
127
|
def default_response_for_save(kind, object, location=nil)
|
|
128
|
-
valid
|
|
129
|
-
valid
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
alternative_notice = "responder.messages.default.#{current_action}"
|
|
128
|
+
valid = false
|
|
129
|
+
valid = object.valid? if object.respond_to?(:valid?)
|
|
130
|
+
default_success_view = "#{controller_name}/#{action_name}"
|
|
131
|
+
default_form_view = "#{controller_name}/#{kind}"
|
|
132
|
+
object_notice = "responder.messages.#{controller_name}.#{action_name}"
|
|
133
|
+
alternative_notice = "responder.messages.default.#{action_name}"
|
|
135
134
|
|
|
136
135
|
if valid
|
|
137
136
|
case content_type
|
|
@@ -143,19 +142,16 @@ module Padrino
|
|
|
143
142
|
))
|
|
144
143
|
redirect location
|
|
145
144
|
else
|
|
146
|
-
render
|
|
145
|
+
render default_success_view
|
|
147
146
|
end
|
|
148
147
|
when :js
|
|
149
|
-
render
|
|
148
|
+
render default_success_view
|
|
150
149
|
else
|
|
151
150
|
render content_type, object, :location => location
|
|
152
151
|
end
|
|
153
152
|
else
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
render form_view
|
|
157
|
-
when :js
|
|
158
|
-
render default_view
|
|
153
|
+
if [:html, :js].include?(content_type)
|
|
154
|
+
render default_form_view
|
|
159
155
|
else
|
|
160
156
|
errors = false
|
|
161
157
|
errors = object.errors if object.respond_to?(:errors)
|
|
@@ -19,7 +19,49 @@ module Padrino
|
|
|
19
19
|
name = 'index' if name == ''
|
|
20
20
|
name
|
|
21
21
|
end
|
|
22
|
+
module Padrino
|
|
23
|
+
module Responders
|
|
24
|
+
module Helpers
|
|
25
|
+
module ControllerHelpers
|
|
26
|
+
protected
|
|
27
|
+
##
|
|
28
|
+
# Shortcut for <code>notifier.say</code> method.
|
|
29
|
+
#
|
|
30
|
+
def notify(kind, message, *args, &block)
|
|
31
|
+
self.class.notifier.say(self, kind, message, *args, &block)
|
|
32
|
+
end
|
|
22
33
|
|
|
34
|
+
##
|
|
35
|
+
# Returns name of current action
|
|
36
|
+
#
|
|
37
|
+
def action_name
|
|
38
|
+
name = request.match.route.instance_variable_get('@name').to_s
|
|
39
|
+
name.gsub!(/^#{controller_name}_?/, '')
|
|
40
|
+
name = 'index' if name == ''
|
|
41
|
+
name
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
##
|
|
45
|
+
# Returns name of current controller
|
|
46
|
+
#
|
|
47
|
+
def controller_name
|
|
48
|
+
request.match.route.controller.to_s
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
##
|
|
52
|
+
# Returns translated, human readable name for specified model.
|
|
53
|
+
#
|
|
54
|
+
def human_model_name(object)
|
|
55
|
+
if object.class.respond_to?(:human_name)
|
|
56
|
+
object.class.human_name
|
|
57
|
+
else
|
|
58
|
+
t("models.#{object.class.to_s.underscore}", :default => object.class.to_s.humanize)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end # ControllerHelpers
|
|
62
|
+
end # Helpers
|
|
63
|
+
end # Responders
|
|
64
|
+
end # Padrino
|
|
23
65
|
##
|
|
24
66
|
# Returns name of current controller
|
|
25
67
|
#
|
data/padrino-responders.gemspec
CHANGED
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
|
|
6
6
|
Gem::Specification.new do |s|
|
|
7
7
|
s.name = %q{padrino-responders}
|
|
8
|
-
s.version = "0.1.
|
|
8
|
+
s.version = "0.1.3"
|
|
9
9
|
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
11
|
-
s.authors = ["Kris Kowalik"]
|
|
12
|
-
s.date = %q{2010-
|
|
11
|
+
s.authors = ["Kris 'nu7hatch' Kowalik"]
|
|
12
|
+
s.date = %q{2010-08-18}
|
|
13
13
|
s.description = %q{This component is used to create slim controllers
|
|
14
14
|
without unnecessery and repetitive code.}
|
|
15
15
|
s.email = %q{kriss.kowalik@gmail.com}
|
|
@@ -28,7 +28,7 @@ Gem::Specification.new do |s|
|
|
|
28
28
|
"lib/padrino-responders/notifiers/flash_notifier.rb",
|
|
29
29
|
"padrino-responders.gemspec"
|
|
30
30
|
]
|
|
31
|
-
s.homepage = %q{http://github.com/
|
|
31
|
+
s.homepage = %q{http://github.com/nu7hatch/padrino-responders}
|
|
32
32
|
s.rdoc_options = ["--charset=UTF-8"]
|
|
33
33
|
s.require_paths = ["lib"]
|
|
34
34
|
s.rubygems_version = %q{1.3.6}
|
metadata
CHANGED
|
@@ -5,16 +5,16 @@ version: !ruby/object:Gem::Version
|
|
|
5
5
|
segments:
|
|
6
6
|
- 0
|
|
7
7
|
- 1
|
|
8
|
-
-
|
|
9
|
-
version: 0.1.
|
|
8
|
+
- 3
|
|
9
|
+
version: 0.1.3
|
|
10
10
|
platform: ruby
|
|
11
11
|
authors:
|
|
12
|
-
- Kris Kowalik
|
|
12
|
+
- Kris 'nu7hatch' Kowalik
|
|
13
13
|
autorequire:
|
|
14
14
|
bindir: bin
|
|
15
15
|
cert_chain: []
|
|
16
16
|
|
|
17
|
-
date: 2010-
|
|
17
|
+
date: 2010-08-18 00:00:00 +02:00
|
|
18
18
|
default_executable:
|
|
19
19
|
dependencies: []
|
|
20
20
|
|
|
@@ -40,7 +40,7 @@ files:
|
|
|
40
40
|
- lib/padrino-responders/notifiers/flash_notifier.rb
|
|
41
41
|
- padrino-responders.gemspec
|
|
42
42
|
has_rdoc: true
|
|
43
|
-
homepage: http://github.com/
|
|
43
|
+
homepage: http://github.com/nu7hatch/padrino-responders
|
|
44
44
|
licenses: []
|
|
45
45
|
|
|
46
46
|
post_install_message:
|