hammock 0.2.25 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/hammock.gemspec +1 -1
- data/lib/hammock/ajaxinate.rb +18 -13
- data/lib/hammock/monkey_patches/array.rb +4 -0
- data/lib/hammock/restful_actions.rb +1 -1
- data/lib/hammock.rb +1 -1
- metadata +1 -1
data/History.txt
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
== 0.3.0 2009-05-25
|
2
|
+
Updated ajax_link, ajaxinate and related methods to accept explicit args instead of a splatted list - this makes it a lot easier to handle different amounts of entities.
|
3
|
+
Only do obj replacement in jquery_xhr callback if it's set.
|
4
|
+
|
1
5
|
== 0.2.25 2009-05-25
|
2
6
|
Added String#clean_email[!].
|
3
7
|
Moved set_new_or_deleted_before_save callback from controller to model.
|
data/hammock.gemspec
CHANGED
data/lib/hammock/ajaxinate.rb
CHANGED
@@ -16,25 +16,30 @@ module Hammock
|
|
16
16
|
ajax_link verb, record, opts.merge(:class => [opts[:class], 'button'].squash.join(' '))
|
17
17
|
end
|
18
18
|
|
19
|
-
def ajax_link verb,
|
20
|
-
|
21
|
-
|
19
|
+
def ajax_link verb, entities, opts
|
20
|
+
entities = [entities] unless entities.is_a?(Array)
|
21
|
+
|
22
|
+
if can_verb_entity?(verb, entities.last)
|
23
|
+
route = ajaxinate verb, entities, opts
|
22
24
|
|
23
25
|
content_tag :a,
|
24
26
|
opts[:text] || route.verb.to_s.capitalize,
|
25
|
-
:class => [opts[:class], link_class_for(route.verb,
|
27
|
+
:class => [opts[:class], link_class_for(route.verb, entities)].squash.join(' '),
|
26
28
|
:href => route.path,
|
27
29
|
:onclick => 'return false;',
|
28
30
|
:style => opts[:style]
|
29
31
|
end
|
30
32
|
end
|
31
33
|
|
32
|
-
def ajaxinate verb,
|
33
|
-
|
34
|
-
|
35
|
-
|
34
|
+
def ajaxinate verb, entities, opts = {}
|
35
|
+
entities = [entities] unless entities.is_a?(Array)
|
36
|
+
entity = entities.last
|
37
|
+
|
38
|
+
record_attributes = entity.is_a?(ActiveRecord::Base) ? {entity.base_model => entity.unsaved_attributes} : {}
|
39
|
+
link_params = {entity.base_model => (opts.delete(:record) || {}) }.merge(opts[:params] || {})
|
40
|
+
route = route_for verb, *entities
|
36
41
|
attribute = link_params[:attribute]
|
37
|
-
link_class = link_class_for route.verb,
|
42
|
+
link_class = link_class_for route.verb, entities, attribute
|
38
43
|
|
39
44
|
link_params[:_method] = route.http_method
|
40
45
|
link_params[:format] = opts[:format].to_s unless opts[:format].blank?
|
@@ -44,7 +49,7 @@ module Hammock
|
|
44
49
|
elsif attribute.blank?
|
45
50
|
"jQuery('form').serializeHash()"
|
46
51
|
else
|
47
|
-
"{ '#{
|
52
|
+
"{ '#{entity.base_model}[#{attribute}]': $('.#{link_class}').val() }"
|
48
53
|
end
|
49
54
|
|
50
55
|
response_action = case link_params[:format].to_s
|
@@ -115,7 +120,7 @@ module Hammock
|
|
115
120
|
when 'js'
|
116
121
|
"eval(data);"
|
117
122
|
else
|
118
|
-
"obj.replaceWith(data);"
|
123
|
+
"if (typeof(obj) != 'undefined') { obj.replaceWith(data); }"
|
119
124
|
end
|
120
125
|
|
121
126
|
%Q{
|
@@ -141,8 +146,8 @@ module Hammock
|
|
141
146
|
|
142
147
|
private
|
143
148
|
|
144
|
-
def link_class_for verb,
|
145
|
-
[verb,
|
149
|
+
def link_class_for verb, entitites, attribute = nil
|
150
|
+
[verb, entitites.map(&:description), attribute].flatten.compact.join '_'
|
146
151
|
end
|
147
152
|
|
148
153
|
def clean_snippet snippet
|
data/lib/hammock.rb
CHANGED