choco 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/HISTORY +3 -0
- data/LICENSE +20 -0
- data/README.rdoc +326 -0
- data/Rakefile +55 -0
- data/bin/choco +45 -0
- data/choco.gemspec +98 -0
- data/lib/choco.rb +16 -0
- data/lib/choco/cli.rb +75 -0
- data/lib/choco/dependency_manager.rb +92 -0
- data/lib/choco/generators/app_generator.rb +72 -0
- data/lib/choco/generators/controller_generator.rb +21 -0
- data/lib/choco/generators/layout_generator.rb +19 -0
- data/lib/choco/generators/model_generator.rb +20 -0
- data/lib/choco/generators/plugin_generator.rb +20 -0
- data/lib/choco/generators/scaffold_generator.rb +65 -0
- data/lib/choco/generators/templates/Jimfile +24 -0
- data/lib/choco/generators/templates/README.rdoc +3 -0
- data/lib/choco/generators/templates/Rakefile +25 -0
- data/lib/choco/generators/templates/application.css +1 -0
- data/lib/choco/generators/templates/choco +7 -0
- data/lib/choco/generators/templates/controllers/application_controller.js +33 -0
- data/lib/choco/generators/templates/controllers/base_controller.js +6 -0
- data/lib/choco/generators/templates/controllers/rest_controller.js +53 -0
- data/lib/choco/generators/templates/help/commands +12 -0
- data/lib/choco/generators/templates/help/generators +33 -0
- data/lib/choco/generators/templates/helpers/application_helper.js +7 -0
- data/lib/choco/generators/templates/index.html +16 -0
- data/lib/choco/generators/templates/lib/plugin.js +40 -0
- data/lib/choco/generators/templates/models/base.js +7 -0
- data/lib/choco/generators/templates/views/edit.template +14 -0
- data/lib/choco/generators/templates/views/index.template +32 -0
- data/lib/choco/generators/templates/views/layout.js +4 -0
- data/lib/choco/generators/templates/views/main/index.template +1 -0
- data/lib/choco/generators/templates/views/new.template +14 -0
- data/lib/choco/generators/templates/views/show.template +10 -0
- data/spec/choco_spec.rb +7 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +9 -0
- metadata +164 -0
@@ -0,0 +1,24 @@
|
|
1
|
+
// Your Jimfile lists your JS dependencies
|
2
|
+
// Launch $ choco --watch at the root of your project
|
3
|
+
// This file and lib/bundled.js will be maintained for you!
|
4
|
+
|
5
|
+
jquery
|
6
|
+
sammy
|
7
|
+
sammy.template
|
8
|
+
sammy.nested_params
|
9
|
+
sammy.smart_renderer
|
10
|
+
js-model 0.8.3
|
11
|
+
underscore
|
12
|
+
mustache
|
13
|
+
choco.utils
|
14
|
+
choco.plugins.models.load
|
15
|
+
|
16
|
+
// Libs # Don't remove this line!
|
17
|
+
|
18
|
+
// Helpers # Don't remove this line!
|
19
|
+
app/helpers/application_helper
|
20
|
+
|
21
|
+
// Models # Don't remove this line!
|
22
|
+
|
23
|
+
// Controllers # Don't remove this line!
|
24
|
+
app/controllers/application_controller
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'rake'
|
2
|
+
|
3
|
+
namespace :choco do
|
4
|
+
|
5
|
+
namespace :js do
|
6
|
+
|
7
|
+
desc "Install Javascript dependencies"
|
8
|
+
task :install do
|
9
|
+
system 'jim install http://code.jquery.com/jquery-1.4.2.js'
|
10
|
+
system 'jim install http://github.com/quirkey/sammy/zipball/v0.5.4'
|
11
|
+
system 'jim install http://github.com/benpickles/js-model/zipball/v0.8.4'
|
12
|
+
system 'jim install http://documentcloud.github.com/underscore/underscore.js'
|
13
|
+
system 'jim install http://github.com/janl/mustache.js/zipball/0.2.3'
|
14
|
+
system 'jim install http://github.com/ahe/choco.libs/raw/master/choco.utils.js'
|
15
|
+
system 'jim install http://github.com/ahe/choco.libs/raw/master/plugins/models/choco.plugins.models.load.js'
|
16
|
+
system 'jim install http://github.com/ahe/choco.libs/raw/master/plugins/sammy/choco.plugins.sammy.smart_renderer.js'
|
17
|
+
system 'jim bundle lib/bundled.js'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
desc "Compress all your JS files into lib/compressed.js"
|
22
|
+
task :deploy do
|
23
|
+
system 'jim compress lib/compressed.js'
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
@import url(http://yui.yahooapis.com/3.0.0/build/cssreset/reset-min.css);
|
@@ -0,0 +1,33 @@
|
|
1
|
+
var app = $.sammy(function() {
|
2
|
+
|
3
|
+
this.element_selector = '#choco';
|
4
|
+
this.template_engine = 'template';
|
5
|
+
|
6
|
+
// Configure your Sammy JS plugins
|
7
|
+
this.use(Sammy.Template);
|
8
|
+
this.use(Sammy.NestedParams);
|
9
|
+
this.use(Sammy.SmartRenderer, '/<%= name %>/app/views/');
|
10
|
+
|
11
|
+
// Event fired by the render() method
|
12
|
+
this.bind('template_loaded', function(e, data) {
|
13
|
+
ChocoUtils.activateDeleteLinks(app);
|
14
|
+
});
|
15
|
+
|
16
|
+
// Root page
|
17
|
+
this.get('#/main', function(cx) {
|
18
|
+
});
|
19
|
+
|
20
|
+
/* Configure your helpers here */
|
21
|
+
this.helpers(ApplicationHelper);
|
22
|
+
|
23
|
+
/* Configure your controllers here ### Don't remove this line! */
|
24
|
+
// PostsController(this);
|
25
|
+
});
|
26
|
+
|
27
|
+
$(function() {
|
28
|
+
// Load your models here, example : var models = [Post, Category]
|
29
|
+
var models = [];
|
30
|
+
ChocoUtils.loadModels(models, function() {
|
31
|
+
app.run('#/main');
|
32
|
+
});
|
33
|
+
});
|
@@ -0,0 +1,53 @@
|
|
1
|
+
<%= @controller_name %>Controller = function(app) { with(app) {
|
2
|
+
|
3
|
+
/** Routes **/
|
4
|
+
|
5
|
+
// GET index
|
6
|
+
get('#/<%= @route_path %>', function(cx) {
|
7
|
+
cx.<%= @model.pluralize %> = <%= @model_name %>.all();
|
8
|
+
});
|
9
|
+
|
10
|
+
// GET new
|
11
|
+
get('#/<%= @route_path %>/new', function(cx) {
|
12
|
+
});
|
13
|
+
|
14
|
+
// POST create
|
15
|
+
post('#/<%= @route_path %>', function(cx) {
|
16
|
+
var <%= @model %> = new <%= @model_name %>(cx.params['<%= @model %>']);
|
17
|
+
<%= @model %>.save(function(success) {
|
18
|
+
cx.redirect('#/<%= @route_path %>/' + <%= @model %>.id());
|
19
|
+
});
|
20
|
+
});
|
21
|
+
|
22
|
+
// GET edit
|
23
|
+
get('#/<%= @route_path %>/edit/:id', function(cx) {
|
24
|
+
cx.<%= @model %> = <%= @model_name %>.find(cx.params['id']);
|
25
|
+
});
|
26
|
+
|
27
|
+
// PUT update
|
28
|
+
put('#/<%= @route_path %>/update/:id', function(cx) {
|
29
|
+
var <%= @model %> = <%= @model_name %>.find(cx.params['id']);
|
30
|
+
<%= @model %>.update(cx.params['<%= @model %>']).save(function(success) {
|
31
|
+
cx.redirect('#/<%= @route_path %>/' + <%= @model %>.id())
|
32
|
+
});
|
33
|
+
});
|
34
|
+
|
35
|
+
// DELETE destroy
|
36
|
+
route('delete', '#/<%= @route_path %>/:id', function(cx) {
|
37
|
+
var <%= @model %> = <%= @model_name %>.find(cx.params['id']);
|
38
|
+
<%= @model %>.destroy();
|
39
|
+
cx.trigger('<%= @model %>_remove', { <%= @model %>_id: <%= @model %>.id() });
|
40
|
+
});
|
41
|
+
|
42
|
+
// GET show
|
43
|
+
get('#/<%= @route_path %>/:id', function(cx) {
|
44
|
+
cx.<%= @model %> = <%= @model_name %>.find(cx.params['id']);
|
45
|
+
});
|
46
|
+
|
47
|
+
/** Events **/
|
48
|
+
|
49
|
+
bind('<%= @model %>_remove', function(e, data) {
|
50
|
+
$('#<%= @model %>_' + data['<%= @model %>_id']).remove();
|
51
|
+
});
|
52
|
+
|
53
|
+
}};
|
@@ -0,0 +1,12 @@
|
|
1
|
+
|
2
|
+
The choco script responds to the following commands and options :
|
3
|
+
|
4
|
+
--watch
|
5
|
+
The Choco watch command will track JS files in your project (create, update, remove).
|
6
|
+
It will regenerate your bundled.js at every modification in one of your JS files.
|
7
|
+
Your Jimfile will also be maintained by this command.
|
8
|
+
|
9
|
+
generate <generator_name> <resource_name> [options]
|
10
|
+
Available generators are : controller, model, scaffold, layout, plugin
|
11
|
+
Run '$ choco generate', for more information.
|
12
|
+
|
@@ -0,0 +1,33 @@
|
|
1
|
+
|
2
|
+
The following Choco generators are available :
|
3
|
+
|
4
|
+
controller
|
5
|
+
$ choco generate controller <controller_name>
|
6
|
+
|
7
|
+
It will create the controller file and a views folder.
|
8
|
+
|
9
|
+
model
|
10
|
+
$ choco generate model <model_name>
|
11
|
+
|
12
|
+
It will create the model file.
|
13
|
+
|
14
|
+
scaffold
|
15
|
+
$ choco generate scaffold <resource_name> [field1 field2 ...]
|
16
|
+
|
17
|
+
It will create a RESTful controller, the model and the views.
|
18
|
+
|
19
|
+
scaffold <url>
|
20
|
+
$ choco generate scaffold <resource_name> <url>
|
21
|
+
|
22
|
+
It will create a RESTful controller, the model and the views.
|
23
|
+
The fields will be determined from the JSON returned by your URL
|
24
|
+
e.g : http://localhost:3000/posts.json
|
25
|
+
|
26
|
+
layout
|
27
|
+
$ choco generate layout <layout_name>
|
28
|
+
|
29
|
+
It will create the layout file.
|
30
|
+
|
31
|
+
plugin
|
32
|
+
$ choco generate plugin <plugin_name>
|
33
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta content='' name='keywords' />
|
5
|
+
<meta content='' name='description' />
|
6
|
+
<meta content='text/html; charset=utf-8' http-equiv='Content-type' />
|
7
|
+
<link href="stylesheets/application.css" media="screen" rel="stylesheet" type="text/css" />
|
8
|
+
<script src="lib/bundled.js" type="text/javascript"></script>
|
9
|
+
<!--[if lt IE 9]>
|
10
|
+
<script src='http://html5shiv.googlecode.com/svn/trunk/html5.js' type='text/javascript'></script>
|
11
|
+
<![endif]-->
|
12
|
+
</head>
|
13
|
+
<body>
|
14
|
+
<div id="choco"></div>
|
15
|
+
</body>
|
16
|
+
</html>
|
@@ -0,0 +1,40 @@
|
|
1
|
+
// js-model plugin
|
2
|
+
// It allows you to add methods to all your models.
|
3
|
+
|
4
|
+
var <%= @plugin_name %>Plugin = {
|
5
|
+
modelsClassMethods : {
|
6
|
+
myhelper: function() {
|
7
|
+
alert('hello world [class method]');
|
8
|
+
}
|
9
|
+
},
|
10
|
+
|
11
|
+
modelsInstanceMethods : {
|
12
|
+
myhelper: function() {
|
13
|
+
alert('hello world [instance method]');
|
14
|
+
}
|
15
|
+
}
|
16
|
+
};
|
17
|
+
|
18
|
+
// Apply the js-model plugin
|
19
|
+
ChocoUtils.modelPlugin(<%= @plugin_name %>Plugin);
|
20
|
+
|
21
|
+
|
22
|
+
// Sammy plugin
|
23
|
+
// It allows you to add helper methods to your controllers and your views.
|
24
|
+
|
25
|
+
(function($) {
|
26
|
+
|
27
|
+
Sammy = Sammy || {};
|
28
|
+
|
29
|
+
Sammy.<%= @plugin_name %> = function() {
|
30
|
+
|
31
|
+
this.helper('<%= @plugin_name.underscore %>', function() {
|
32
|
+
alert('hello world [sammy plugin]');
|
33
|
+
});
|
34
|
+
|
35
|
+
};
|
36
|
+
|
37
|
+
})(jQuery);
|
38
|
+
|
39
|
+
// Add this line to your application_controller.js to use this plugin :
|
40
|
+
// this.use(Sammy.<%= @plugin_name %>);
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<h1>Edit a <%= @model %></h1>
|
2
|
+
<form action="#/<%= @route_path %>/update/<%%= <%= @model %>.id() %>" method="put">
|
3
|
+
<% @keys.each do |key| %>
|
4
|
+
<% if key != 'id' %>
|
5
|
+
<p>
|
6
|
+
<label><%= key.camelcase %></label><br/>
|
7
|
+
<input type="text" name="<%= @model %>[<%= key %>]" value="<%%= <%= @model %>.attr('<%= key %>') %>"/>
|
8
|
+
</p>
|
9
|
+
<% end %>
|
10
|
+
<% end %>
|
11
|
+
<p>
|
12
|
+
<input type="submit" value="Update" />
|
13
|
+
</p>
|
14
|
+
</form>
|
@@ -0,0 +1,32 @@
|
|
1
|
+
<h1>Listing <%= @model.pluralize %></h1>
|
2
|
+
|
3
|
+
<%% if(_.isEmpty(<%= @model.pluralize %>)) { %>
|
4
|
+
Sorry, we don't have any <%= @model %> yet!
|
5
|
+
<%% } %>
|
6
|
+
|
7
|
+
<table>
|
8
|
+
<thead>
|
9
|
+
<% @keys.each do |key| %>
|
10
|
+
<th><%= key.camelcase %></th>
|
11
|
+
<% end %>
|
12
|
+
<th>Actions</th>
|
13
|
+
</thead>
|
14
|
+
<tbody>
|
15
|
+
<%% $.each(<%= @model.pluralize %>, function(i, <%= @model %>) { %>
|
16
|
+
<tr id="<%= @model %>_<%%= <%= @model %>.id() %>">
|
17
|
+
<% @keys.each do |key| %>
|
18
|
+
<td><%%= <%= @model %>.attr('<%= key %>') %></td>
|
19
|
+
<% end %>
|
20
|
+
<td>
|
21
|
+
<a href="#/<%= @route_path %>/<%%= <%= @model %>.id() %>">Permalink</a>
|
22
|
+
<a href="#/<%= @route_path %>/edit/<%%= <%= @model %>.id() %>">Edit</a>
|
23
|
+
<a href="#/<%= @route_path %>/<%%= <%= @model %>.id() %>" verb="delete" confirm="Are you sure?">Delete</a>
|
24
|
+
</td>
|
25
|
+
</tr>
|
26
|
+
<%% }); %>
|
27
|
+
</tbody>
|
28
|
+
</table>
|
29
|
+
|
30
|
+
<br/>
|
31
|
+
<br/>
|
32
|
+
<a href="#/<%= @route_path %>/new">Add a new <%= @model %></a>
|
@@ -0,0 +1 @@
|
|
1
|
+
Welcome to Choco!
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<h1>Add a new <%= @model %></h1>
|
2
|
+
<form action="#/<%= @route_path %>" method="post">
|
3
|
+
<% @keys.each do |key| %>
|
4
|
+
<% if key != 'id' %>
|
5
|
+
<p>
|
6
|
+
<label><%= key.camelcase %></label><br/>
|
7
|
+
<input type="text" name="<%= @model %>[<%= key %>]"/>
|
8
|
+
</p>
|
9
|
+
<% end %>
|
10
|
+
<% end %>
|
11
|
+
<p>
|
12
|
+
<input type="submit" value="Add" />
|
13
|
+
</p>
|
14
|
+
</form>
|
data/spec/choco_spec.rb
ADDED
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,164 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: choco
|
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
|
+
- Anthony Heukmes
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-07-23 00:00:00 +02:00
|
18
|
+
default_executable: choco
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: jim
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
version: "0"
|
30
|
+
type: :runtime
|
31
|
+
version_requirements: *id001
|
32
|
+
- !ruby/object:Gem::Dependency
|
33
|
+
name: fssm
|
34
|
+
prerelease: false
|
35
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
segments:
|
40
|
+
- 0
|
41
|
+
version: "0"
|
42
|
+
type: :runtime
|
43
|
+
version_requirements: *id002
|
44
|
+
- !ruby/object:Gem::Dependency
|
45
|
+
name: thor
|
46
|
+
prerelease: false
|
47
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
segments:
|
52
|
+
- 0
|
53
|
+
version: "0"
|
54
|
+
type: :runtime
|
55
|
+
version_requirements: *id003
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: activesupport
|
58
|
+
prerelease: false
|
59
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
segments:
|
64
|
+
- 0
|
65
|
+
version: "0"
|
66
|
+
type: :runtime
|
67
|
+
version_requirements: *id004
|
68
|
+
- !ruby/object:Gem::Dependency
|
69
|
+
name: rspec
|
70
|
+
prerelease: false
|
71
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
segments:
|
76
|
+
- 1
|
77
|
+
- 2
|
78
|
+
- 9
|
79
|
+
version: 1.2.9
|
80
|
+
type: :development
|
81
|
+
version_requirements: *id005
|
82
|
+
description: Choco brings the MVC to the client side! It allows you to easily develop maintainable Rich Internet Applications using Javascript.
|
83
|
+
email: anthony.heukmes@skynet.be
|
84
|
+
executables:
|
85
|
+
- choco
|
86
|
+
extensions: []
|
87
|
+
|
88
|
+
extra_rdoc_files:
|
89
|
+
- LICENSE
|
90
|
+
- README.rdoc
|
91
|
+
files:
|
92
|
+
- .document
|
93
|
+
- .gitignore
|
94
|
+
- HISTORY
|
95
|
+
- LICENSE
|
96
|
+
- README.rdoc
|
97
|
+
- Rakefile
|
98
|
+
- bin/choco
|
99
|
+
- choco.gemspec
|
100
|
+
- lib/choco.rb
|
101
|
+
- lib/choco/cli.rb
|
102
|
+
- lib/choco/dependency_manager.rb
|
103
|
+
- lib/choco/generators/app_generator.rb
|
104
|
+
- lib/choco/generators/controller_generator.rb
|
105
|
+
- lib/choco/generators/layout_generator.rb
|
106
|
+
- lib/choco/generators/model_generator.rb
|
107
|
+
- lib/choco/generators/plugin_generator.rb
|
108
|
+
- lib/choco/generators/scaffold_generator.rb
|
109
|
+
- lib/choco/generators/templates/Jimfile
|
110
|
+
- lib/choco/generators/templates/README.rdoc
|
111
|
+
- lib/choco/generators/templates/Rakefile
|
112
|
+
- lib/choco/generators/templates/application.css
|
113
|
+
- lib/choco/generators/templates/choco
|
114
|
+
- lib/choco/generators/templates/controllers/application_controller.js
|
115
|
+
- lib/choco/generators/templates/controllers/base_controller.js
|
116
|
+
- lib/choco/generators/templates/controllers/rest_controller.js
|
117
|
+
- lib/choco/generators/templates/help/commands
|
118
|
+
- lib/choco/generators/templates/help/generators
|
119
|
+
- lib/choco/generators/templates/helpers/application_helper.js
|
120
|
+
- lib/choco/generators/templates/index.html
|
121
|
+
- lib/choco/generators/templates/lib/plugin.js
|
122
|
+
- lib/choco/generators/templates/models/base.js
|
123
|
+
- lib/choco/generators/templates/views/edit.template
|
124
|
+
- lib/choco/generators/templates/views/index.template
|
125
|
+
- lib/choco/generators/templates/views/layout.js
|
126
|
+
- lib/choco/generators/templates/views/main/index.template
|
127
|
+
- lib/choco/generators/templates/views/new.template
|
128
|
+
- lib/choco/generators/templates/views/show.template
|
129
|
+
- spec/choco_spec.rb
|
130
|
+
- spec/spec.opts
|
131
|
+
- spec/spec_helper.rb
|
132
|
+
has_rdoc: true
|
133
|
+
homepage: http://github.com/ahe/choco
|
134
|
+
licenses: []
|
135
|
+
|
136
|
+
post_install_message:
|
137
|
+
rdoc_options:
|
138
|
+
- --charset=UTF-8
|
139
|
+
require_paths:
|
140
|
+
- lib
|
141
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
segments:
|
146
|
+
- 0
|
147
|
+
version: "0"
|
148
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
segments:
|
153
|
+
- 0
|
154
|
+
version: "0"
|
155
|
+
requirements: []
|
156
|
+
|
157
|
+
rubyforge_project:
|
158
|
+
rubygems_version: 1.3.6
|
159
|
+
signing_key:
|
160
|
+
specification_version: 3
|
161
|
+
summary: A delicious Javascript web framework made in Belgium!
|
162
|
+
test_files:
|
163
|
+
- spec/choco_spec.rb
|
164
|
+
- spec/spec_helper.rb
|