jelly 0.5.4 → 0.5.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +78 -29
- data/VERSION.yml +1 -1
- data/generators/jelly/templates/javascripts/ajax_with_jelly.js +12 -2
- data/generators/jelly/templates/javascripts/jelly.js +16 -13
- data/jelly.gemspec +14 -14
- metadata +13 -13
data/README.markdown
CHANGED
@@ -1,61 +1,107 @@
|
|
1
1
|
Jelly
|
2
2
|
=====
|
3
3
|
|
4
|
-
|
4
|
+
What is Jelly?
|
5
|
+
--------------
|
6
|
+
Jelly is an unobtrusive Javascript framework for [jQuery](http://jquery.com) and [Rails](http://rubyonrails.org).
|
7
|
+
It provides a set of conventions and tools that help you organize your AJAX and client-side code,
|
8
|
+
while keeping Javascript out of your views and markup. Jelly is the glue between your Rails controllers
|
9
|
+
and jQuery events.
|
10
|
+
|
11
|
+
Jelly encourages and enables unit testing your Javascript code. Using a Javascript testing framework such as [Jasmine](http://github.com/pivotal/jasmine)
|
12
|
+
or [Screw Unit](http://github.com/nathansobo/screw-unit), Jelly allows you to test AJAX and client-side
|
13
|
+
events independently from your Rails app.
|
14
|
+
|
15
|
+
What Jelly is NOT
|
16
|
+
-----------------
|
17
|
+
**Jelly is NOT a Javascript generator.** With Jelly, you're writing pure Javascript to define your AJAX browser events. Jelly simply
|
18
|
+
provides a set of Javascript functions to make interacting with Rails easier. It's nothing like RJS.
|
19
|
+
|
20
|
+
**Jelly is NOT a Javascript framework.** Jelly is designed to be used with jQuery and jQuery's event-based
|
21
|
+
AJAX framework. Jelly also supports the popular [jQuery ajaxForm](http://malsup.com/jquery/form/) plugin.
|
22
|
+
|
23
|
+
Requirements
|
5
24
|
------------
|
25
|
+
* Rails 2.3.x
|
26
|
+
* jQuery 1.3.x
|
6
27
|
|
7
|
-
|
28
|
+
Installation
|
29
|
+
------------
|
8
30
|
|
9
|
-
|
31
|
+
Jelly is now available as a gem on on [RubyForge](http://rubyforge.org/projects/pivotalrb/):
|
10
32
|
|
11
|
-
|
33
|
+
sudo gem install jelly
|
12
34
|
|
13
|
-
|
35
|
+
Then, install the required Javascript files to your <code>public/javascripts</code> directory by running the Jelly generator:
|
14
36
|
|
37
|
+
script/generate jelly
|
15
38
|
|
16
|
-
|
17
|
-
|
39
|
+
Getting Started
|
40
|
+
--------------------------------
|
18
41
|
|
19
|
-
|
42
|
+
Be sure to require <code>jelly</code> when your application loads. This can be done in your `environment.rb` in the `Rails::Initializer.run` block:
|
20
43
|
|
21
44
|
config.gem "jelly"
|
22
45
|
|
23
|
-
Then
|
24
|
-
|
25
|
-
script/generate jelly
|
26
|
-
|
27
|
-
Then, in your layout, add the following:
|
46
|
+
Then, in your layouts, add the following to the `<head>` section:
|
28
47
|
|
29
48
|
<%= javascript_include_tag :jelly, *application_jelly_files %>
|
30
49
|
<%= spread_jelly %>
|
31
50
|
|
32
|
-
|
33
|
-
includes jQuery.
|
51
|
+
The `javascript_include_tag` line will include the required Javascript libraries for jelly. The `:jelly` javascript
|
52
|
+
expansion includes the latest version of jQuery. If you already have jQuery included in the page, use the `:only_jelly`
|
53
|
+
expansion instead
|
34
54
|
|
35
|
-
|
55
|
+
The `spread_jelly` line activates the events that you have defined on the current page.
|
56
|
+
|
57
|
+
Usage
|
36
58
|
-------------
|
37
59
|
|
38
|
-
|
39
|
-
|
60
|
+
Jelly maps page-specific Javascript functions to Rails Actions and Controllers. For example: FunController#index will
|
61
|
+
activate the `index` function in the `Fun` Jelly object. Jelly uses jQuery's `$(document).ready()` to execute the
|
62
|
+
page-specifc function when the page has loaded. Let's look at some code:
|
63
|
+
|
64
|
+
In `public/javascripts/pages/fun.js`, I write a simple Jelly file:
|
40
65
|
|
41
|
-
|
42
|
-
|
66
|
+
Jelly.add("Fun", {
|
67
|
+
|
68
|
+
index: function() {
|
69
|
+
$('a.clickme').click(function() {
|
70
|
+
alert('Hello world!');
|
71
|
+
});
|
72
|
+
}
|
73
|
+
|
74
|
+
});
|
43
75
|
|
44
|
-
|
76
|
+
Jelly will automatically execute the `index` function when the Rails app runs the `FunController#index` action. Lets
|
77
|
+
continue the example by adding more Javascript functions that map to the `new` and `show` Rails actions. We can also
|
78
|
+
specify an `all` function, which will be executed on all actions in the `FunController`.
|
45
79
|
|
46
80
|
Jelly.add("Fun", {
|
47
|
-
|
48
|
-
$('span.all').text("I am displayed on every action in this controller.");
|
49
|
-
},
|
81
|
+
|
50
82
|
index: function() {
|
51
|
-
$('
|
83
|
+
$('a.clickme').click(function() {
|
84
|
+
alert('Hello world!');
|
85
|
+
});
|
86
|
+
},
|
87
|
+
|
88
|
+
'new': function() {
|
89
|
+
$('#mydiv').html('<span>Hello World</span>');
|
90
|
+
},
|
91
|
+
|
92
|
+
show : function() {},
|
93
|
+
|
94
|
+
all: function() {
|
95
|
+
$('#hidden_stuff').show();
|
52
96
|
}
|
97
|
+
|
53
98
|
});
|
54
99
|
|
55
|
-
|
100
|
+
Notice the slightly different syntax for `new`. This is because `new` is a reserved word in Javascript.
|
101
|
+
Create a separate file in `public/javascripts/pages` for each of your controllers as you use Jelly throughout your application.
|
56
102
|
|
57
|
-
AJAX
|
58
|
-
|
103
|
+
AJAX With Jelly
|
104
|
+
---------------
|
59
105
|
|
60
106
|
You can trigger callbacks on the page object from Rails with the `jelly_callback` method.
|
61
107
|
Adding to the `index.html.erb` file from above:
|
@@ -108,5 +154,8 @@ either one parameter, or an array of parameters.
|
|
108
154
|
DEVELOPMENT
|
109
155
|
-----------
|
110
156
|
|
157
|
+
Track Jelly's development roadmap on [Jelly's Pivotal Tracker project](http://www.pivotaltracker.com/projects/30454)
|
158
|
+
|
111
159
|
To run ruby tests, run `rake spec`.
|
112
|
-
|
160
|
+
|
161
|
+
To run Javascript tests, open `jelly/spec/jasmine_runner.html` in a web browser.
|
data/VERSION.yml
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
(
|
1
|
+
if(!window.Jelly) Jelly = new Object();
|
2
|
+
|
3
|
+
(Jelly.defineAjaxWithJellyFunctions = function($) {
|
2
4
|
$.ajaxWithJelly = function(params) {
|
3
5
|
$.ajax($.ajaxWithJelly.params(params));
|
4
6
|
};
|
@@ -26,7 +28,15 @@
|
|
26
28
|
|
27
29
|
$.ajaxWithJelly.onSuccess = function(json) {
|
28
30
|
var context = json.on ? eval(json.on) : page;
|
29
|
-
context[json.method]
|
31
|
+
if(context[json.method]) {
|
32
|
+
context[json.method].apply(context, json.arguments);
|
33
|
+
}
|
34
|
+
$.protify(page.components).each(function(componentAndArgs) {
|
35
|
+
var component = componentAndArgs[0];
|
36
|
+
if(component[json.method]) {
|
37
|
+
component[json.method].apply(component, json.arguments);
|
38
|
+
}
|
39
|
+
});
|
30
40
|
return true;
|
31
41
|
};
|
32
42
|
})(jQuery);
|
@@ -11,7 +11,7 @@
|
|
11
11
|
*
|
12
12
|
*/
|
13
13
|
|
14
|
-
|
14
|
+
if(!window.Jelly) Jelly = new Object();
|
15
15
|
Jelly.all = {};
|
16
16
|
|
17
17
|
Jelly.add = function(name) {
|
@@ -26,31 +26,34 @@ var page;
|
|
26
26
|
Jelly.activatePage = function(controllerName, actionName) {
|
27
27
|
page = Jelly.all[controllerName] || new Jelly.Page(controllerName);
|
28
28
|
$(document).ready(function(){
|
29
|
-
Jelly._activatePage(actionName);
|
29
|
+
Jelly._activatePage(actionName);
|
30
30
|
});
|
31
31
|
};
|
32
32
|
|
33
33
|
Jelly._activatePage = function(actionName){
|
34
34
|
if(page.all) page.all();
|
35
35
|
if(page[actionName]) page[actionName].call(page);
|
36
|
-
Jelly.
|
36
|
+
Jelly.initComponents();
|
37
37
|
page.loaded = true;
|
38
38
|
};
|
39
39
|
|
40
|
-
Jelly.
|
41
|
-
|
42
|
-
Jelly.all[name] = this;
|
43
|
-
};
|
44
|
-
|
45
|
-
Jelly.Page.all = function() {
|
46
|
-
$.protify(Jelly.Page.components).each(function(componentAndArgs) {
|
40
|
+
Jelly.initComponents = function() {
|
41
|
+
$.protify(page.components).each(function(componentAndArgs) {
|
47
42
|
var component = componentAndArgs[0];
|
48
43
|
var args = componentAndArgs[1] || [];
|
49
44
|
if(component.init) component.init.apply(component, args);
|
50
45
|
});
|
51
46
|
};
|
52
|
-
|
47
|
+
|
48
|
+
Jelly.Page = function(name) {
|
49
|
+
this.name = name;
|
50
|
+
this.components = [];
|
51
|
+
Jelly.all[name] = this;
|
52
|
+
};
|
53
|
+
|
53
54
|
Jelly.Page.prototype.loaded = false;
|
55
|
+
Jelly.Page.prototype.all = function() {
|
56
|
+
};
|
54
57
|
Jelly.Page.prototype.documentHref = function() {
|
55
58
|
return document.location.href;
|
56
59
|
};
|
@@ -60,12 +63,12 @@ Jelly.Page.prototype.on_redirect = function(location){
|
|
60
63
|
|
61
64
|
Jelly.Page.prototype.attach = function(component, args) {
|
62
65
|
var methodNames = [];
|
63
|
-
// TODO: Figure out a better way to do this.
|
64
66
|
for(var methodName in component.pageMixin) {
|
65
67
|
methodNames.push(methodName);
|
66
68
|
}
|
67
69
|
var self = this;
|
68
70
|
$.protify(methodNames).each(function(methodName) {
|
71
|
+
// TODO: is anybody using these before_/after_ hooks? if not, delete them and use components as observers
|
69
72
|
self[methodName] = function() {
|
70
73
|
if(this['before_' + methodName]) {
|
71
74
|
this['before_' + methodName].apply(this, arguments);
|
@@ -77,5 +80,5 @@ Jelly.Page.prototype.attach = function(component, args) {
|
|
77
80
|
return returnValue;
|
78
81
|
};
|
79
82
|
});
|
80
|
-
|
83
|
+
page.components.push([component, args]);
|
81
84
|
};
|
data/jelly.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{jelly}
|
8
|
-
s.version = "0.5.
|
8
|
+
s.version = "0.5.5"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Pivotal Labs, Inc"]
|
12
|
-
s.date = %q{2009-
|
12
|
+
s.date = %q{2009-10-01}
|
13
13
|
s.description = %q{Jelly provides a set of tools and conventions for creating rich ajax/javascript web applications with jQuery and Ruby on Rails.}
|
14
14
|
s.email = %q{opensource@pivotallabs.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -42,24 +42,24 @@ Gem::Specification.new do |s|
|
|
42
42
|
s.rubygems_version = %q{1.3.5}
|
43
43
|
s.summary = %q{a sweet unobtrusive javascript framework for jQuery and Rails}
|
44
44
|
s.test_files = [
|
45
|
-
"spec/
|
46
|
-
"spec/
|
47
|
-
"spec/
|
45
|
+
"spec/helpers/jelly_helper_spec.rb",
|
46
|
+
"spec/controllers/jelly_controller_spec.rb",
|
47
|
+
"spec/spec_helper.rb",
|
48
|
+
"spec/rails_root/test/performance/browsing_test.rb",
|
49
|
+
"spec/rails_root/test/test_helper.rb",
|
48
50
|
"spec/rails_root/app/helpers/application_helper.rb",
|
51
|
+
"spec/rails_root/app/controllers/application_controller.rb",
|
49
52
|
"spec/rails_root/config/boot.rb",
|
50
53
|
"spec/rails_root/config/environment.rb",
|
51
|
-
"spec/rails_root/config/
|
52
|
-
"spec/rails_root/config/environments/production.rb",
|
53
|
-
"spec/rails_root/config/environments/test.rb",
|
54
|
-
"spec/rails_root/config/initializers/backtrace_silencers.rb",
|
54
|
+
"spec/rails_root/config/initializers/session_store.rb",
|
55
55
|
"spec/rails_root/config/initializers/inflections.rb",
|
56
|
-
"spec/rails_root/config/initializers/
|
56
|
+
"spec/rails_root/config/initializers/backtrace_silencers.rb",
|
57
57
|
"spec/rails_root/config/initializers/new_rails_defaults.rb",
|
58
|
-
"spec/rails_root/config/initializers/
|
58
|
+
"spec/rails_root/config/initializers/mime_types.rb",
|
59
59
|
"spec/rails_root/config/routes.rb",
|
60
|
-
"spec/rails_root/
|
61
|
-
"spec/rails_root/test
|
62
|
-
"spec/
|
60
|
+
"spec/rails_root/config/environments/production.rb",
|
61
|
+
"spec/rails_root/config/environments/test.rb",
|
62
|
+
"spec/rails_root/config/environments/development.rb"
|
63
63
|
]
|
64
64
|
|
65
65
|
if s.respond_to? :specification_version then
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jelly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pivotal Labs, Inc
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-10-01 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -79,21 +79,21 @@ signing_key:
|
|
79
79
|
specification_version: 3
|
80
80
|
summary: a sweet unobtrusive javascript framework for jQuery and Rails
|
81
81
|
test_files:
|
82
|
-
- spec/controllers/jelly_controller_spec.rb
|
83
82
|
- spec/helpers/jelly_helper_spec.rb
|
84
|
-
- spec/
|
83
|
+
- spec/controllers/jelly_controller_spec.rb
|
84
|
+
- spec/spec_helper.rb
|
85
|
+
- spec/rails_root/test/performance/browsing_test.rb
|
86
|
+
- spec/rails_root/test/test_helper.rb
|
85
87
|
- spec/rails_root/app/helpers/application_helper.rb
|
88
|
+
- spec/rails_root/app/controllers/application_controller.rb
|
86
89
|
- spec/rails_root/config/boot.rb
|
87
90
|
- spec/rails_root/config/environment.rb
|
88
|
-
- spec/rails_root/config/
|
89
|
-
- spec/rails_root/config/environments/production.rb
|
90
|
-
- spec/rails_root/config/environments/test.rb
|
91
|
-
- spec/rails_root/config/initializers/backtrace_silencers.rb
|
91
|
+
- spec/rails_root/config/initializers/session_store.rb
|
92
92
|
- spec/rails_root/config/initializers/inflections.rb
|
93
|
-
- spec/rails_root/config/initializers/
|
93
|
+
- spec/rails_root/config/initializers/backtrace_silencers.rb
|
94
94
|
- spec/rails_root/config/initializers/new_rails_defaults.rb
|
95
|
-
- spec/rails_root/config/initializers/
|
95
|
+
- spec/rails_root/config/initializers/mime_types.rb
|
96
96
|
- spec/rails_root/config/routes.rb
|
97
|
-
- spec/rails_root/
|
98
|
-
- spec/rails_root/test
|
99
|
-
- spec/
|
97
|
+
- spec/rails_root/config/environments/production.rb
|
98
|
+
- spec/rails_root/config/environments/test.rb
|
99
|
+
- spec/rails_root/config/environments/development.rb
|