casey_jones 0.0.99 → 0.0.100

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ module AjaxLoading
2
+ module ActiveRecordExtensions
3
+ def element_id(*args)
4
+ args << self
5
+ args.map{|t|
6
+ t.kind_of?(ActiveRecord::Base) ?
7
+ "#{t.class.name.underscore}_#{t.new_record? ? "new" : t.id}" :
8
+ t.to_s
9
+ }.join('_')
10
+ end
11
+ end
12
+ end
13
+
14
+ ActiveRecord::Base.send :include, AjaxLoading::ActiveRecordExtensions
15
+
@@ -1,2 +1,4 @@
1
1
  require 'ajax_loading/controller_resource'
2
+ require 'ajax_loading/active_record_extensions'
3
+ require 'ajax_loading/application_helpers'
2
4
 
@@ -0,0 +1,29 @@
1
+ module AjaxLoading
2
+ module ApplicationHelpers
3
+ def loadbehind_link(name, object, association, options={})
4
+ # This should go to the controller for the association class!
5
+ ass_info = object.class.reflect_on_association(association)
6
+ ass_controller = options[:controller] ||= ass_info.klass.name.tableize
7
+ controller_action = (ass_info.macro==:belongs_to) ? :show : :index
8
+
9
+ if ass_info.macro == :belongs_to
10
+ link_to name, :controller=>ass_controller,
11
+ :action=>:show,
12
+ :id=>object.send(ass_info.association_foreign_key),
13
+ :container=>object.element_id(association),
14
+ :remote=>true
15
+ else
16
+ form_tag({:controller=>ass_controller, :action=>:index},
17
+ :method=>:get, :remote=>true, :id=>object.element_id(:show, association)) do
18
+ concat hidden_field(:associated, :class_name, :value=>object.class.name) +
19
+ hidden_field(:associated, :id, :value=>object.id) +
20
+ hidden_field(:associated, :association, :value=>association.to_s) +
21
+ link_to(name,{},{:href=>"#", "data-submit"=>object.element_id(:show, association)})
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ ActionView::Base.send :include, AjaxLoading::ApplicationHelpers
29
+
@@ -1,4 +1,4 @@
1
- module AjaxLoading
1
+ module LoadBehind
2
2
  class ControllerResource < CanCan::ControllerResource
3
3
  def initialize(controller, name, parent = nil, options = {})
4
4
  super(controller, name, parent, options)
@@ -7,12 +7,15 @@ module AjaxLoading
7
7
  def load_resource
8
8
  puts "AjaxLoading::load_resource"
9
9
  params = @controller.params
10
+ set_controller_var 'container', params[:container] if params.has_key?(:container)
11
+
10
12
  if params.has_key?(:associated)
11
13
  ass_params = params[:associated]
12
14
  relation = ass_params["class_name"].constantize.find(ass_params["id"])
13
15
  association = ass_params["association"]
14
- instance_variable_set 'container',
15
- ass_params["container"] ||= relation.element_id(:show, association)
16
+
17
+ set_controller_var 'container', get_controller_var('container') ||
18
+ relation.element_id(:show, association)
16
19
 
17
20
  self.model_instance = relation.send(association)
18
21
  elsif collection_action?
@@ -20,15 +23,16 @@ module AjaxLoading
20
23
  else
21
24
  super
22
25
  end
26
+ set_controller_var 'container', get_controller_var('container') || 'main_container'
23
27
  end
24
28
 
25
29
  private
26
30
 
27
- def instance_variable_set(name, value)
31
+ def set_controller_var(name, value)
28
32
  name = '@'+name unless name.include?('@')
29
33
  @controller.instance_variable_set(name, value)
30
34
  end
31
- def instance_variable_get(name)
35
+ def get_controller_var(name)
32
36
  name = '@'+name unless name.include?('@')
33
37
  @controller.instance_variable_get(name)
34
38
  end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ rails generate loadbehind Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,43 @@
