choco 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/HISTORY +9 -1
- data/README.rdoc +19 -10
- data/choco.gemspec +7 -2
- data/lib/choco.rb +1 -1
- data/lib/choco/dependency_manager.rb +1 -1
- data/lib/choco/generators/app_generator.rb +1 -4
- data/lib/choco/generators/controller_generator.rb +2 -2
- data/lib/choco/generators/scaffold_generator.rb +2 -0
- data/lib/choco/generators/templates/lib/application.js +3 -0
- data/lib/choco/generators/templates/views/edit.template +8 -8
- data/lib/choco/generators/templates/views/index.template +11 -11
- data/lib/choco/generators/templates/views/new.template +8 -8
- data/lib/choco/generators/templates/views/show.template +7 -7
- data/spec/choco_spec.rb +0 -3
- data/spec/dependency_manager_spec.rb +106 -0
- data/spec/generators_spec.rb +300 -0
- data/spec/spec_helper.rb +8 -0
- metadata +8 -3
data/.gitignore
CHANGED
data/HISTORY
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
-
== 0.1.
|
1
|
+
== 0.1.1 [07-27-10]
|
2
|
+
|
3
|
+
* Clean generated HTML (indentation)
|
4
|
+
* Add lib/application.js file at project generation
|
5
|
+
* Remove compressed folder
|
6
|
+
* When a controller is deleted, the watcher script removes it from the app controller
|
7
|
+
* Add specifications
|
8
|
+
|
9
|
+
== 0.1.0 [07-23-10]
|
2
10
|
|
3
11
|
* Initial release
|
data/README.rdoc
CHANGED
@@ -20,6 +20,11 @@ Choco is based on powerful libaries :
|
|
20
20
|
|
21
21
|
Huge thanks to Aaron Quint and Ben Pickles for their incredible work.
|
22
22
|
|
23
|
+
A sample project based on Rails 3 is available here : http://github.com/ahe/choco_demo
|
24
|
+
|
25
|
+
An awesome screencast with an awesome belgian accent is available here :
|
26
|
+
http://www.2dconcept.com/images/choco.mov
|
27
|
+
|
23
28
|
== Installation
|
24
29
|
|
25
30
|
Choco is a Ruby gem, simply install it :
|
@@ -93,39 +98,39 @@ You have to include this # in every HTML link you add into your views.
|
|
93
98
|
|
94
99
|
A Choco project has the following structure :
|
95
100
|
|
96
|
-
|
101
|
+
=== Jimfile
|
97
102
|
This file list all the dependencies for your project (libraries & local files).
|
98
103
|
|
99
|
-
|
104
|
+
=== app
|
100
105
|
It contains four sub-folders : controllers, helpers, models & views.
|
101
106
|
This is where you will spend most of your development time.
|
102
107
|
|
103
|
-
|
108
|
+
=== compressed
|
104
109
|
This is where the bundled.js file is created, it bundles all your JS files in one single file.
|
105
110
|
It is highly recommended to compress this file before going live (rake choco:deploy).
|
106
111
|
|
107
|
-
|
112
|
+
=== images
|
108
113
|
Store all the images used by your application in this folder.
|
109
114
|
|
110
|
-
|
115
|
+
=== index.html
|
111
116
|
This is the file you have to open in your browser to launch your Choco application.
|
112
117
|
It includes your bundled.js file, your stylesheets and defines the layout of your application.
|
113
118
|
|
114
119
|
The #choco div is very important, this is where the HTML generated by your views will be inserted.
|
115
120
|
If you change his name, you must configure it into the app/controllers/application_controller.js as well.
|
116
121
|
|
117
|
-
|
122
|
+
=== lib
|
118
123
|
Use this folder to store your JS files which are specific to your project but don't have their place in the app folder.
|
119
124
|
If this is a library that can be used by other projects, you should use Jim instead.
|
120
125
|
|
121
|
-
|
126
|
+
=== script
|
122
127
|
This folder contains the choco script file.
|
123
128
|
It brings you a few generators (model, controller, layout, scaffold, json, plugin).
|
124
129
|
|
125
|
-
|
130
|
+
=== spec
|
126
131
|
Test your application using Behavior Driven Development (BDD).
|
127
132
|
|
128
|
-
|
133
|
+
=== stylesheets
|
129
134
|
Store all the stylesheets used by your application in this folder.
|
130
135
|
|
131
136
|
= A first resource (CRUD)
|
@@ -306,6 +311,10 @@ Then just copy the required files on your web server.
|
|
306
311
|
BDD is currently being implemented, it will be soon very easy to test all the parts of your Choco apps.
|
307
312
|
A first solution can be found here : http://github.com/ahe/sammy_demo/tree/master/test/javascript
|
308
313
|
|
314
|
+
= Mailing list
|
315
|
+
|
316
|
+
http://groups.google.com/group/choco-js
|
317
|
+
|
309
318
|
= Note on Patches/Pull Requests
|
310
319
|
|
311
320
|
* Fork the project.
|
@@ -316,7 +325,7 @@ A first solution can be found here : http://github.com/ahe/sammy_demo/tree/maste
|
|
316
325
|
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
317
326
|
* Send me a pull request. Bonus points for topic branches.
|
318
327
|
|
319
|
-
|
328
|
+
= Copyright
|
320
329
|
|
321
330
|
Copyright (c) 2010 Anthony Heukmes. See LICENSE for details.
|
322
331
|
|
data/choco.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{choco}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Anthony Heukmes"]
|
12
|
-
s.date = %q{2010-07-
|
12
|
+
s.date = %q{2010-07-27}
|
13
13
|
s.default_executable = %q{choco}
|
14
14
|
s.description = %q{Choco brings the MVC to the client side! It allows you to easily develop maintainable Rich Internet Applications using Javascript.}
|
15
15
|
s.email = %q{anthony.heukmes@skynet.be}
|
@@ -48,6 +48,7 @@ Gem::Specification.new do |s|
|
|
48
48
|
"lib/choco/generators/templates/help/generators",
|
49
49
|
"lib/choco/generators/templates/helpers/application_helper.js",
|
50
50
|
"lib/choco/generators/templates/index.html",
|
51
|
+
"lib/choco/generators/templates/lib/application.js",
|
51
52
|
"lib/choco/generators/templates/lib/plugin.js",
|
52
53
|
"lib/choco/generators/templates/models/base.js",
|
53
54
|
"lib/choco/generators/templates/views/edit.template",
|
@@ -57,6 +58,8 @@ Gem::Specification.new do |s|
|
|
57
58
|
"lib/choco/generators/templates/views/new.template",
|
58
59
|
"lib/choco/generators/templates/views/show.template",
|
59
60
|
"spec/choco_spec.rb",
|
61
|
+
"spec/dependency_manager_spec.rb",
|
62
|
+
"spec/generators_spec.rb",
|
60
63
|
"spec/spec.opts",
|
61
64
|
"spec/spec_helper.rb"
|
62
65
|
]
|
@@ -67,6 +70,8 @@ Gem::Specification.new do |s|
|
|
67
70
|
s.summary = %q{A delicious Javascript web framework made in Belgium!}
|
68
71
|
s.test_files = [
|
69
72
|
"spec/choco_spec.rb",
|
73
|
+
"spec/dependency_manager_spec.rb",
|
74
|
+
"spec/generators_spec.rb",
|
70
75
|
"spec/spec_helper.rb"
|
71
76
|
]
|
72
77
|
|
data/lib/choco.rb
CHANGED
@@ -73,7 +73,7 @@ module Choco
|
|
73
73
|
file = extract_filename(filename)
|
74
74
|
application_controller = ""
|
75
75
|
File.new('app/controllers/application_controller.js', "r").each do |line|
|
76
|
-
application_controller << line unless line.include?(
|
76
|
+
application_controller << line unless line.include?(file)
|
77
77
|
end
|
78
78
|
|
79
79
|
File.open('app/controllers/application_controller.js', "wb") { |io| io.print application_controller }
|
@@ -29,10 +29,7 @@ module Choco
|
|
29
29
|
|
30
30
|
def create_lib_folder
|
31
31
|
empty_directory "#{name}/lib"
|
32
|
-
|
33
|
-
|
34
|
-
def create_compressed_folder
|
35
|
-
empty_directory "#{name}/compressed"
|
32
|
+
template("templates/lib/application.js", "#{name}/lib/application.js")
|
36
33
|
end
|
37
34
|
|
38
35
|
def create_images_folder
|
@@ -10,11 +10,11 @@ module Choco
|
|
10
10
|
argument :name
|
11
11
|
|
12
12
|
def create_controller_file
|
13
|
-
template('templates/controllers/base_controller.js', "app/controllers/#{name}_controller.js")
|
13
|
+
template('templates/controllers/base_controller.js', "app/controllers/#{name.underscore}_controller.js")
|
14
14
|
end
|
15
15
|
|
16
16
|
def create_views_folder
|
17
|
-
empty_directory "app/views/#{name}"
|
17
|
+
empty_directory "app/views/#{name.underscore}"
|
18
18
|
end
|
19
19
|
|
20
20
|
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
<h1>Edit a <%= @model %></h1>
|
2
2
|
<form action="#/<%= @route_path %>/update/<%%= <%= @model %>.id() %>" method="put">
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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
11
|
<p>
|
12
12
|
<input type="submit" value="Update" />
|
13
13
|
</p>
|
@@ -6,22 +6,22 @@
|
|
6
6
|
|
7
7
|
<table>
|
8
8
|
<thead>
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
<% @keys.each do |key| -%>
|
10
|
+
<th><%= key.camelcase %></th>
|
11
|
+
<% end -%>
|
12
12
|
<th>Actions</th>
|
13
13
|
</thead>
|
14
14
|
<tbody>
|
15
15
|
<%% $.each(<%= @model.pluralize %>, function(i, <%= @model %>) { %>
|
16
16
|
<tr id="<%= @model %>_<%%= <%= @model %>.id() %>">
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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
25
|
</tr>
|
26
26
|
<%% }); %>
|
27
27
|
</tbody>
|
@@ -1,13 +1,13 @@
|
|
1
1
|
<h1>Add a new <%= @model %></h1>
|
2
2
|
<form action="#/<%= @route_path %>" method="post">
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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
11
|
<p>
|
12
12
|
<input type="submit" value="Add" />
|
13
13
|
</p>
|
@@ -1,10 +1,10 @@
|
|
1
|
-
<% @keys.each do |key|
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
<% end
|
1
|
+
<% @keys.each do |key| -%>
|
2
|
+
<p>
|
3
|
+
<label><%= key.camelcase %></label>
|
4
|
+
<br/>
|
5
|
+
<%%= <%= @model %>.attr('<%= key %>') %>
|
6
|
+
</p>
|
7
|
+
<% end -%>
|
8
8
|
<br/>
|
9
9
|
<br/>
|
10
10
|
<a href="#/<%= @route_path %>">Back to index</a>
|
data/spec/choco_spec.rb
CHANGED
@@ -0,0 +1,106 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe Choco::DependencyManager do
|
4
|
+
|
5
|
+
def in_file(file, dependency, after = '')
|
6
|
+
i = 0
|
7
|
+
after_after = false
|
8
|
+
|
9
|
+
File.new(file, "r").each do |line|
|
10
|
+
after_after = true if line.include?(after)
|
11
|
+
if after != ''
|
12
|
+
i += 1 if after_after && line.include?(dependency)
|
13
|
+
else
|
14
|
+
i += 1 if line.include?(dependency)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
i
|
18
|
+
end
|
19
|
+
|
20
|
+
before(:each) do
|
21
|
+
@project_path = 'spec/tmp/test_project'
|
22
|
+
Choco::AppGenerator.start @project_path
|
23
|
+
FileUtils.cd(@project_path)
|
24
|
+
end
|
25
|
+
|
26
|
+
after(:each) do
|
27
|
+
FileUtils.cd('../../..')
|
28
|
+
FileUtils.rm_rf(@project_path)
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "adding dependencies" do
|
32
|
+
|
33
|
+
describe "when it's a controller" do
|
34
|
+
|
35
|
+
it "should add an entry in the Jimfile (controllers section)" do
|
36
|
+
in_file('Jimfile', 'app/controllers/posts_controller').should == 0
|
37
|
+
Choco::DependencyManager.add_dependency('app/controllers/posts_controller.js')
|
38
|
+
in_file('Jimfile', 'app/controllers/posts_controller', "// Controllers # Don't remove this line!").should == 1
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should configure it in the application controller" do
|
42
|
+
in_file('app/controllers/application_controller.js', 'ArticlesController(this);').should == 0
|
43
|
+
Choco::DependencyManager.add_dependency('app/controllers/articles_controller.js')
|
44
|
+
in_file('app/controllers/application_controller.js',
|
45
|
+
'ArticlesController(this);',
|
46
|
+
"/* Configure your controllers here ### Don't remove this line! */").should == 1
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "when it's a model" do
|
52
|
+
|
53
|
+
it "should add an entry in the Jimfile (models section)" do
|
54
|
+
in_file('Jimfile', 'app/models/post').should == 0
|
55
|
+
Choco::DependencyManager.add_dependency('app/models/post.js')
|
56
|
+
in_file('Jimfile', 'app/models/post', "// Models # Don't remove this line!").should == 1
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "when it's a helper" do
|
62
|
+
|
63
|
+
it "should add an entry in the Jimfile (helpers section)" do
|
64
|
+
in_file('Jimfile', 'app/helpers/test').should == 0
|
65
|
+
Choco::DependencyManager.add_dependency('app/helpers/test.js')
|
66
|
+
in_file('Jimfile', 'app/helpers/test', "// Helpers # Don't remove this line!").should == 1
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "when it's a lib" do
|
72
|
+
|
73
|
+
it "should add an entry in the Jimfile (libs section)" do
|
74
|
+
in_file('Jimfile', 'lib/my_lib').should == 0
|
75
|
+
Choco::DependencyManager.add_dependency('lib/my_lib.js')
|
76
|
+
in_file('Jimfile', 'lib/my_lib', "// Libs # Don't remove this line!").should == 1
|
77
|
+
|
78
|
+
in_file('Jimfile', 'another/file').should == 0
|
79
|
+
Choco::DependencyManager.add_dependency('another/file.js')
|
80
|
+
in_file('Jimfile', 'another/file', "// Libs # Don't remove this line!").should == 1
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "removing dependencies" do
|
88
|
+
|
89
|
+
it "should remove the dependency from the jimfile" do
|
90
|
+
Choco::DependencyManager.add_dependency('app/models/post.js')
|
91
|
+
in_file('Jimfile', 'app/models/post').should == 1
|
92
|
+
Choco::DependencyManager.remove_dependency('app/models/post.js')
|
93
|
+
in_file('Jimfile', 'app/models/post').should == 0
|
94
|
+
end
|
95
|
+
|
96
|
+
describe "when it's a controller" do
|
97
|
+
it "should remove the configuration from the application controller" do
|
98
|
+
Choco::DependencyManager.add_dependency('app/controllers/articles_controller.js')
|
99
|
+
in_file('app/controllers/application_controller.js', 'ArticlesController(this);').should == 1
|
100
|
+
Choco::DependencyManager.remove_dependency('app/controllers/articles_controller.js')
|
101
|
+
in_file('app/controllers/application_controller.js', 'ArticlesController(this);').should == 0
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
end
|
@@ -0,0 +1,300 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "Generators" do
|
4
|
+
|
5
|
+
describe Choco::AppGenerator do
|
6
|
+
|
7
|
+
before(:all) do
|
8
|
+
@project_path = 'spec/tmp/test_project'
|
9
|
+
Choco::AppGenerator.start @project_path
|
10
|
+
end
|
11
|
+
|
12
|
+
after(:all) do
|
13
|
+
FileUtils.rm_rf @project_path
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should generate the project folder" do
|
17
|
+
File.exist?(@project_path).should be_true
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should generate the app folder" do
|
21
|
+
File.exist?(@project_path + '/app').should be_true
|
22
|
+
File.exist?(@project_path + '/app/controllers').should be_true
|
23
|
+
File.exist?(@project_path + '/app/helpers').should be_true
|
24
|
+
File.exist?(@project_path + '/app/models').should be_true
|
25
|
+
File.exist?(@project_path + '/app/views').should be_true
|
26
|
+
File.exist?(@project_path + '/app/controllers/application_controller.js').should be_true
|
27
|
+
File.exist?(@project_path + '/app/views/main/index.template').should be_true
|
28
|
+
File.exist?(@project_path + '/app/helpers/application_helper.js').should be_true
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should generate the lib folder" do
|
32
|
+
File.exist?(@project_path + '/lib').should be_true
|
33
|
+
File.exist?(@project_path + '/lib/application.js').should be_true
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should generate the images folder" do
|
37
|
+
File.exist?(@project_path + '/images').should be_true
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should generate the stylesheets folder" do
|
41
|
+
File.exist?(@project_path + '/stylesheets').should be_true
|
42
|
+
File.exist?(@project_path + '/stylesheets/application.css').should be_true
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should generate the spec folder" do
|
46
|
+
File.exist?(@project_path + '/spec').should be_true
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should generate the script folder" do
|
50
|
+
File.exist?(@project_path + '/script').should be_true
|
51
|
+
File.exist?(@project_path + '/script/choco').should be_true
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should generate the main files" do
|
55
|
+
File.exist?(@project_path + '/Jimfile').should be_true
|
56
|
+
File.exist?(@project_path + '/Rakefile').should be_true
|
57
|
+
File.exist?(@project_path + '/README.rdoc').should be_true
|
58
|
+
File.exist?(@project_path + '/index.html').should be_true
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "templates" do
|
62
|
+
|
63
|
+
describe "ApplicationController" do
|
64
|
+
|
65
|
+
it "should set the views path to the project views folder" do
|
66
|
+
file = get_file_as_string(@project_path + '/app/controllers/application_controller.js')
|
67
|
+
file.include?("this.use(Sammy.SmartRenderer, '/spec/tmp/test_project/app/views/');").should be_true
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "index.html" do
|
72
|
+
|
73
|
+
before(:all) do
|
74
|
+
@file = get_file_as_string(@project_path + '/index.html')
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should include the bundled.js file" do
|
78
|
+
@file.include?('<script src="lib/bundled.js" type="text/javascript"></script>').should be_true
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should include the root div" do
|
82
|
+
@file.include?('<div id="choco"></div>').should be_true
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe "code generators" do
|
91
|
+
|
92
|
+
before(:all) do
|
93
|
+
@project_path = 'spec/tmp/test_project'
|
94
|
+
Choco::AppGenerator.start @project_path
|
95
|
+
FileUtils.cd(@project_path)
|
96
|
+
end
|
97
|
+
|
98
|
+
after(:all) do
|
99
|
+
FileUtils.cd('..')
|
100
|
+
FileUtils.rm_rf('test_project')
|
101
|
+
FileUtils.cd('../..')
|
102
|
+
end
|
103
|
+
|
104
|
+
describe Choco::ControllerGenerator do
|
105
|
+
|
106
|
+
it "should generate a controller file and a views folder" do
|
107
|
+
Choco::ControllerGenerator.start 'posts'
|
108
|
+
File.exist?('app/controllers/posts_controller.js').should be_true
|
109
|
+
File.exist?('app/views/posts').should be_true
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should not pluralize the controller name" do
|
113
|
+
Choco::ControllerGenerator.start 'singular'
|
114
|
+
File.exist?('app/controllers/singular_controller.js').should be_true
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should underscore the name" do
|
118
|
+
Choco::ControllerGenerator.start 'UnderScore'
|
119
|
+
File.exist?('app/controllers/under_score_controller.js').should be_true
|
120
|
+
end
|
121
|
+
|
122
|
+
describe "templates" do
|
123
|
+
|
124
|
+
before(:all) do
|
125
|
+
Choco::ControllerGenerator.start 'UnderScore'
|
126
|
+
@file = get_file_as_string('app/controllers/under_score_controller.js')
|
127
|
+
end
|
128
|
+
|
129
|
+
describe "the generated controller" do
|
130
|
+
it "should be named correctly" do
|
131
|
+
@file.include?('UnderScoreController').should be_true
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should define an index route" do
|
135
|
+
@file.include?("get('#/under_score'").should be_true
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
describe Choco::ModelGenerator do
|
142
|
+
it "should generate a model file" do
|
143
|
+
Choco::ModelGenerator.start 'post'
|
144
|
+
File.exist?('app/models/post.js').should be_true
|
145
|
+
end
|
146
|
+
|
147
|
+
it "should generate a model file with a singular name" do
|
148
|
+
Choco::ModelGenerator.start 'posts'
|
149
|
+
File.exist?('app/models/post.js').should be_true
|
150
|
+
end
|
151
|
+
|
152
|
+
describe "templates" do
|
153
|
+
|
154
|
+
describe "the generated model" do
|
155
|
+
|
156
|
+
before(:all) do
|
157
|
+
Choco::ModelGenerator.start 'post'
|
158
|
+
@file = get_file_as_string('app/models/post.js')
|
159
|
+
end
|
160
|
+
|
161
|
+
it "should be named correctly" do
|
162
|
+
@file.include?('var Post = Model("post"').should be_true
|
163
|
+
end
|
164
|
+
|
165
|
+
it "model persistence URL should be correct" do
|
166
|
+
@file.include?('Model.RestPersistence("/posts")').should be_true
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
describe Choco::LayoutGenerator do
|
174
|
+
it "should generate a layout file" do
|
175
|
+
Choco::LayoutGenerator.start 'main'
|
176
|
+
File.exist?('app/views/layouts/main.js').should be_true
|
177
|
+
end
|
178
|
+
|
179
|
+
describe "templates" do
|
180
|
+
|
181
|
+
it "the layout should be named correctly" do
|
182
|
+
Choco::LayoutGenerator.start 'main'
|
183
|
+
file = get_file_as_string('app/views/layouts/main.js')
|
184
|
+
file.include?('var MainLayout').should be_true
|
185
|
+
end
|
186
|
+
|
187
|
+
end
|
188
|
+
|
189
|
+
end
|
190
|
+
|
191
|
+
describe Choco::PluginGenerator do
|
192
|
+
it "should generate a plugin file" do
|
193
|
+
Choco::PluginGenerator.start 'live'
|
194
|
+
File.exist?('lib/plugin_live.js').should be_true
|
195
|
+
end
|
196
|
+
|
197
|
+
describe "templates" do
|
198
|
+
|
199
|
+
describe "the generated plugin" do
|
200
|
+
|
201
|
+
before(:all) do
|
202
|
+
Choco::PluginGenerator.start 'live'
|
203
|
+
@file = get_file_as_string('lib/plugin_live.js')
|
204
|
+
end
|
205
|
+
|
206
|
+
it "should be named correctly" do
|
207
|
+
@file.include?('var LivePlugin').should be_true
|
208
|
+
end
|
209
|
+
|
210
|
+
it "should apply the js-model plugin" do
|
211
|
+
@file.include?('ChocoUtils.modelPlugin(LivePlugin);').should be_true
|
212
|
+
end
|
213
|
+
|
214
|
+
it "should display the syntax to activate the sammy plugin" do
|
215
|
+
@file.include?('// this.use(Sammy.Live);').should be_true
|
216
|
+
end
|
217
|
+
|
218
|
+
end
|
219
|
+
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
describe Choco::ScaffoldGenerator do
|
224
|
+
describe "with a list of fields" do
|
225
|
+
it "should generate a scaffold based on the list of fields given as argument" do
|
226
|
+
gen = Choco::ScaffoldGenerator.new(['post', ['author', 'title', 'content']])
|
227
|
+
gen.invoke
|
228
|
+
|
229
|
+
File.exist?('app/controllers/posts_controller.js').should be_true
|
230
|
+
File.exist?('app/models/post.js').should be_true
|
231
|
+
File.exist?('app/views/posts/index.template').should be_true
|
232
|
+
File.exist?('app/views/posts/show.template').should be_true
|
233
|
+
File.exist?('app/views/posts/new.template').should be_true
|
234
|
+
File.exist?('app/views/posts/edit.template').should be_true
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
describe "with a URL" do
|
239
|
+
it "should generate a scaffold based on the fields present in the JSON response" do
|
240
|
+
url = 'http://localhost:3000/posts'
|
241
|
+
gen = Choco::ScaffoldGenerator.new(['post', url])
|
242
|
+
json = [{"title" => "Please, contribute!","author" => "antho","content" => "What do you think about Choco?"}]
|
243
|
+
|
244
|
+
gen.should_receive(:open).with(url, 'UserAgent' => 'Choco').and_return(StringIO.new)
|
245
|
+
JSON.should_receive(:parse).and_return(json)
|
246
|
+
|
247
|
+
gen.invoke
|
248
|
+
|
249
|
+
gen.keys.should == ["author", "title", "content"]
|
250
|
+
File.exist?('app/controllers/posts_controller.js').should be_true
|
251
|
+
File.exist?('app/models/post.js').should be_true
|
252
|
+
File.exist?('app/views/posts/index.template').should be_true
|
253
|
+
File.exist?('app/views/posts/show.template').should be_true
|
254
|
+
File.exist?('app/views/posts/new.template').should be_true
|
255
|
+
File.exist?('app/views/posts/edit.template').should be_true
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
describe "templates" do
|
260
|
+
|
261
|
+
before(:each) do
|
262
|
+
gen = Choco::ScaffoldGenerator.new(['post', ['author', 'title', 'content']])
|
263
|
+
gen.invoke
|
264
|
+
end
|
265
|
+
|
266
|
+
it "the index file should have a column for each field" do
|
267
|
+
file = get_file_as_string('app/views/posts/index.template')
|
268
|
+
file.include?("<th>Author</th>").should be_true
|
269
|
+
file.include?("<th>Title</th>").should be_true
|
270
|
+
file.include?("<th>Content</th>").should be_true
|
271
|
+
file.include?("<td><%= post.attr('author') %></td>").should be_true
|
272
|
+
file.include?("<td><%= post.attr('title') %></td>").should be_true
|
273
|
+
file.include?("<td><%= post.attr('content') %></td>").should be_true
|
274
|
+
end
|
275
|
+
|
276
|
+
it "the show file should have a label for each field" do
|
277
|
+
file = get_file_as_string('app/views/posts/show.template')
|
278
|
+
file.include?("<label>Author</label>").should be_true
|
279
|
+
file.include?("<label>Title</label>").should be_true
|
280
|
+
file.include?("<label>Content</label>").should be_true
|
281
|
+
end
|
282
|
+
|
283
|
+
it "the new file should have a field for each field" do
|
284
|
+
file = get_file_as_string('app/views/posts/new.template')
|
285
|
+
file.include?('<input type="text" name="post[author]"/>').should be_true
|
286
|
+
file.include?('<input type="text" name="post[title]"/>').should be_true
|
287
|
+
file.include?('<input type="text" name="post[content]"/>').should be_true
|
288
|
+
end
|
289
|
+
|
290
|
+
it "the edit file should have a field for each field" do
|
291
|
+
file = get_file_as_string('app/views/posts/edit.template')
|
292
|
+
file.include?(%Q(<input type="text" name="post[author]" value="<%= post.attr('author') %>"/>)).should be_true
|
293
|
+
file.include?(%Q(<input type="text" name="post[title]" value="<%= post.attr('title') %>"/>)).should be_true
|
294
|
+
file.include?(%Q(<input type="text" name="post[content]" value="<%= post.attr('content') %>"/>)).should be_true
|
295
|
+
end
|
296
|
+
|
297
|
+
end
|
298
|
+
end
|
299
|
+
end
|
300
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,9 +1,17 @@
|
|
1
1
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
2
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
require 'rubygems'
|
3
4
|
require 'choco'
|
4
5
|
require 'spec'
|
5
6
|
require 'spec/autorun'
|
6
7
|
|
8
|
+
def get_file_as_string(filename)
|
9
|
+
data = ''
|
10
|
+
f = File.open(filename, "r")
|
11
|
+
f.each_line { |line| data += line }
|
12
|
+
data
|
13
|
+
end
|
14
|
+
|
7
15
|
Spec::Runner.configure do |config|
|
8
16
|
|
9
17
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 1
|
9
|
+
version: 0.1.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Anthony Heukmes
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-07-
|
17
|
+
date: 2010-07-27 00:00:00 +02:00
|
18
18
|
default_executable: choco
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -118,6 +118,7 @@ files:
|
|
118
118
|
- lib/choco/generators/templates/help/generators
|
119
119
|
- lib/choco/generators/templates/helpers/application_helper.js
|
120
120
|
- lib/choco/generators/templates/index.html
|
121
|
+
- lib/choco/generators/templates/lib/application.js
|
121
122
|
- lib/choco/generators/templates/lib/plugin.js
|
122
123
|
- lib/choco/generators/templates/models/base.js
|
123
124
|
- lib/choco/generators/templates/views/edit.template
|
@@ -127,6 +128,8 @@ files:
|
|
127
128
|
- lib/choco/generators/templates/views/new.template
|
128
129
|
- lib/choco/generators/templates/views/show.template
|
129
130
|
- spec/choco_spec.rb
|
131
|
+
- spec/dependency_manager_spec.rb
|
132
|
+
- spec/generators_spec.rb
|
130
133
|
- spec/spec.opts
|
131
134
|
- spec/spec_helper.rb
|
132
135
|
has_rdoc: true
|
@@ -161,4 +164,6 @@ specification_version: 3
|
|
161
164
|
summary: A delicious Javascript web framework made in Belgium!
|
162
165
|
test_files:
|
163
166
|
- spec/choco_spec.rb
|
167
|
+
- spec/dependency_manager_spec.rb
|
168
|
+
- spec/generators_spec.rb
|
164
169
|
- spec/spec_helper.rb
|