casey_jones 0.0.115 → 0.0.116
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/lib/acts_as_linkable/acts_as_linkable.rb +18 -46
- data/lib/ajax_loading/action_controller_extensions.rb +36 -0
- data/lib/ajax_loading/ajax_loading.rb +1 -0
- data/lib/generators/loadbehind/templates/destroy.js.haml +1 -1
- data/lib/generators/loadbehind/templates/edit.js.haml +1 -1
- data/lib/generators/loadbehind/templates/view.js.haml +1 -1
- metadata +5 -4
@@ -1,7 +1,7 @@
|
|
1
1
|
module ActsAsLinkable
|
2
2
|
module ActiveRecordExtensions
|
3
3
|
def acts_as_linkable(opts={}, &block)
|
4
|
-
class_eval "def link_attr; #{opts.inspect}; end;"
|
4
|
+
class_eval "def link_attr; #{opts.except(:parent).inspect}; end; cattr_accessor :parent; self.parent = #{opts[:parent].inspect}"
|
5
5
|
end
|
6
6
|
end
|
7
7
|
|
@@ -11,65 +11,37 @@ module ActsAsLinkable
|
|
11
11
|
if (obj.class == Array) || (obj.class == ActiveRecord::Relation)
|
12
12
|
obj.map{|v| link(v)}.to_sentence
|
13
13
|
else
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
obj_name = (
|
18
|
-
(render :partial =>
|
14
|
+
link_attr = obj.link_attr
|
15
|
+
link_attr[:partial] = "#{obj.class.name.tableize}/link" if link_attr.empty?
|
16
|
+
if link_attr[:partial]
|
17
|
+
obj_name = (link_attr[:object_name] ||= obj.class.name.underscore).to_s.to_sym
|
18
|
+
(render :partial => link_attr[:partial], :locals => {obj_name => obj}).strip
|
19
19
|
else
|
20
20
|
name = obj.send(obj.link_attr[:name])
|
21
21
|
obj.link_attr.except(:name).each do |key, val|
|
22
22
|
html_options[key] ||= ((val.class==Symbol) ? obj.send(val) : val)
|
23
23
|
end
|
24
24
|
link_obj = options.empty? ? obj : self.send("#{obj.class.name.tableize}_path", obj, options.except(:remote))
|
25
|
-
link_to name, link_obj, html_options, :remote => (options[:remote]||true)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
def index_link(controller, name=nil, options={}, html_options={})
|
30
|
-
name ||= controller.titleize
|
31
|
-
url = self.send("#{controller}_path", options.except(:remote))
|
32
|
-
html_options[:remote] ||= true
|
33
|
-
link_to name, url, html_options
|
34
|
-
end
|
35
|
-
|
36
|
-
def new_link(klass, name=nil, options={}, html_options={})
|
37
|
-
name ||= "New #{klass.name.titleize}"
|
38
|
-
if can? :create, klass
|
39
|
-
url = self.send("new_#{klass.name.underscore}_path", options.except(:remote))
|
40
|
-
html_options[:remote] ||= true
|
41
|
-
link_to name, url, html_options
|
42
|
-
end
|
43
|
-
end
|
44
25
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
html_options[:remote] ||= true
|
49
|
-
link_to name, url, html_options
|
50
|
-
else
|
51
|
-
name
|
26
|
+
link_obj = [link_obj.send(link_obj.parent), link_obj] if link_obj.parent
|
27
|
+
link_to name, link_obj, html_options
|
28
|
+
end
|
52
29
|
end
|
53
30
|
end
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
link_to name, url, html_options
|
31
|
+
def tag_list(item, options={})
|
32
|
+
tags = item.send(:tag_list_on, options[:on] || :tags)
|
33
|
+
url = href(item)
|
34
|
+
tags.map! do |t|
|
35
|
+
link_to t, "#{url}?tag=#{t}"
|
60
36
|
end
|
37
|
+
tags.join(", ")
|
61
38
|
end
|
62
|
-
|
63
|
-
|
64
|
-
if can? :destroy, resource
|
65
|
-
html_options["data-confirm"] ||= "Really delete this #{resource.class.name.titleize}?"
|
66
|
-
html_options[:remote] ||= true
|
67
|
-
html_options[:method] |= :delete
|
68
|
-
link_to name, resource, html_options
|
69
|
-
end
|
39
|
+
def href(item)
|
40
|
+
url_for (item.parent ? [item.parent, item] : item)
|
70
41
|
end
|
71
42
|
end
|
72
43
|
end
|
44
|
+
|
73
45
|
ActiveRecord::Base.extend(ActsAsLinkable::ActiveRecordExtensions)
|
74
46
|
ActionView::Base.send :include, ActsAsLinkable::ActionViewExtensions
|
75
47
|
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module AjaxLoading
|
2
|
+
module ActionControllerExtensions
|
3
|
+
def ajax_loading
|
4
|
+
class_eval do
|
5
|
+
def container
|
6
|
+
@container ||= (params[:container] || "main_container")
|
7
|
+
end
|
8
|
+
def ajax_function
|
9
|
+
@ajax_function ||= (params[:ajax_function] || choose_ajax_function)
|
10
|
+
end
|
11
|
+
def choose_ajax_function
|
12
|
+
case params[:action]
|
13
|
+
when :destroy
|
14
|
+
"remove"
|
15
|
+
when :create
|
16
|
+
"append"
|
17
|
+
when :new
|
18
|
+
"append"
|
19
|
+
when :edit
|
20
|
+
"html"
|
21
|
+
when :show
|
22
|
+
"html"
|
23
|
+
when :index
|
24
|
+
"html"
|
25
|
+
when :update
|
26
|
+
"html"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
helper_method :container
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
ActionController::Base.extend AjaxLoading::ActionControllerExtensions
|
36
|
+
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: casey_jones
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 247
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 116
|
10
|
+
version: 0.0.116
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Tyler Gannon
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-08-
|
18
|
+
date: 2010-08-16 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -33,6 +33,7 @@ files:
|
|
33
33
|
- Rakefile
|
34
34
|
- install.rb
|
35
35
|
- lib/acts_as_linkable/acts_as_linkable.rb
|
36
|
+
- lib/ajax_loading/action_controller_extensions.rb
|
36
37
|
- lib/ajax_loading/active_record_extensions.rb
|
37
38
|
- lib/ajax_loading/ajax_loading.rb
|
38
39
|
- lib/ajax_loading/application_helpers.rb
|