kenny_dialoggins 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.specification ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kenny_dialoggins
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Coroutine
13
+ - Tim Lowrimore
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-03-26 00:00:00 -05:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: actionpack
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ type: :runtime
32
+ version_requirements: *id001
33
+ description: Kenny Dialoggins allows you to include scriptaculous dialogs in Rails applications using the same syntax employed for rendering partials.
34
+ email: "@coroutine.com"
35
+ executables: []
36
+
37
+ extensions: []
38
+
39
+ extra_rdoc_files:
40
+ - README.rdoc
41
+ files:
42
+ - MIT-LICENSE
43
+ - README.rdoc
44
+ - Rakefile
45
+ - VERSION
46
+ - generators/kenny_dialoggins_assets/kenny_dialoggins_assets_generator.rb
47
+ - generators/kenny_dialoggins_assets/templates/kenny_dialoggins.css
48
+ - generators/kenny_dialoggins_assets/templates/kenny_dialoggins.js
49
+ - init.rb
50
+ - kenny_dialoggins.gemspec
51
+ - lib/kenny_dialoggins.rb
52
+ - lib/kenny_dialoggins/helpers.rb
53
+ - rails/init.rb
54
+ - test/kenny_dialoggins_test.rb
55
+ - test/test_helper.rb
56
+ has_rdoc: true
57
+ homepage: http://github.com/coroutine/kenny_dialoggins
58
+ licenses: []
59
+
60
+ post_install_message:
61
+ rdoc_options:
62
+ - --charset=UTF-8
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ segments:
70
+ - 0
71
+ version: "0"
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ requirements: []
80
+
81
+ rubyforge_project:
82
+ rubygems_version: 1.3.6
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: Dead simple, beautiful dialogs for Rails.
86
+ test_files:
87
+ - test/kenny_dialoggins_test.rb
88
+ - test/test_helper.rb
89
+
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Coroutine LLC
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,97 @@
1
+ = Kenny Dialoggins
2
+
3
+ Hey, there.
4
+
5
+ I'm Kenny Dialoggins. A lot of people confuse me with the singer who rose to fame in the 1980s, but
6
+ I'm a different guy altogether.
7
+
8
+ Don't get me wrong, that Kenny and I are into a lot of the same things, like manly beards and Miami Vice-
9
+ inspired attire. But while that Kenny spent his career focused on synth beats and lyrics that cut to
10
+ the bone, I only care about one thing.
11
+
12
+ <b>Freakin' Dialogs</b>.
13
+
14
+ If you're a Rails developer who wants to use dialogs but doesn't want to mess with Javascript, you
15
+ might want to prep your best friend for some bad news. We're about to become <b>tight</b>.
16
+
17
+ Let me lay it out for you. If you want my dialog in one of your views, here's what you do:
18
+
19
+ # Create the dialog
20
+ <%= render_dialog :danger_zone_dialog, :partial => "danger_zone", :locals => { :pilot => current_user } %>
21
+
22
+ # Invoke the dialog
23
+ <%= link_to_function "Take Me to the Danger Zone", show_dialog(:danger_zone_dialog) %>
24
+
25
+ That's pretty much it. Did you notice how <tt>render_dialog</tt> takes the same options as
26
+ <tt>render</tt>? The content for your dialog can just be a regular old partial.
27
+
28
+ You like that. I can tell. Don't fight it.
29
+
30
+ Wait, you want more details? You got it, buddy.
31
+
32
+ <tt>render_dialog</tt> always needs a unique id for its first argument. After that, it will
33
+ take the same options as <tt>ActionController::Base#render</tt>. It'll also take a few more, namely:
34
+
35
+ * <tt>:before_show</tt> - a Javascript function that will be invoked before the dialog is shown
36
+ * <tt>:after_show</tt> - a Javascript function that will be invoked after the dialog has become visible
37
+ * <tt>:before_hide</tt> - a Javascript function that will be invoked before the dialog is hidden
38
+ * <tt>:after_hide</tt> - a Javascript function that will be invoked after the dialog has been hidden
39
+
40
+ Here's an example using the <tt>before_show</tt> option:
41
+
42
+ # Create the dialog with a callback
43
+ <%= render_dialog :footloose_dialog, :partial => "footloose", :before_show => "function() { alert('Everybody get footloose!'); }" %>
44
+
45
+ # Invoke the dialog
46
+ <%= link_to_function "Dance party!", show_dialog(:footloose_dialog) %>
47
+
48
+ If you need more help than that, maybe you should just look at the source code. There are a ton of comments
49
+ in there.
50
+
51
+
52
+ Your pal,
53
+
54
+ Kenny Dialoggins
55
+
56
+
57
+
58
+
59
+ == Helpful Links
60
+
61
+ * <b>Repository:</b> http://github.com/coroutine/kenny_dialoggins
62
+ * <b>Gem:</b> http://rubygems.org/gems/kenny_dialoggins
63
+ * <b>Authors:</b> http://coroutine.com
64
+
65
+
66
+
67
+ == Prerequisites
68
+
69
+ To take you to the danger zone, I need my kick ass backup singers Prototype and Scriptaculous.
70
+
71
+ But since I was designed as a Rails extension, chances are you already have my boys
72
+ in the mix.
73
+
74
+ * <b>Prototype:</b> http://prototypejs.org
75
+ * <b>Scriptaculous:</b> http://script.aculo.us
76
+
77
+
78
+
79
+ == Installation & Generators
80
+
81
+ Install me from RubyGems.org and add a gem dependency in your configuration file.
82
+
83
+ $ sudo gem install kenny_dialoggins
84
+
85
+ Or install me as a plugin.
86
+
87
+ $ script/plugin install git://github.com/coroutine/kenny_dialoggins.git
88
+
89
+ Then, generate the stylesheet and javascript files I need.
90
+
91
+ $ script/generate kenny_dialoggins_assets
92
+
93
+
94
+
95
+ == License
96
+
97
+ Copyright (c) 2010 {Coroutine LLC}[http://coroutine.com].
data/Rakefile ADDED
@@ -0,0 +1,46 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+ require 'jeweler'
5
+
6
+
7
+ desc 'Default: run tests.'
8
+ task :default => [:test]
9
+
10
+
11
+ desc 'Test the plugin.'
12
+ Rake::TestTask.new(:test) do |t|
13
+ t.libs << 'lib'
14
+ t.pattern = 'test/**/*_test.rb'
15
+ t.verbose = true
16
+ end
17
+
18
+
19
+ desc 'Generate documentation for the plugin.'
20
+ Rake::RDocTask.new(:rdoc) do |rdoc|
21
+ rdoc.rdoc_dir = 'rdoc'
22
+ rdoc.title = 'kenny_dialoggins'
23
+ rdoc.options << '--line-numbers --inline-source'
24
+ rdoc.rdoc_files.include('README')
25
+ rdoc.rdoc_files.include('lib/**/*.rb')
26
+ end
27
+
28
+
29
+ begin
30
+ Jeweler::Tasks.new do |gemspec|
31
+ gemspec.authors = ["Coroutine", "Tim Lowrimore", "John Dugan"]
32
+ gemspec.description = "Kenny Dialoggins allows you to include scriptaculous dialogs in Rails applications using the same syntax employed for rendering partials."
33
+ gemspec.email = "gems@coroutine.com"
34
+ gemspec.homepage = "http://github.com/coroutine/kenny_dialoggins"
35
+ gemspec.name = "kenny_dialoggins"
36
+ gemspec.summary = "Dead simple, beautiful dialogs for Rails."
37
+
38
+ gemspec.files.include("lib/**/*.rb")
39
+ gemspec.files.include("test/**/*.rb")
40
+ end
41
+ Jeweler::GemcutterTasks.new
42
+ rescue LoadError
43
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
44
+ end
45
+
46
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,8 @@
1
+ class KennyDialogginsAssetsGenerator < Rails::Generator::Base
2
+ def manifest
3
+ record do |m|
4
+ m.file "kenny_dialoggins.js", "public/javascripts/kenny_dialoggins.js"
5
+ m.file "kenny_dialoggins.css", "public/stylesheets/kenny_dialoggins.css"
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,20 @@
1
+ /**
2
+ * These styles are provided as examples. Feel free to change them however you like.
3
+ */
4
+ .kenny_dialoggins_dialog {
5
+ position: absolute;
6
+ padding: 1em;
7
+ border: 1px solid #BBB;
8
+ background: #FFF;
9
+ z-index: 2;
10
+ -moz-box-shadow: 4px 4px 16px rgba(0,0,0,0.5);
11
+ -webkit-box-shadow: 4px 4px 16px rgba(0,0,0,0.5);
12
+ filter: alpha(opacity=100); /* really only needed if ie6 suport is enabled */
13
+ }
14
+
15
+ .kenny_dialoggins_dialog_frame {
16
+ position: absolute;
17
+ border: none;
18
+ z-index: 1;
19
+ filter: alpha(opacity=0); /* really only needed if ie6 suport is enabled */
20
+ }
@@ -0,0 +1,268 @@
1
+ /**
2
+ * Kenny Dialoggins creates pretty dialogs using prototype and
3
+ * scriptaculous. These functions work with ActionView
4
+ * helpers to provide dialog components that can be programmed
5
+ * using the same syntax as rendering partials.
6
+ *
7
+ *
8
+ * Brought to you by the good folks at Coroutine. Hire us!
9
+ * http://coroutine.com
10
+ */
11
+ var KennyDialoggins = {}
12
+
13
+
14
+ /**
15
+ * This property governs whether or not KD bothers creating and
16
+ * managing a blocking iframe to accommodate ie6.
17
+ *
18
+ * Defaults to false, but override if you must.
19
+ */
20
+ KennyDialoggins.SUPPORT_IE6_BULLSHIT = false;
21
+
22
+
23
+
24
+ /**
25
+ * This function puts you on the highway to the danger
26
+ * zone by defining the KD dialog class.
27
+ */
28
+ KennyDialoggins.Dialog = function(content, options) {
29
+ options = options || {};
30
+
31
+ this._element = null;
32
+ this._frame = null;
33
+ this._hideListener = this._generateHideListener();
34
+ this._is_showing = false;
35
+
36
+ this._beforeShow = options["beforeShow"] || Prototype.emptyFunction
37
+ this._afterShow = options["afterShow"] || Prototype.emptyFunction
38
+ this._beforeHide = options["beforeHide"] || Prototype.emptyFunction
39
+ this._afterHide = options["afterHide"] || Prototype.emptyFunction
40
+
41
+ this._makeDialog();
42
+ this.setContent(content);
43
+ document.body.appendChild(this._element);
44
+
45
+ if (KennyDialoggins.SUPPORT_IE6_BULLSHIT) {
46
+ this._makeFrame();
47
+ document.body.appendChild(this._frame);
48
+ }
49
+ }
50
+
51
+
52
+
53
+ // ----------------------------------------------------------------------------
54
+ // Class methods
55
+ // ----------------------------------------------------------------------------
56
+
57
+ /**
58
+ * This hash maps the dialog id to the dialog object itself. It allows the Rails
59
+ * code a way to specify the js object it wishes to invoke.
60
+ */
61
+ KennyDialoggins.Dialog.instances = {};
62
+
63
+
64
+ /**
65
+ * This hash is a convenience that allows us to write slightly denser code when
66
+ * calculating the dialog's position.
67
+ */
68
+ KennyDialoggins.Dialog._POSITION_FN_MAP = $H({
69
+ left: "getWidth",
70
+ top: "getHeight"
71
+ });
72
+
73
+
74
+ /**
75
+ * This method shows the dialog with the corresponding id.
76
+ *
77
+ * @param {String} id The id value of the dialog element (also the key
78
+ * in the instances hash.)
79
+ *
80
+ * @return {Object} an instance of KennyDialoggins.Dialog
81
+ *
82
+ */
83
+ KennyDialoggins.Dialog.show = function(id) {
84
+ var dialog = this.instances[id];
85
+ if(dialog) {
86
+ dialog.show();
87
+ }
88
+ return dialog;
89
+ }
90
+
91
+
92
+ /**
93
+ * This method hides the dialog with the corresponding id.
94
+ *
95
+ * @param {String} id The id value of the dialog element (also the key
96
+ * in the instances hash.)
97
+ *
98
+ * @return {Object} an instance of KennyDialoggins.Dialog
99
+ *
100
+ */
101
+ KennyDialoggins.Dialog.hide = function(id) {
102
+ var dialog = this.instances[id];
103
+ if(dialog) {
104
+ dialog.hide();
105
+ }
106
+ return dialog;
107
+ }
108
+
109
+
110
+ /**
111
+ * This method returns a boolean indiciating whether or not the
112
+ * dialog with the corresponding id is showing.
113
+ *
114
+ * @param {String} id The id value of the dialog element (also the key
115
+ * in the instances hash.)
116
+ *
117
+ * @return {Boolean} Whether or not the dialog with the corresponding
118
+ * id is showing.
119
+ *
120
+ */
121
+ KennyDialoggins.Dialog.is_showing = function(id) {
122
+ var dialog = this.instances[id];
123
+ if (!dialog) {
124
+ throw "No dialog cound be found for the supplied id.";
125
+ }
126
+ return dialog.is_showing();
127
+ }
128
+
129
+
130
+
131
+ // ----------------------------------------------------------------------------
132
+ // Instance methods
133
+ // ----------------------------------------------------------------------------
134
+
135
+ Object.extend(KennyDialoggins.Dialog.prototype, {
136
+
137
+ /**
138
+ * This function constructs the dialog element and hides it by default.
139
+ *
140
+ * The class name is set outside the element constructor to accommodate
141
+ * a discrepancy in how prototype handles this particular attribute. The
142
+ * attribute is set as className in IE8--rather than class--which means the
143
+ * styles are not applied and the element's positioning gets royally
144
+ * screwed up.
145
+ */
146
+ _makeDialog: function() {
147
+ if (!this._element) {
148
+ this._element = new Element("DIV");
149
+ this._element.className = "kenny_dialoggins_dialog";
150
+ this._element.hide();
151
+ }
152
+ },
153
+
154
+
155
+ /**
156
+ * This function constructs the iframe element and hides it by default.
157
+ *
158
+ * The class name is set outside the element constructor to accommodate
159
+ * a discrepancy in how prototype handles this particular attribute. The
160
+ * attribute is set as className in IE8--rather than class--which means the
161
+ * styles are not applied and the element's positioning gets royally
162
+ * screwed up.
163
+ */
164
+ _makeFrame: function() {
165
+ if (!this._frame) {
166
+ this._frame = new Element("IFRAME");
167
+ this._frame.className = "kenny_dialoggins_dialog_frame";
168
+ this._frame.setAttribute("src", "about:blank");
169
+ this._frame.hide();
170
+ }
171
+ },
172
+
173
+
174
+ /**
175
+ * This function creates the function that handles click events when the dialog is
176
+ * shown. The handler ignores clicks targeted from within the dialog; any click
177
+ * targeted outside the dialog causes the dialog to hide itself and cancel the
178
+ * observer.
179
+ */
180
+ _generateHideListener: function() {
181
+ return function(evt) {
182
+ var origin = evt.findElement(".kenny_dialoggins_dialog");
183
+ if (this._element !== origin) {
184
+ this.hide();
185
+ }
186
+ }.bind(this);
187
+ },
188
+
189
+
190
+ /**
191
+ * This function sets the content of the dialog element.
192
+ *
193
+ * @param {Object} content The html content for the dialog.
194
+ */
195
+ setContent: function(content) {
196
+ this._element.update(content);
197
+ },
198
+
199
+
200
+ /**
201
+ * This function displays the dialog. It uses a scriptaculous effect to fade in,
202
+ * centers the dialog in the viewport (and adjusts the blocking iframe, if in use),
203
+ * and connects a click observer to hide the dialog whenever mouse focus leaves
204
+ * the dialog.
205
+ */
206
+ show: function() {
207
+ KennyDialoggins.Dialog._POSITION_FN_MAP.each(function(pair) {
208
+ var method = pair.last();
209
+ this._element.style[pair.first()] =
210
+ (document.viewport[method]() / 2 + document.viewport.getScrollOffsets()[pair.first()] - this._element[method]() / 2) + "px";
211
+ }.bind(this));
212
+
213
+ if (this._frame) {
214
+ this._frame.style.top = this._element.style.top;
215
+ this._frame.style.left = this._element.style.left;
216
+ this._frame.style.width = this._element.getWidth() + "px";
217
+ this._frame.style.height = this._element.getHeight() + "px";
218
+
219
+ new Effect.Appear(this._frame, {
220
+ duration: 0.2
221
+ });
222
+ }
223
+
224
+ new Effect.Appear(this._element, {
225
+ duration: 0.2,
226
+ beforeStart: this._beforeShow,
227
+ afterFinish: function() {
228
+ this._is_showing = true;
229
+ this._afterShow();
230
+ document.observe("click", this._hideListener);
231
+ }.bind(this)
232
+ });
233
+ },
234
+
235
+
236
+ /**
237
+ * This function hides the dialog. It uses a scriptaculous effect to fade out
238
+ * and disconnects the click observer to prevent memory leaks.
239
+ */
240
+ hide: function() {
241
+ new Effect.Fade(this._element, {
242
+ duration: 0.2,
243
+ beforeStart: this._beforeHide,
244
+ afterFinish: function() {
245
+ this._is_showing = false;
246
+ this._afterHide();
247
+ document.stopObserving("click", this._hideListener);
248
+ }.bind(this)
249
+ });
250
+
251
+ if (this._frame) {
252
+ new Effect.Fade(this._frame, {
253
+ duration: 0.2
254
+ });
255
+ }
256
+ },
257
+
258
+
259
+ /**
260
+ * This function indicates whether or not the dialog is currently
261
+ * being shown.
262
+ *
263
+ * @return {Boolean} Whether or not the dialog is being shown.
264
+ */
265
+ is_showing: function() {
266
+ return this._is_showing;
267
+ }
268
+ });
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require File.dirname(__FILE__) + "/rails/init.rb"
@@ -0,0 +1,55 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{kenny_dialoggins}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Coroutine", "Tim Lowrimore", "John Dugan"]
12
+ s.date = %q{2010-03-29}
13
+ s.description = %q{Kenny Dialoggins allows you to include scriptaculous dialogs in Rails applications using the same syntax employed for rendering partials.}
14
+ s.email = %q{gems@coroutine.com}
15
+ s.extra_rdoc_files = [
16
+ "README.rdoc"
17
+ ]
18
+ s.files = [
19
+ ".specification",
20
+ "MIT-LICENSE",
21
+ "README.rdoc",
22
+ "Rakefile",
23
+ "VERSION",
24
+ "generators/kenny_dialoggins_assets/kenny_dialoggins_assets_generator.rb",
25
+ "generators/kenny_dialoggins_assets/templates/kenny_dialoggins.css",
26
+ "generators/kenny_dialoggins_assets/templates/kenny_dialoggins.js",
27
+ "init.rb",
28
+ "kenny_dialoggins.gemspec",
29
+ "lib/kenny_dialoggins.rb",
30
+ "lib/kenny_dialoggins/helpers.rb",
31
+ "rails/init.rb",
32
+ "test/kenny_dialoggins/helpers_test.rb",
33
+ "test/test_helper.rb"
34
+ ]
35
+ s.homepage = %q{http://github.com/coroutine/kenny_dialoggins}
36
+ s.rdoc_options = ["--charset=UTF-8"]
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = %q{1.3.6}
39
+ s.summary = %q{Dead simple, beautiful dialogs for Rails.}
40
+ s.test_files = [
41
+ "test/kenny_dialoggins/helpers_test.rb",
42
+ "test/test_helper.rb"
43
+ ]
44
+
45
+ if s.respond_to? :specification_version then
46
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
47
+ s.specification_version = 3
48
+
49
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
50
+ else
51
+ end
52
+ else
53
+ end
54
+ end
55
+
@@ -0,0 +1,79 @@
1
+ module Coroutine
2
+ module KennyDialoggins
3
+ module Helpers
4
+
5
+ # Returns a javascript tag containing the dialog initialization logic. The first argument
6
+ # to this method is the dialog's <tt>id</tt>. The id is required and should be unique.
7
+ # Further options may be provided; those that are specific to the dialog are:
8
+ #
9
+ # * <tt>:before_show</tt> - a Javascript function that will be invoked before the dialog is shown
10
+ # * <tt>:after_show</tt> - a Javascript function that will be invoked after the dialog has become visible
11
+ # * <tt>:before_hide</tt> - a Javascript function that will be invoked before the dialog is hidden
12
+ # * <tt>:after_hide</tt> - a Javascript function that will be invoked after the dialog has been hidden
13
+ #
14
+ # All remaining options are the same as the options available to ActionController::Base#render. Please
15
+ # see the documentation for ActionController::Base#render for further details.
16
+ #
17
+ # ==== Example
18
+ #
19
+ # # Generates:
20
+ # #
21
+ # # <script type="text/javascript">
22
+ # # //<![CDATA[
23
+ # # KennyDialoggins.Dialog.instances['foo_dialog'] = new KennyDialoggins.Dialog('Hello, Foo!', {});
24
+ # # //]]>
25
+ # # </script>
26
+ # <%= render_dialog :foo_dialog, :partial => "foo" %>
27
+ #
28
+ # In this case, a partial named "_foo.html.erb"--containing the string, "Hello, Foo!"--
29
+ # is rendered into the dialog.
30
+ #
31
+ # ==== Example
32
+ #
33
+ # # Generates:
34
+ # # <script type="text/javascript">
35
+ # # //<![CDATA[
36
+ # # KennyDialoggins.Dialog.instances['foo_dialog'] = new KennyDialoggins.Dialog('Hello, Foo!', {beforeShow:function() { alert('bar!') }});
37
+ # # //]]>
38
+ # # </script>
39
+ # <%= render_dialog :foo_dialog, :partial => "foo", :before_show => "function() { alert('bar!') }" %>
40
+ #
41
+ # This case is similar to the previous case, except that an alert containing the string, "bar!" will
42
+ # appear before the dialog is shown
43
+ def render_dialog(id, options={})
44
+ dialog_options = [:before_show, :after_show, :before_hide, :after_hide].inject({}) do |result, key|
45
+ result[key] = options.delete(key) if options[key]
46
+ result
47
+ end
48
+
49
+ content = escape_javascript render(options)
50
+ javascript_tag "KennyDialoggins.Dialog.instances['#{id.to_s}'] = new KennyDialoggins.Dialog('#{content}', #{dialog_options_to_js dialog_options});"
51
+ end
52
+
53
+ # Returns a string of Javascript that will show the dialog identified by the supplied
54
+ # dialog_id. As an example of useage, this method might be called as the second argument
55
+ # to ActionView::Helpers::JavaScriptHelper#link_to_function.
56
+ def show_dialog(dialog_id)
57
+ "KennyDialoggins.Dialog.show('#{dialog_id.to_s}')"
58
+ end
59
+
60
+ # Returns a string of Javascript that will hide the dialog identified by the supplied
61
+ # dialog_id. As an example of useage, this method might be called as the second argument
62
+ # to ActionView::Helpers::JavaScriptHelper#link_to_function.
63
+ def hide_dialog(dialog_id)
64
+ "KennyDialoggins.Dialog.hide('#{dialog_id.to_s}')"
65
+ end
66
+
67
+ private
68
+
69
+ def dialog_options_to_js(options={})
70
+ js_kv_pairs = []
71
+ options.each do |key, value|
72
+ js_kv_pairs << "#{key.to_s.camelize(:lower)}:#{value || 'null'}"
73
+ end
74
+ "{#{js_kv_pairs.join(',')}}"
75
+ end
76
+
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,10 @@
1
+ # external gems
2
+ require "action_pack"
3
+
4
+
5
+ # helpers
6
+ require File.dirname(__FILE__) + "/kenny_dialoggins/helpers"
7
+
8
+
9
+ # add action view extensions
10
+ ActionView::Base.module_eval { include Coroutine::KennyDialoggins::Helpers }
data/rails/init.rb ADDED
@@ -0,0 +1 @@
1
+ require "kenny_dialoggins"
@@ -0,0 +1,89 @@
1
+ #---------------------------------------------------------
2
+ # Requirements
3
+ #---------------------------------------------------------
4
+
5
+ # all generic stuff required by test helper
6
+ require "test/test_helper"
7
+
8
+
9
+
10
+ #---------------------------------------------------------
11
+ # Class Definitions
12
+ #---------------------------------------------------------
13
+
14
+ class TestView < ActionView::Base
15
+ def dialog_options_to_js_proxy(options)
16
+ dialog_options_to_js(options)
17
+ end
18
+ end
19
+
20
+
21
+
22
+ #---------------------------------------------------------
23
+ # Tests
24
+ #---------------------------------------------------------
25
+
26
+ class KennyDialogginsHelpersTest < ActionView::TestCase
27
+
28
+ # build a test view object
29
+ def setup
30
+ @view = TestView.new
31
+ end
32
+
33
+
34
+ # verify methods were mixed in properly
35
+ def test_composition
36
+ assert @view.respond_to?(:render_dialog, false)
37
+ assert @view.respond_to?(:show_dialog, false)
38
+ assert @view.respond_to?(:hide_dialog, false)
39
+ assert @view.respond_to?(:dialog_options_to_js, true)
40
+ end
41
+
42
+
43
+ # verify render returns proper script tag and content
44
+ # (just testing simple text example here)
45
+ def test_render_dialog
46
+ text = "Who wants to play volleyball on a court with a four-foot net?"
47
+ expected = "<script type=\"text/javascript\">\n" \
48
+ "//<![CDATA[\n" \
49
+ "KennyDialoggins.Dialog.instances['danger_zone'] = new KennyDialoggins.Dialog('" + text + "', {});\n" \
50
+ "//]]>\n" \
51
+ "</script>"
52
+ actual = @view.render_dialog(:danger_zone, :text => text)
53
+
54
+ assert_equal expected, actual
55
+ end
56
+
57
+
58
+ # verify show dialog returns proper javascript command.
59
+ def test_show_dialog
60
+ expected = "KennyDialoggins.Dialog.show('danger_zone')"
61
+ actual = @view.show_dialog(:danger_zone)
62
+
63
+ assert_equal expected, actual
64
+ end
65
+
66
+
67
+ # verify hide dialog returns proper javascript command.
68
+ def test_hide_dialog
69
+ expected = "KennyDialoggins.Dialog.hide('danger_zone')"
70
+ actual = @view.hide_dialog(:danger_zone)
71
+
72
+ assert_equal expected, actual
73
+ end
74
+
75
+
76
+ # verify private function converts ruby hash to javascript hash properly.
77
+ def test_dialog_options_to_js
78
+ options = {
79
+ :before_show => "function{ alert('hello, world!'); }",
80
+ :after_show => "function{ alert('goodbye, world!'); }"
81
+ }
82
+
83
+ expected = "{beforeShow:#{options[:before_show]},afterShow:#{options[:after_show]}}"
84
+ actual = @view.dialog_options_to_js_proxy(options)
85
+
86
+ assert_equal expected, actual
87
+ end
88
+
89
+ end
@@ -0,0 +1,16 @@
1
+ #----------------------------------------------------------
2
+ # Requirements
3
+ #----------------------------------------------------------
4
+
5
+ # rails stuff
6
+ require "rubygems"
7
+ require "active_support"
8
+ require "active_support/test_case"
9
+ require "action_controller"
10
+ require "action_controller/test_case"
11
+ require "action_view"
12
+ require "action_view/test_case"
13
+ require "test/unit"
14
+
15
+ # the plugin itself
16
+ require "#{File.dirname(__FILE__)}/../init"
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kenny_dialoggins
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Coroutine
13
+ - Tim Lowrimore
14
+ - John Dugan
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2010-03-29 00:00:00 -05:00
20
+ default_executable:
21
+ dependencies: []
22
+
23
+ description: Kenny Dialoggins allows you to include scriptaculous dialogs in Rails applications using the same syntax employed for rendering partials.
24
+ email: gems@coroutine.com
25
+ executables: []
26
+
27
+ extensions: []
28
+
29
+ extra_rdoc_files:
30
+ - README.rdoc
31
+ files:
32
+ - .specification
33
+ - MIT-LICENSE
34
+ - README.rdoc
35
+ - Rakefile
36
+ - VERSION
37
+ - generators/kenny_dialoggins_assets/kenny_dialoggins_assets_generator.rb
38
+ - generators/kenny_dialoggins_assets/templates/kenny_dialoggins.css
39
+ - generators/kenny_dialoggins_assets/templates/kenny_dialoggins.js
40
+ - init.rb
41
+ - kenny_dialoggins.gemspec
42
+ - lib/kenny_dialoggins.rb
43
+ - lib/kenny_dialoggins/helpers.rb
44
+ - rails/init.rb
45
+ - test/kenny_dialoggins/helpers_test.rb
46
+ - test/test_helper.rb
47
+ has_rdoc: true
48
+ homepage: http://github.com/coroutine/kenny_dialoggins
49
+ licenses: []
50
+
51
+ post_install_message:
52
+ rdoc_options:
53
+ - --charset=UTF-8
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ segments:
68
+ - 0
69
+ version: "0"
70
+ requirements: []
71
+
72
+ rubyforge_project:
73
+ rubygems_version: 1.3.6
74
+ signing_key:
75
+ specification_version: 3
76
+ summary: Dead simple, beautiful dialogs for Rails.
77
+ test_files:
78
+ - test/kenny_dialoggins/helpers_test.rb
79
+ - test/test_helper.rb