jelly 0.5.9 → 0.6.5
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/VERSION.yml +2 -2
- data/generators/jelly/templates/javascripts/jelly.js +55 -58
- data/jelly.gemspec +13 -11
- data/lib/jelly.rb +1 -0
- data/lib/jelly/common.rb +7 -0
- data/lib/jelly/jelly_controller.rb +2 -1
- data/lib/jelly/jelly_helper.rb +10 -4
- data/spec/controllers/jelly_controller_spec.rb +1 -1
- data/spec/helpers/jelly_helper_spec.rb +31 -16
- data/spec/rails_root/config/environment.rb +1 -1
- data/spec/spec_helper.rb +17 -1
- data/spec/spec_suite.rb +3 -0
- metadata +4 -2
data/Rakefile
CHANGED
@@ -25,7 +25,7 @@ end
|
|
25
25
|
begin
|
26
26
|
require 'jeweler'
|
27
27
|
Jeweler::Tasks.new do |gemspec|
|
28
|
-
gemspec.name = "jelly"
|
28
|
+
gemspec.name = ENV["GEM_PREFIX"] ? "#{ENV["GEM_PREFIX"]}-jelly" : "jelly"
|
29
29
|
gemspec.summary = "a sweet unobtrusive javascript framework for jQuery and Rails"
|
30
30
|
gemspec.description = "Jelly provides a set of tools and conventions for creating rich ajax/javascript web applications with jQuery and Ruby on Rails."
|
31
31
|
gemspec.email = "opensource@pivotallabs.com"
|
data/VERSION.yml
CHANGED
@@ -11,87 +11,84 @@
|
|
11
11
|
*
|
12
12
|
*/
|
13
13
|
|
14
|
-
if(!window.Jelly) Jelly = new Object();
|
15
|
-
Jelly.
|
16
|
-
|
17
|
-
Jelly.
|
18
|
-
|
19
|
-
|
20
|
-
$.extend(page, arguments[i]);
|
21
|
-
}
|
22
|
-
return page;
|
23
|
-
};
|
24
|
-
|
25
|
-
var page;
|
26
|
-
Jelly.activatePage = function(controllerName, actionName) {
|
27
|
-
page = Jelly.all[controllerName] || new Jelly.Page(controllerName);
|
28
|
-
$(document).ready(function(){
|
29
|
-
Jelly._activatePage(actionName);
|
14
|
+
if (!window.Jelly) Jelly = new Object();
|
15
|
+
Jelly.init = function() {
|
16
|
+
this.components = [];
|
17
|
+
Jelly.Pages.init();
|
18
|
+
$(document).ready(function() {
|
19
|
+
Jelly.Components.init();
|
30
20
|
});
|
31
21
|
};
|
32
22
|
|
33
|
-
Jelly.
|
34
|
-
|
35
|
-
if(page.all) page.all();
|
36
|
-
if(page[actionName]) page[actionName].call(page);
|
37
|
-
page.loaded = true;
|
38
|
-
};
|
39
|
-
|
40
|
-
Jelly.initComponents = function() {
|
41
|
-
$.protify(page.components).each(function(componentAndArgs) {
|
42
|
-
var component = componentAndArgs[0];
|
43
|
-
var args = componentAndArgs[1] || [];
|
44
|
-
if(component.init) component.init.apply(component, args);
|
45
|
-
});
|
23
|
+
Jelly.attach = function(component, args) {
|
24
|
+
this.components.push([component, args]);
|
46
25
|
};
|
47
26
|
|
48
27
|
Jelly.notifyObservers = function(params) {
|
49
28
|
var context = params.on ? eval(params.on) : page;
|
50
|
-
if(context[params.method]) {
|
29
|
+
if (context[params.method]) {
|
51
30
|
context[params.method].apply(context, params.arguments);
|
52
31
|
}
|
53
|
-
$.protify(
|
32
|
+
$.protify(Jelly.components).each(function(componentAndArgs) {
|
54
33
|
var component = componentAndArgs[0];
|
55
|
-
if(component[params.method]) {
|
34
|
+
if (component[params.method] && component != context) {
|
56
35
|
component[params.method].apply(component, params.arguments);
|
57
36
|
}
|
58
37
|
});
|
59
38
|
};
|
60
39
|
|
40
|
+
Jelly.Components = {
|
41
|
+
init: function() {
|
42
|
+
$.protify(Jelly.components).each(function(componentAndArgs) {
|
43
|
+
var component = componentAndArgs[0];
|
44
|
+
var args = componentAndArgs[1] || [];
|
45
|
+
if (component.init) component.init.apply(component, args);
|
46
|
+
});
|
47
|
+
}
|
48
|
+
};
|
49
|
+
|
50
|
+
Jelly.Pages = {
|
51
|
+
init: function() {
|
52
|
+
this.all = {};
|
53
|
+
Jelly.all = this.all; // Deprecated
|
54
|
+
},
|
55
|
+
|
56
|
+
add: function(name) {
|
57
|
+
var page = new Jelly.Page(name);
|
58
|
+
for (var i = 1; i < arguments.length; i++) {
|
59
|
+
$.extend(page, arguments[i]);
|
60
|
+
}
|
61
|
+
return page;
|
62
|
+
}
|
63
|
+
};
|
64
|
+
Jelly.add = Jelly.Pages.add; // Deprecated
|
65
|
+
|
61
66
|
Jelly.Page = function(name) {
|
67
|
+
this.documentHref = Jelly.Location.documentHref;
|
68
|
+
|
62
69
|
this.name = name;
|
63
70
|
this.components = [];
|
64
|
-
Jelly.all[name] = this;
|
71
|
+
Jelly.Pages.all[name] = this;
|
65
72
|
};
|
66
|
-
|
67
73
|
Jelly.Page.prototype.loaded = false;
|
68
74
|
Jelly.Page.prototype.all = function() {
|
69
75
|
};
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
76
|
+
|
77
|
+
Jelly.Page.init = function(controllerName, actionName) {
|
78
|
+
var page = Jelly.Pages.all[controllerName] || new Jelly.Page(controllerName);
|
79
|
+
window.page = page;
|
80
|
+
if (page.all) page.all();
|
81
|
+
if (page[actionName]) page[actionName].call(page);
|
82
|
+
page.loaded = true;
|
75
83
|
};
|
76
84
|
|
77
|
-
Jelly.
|
78
|
-
|
79
|
-
|
80
|
-
|
85
|
+
Jelly.Location = {
|
86
|
+
init: function() {
|
87
|
+
},
|
88
|
+
|
89
|
+
on_redirect: function(location) {
|
90
|
+
top.location.href = location;
|
81
91
|
}
|
82
|
-
var self = this;
|
83
|
-
$.protify(methodNames).each(function(methodName) {
|
84
|
-
// TODO: is anybody using these before_/after_ hooks? if not, delete them and use components as observers
|
85
|
-
self[methodName] = function() {
|
86
|
-
if(this['before_' + methodName]) {
|
87
|
-
this['before_' + methodName].apply(this, arguments);
|
88
|
-
}
|
89
|
-
var returnValue = component.pageMixin[methodName].apply(this, arguments);
|
90
|
-
if(this['after_' + methodName]) {
|
91
|
-
this['after_' + methodName].apply(this, arguments);
|
92
|
-
}
|
93
|
-
return returnValue;
|
94
|
-
};
|
95
|
-
});
|
96
|
-
page.components.push([component, args]);
|
97
92
|
};
|
93
|
+
|
94
|
+
Jelly.init();
|
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.6.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-11-19}
|
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 = [
|
@@ -30,6 +30,7 @@ Gem::Specification.new do |s|
|
|
30
30
|
"install.rb",
|
31
31
|
"jelly.gemspec",
|
32
32
|
"lib/jelly.rb",
|
33
|
+
"lib/jelly/common.rb",
|
33
34
|
"lib/jelly/jelly_controller.rb",
|
34
35
|
"lib/jelly/jelly_helper.rb",
|
35
36
|
"tasks/jelly_tasks.rake",
|
@@ -42,23 +43,24 @@ Gem::Specification.new do |s|
|
|
42
43
|
s.summary = %q{a sweet unobtrusive javascript framework for jQuery and Rails}
|
43
44
|
s.test_files = [
|
44
45
|
"spec/controllers/jelly_controller_spec.rb",
|
45
|
-
"spec/
|
46
|
-
"spec/rails_root/test/performance/browsing_test.rb",
|
47
|
-
"spec/rails_root/test/test_helper.rb",
|
46
|
+
"spec/helpers/jelly_helper_spec.rb",
|
48
47
|
"spec/rails_root/app/controllers/application_controller.rb",
|
49
48
|
"spec/rails_root/app/helpers/application_helper.rb",
|
49
|
+
"spec/rails_root/config/boot.rb",
|
50
50
|
"spec/rails_root/config/environment.rb",
|
51
|
-
"spec/rails_root/config/environments/production.rb",
|
52
51
|
"spec/rails_root/config/environments/development.rb",
|
52
|
+
"spec/rails_root/config/environments/production.rb",
|
53
53
|
"spec/rails_root/config/environments/test.rb",
|
54
|
-
"spec/rails_root/config/routes.rb",
|
55
|
-
"spec/rails_root/config/boot.rb",
|
56
54
|
"spec/rails_root/config/initializers/backtrace_silencers.rb",
|
57
|
-
"spec/rails_root/config/initializers/new_rails_defaults.rb",
|
58
|
-
"spec/rails_root/config/initializers/mime_types.rb",
|
59
55
|
"spec/rails_root/config/initializers/inflections.rb",
|
56
|
+
"spec/rails_root/config/initializers/mime_types.rb",
|
57
|
+
"spec/rails_root/config/initializers/new_rails_defaults.rb",
|
60
58
|
"spec/rails_root/config/initializers/session_store.rb",
|
61
|
-
"spec/
|
59
|
+
"spec/rails_root/config/routes.rb",
|
60
|
+
"spec/rails_root/test/performance/browsing_test.rb",
|
61
|
+
"spec/rails_root/test/test_helper.rb",
|
62
|
+
"spec/spec_helper.rb",
|
63
|
+
"spec/spec_suite.rb"
|
62
64
|
]
|
63
65
|
|
64
66
|
if s.respond_to? :specification_version then
|
data/lib/jelly.rb
CHANGED
data/lib/jelly/common.rb
ADDED
@@ -1,5 +1,6 @@
|
|
1
1
|
module JellyController
|
2
2
|
protected
|
3
|
+
include Jelly::Common
|
3
4
|
|
4
5
|
def jelly_callback(callback_base_name = @action_name, options = {}, &block)
|
5
6
|
render :inline => jelly_callback_erb("on_#{callback_base_name}", options, block)
|
@@ -13,7 +14,7 @@ module JellyController
|
|
13
14
|
<%= begin
|
14
15
|
args = @block ? instance_eval(&@block) : []
|
15
16
|
args = [args] unless args.is_a?(Array)
|
16
|
-
|
17
|
+
jelly_callback_hash(@callback_name, *args).reverse_merge(@options).to_json
|
17
18
|
end %>
|
18
19
|
ERB
|
19
20
|
request.xhr? ? erb : "<textarea>#{erb}</textarea>"
|
data/lib/jelly/jelly_helper.rb
CHANGED
@@ -1,15 +1,21 @@
|
|
1
1
|
module JellyHelper
|
2
|
+
include Jelly::Common
|
2
3
|
|
3
4
|
def application_jelly_files(jelly_files_path_from_javascripts = '', rails_root = RAILS_ROOT)
|
4
|
-
|
5
|
+
rails_root = File.expand_path(rails_root)
|
6
|
+
(
|
7
|
+
Dir[File.expand_path("#{rails_root}/public/javascripts/#{jelly_files_path_from_javascripts}/components/**/*.js")] +
|
8
|
+
Dir[File.expand_path("#{rails_root}/public/javascripts/#{jelly_files_path_from_javascripts}/pages/**/*.js")]
|
9
|
+
).map do |path|
|
5
10
|
path.gsub("#{rails_root}/public/javascripts/", "").gsub(/\.js$/, "")
|
6
11
|
end
|
7
12
|
end
|
8
13
|
|
9
14
|
def spread_jelly
|
15
|
+
attach_javascript_component("Jelly.Location")
|
16
|
+
attach_javascript_component("Jelly.Page", controller.controller_path.camelcase, controller.action_name)
|
10
17
|
javascript_tag <<-JS
|
11
18
|
window._token = '#{form_authenticity_token}'
|
12
|
-
Jelly.activatePage('#{controller.controller_path.camelcase}', '#{controller.action_name}');
|
13
19
|
#{@content_for_javascript}
|
14
20
|
$(document).ready(function() {
|
15
21
|
#{@content_for_javascript_on_ready}
|
@@ -23,7 +29,7 @@ module JellyHelper
|
|
23
29
|
|
24
30
|
def attach_javascript_component(component_name, *args)
|
25
31
|
@jelly_attached_components ||= []
|
26
|
-
key = "
|
32
|
+
key = "Jelly.attach(#{component_name}, #{args.to_json});"
|
27
33
|
unless @jelly_attached_components.include? key
|
28
34
|
@jelly_attached_components << key
|
29
35
|
content_for(:javascript, key)
|
@@ -32,7 +38,7 @@ module JellyHelper
|
|
32
38
|
|
33
39
|
def attach_javascript_component_on_ready(component_name, *args)
|
34
40
|
@jelly_attached_components_on_ready ||= []
|
35
|
-
key = "
|
41
|
+
key = "Jelly.attach(#{component_name}, #{args.to_json});"
|
36
42
|
unless @jelly_attached_components_on_ready.include? key
|
37
43
|
@jelly_attached_components_on_ready << key
|
38
44
|
content_for(:javascript_on_ready, key)
|
@@ -1,24 +1,39 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../spec_helper.rb'
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe JellyHelper do
|
4
4
|
|
5
|
-
describe "#
|
6
|
-
|
5
|
+
describe "#spread_jelly" do
|
6
|
+
before do
|
7
7
|
stub_controller = mock(Object, :controller_path => 'my_fun_controller', :action_name => 'super_good_action')
|
8
8
|
helper.should_receive(:controller).any_number_of_times.and_return(stub_controller)
|
9
9
|
helper.should_receive(:form_authenticity_token).and_return('areallysecuretoken')
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should create a javascript include tag that attaches the Jelly.Location and Jelly.Page components" do
|
10
13
|
output = helper.spread_jelly
|
11
14
|
output.should include('<script type="text/javascript">')
|
12
|
-
output.should include("Jelly.
|
15
|
+
output.should include("Jelly.attach(Jelly.Location, #{[].to_json});")
|
16
|
+
output.should include("Jelly.attach(Jelly.Page, #{['MyFunController', 'super_good_action'].to_json});")
|
13
17
|
end
|
14
18
|
end
|
15
19
|
|
16
20
|
describe "#application_jelly_files" do
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
21
|
+
context "when passing in a jelly path" do
|
22
|
+
it "returns the javascript files in /javascipts/:jelly_path/pages and /javascipts/:jelly_path/components" do
|
23
|
+
my_rails_root = File.join(File.dirname(__FILE__), '/../fixtures')
|
24
|
+
files = helper.application_jelly_files("foo", my_rails_root)
|
25
|
+
files.should_not be_empty
|
26
|
+
files.should =~ ['foo/components/paw', 'foo/components/teeth', 'foo/pages/lions', 'foo/pages/tigers', 'foo/pages/bears']
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context "when not passing in a jelly path" do
|
31
|
+
it "returns the javascript files in /javascipts/pages and /javascipts/components" do
|
32
|
+
my_rails_root = File.join(File.dirname(__FILE__), '/../fixtures')
|
33
|
+
files = helper.application_jelly_files("", my_rails_root)
|
34
|
+
files.should_not be_empty
|
35
|
+
files.should =~ ['components/component1', 'pages/page1']
|
36
|
+
end
|
22
37
|
end
|
23
38
|
end
|
24
39
|
|
@@ -30,23 +45,23 @@ describe "JellyHelper" do
|
|
30
45
|
helper.clear_jelly_attached()
|
31
46
|
end
|
32
47
|
|
33
|
-
it "fails to add multiple calls to
|
48
|
+
it "fails to add multiple calls to Jelly.attach for the same component" do
|
34
49
|
helper.attach_javascript_component("MyComponent", 'arg1', 'arg2', 'arg3')
|
35
50
|
helper.attach_javascript_component("MyComponent", 'arg1', 'arg2', 'arg3')
|
36
51
|
helper.attach_javascript_component("MyComponent", 'arg1', 'arg2', 'arg5')
|
37
|
-
assigns[:content_for_javascript].should == '
|
52
|
+
assigns[:content_for_javascript].should == 'Jelly.attach(MyComponent, ["arg1","arg2","arg3"]);Jelly.attach(MyComponent, ["arg1","arg2","arg5"]);'
|
38
53
|
end
|
39
54
|
|
40
|
-
it "adds a call to
|
55
|
+
it "adds a call to Jelly.attach in the javascript content" do
|
41
56
|
helper.attach_javascript_component("MyComponent", 'arg1', 'arg2', 'arg3')
|
42
57
|
expected_args = ['arg1','arg2','arg3'].to_json
|
43
|
-
assigns[:content_for_javascript].should == "
|
58
|
+
assigns[:content_for_javascript].should == "Jelly.attach(MyComponent, #{expected_args});"
|
44
59
|
end
|
45
60
|
|
46
|
-
it "adds a call to
|
61
|
+
it "adds a call to Jelly.attach in the javascript_on_ready content" do
|
47
62
|
helper.attach_javascript_component_on_ready("MyComponent", 'arg1', 'arg2', 'arg3')
|
48
63
|
expected_args = ['arg1','arg2','arg3'].to_json
|
49
|
-
assigns[:content_for_javascript_on_ready].should == "
|
64
|
+
assigns[:content_for_javascript_on_ready].should == "Jelly.attach(MyComponent, #{expected_args});"
|
50
65
|
end
|
51
66
|
|
52
67
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# Be sure to restart your server when you modify this file
|
2
2
|
|
3
3
|
# Specifies gem version of Rails to use when vendor/rails is not present
|
4
|
-
RAILS_GEM_VERSION = '2.3.
|
4
|
+
RAILS_GEM_VERSION = '2.3.4' unless defined? RAILS_GEM_VERSION
|
5
5
|
|
6
6
|
# Bootstrap the Rails environment, frameworks, and default configuration
|
7
7
|
require File.join(File.dirname(__FILE__), 'boot')
|
data/spec/spec_helper.rb
CHANGED
@@ -4,10 +4,26 @@ ENV["RAILS_ENV"] ||= 'test'
|
|
4
4
|
ENV['RAILS_ROOT'] ||= File.dirname(__FILE__) + '/rails_root'
|
5
5
|
require File.expand_path(File.join(ENV['RAILS_ROOT'], 'config/environment.rb'))
|
6
6
|
require 'rubygems'
|
7
|
+
gem "test-unit"
|
8
|
+
require 'test/unit'
|
9
|
+
|
10
|
+
class Test::Unit::TestCase
|
11
|
+
class << self
|
12
|
+
def inherited(sub_class)
|
13
|
+
super
|
14
|
+
DESCENDANTS << sub_class
|
15
|
+
end
|
16
|
+
alias_method :inherited_without_test_unit_gem_inherited_fix, :inherited
|
17
|
+
alias_method :inherited, :inherited_without_test_unit_gem_inherited_fix
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
7
21
|
require 'spec'
|
8
22
|
require 'spec/rails'
|
23
|
+
require 'spec/autorun'
|
9
24
|
|
10
|
-
|
25
|
+
$LOAD_PATH.unshift(File.expand_path("#{File.dirname(__FILE__)}/../lib"))
|
26
|
+
require "jelly"
|
11
27
|
|
12
28
|
Spec::Runner.configure do |configuration|
|
13
29
|
end
|
data/spec/spec_suite.rb
ADDED
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.6.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-11-
|
12
|
+
date: 2009-11-19 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -45,6 +45,7 @@ files:
|
|
45
45
|
- install.rb
|
46
46
|
- jelly.gemspec
|
47
47
|
- lib/jelly.rb
|
48
|
+
- lib/jelly/common.rb
|
48
49
|
- lib/jelly/jelly_controller.rb
|
49
50
|
- lib/jelly/jelly_helper.rb
|
50
51
|
- tasks/jelly_tasks.rake
|
@@ -96,3 +97,4 @@ test_files:
|
|
96
97
|
- spec/rails_root/test/performance/browsing_test.rb
|
97
98
|
- spec/rails_root/test/test_helper.rb
|
98
99
|
- spec/spec_helper.rb
|
100
|
+
- spec/spec_suite.rb
|