Skip to content

Commit

Permalink
Add the choco server command to launch your application locally on a …
Browse files Browse the repository at this point in the history
…rack server
  • Loading branch information
Anthony Heukmes committed Jul 31, 2010
1 parent eef51c0 commit f8fb589
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 13 deletions.
4 changes: 4 additions & 0 deletions HISTORY
@@ -1,3 +1,7 @@
== 0.1.3 [08-31-10]
* Add $ choco server command to launch a local rack server
* A config.ru file is created at the root of each new project

== 0.1.2 [08-27-10] == 0.1.2 [08-27-10]
* Add fixtures generate (mock ajax requests) * Add fixtures generate (mock ajax requests)


Expand Down
8 changes: 8 additions & 0 deletions README.rdoc
Expand Up @@ -42,10 +42,18 @@ This will generate your project structure.
You can then install the required JS dependencies (jQuery, Sammy, ...) by executing the following command at the root of your project : You can then install the required JS dependencies (jQuery, Sammy, ...) by executing the following command at the root of your project :


$ rake choco:js:install $ rake choco:js:install

Launch your local server :

$ choco server



== Location == Location


A Choco app is composed of static files (js, css, images, ...), it must be directly accessible on your web server. A Choco app is composed of static files (js, css, images, ...), it must be directly accessible on your web server.

A local Rack web server can be launched directly using the '$ choco server' command. You'll have to install WEBRick or Mongrel.

If you use Rails, you can for example put your Choco app inside the public/javascripts folder. If you use Rails, you can for example put your Choco app inside the public/javascripts folder.


Once you've chosen the location where your application will reside, don't forget to configure the path to your view files. Once you've chosen the location where your application will reside, don't forget to configure the path to your view files.
Expand Down
6 changes: 5 additions & 1 deletion choco.gemspec
Expand Up @@ -9,7 +9,7 @@ Gem::Specification.new do |s|


s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Anthony Heukmes"] s.authors = ["Anthony Heukmes"]
s.date = %q{2010-07-28} s.date = %q{2010-07-31}
s.default_executable = %q{choco} s.default_executable = %q{choco}
s.description = %q{Choco brings the MVC to the client side! It allows you to easily develop maintainable Rich Internet Applications using Javascript.} s.description = %q{Choco brings the MVC to the client side! It allows you to easily develop maintainable Rich Internet Applications using Javascript.}
s.email = %q{anthony.heukmes@skynet.be} s.email = %q{anthony.heukmes@skynet.be}
Expand Down Expand Up @@ -42,6 +42,7 @@ Gem::Specification.new do |s|
"lib/choco/generators/templates/Rakefile", "lib/choco/generators/templates/Rakefile",
"lib/choco/generators/templates/application.css", "lib/choco/generators/templates/application.css",
"lib/choco/generators/templates/choco", "lib/choco/generators/templates/choco",
"lib/choco/generators/templates/config.ru",
"lib/choco/generators/templates/controllers/application_controller.js", "lib/choco/generators/templates/controllers/application_controller.js",
"lib/choco/generators/templates/controllers/base_controller.js", "lib/choco/generators/templates/controllers/base_controller.js",
"lib/choco/generators/templates/controllers/rest_controller.js", "lib/choco/generators/templates/controllers/rest_controller.js",
Expand Down Expand Up @@ -87,19 +88,22 @@ Gem::Specification.new do |s|
s.add_runtime_dependency(%q<fssm>, [">= 0"]) s.add_runtime_dependency(%q<fssm>, [">= 0"])
s.add_runtime_dependency(%q<thor>, [">= 0"]) s.add_runtime_dependency(%q<thor>, [">= 0"])
s.add_runtime_dependency(%q<activesupport>, [">= 0"]) s.add_runtime_dependency(%q<activesupport>, [">= 0"])
s.add_runtime_dependency(%q<rack>, [">= 0"])
s.add_development_dependency(%q<rspec>, [">= 1.2.9"]) s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
else else
s.add_dependency(%q<jim>, [">= 0"]) s.add_dependency(%q<jim>, [">= 0"])
s.add_dependency(%q<fssm>, [">= 0"]) s.add_dependency(%q<fssm>, [">= 0"])
s.add_dependency(%q<thor>, [">= 0"]) s.add_dependency(%q<thor>, [">= 0"])
s.add_dependency(%q<activesupport>, [">= 0"]) s.add_dependency(%q<activesupport>, [">= 0"])
s.add_dependency(%q<rack>, [">= 0"])
s.add_dependency(%q<rspec>, [">= 1.2.9"]) s.add_dependency(%q<rspec>, [">= 1.2.9"])
end end
else else
s.add_dependency(%q<jim>, [">= 0"]) s.add_dependency(%q<jim>, [">= 0"])
s.add_dependency(%q<fssm>, [">= 0"]) s.add_dependency(%q<fssm>, [">= 0"])
s.add_dependency(%q<thor>, [">= 0"]) s.add_dependency(%q<thor>, [">= 0"])
s.add_dependency(%q<activesupport>, [">= 0"]) s.add_dependency(%q<activesupport>, [">= 0"])
s.add_dependency(%q<rack>, [">= 0"])
s.add_dependency(%q<rspec>, [">= 1.2.9"]) s.add_dependency(%q<rspec>, [">= 1.2.9"])
end end
end end
Expand Down
2 changes: 1 addition & 1 deletion lib/choco.rb
Expand Up @@ -3,7 +3,7 @@
require 'active_support/inflector' require 'active_support/inflector'


