casey_jones 0.0.115 → 0.0.116

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
- p = obj.link_attr
15
- p[:partial] = "#{obj.class.name.tableize}/link" if p.empty?
16
- unless p[:partial].nil?
17
- obj_name = (p[:object_name] ||= obj.class.name.underscore).to_s.to_sym
18
- (render :partial => p[:partial], :locals => {obj_name => obj}).strip
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
- def show_link(resource, name='Show', options={}, html_options={})
46
- if can? :read, resource
47
- url = self.send("#{resource.class.name.underscore}_path", resource, options.except(:remote))
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
- def edit_link(resource, name='Edit', options={}, html_options={})
56
- if can? :edit, resource
57
- url = self.send("edit_#{resource.class.name.underscore}_path", resource, options.except(:remote))
58
- html_options[:remote] ||= true
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
- def destroy_link(resource, name='Delete', options={}, html_options={})
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
+
@@ -1,4 +1,5 @@
1
1
  # require 'ajax_loading/controller_resource'
2
2
  require 'ajax_loading/active_record_extensions'
3
3
  require 'ajax_loading/application_helpers'
4
+ require 'ajax_loading/action_controller_extensions'
4
5
 
@@ -1,3 +1,3 @@
1
- $('##{@container}').remove;
1
+ $('##{container}').remove;
2
2
  = render :partial => "loadbehind/destroy"
3
3
 
@@ -1,3 +1,3 @@
1
- $('##{@container}').#{@ajax_function}(#{raw render_js('<%= action_name%>')});
1
+ $('##{container}').#{ajax_function}(#{raw render_js('<%= action_name%>')});
2
2
  = render :partial => "loadbehind/edit"
3
3
 
@@ -1,3 +1,3 @@
1
- $('##{@container}').#{@ajax_function}(#{raw render_js('<%= action_name%>')});
1
+ $('##{container}').#{ajax_function}(#{raw render_js('<%= action_name%>')});
2
2
  = render :partial => "loadbehind/view"
3
3
 
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: 249
4
+ hash: 247
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 115
10
- version: 0.0.115
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-07 00:00:00 -07:00
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