1
+ class LoadbehindGenerator < Rails::Generators::NamedBase
2
+ source_root File.expand_path('../templates', __FILE__)
3
+
4
+ IMAGES=["error", "growl_bottom", "growl_repeat", "growl_top", "info"]
5
+ JAVASCRIPTS=["loadbehind", "jquery.growl"]
6
+
7
+ def generate_loadbehind
8
+ view_dir = "app/views/#{plural_name}"
9
+
10
+ JAVASCRIPTS.each do |js|
11
+ copy_file "#{js}.js", "public/javascripts/#{js}.js"
12
+ end
13
+
14
+ IMAGES.each do |image|
15
+ copy_file "images/#{image}.png", "public/images/growl/#{image}.png"
16
+ end
17
+
18
+ ["index", "show"].each do |act|
19
+ self.action_name = act
20
+ template "view.js.haml", "#{view_dir}/#{action_name}.js.haml"
21
+ end
22
+ self.action_name = "show"
23
+ template "view.js.haml", "#{view_dir}/update.js.haml"
24
+
25
+ ["edit", "new"].each do |act|
26
+ self.action_name = act
27
+ template "edit.js.haml", "#{view_dir}/#{action_name}.js.haml"
28
+ end
29
+
30
+ ["destroy.js", "_errors.html"].each do |file|
31
+ template "#{file}.haml", "#{view_dir}/#{file}.haml"
32
+ end
33
+
34
+ puts "**** Remember to add loadbehind.js and jquery.growl.js to the
35
+ javascript tags, or add it to your own js files.
36
+ You'll also need to add handling to see that all your
37
+ events are reconnected each time you reload. "
38
+ end
39
+
40
+ attr_accessor :action_name
41
+
42
+ end
43
+
@@ -0,0 +1,5 @@
1
+ .errorTitle= "#{pluralize(@<%= singular_name %>.errors.count, 'error')} prohibited this <%= singular_name %> from being saved:"
2
+ %ul
3
+ - @<%= singular_name %>.errors.full_messages.each do |msg|
4
+ %li= msg
5
+
@@ -0,0 +1,4 @@
1
+ $('##{@container}').remove;
2
+ - if @<%= singular_name %>.errors.any?
3
+ = growl('Error', raw(render_js('errors')), :error)
4
+
@@ -0,0 +1,4 @@
1
+ $('##{@container}').html(#{raw render_js('<%= action_name%>')});
2
+ - if @<%= singular_name %>.errors.any?
3
+ = growl('Error', raw(render_js('errors')), :error)
4
+
@@ -0,0 +1,143 @@
1
+ /*
2
+ * jQuery Growl plugin
3
+ * Version 1.0.2 (8/1/2009)
4
+ * @requires jQuery v1.3.2 or later
5
+ *
6
+ * Examples at: http://fragmentedcode.com/jquery-growl
7
+ * Copyright (c) 2008-2009 David Higgins
8
+ *
9
+ * Special thanks to Daniel Mota for inspiration:
10
+ * http://icebeat.bitacoras.com/mootools/growl/
11
+ */
12
+
13
+ /*
14
+ USAGE:
15
+
16
+ $.growl(title, msg);
17
+ $.growl(title, msg, image);
18
+ $.growl(title, msg, image, priority);
19
+
20
+ THEME/SKIN:
21
+
22
+ You can override the default look and feel by updating these objects:
23
+ $.growl.settings.displayTimeout = 4000;
24
+ $.growl.settings.noticeTemplate = ''
25
+ + '<div>'
26
+ + '<div style="float: right; background-image: url(my.growlTheme/normalTop.png); position: relative; width: 259px; height: 16px; margin: 0pt;"></div>'
27
+ + '<div style="float: right; background-image: url(my.growlTheme/normalBackground.png); position: relative; display: block; color: #ffffff; font-family: Arial; font-size: 12px; line-height: 14px; width: 259px; margin: 0pt;">'
28
+ + ' <img style="margin: 14px; margin-top: 0px; float: left;" src="%image%" />'
29
+ + ' <h3 style="margin: 0pt; margin-left: 77px; padding-bottom: 10px; font-size: 13px;">%title%</h3>'
30
+ + ' <p style="margin: 0pt 14px; margin-left: 77px; font-size: 12px;">%message%</p>'
31
+ + '</div>'
32
+ + '<div style="float: right; background-image: url(my.growlTheme/normalBottom.png); position: relative; width: 259px; height: 16px; margin-bottom: 10px;"></div>'
33
+ + '</div>';
34
+ $.growl.settings.noticeCss = {
35
+ position: 'relative'
36
+ };
37
+
38
+ To change the 'dock' look, and position:
39
+
40
+ $.growl.settings.dockTemplate = '<div></div>';
41
+ $.growl.settings.dockCss = {
42
+ position: 'absolute',
43
+ top: '10px',
44
+ right: '10px',
45
+ width: '300px'
46
+ };
47
+
48
+ The dockCss will allow you to 'dock' the notifications to a specific area
49
+ on the page, such as TopRight (the default) or TopLeft, perhaps even in a
50
+ smaller area with "overflow: scroll" enabled?
51
+ */
52
+
53
+ (function($) {
54
+
55
+ $.growl = function(title,message,image,priority) { notify(title,message,image,priority); }
56
+ $.growl.version = "1.0.2";
57
+
58
+ function create(rebuild) {
59
+ var instance = document.getElementById('growlDock');
60
+ if(!instance || rebuild) {
61
+ instance = $(jQuery.growl.settings.dockTemplate).attr('id', 'growlDock').addClass('growl');
62
+ if(jQuery.growl.settings.defaultStylesheet) {
63
+ $('head').append('<link rel="stylesheet" type="text/css" href="' + jQuery.growl.settings.defaultStylesheet + '" />');
64
+ }
65
+
66
+ } else {
67
+ instance = $(instance);
68
+ }
69
+ $('body').append(instance.css(jQuery.growl.settings.dockCss));
70
+ return instance;
71
+ };
72
+
73
+ function r(text, expr, val) {
74
+ while(expr.test(text)) {
75
+ text = text.replace(expr, val);
76
+ }
77
+ return text;
78
+ };
79
+
80
+ function notify(title,message,image,priority) {
81
+ var instance = create();
82
+ var html = jQuery.growl.settings.noticeTemplate;
83
+ if(typeof(html) == 'object') html = $(html).html();
84
+ html = r(html, /%message%/, (message?message:''));
85
+ html = r(html, /%title%/, (title?title:''));
86
+ html = r(html, /%image%/, (image?image:jQuery.growl.settings.defaultImage));
87
+ html = r(html, /%priority%/, (priority?priority:'normal'));
88
+
89
+ var notice = $(html)
90
+ .hide()
91
+ .css(jQuery.growl.settings.noticeCss)
92
+ .fadeIn(jQuery.growl.settings.notice);;
93
+
94
+ $.growl.settings.noticeDisplay(notice);
95
+ instance.append(notice);
96
+ $('a[rel="close"]', notice).click(function() {
97
+ notice.remove();
98
+ });
99
+ if ($.growl.settings.displayTimeout > 0) {
100
+ setTimeout(function(){
101
+ jQuery.growl.settings.noticeRemove(notice, function(){
102
+ notice.remove();
103
+ });
104
+ }, jQuery.growl.settings.displayTimeout);
105
+ }
106
+ };
107
+
108
+
109
+ // default settings
110
+ $.growl.settings = {
111
+ dockTemplate: '<div></div>',
112
+ dockCss: {
113
+ position: 'fixed',
114
+ top: '10px',
115
+ right: '10px',
116
+ width: '300px',
117
+ zIndex: 50000
118
+ },
119
+ noticeTemplate:
120
+ '<div class="notice">' +
121
+ ' <h3 style="margin-top: 15px"><a rel="close">%title%</a></h3>' +
122
+ ' <p>%message%</p>' +
123
+ '</div>',
124
+ noticeCss: {
125
+ opacity: .75,
126
+ backgroundColor: '#333333',
127
+ color: '#ffffff'
128
+ },
129
+ noticeDisplay: function(notice) {
130
+ notice.css({'opacity':'0'}).fadeIn(jQuery.growl.settings.noticeFadeTimeout);
131
+ },
132
+ noticeRemove: function(notice, callback) {
133
+ notice.animate({opacity: '0', height: '0px'}, {duration:jQuery.growl.settings.noticeFadeTimeout, complete: callback});
134
+ },
135
+ noticeFadeTimeout: 'slow',
136
+ displayTimeout: 3500,
137
+ defaultImage: 'growl.jpg',
138
+ defaultStylesheet: null,
139
+ noticeElement: function(el) {
140
+ $.growl.settings.noticeTemplate = $(el);
141
+ }
142
+ };
143
+ })(jQuery);
@@ -0,0 +1,33 @@
1
+ $(function () {
2
+ $('[data-submit]').click(function() {
3
+ $('#'+$(this).attr('data-submit')).submit();
4
+ return false;
5
+ });
6
+
7
+ $.growl.settings.dockCss.width = '225px';
8
+ $.growl.settings.noticeTemplate = ''
9
+ + '<table width="225" border="0" cellpadding="0" cellspacing="0">'
10
+ + ' <tr>'
11
+ + ' <td style="background-image: url(images/growl/growl_top.png); width: 225px; height: 49px; background-repeat: no-repeat; color: #fff;">'
12
+ + ' <img src="%image%" style="max-width: 25px; max-height: 25px; text-align: center; margin-left: 19px; margin-top: 19px;" />'
13
+ + ' <h1 style="font-size: 18px; margin: 0pt; margin-left: 5px; margin-bottom: 10px; display: inline;">%title%</h1>'
14
+ + ' </td>'
15
+ + ' </tr>'
16
+ + ' <tr>'
17
+ + ' <td style="background-image: url(images/growl/growl_repeat.png); width: 225px; background-repeat: repeat-y; color: #ddd;">'
18
+ + ' <p style="margin: 20px;">%message%</p>'
19
+ + ' </td>'
20
+ + ' </tr>'
21
+ + ' <tr>'
22
+ + ' <td style="background-image: url(images/growl/growl_bottom.png); background-repeat: no-repeat; width: 225px; height: 27px;" valign="top" align="right" >'
23
+ + ' <a style="margin-right: 25px; font-size: 10px; color: #fff; text-align: right;" href="" onclick="return false;" rel="close">Close</a>'
24
+ + ' </td>'
25
+ + ' </tr>'
26
+ '+ </table>';
27
+ $.growl.settings.noticeCss = {
28
+ position: 'relative'
29
+ };
30
+
31
+
32
+ });
33
+
@@ -0,0 +1,4 @@
1
+ $('##{@container}').html(#{raw render_js('<%= action_name%>')});
2
+ - unless flash[:notice].empty?
3
+ = growl("Success", flash[:notice])
4
+
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: 217
4
+ hash: 215
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 99
10
- version: 0.0.99
9
+ - 100
10
+ version: 0.0.100
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-07-21 00:00:00 -07:00
18
+ date: 2010-07-22 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -33,7 +33,9 @@ files:
33
33
  - Rakefile
34
34
  - install.rb
35
35
  - lib/acts_as_linkable/acts_as_linkable.rb
36
+ - lib/ajax_loading/active_record_extensions.rb
36
37
  - lib/ajax_loading/ajax_loading.rb
38
+ - lib/ajax_loading/application_helpers.rb
37
39
  - lib/ajax_loading/controller_resource.rb
38
40
  - lib/anaf_active_record.rb
39
41
  - lib/casey_jones.rb
@@ -43,6 +45,19 @@ files:
43
45
  - lib/generators/anaf_habtm/anaf_habtm_generator.rb
44
46
  - lib/generators/anaf_habtm/assets/nested_attributes.css
45
47
  - lib/generators/anaf_habtm/assets/nested_attributes.js
48
+ - lib/generators/loadbehind/USAGE
49
+ - lib/generators/loadbehind/loadbehind_generator.rb
50
+ - lib/generators/loadbehind/templates/_errors.html.haml
51
+ - lib/generators/loadbehind/templates/destroy.js.haml
52
+ - lib/generators/loadbehind/templates/edit.js.haml
53
+ - lib/generators/loadbehind/templates/images/error.png
54
+ - lib/generators/loadbehind/templates/images/growl_bottom.png
55
+ - lib/generators/loadbehind/templates/images/growl_repeat.png
56
+ - lib/generators/loadbehind/templates/images/growl_top.png
57
+ - lib/generators/loadbehind/templates/images/info.png
58
+ - lib/generators/loadbehind/templates/jquery.growl.js
59
+ - lib/generators/loadbehind/templates/loadbehind.js
60
+ - lib/generators/loadbehind/templates/view.js.haml
46
61
  - test/anaf_habtm_test.rb
47
62
  - test/test_helper.rb
48
63
  - uninstall.rb