module Choco module Choco
VERSION = '0.1.2' VERSION = '0.1.3'


autoload :DependencyManager, 'choco/dependency_manager' autoload :DependencyManager, 'choco/dependency_manager'
autoload :CLI, 'choco/cli' autoload :CLI, 'choco/cli'
Expand Down
11 changes: 10 additions & 1 deletion lib/choco/cli.rb
Expand Up @@ -13,7 +13,8 @@ def run
@args << '--help' if @args.empty? @args << '--help' if @args.empty?


aliases = { aliases = {
"g" => "generate" "g" => "generate",
"s" => "server"
} }


command = @args.shift command = @args.shift
Expand All @@ -28,6 +29,14 @@ def run
else else
@output = template('generators') @output = template('generators')
end end

when 'server'
port = 9292
port = @args[@args.index('-p') + 1] if @args.include?('-p')
port = @args[@args.index('--port') + 1] if @args.include?('--port')
puts "*** Choco server is now running on port #{port}"
puts "*** Launch http://localhost:#{port}/index.html to start your Choco application"
system "rackup #{@args.join(' ')}"


when '--watch' when '--watch'
require 'fssm' require 'fssm'
Expand Down
4 changes: 4 additions & 0 deletions lib/choco/generators/app_generator.rb
Expand Up @@ -62,6 +62,10 @@ def create_rakefile
template('templates/Rakefile', "#{name}/Rakefile") template('templates/Rakefile', "#{name}/Rakefile")
end end


def create_rackup_file
template('templates/config.ru', "#{name}/config.ru")
end

def create_readme_file def create_readme_file
create_file "#{name}/README.rdoc" create_file "#{name}/README.rdoc"
end end
Expand Down
3 changes: 3 additions & 0 deletions lib/choco/generators/templates/config.ru
@@ -0,0 +1,3 @@
map '/' do
run Rack::Directory.new('.')
end
Expand Up @@ -2,7 +2,7 @@ var app = $.sammy(function() {


this.element_selector = '#choco'; this.element_selector = '#choco';
this.template_engine = 'template'; this.template_engine = 'template';
this.project_path = '/<%= name %>'; this.project_path = '';
this.fixtures = true; this.fixtures = true;


// Configure your Sammy JS plugins // Configure your Sammy JS plugins
Expand Down
6 changes: 5 additions & 1 deletion lib/choco/generators/templates/help/commands
Expand Up @@ -9,4 +9,8 @@ The choco script responds to the following commands and options :
generate <generator_name> <resource_name> [options] generate <generator_name> <resource_name> [options]
Available generators are : controller, model, scaffold, fixture, layout, plugin Available generators are : controller, model, scaffold, fixture, layout, plugin
Run '$ choco generate', for more information. Run '$ choco generate', for more information.


server [options]
-s, --server SERVER serve using SERVER (webrick/mongrel)
-p, --port PORT use PORT (default: 9292)

8 changes: 0 additions & 8 deletions spec/generators_spec.rb
Expand Up @@ -64,14 +64,6 @@


describe "templates" do describe "templates" do


describe "ApplicationController" do

it "should set the views path to the project views folder" do
file = get_file_as_string(@project_path + '/app/controllers/application_controller.js')
file.include?("this.project_path = '/spec/tmp/test_project';").should be_true
end
end

describe "index.html" do describe "index.html" do


before(:all) do before(:all) do
Expand Down

0 comments on commit f8fb589

Please sign in to comment.