choco 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/HISTORY +3 -0
- data/README.rdoc +7 -2
- data/choco.gemspec +5 -2
- data/lib/choco.rb +2 -1
- data/lib/choco/dependency_manager.rb +2 -0
- data/lib/choco/generators/app_generator.rb +4 -0
- data/lib/choco/generators/fixture_generator.rb +23 -0
- data/lib/choco/generators/templates/Jimfile +5 -1
- data/lib/choco/generators/templates/Rakefile +1 -0
- data/lib/choco/generators/templates/controllers/application_controller.js +3 -1
- data/lib/choco/generators/templates/fixtures/base.js +20 -0
- data/lib/choco/generators/templates/fixtures/model/array.js +4 -0
- data/lib/choco/generators/templates/help/commands +1 -1
- data/lib/choco/generators/templates/help/generators +9 -0
- data/spec/dependency_manager_spec.rb +10 -0
- data/spec/generators_spec.rb +29 -1
- metadata +6 -3
data/HISTORY
CHANGED
data/README.rdoc
CHANGED
@@ -50,8 +50,8 @@ Once you've chosen the location where your application will reside, don't forget
|
|
50
50
|
You can find the line to edit in your application_controller (app/controllers).
|
51
51
|
|
52
52
|
Example for Rails :
|
53
|
-
|
54
|
-
this.
|
53
|
+
|
54
|
+
this.project_path = '/javascripts/my_project';
|
55
55
|
|
56
56
|
== Jim
|
57
57
|
|
@@ -206,6 +206,10 @@ The Choco application will then be launched when all the responses have been rec
|
|
206
206
|
To create, remove & update posts, you have to create your REST controller on the server side.
|
207
207
|
Have a look at the sample demo for an example (http://github.com/ahe/choco_demo).
|
208
208
|
|
209
|
+
You can also use fixtures instead. Fixtures are located in the /fixtures folder, they use the jquery.mockjax plugin to mock Ajax requests and return the JSON you defined in your fixtures.
|
210
|
+
|
211
|
+
Use the choco generate fixture command to easily create your fixtures (e.g : $ choco generate fixture post, will mock requests sent to the /posts URL).
|
212
|
+
|
209
213
|
= Generators
|
210
214
|
|
211
215
|
The following code generators are available :
|
@@ -214,6 +218,7 @@ The following code generators are available :
|
|
214
218
|
* $ choco generate model <model_name>
|
215
219
|
* $ choco generate scaffold <name> [field1 field2 ...]
|
216
220
|
* $ choco generate scaffold <name> <url>
|
221
|
+
* $ choco generate fixture <name>
|
217
222
|
* $ choco generate layout <layout_name>
|
218
223
|
* $ choco generate plugin <plugin_name>
|
219
224
|
|
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.2"
|
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-28}
|
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}
|
@@ -32,6 +32,7 @@ Gem::Specification.new do |s|
|
|
32
32
|
"lib/choco/dependency_manager.rb",
|
33
33
|
"lib/choco/generators/app_generator.rb",
|
34
34
|
"lib/choco/generators/controller_generator.rb",
|
35
|
+
"lib/choco/generators/fixture_generator.rb",
|
35
36
|
"lib/choco/generators/layout_generator.rb",
|
36
37
|
"lib/choco/generators/model_generator.rb",
|
37
38
|
"lib/choco/generators/plugin_generator.rb",
|
@@ -44,6 +45,8 @@ Gem::Specification.new do |s|
|
|
44
45
|
"lib/choco/generators/templates/controllers/application_controller.js",
|
45
46
|
"lib/choco/generators/templates/controllers/base_controller.js",
|
46
47
|
"lib/choco/generators/templates/controllers/rest_controller.js",
|
48
|
+
"lib/choco/generators/templates/fixtures/base.js",
|
49
|
+
"lib/choco/generators/templates/fixtures/model/array.js",
|
47
50
|
"lib/choco/generators/templates/help/commands",
|
48
51
|
"lib/choco/generators/templates/help/generators",
|
49
52
|
"lib/choco/generators/templates/helpers/application_helper.js",
|
data/lib/choco.rb
CHANGED
@@ -3,13 +3,14 @@ require 'thor/group'
|
|
3
3
|
require 'active_support/inflector'
|
4
4
|
|
5
5
|
module Choco
|
6
|
-
VERSION = '0.1.
|
6
|
+
VERSION = '0.1.2'
|
7
7
|
|
8
8
|
autoload :DependencyManager, 'choco/dependency_manager'
|
9
9
|
autoload :CLI, 'choco/cli'
|
10
10
|
autoload :AppGenerator, 'choco/generators/app_generator'
|
11
11
|
autoload :ControllerGenerator, 'choco/generators/controller_generator'
|
12
12
|
autoload :LayoutGenerator, 'choco/generators/layout_generator'
|
13
|
+
autoload :FixtureGenerator, 'choco/generators/fixture_generator'
|
13
14
|
autoload :ModelGenerator, 'choco/generators/model_generator'
|
14
15
|
autoload :PluginGenerator, 'choco/generators/plugin_generator'
|
15
16
|
autoload :ScaffoldGenerator, 'choco/generators/scaffold_generator'
|
@@ -40,6 +40,10 @@ module Choco
|
|
40
40
|
empty_directory "#{name}/stylesheets"
|
41
41
|
template('templates/application.css', "#{name}/stylesheets/application.css")
|
42
42
|
end
|
43
|
+
|
44
|
+
def create_fixtures_folder
|
45
|
+
empty_directory "#{name}/fixtures"
|
46
|
+
end
|
43
47
|
|
44
48
|
def create_spec_folder
|
45
49
|
empty_directory "#{name}/spec"
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Choco
|
2
|
+
class FixtureGenerator < Thor::Group
|
3
|
+
include Thor::Actions
|
4
|
+
|
5
|
+
def self.source_root
|
6
|
+
File.dirname(__FILE__)
|
7
|
+
end
|
8
|
+
|
9
|
+
desc 'Generates Ajax fixtures (mocks)'
|
10
|
+
argument :name, :required => true
|
11
|
+
|
12
|
+
def create_mock_file
|
13
|
+
@name = name.underscore.pluralize
|
14
|
+
template('templates/fixtures/base.js', "fixtures/#{@name}.js")
|
15
|
+
end
|
16
|
+
|
17
|
+
def create_json_folder
|
18
|
+
empty_directory "fixtures/#{@name}"
|
19
|
+
template('templates/fixtures/model/array.js', "fixtures/#{@name}/#{@name}.json")
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -10,10 +10,12 @@ sammy.smart_renderer
|
|
10
10
|
js-model 0.8.3
|
11
11
|
underscore
|
12
12
|
mustache
|
13
|
+
jquery.mockjax
|
13
14
|
choco.utils
|
14
15
|
choco.plugins.models.load
|
15
16
|
|
16
17
|
// Libs # Don't remove this line!
|
18
|
+
lib/application
|
17
19
|
|
18
20
|
// Helpers # Don't remove this line!
|
19
21
|
app/helpers/application_helper
|
@@ -21,4 +23,6 @@ app/helpers/application_helper
|
|
21
23
|
// Models # Don't remove this line!
|
22
24
|
|
23
25
|
// Controllers # Don't remove this line!
|
24
|
-
app/controllers/application_controller
|
26
|
+
app/controllers/application_controller
|
27
|
+
|
28
|
+
// Fixtures # Don't remove this line!
|
@@ -14,6 +14,7 @@ namespace :choco do
|
|
14
14
|
system 'jim install http://github.com/ahe/choco.libs/raw/master/choco.utils.js'
|
15
15
|
system 'jim install http://github.com/ahe/choco.libs/raw/master/plugins/models/choco.plugins.models.load.js'
|
16
16
|
system 'jim install http://github.com/ahe/choco.libs/raw/master/plugins/sammy/choco.plugins.sammy.smart_renderer.js'
|
17
|
+
system 'jim install http://github.com/appendto/jquery-mockjax/raw/master/jquery.mockjax.js'
|
17
18
|
system 'jim bundle lib/bundled.js'
|
18
19
|
end
|
19
20
|
end
|
@@ -2,11 +2,13 @@ var app = $.sammy(function() {
|
|
2
2
|
|
3
3
|
this.element_selector = '#choco';
|
4
4
|
this.template_engine = 'template';
|
5
|
+
this.project_path = '/<%= name %>';
|
6
|
+
this.fixtures = true;
|
5
7
|
|
6
8
|
// Configure your Sammy JS plugins
|
7
9
|
this.use(Sammy.Template);
|
8
10
|
this.use(Sammy.NestedParams);
|
9
|
-
this.use(Sammy.SmartRenderer,
|
11
|
+
this.use(Sammy.SmartRenderer, this.project_path + '/app/views/');
|
10
12
|
|
11
13
|
// Event fired by the render() method
|
12
14
|
this.bind('template_loaded', function(e, data) {
|
@@ -0,0 +1,20 @@
|
|
1
|
+
if(app.fixtures) {
|
2
|
+
var model = '{ "id": 1, "title": "Hello Choco!" }';
|
3
|
+
|
4
|
+
$.mockjax({
|
5
|
+
url: '/<%= @name %>/*',
|
6
|
+
responseText: model
|
7
|
+
});
|
8
|
+
|
9
|
+
$.mockjax({
|
10
|
+
url: '/<%= @name %>',
|
11
|
+
type: 'POST',
|
12
|
+
responseText: model
|
13
|
+
});
|
14
|
+
|
15
|
+
$.mockjax({
|
16
|
+
url: '/<%= @name %>',
|
17
|
+
type: 'GET',
|
18
|
+
proxy: app.project_path + '/fixtures/<%= @name %>/<%= @name %>.json'
|
19
|
+
});
|
20
|
+
}
|
@@ -7,6 +7,6 @@ The choco script responds to the following commands and options :
|
|
7
7
|
Your Jimfile will also be maintained by this command.
|
8
8
|
|
9
9
|
generate <generator_name> <resource_name> [options]
|
10
|
-
Available generators are : controller, model, scaffold, layout, plugin
|
10
|
+
Available generators are : controller, model, scaffold, fixture, layout, plugin
|
11
11
|
Run '$ choco generate', for more information.
|
12
12
|
|
@@ -23,6 +23,15 @@ scaffold <url>
|
|
23
23
|
The fields will be determined from the JSON returned by your URL
|
24
24
|
e.g : http://localhost:3000/posts.json
|
25
25
|
|
26
|
+
fixture
|
27
|
+
$ choco generate fixture <resource_name>
|
28
|
+
|
29
|
+
It will create fixture & JSON files.
|
30
|
+
resource_name will be pluralized.
|
31
|
+
|
32
|
+
$ choco generate fixture post
|
33
|
+
Will mock requests sent to /posts
|
34
|
+
|
26
35
|
layout
|
27
36
|
$ choco generate layout <layout_name>
|
28
37
|
|
@@ -68,6 +68,16 @@ describe Choco::DependencyManager do
|
|
68
68
|
|
69
69
|
end
|
70
70
|
|
71
|
+
describe "when it's a fixture" do
|
72
|
+
|
73
|
+
it "should add an entry in the Jimfile (models section)" do
|
74
|
+
in_file('Jimfile', 'fixtures/posts').should == 0
|
75
|
+
Choco::DependencyManager.add_dependency('fixtures/posts.js')
|
76
|
+
in_file('Jimfile', 'fixtures/posts', "// Fixtures # Don't remove this line!").should == 1
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
71
81
|
describe "when it's a lib" do
|
72
82
|
|
73
83
|
it "should add an entry in the Jimfile (libs section)" do
|
data/spec/generators_spec.rb
CHANGED
@@ -42,6 +42,10 @@ describe "Generators" do
|
|
42
42
|
File.exist?(@project_path + '/stylesheets/application.css').should be_true
|
43
43
|
end
|
44
44
|
|
45
|
+
it "should generate the fixtures folder" do
|
46
|
+
File.exist?(@project_path + '/fixtures').should be_true
|
47
|
+
end
|
48
|
+
|
45
49
|
it "should generate the spec folder" do
|
46
50
|
File.exist?(@project_path + '/spec').should be_true
|
47
51
|
end
|
@@ -64,7 +68,7 @@ describe "Generators" do
|
|
64
68
|
|
65
69
|
it "should set the views path to the project views folder" do
|
66
70
|
file = get_file_as_string(@project_path + '/app/controllers/application_controller.js')
|
67
|
-
file.include?("this.
|
71
|
+
file.include?("this.project_path = '/spec/tmp/test_project';").should be_true
|
68
72
|
end
|
69
73
|
end
|
70
74
|
|
@@ -188,6 +192,30 @@ describe "Generators" do
|
|
188
192
|
|
189
193
|
end
|
190
194
|
|
195
|
+
describe Choco::FixtureGenerator do
|
196
|
+
it "should generate a fixture file" do
|
197
|
+
Choco::FixtureGenerator.start 'posts'
|
198
|
+
File.exist?('fixtures/posts.js').should be_true
|
199
|
+
end
|
200
|
+
|
201
|
+
it "should generate a fixture folder" do
|
202
|
+
Choco::FixtureGenerator.start 'posts'
|
203
|
+
File.exist?('fixtures/posts').should be_true
|
204
|
+
File.exist?('fixtures/posts/posts.json').should be_true
|
205
|
+
end
|
206
|
+
|
207
|
+
describe "templates" do
|
208
|
+
|
209
|
+
it "the URL should have a correct format" do
|
210
|
+
Choco::FixtureGenerator.start 'post'
|
211
|
+
file = get_file_as_string('fixtures/posts.js')
|
212
|
+
file.include?("url: '/posts',").should be_true
|
213
|
+
end
|
214
|
+
|
215
|
+
end
|
216
|
+
|
217
|
+
end
|
218
|
+
|
191
219
|
describe Choco::PluginGenerator do
|
192
220
|
it "should generate a plugin file" do
|
193
221
|
Choco::PluginGenerator.start 'live'
|
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
|
+
- 2
|
9
|
+
version: 0.1.2
|
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-28 00:00:00 +02:00
|
18
18
|
default_executable: choco
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -102,6 +102,7 @@ files:
|
|
102
102
|
- lib/choco/dependency_manager.rb
|
103
103
|
- lib/choco/generators/app_generator.rb
|
104
104
|
- lib/choco/generators/controller_generator.rb
|
105
|
+
- lib/choco/generators/fixture_generator.rb
|
105
106
|
- lib/choco/generators/layout_generator.rb
|
106
107
|
- lib/choco/generators/model_generator.rb
|
107
108
|
- lib/choco/generators/plugin_generator.rb
|
@@ -114,6 +115,8 @@ files:
|
|
114
115
|
- lib/choco/generators/templates/controllers/application_controller.js
|
115
116
|
- lib/choco/generators/templates/controllers/base_controller.js
|
116
117
|
- lib/choco/generators/templates/controllers/rest_controller.js
|
118
|
+
- lib/choco/generators/templates/fixtures/base.js
|
119
|
+
- lib/choco/generators/templates/fixtures/model/array.js
|
117
120
|
- lib/choco/generators/templates/help/commands
|
118
121
|
- lib/choco/generators/templates/help/generators
|
119
122
|
- lib/choco/generators/templates/helpers/application_helper.js
|