spinebox 0.0.5 → 0.0.6

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.
Files changed (42) hide show
  1. data/Gemfile +1 -0
  2. data/README.textile +17 -0
  3. data/bin/spinebox +41 -1
  4. data/lib/spinebox/command.rb +10 -0
  5. data/lib/spinebox/generator.rb +94 -13
  6. data/lib/spinebox/templates/controller/controller.js.coffee.erb +7 -0
  7. data/lib/spinebox/templates/model/model.js.coffee.erb +3 -0
  8. data/lib/spinebox/version.rb +1 -1
  9. data/lib/spinebox.rb +2 -0
  10. data/spec/base_spec.rb +1 -1
  11. data/spec/compiler_spec.rb +1 -1
  12. data/spec/config_spec.rb +1 -1
  13. data/spec/erb_context_spec.rb +1 -1
  14. data/spec/generator_spec.rb +81 -13
  15. data/spec/routes_spec.rb +1 -1
  16. metadata +29 -27
  17. /data/lib/spinebox/templates/{Gemfile → app/Gemfile} +0 -0
  18. /data/lib/spinebox/templates/{Rakefile → app/Rakefile} +0 -0
  19. /data/lib/spinebox/templates/app/{assets → app/assets}/images/.gitignore +0 -0
  20. /data/lib/spinebox/templates/app/{assets → app/assets}/javascripts/app/config/namespace.js.coffee +0 -0
  21. /data/lib/spinebox/templates/app/{assets → app/assets}/javascripts/app/config/routes.js.coffee +0 -0
  22. /data/lib/spinebox/templates/app/{assets → app/assets}/javascripts/app/controllers/.gitignore +0 -0
  23. /data/lib/spinebox/templates/app/{assets → app/assets}/javascripts/app/controllers/root.js.coffee +0 -0
  24. /data/lib/spinebox/templates/app/{assets → app/assets}/javascripts/app/index.js.coffee +0 -0
  25. /data/lib/spinebox/templates/app/{assets → app/assets}/javascripts/app/models/.gitignore +0 -0
  26. /data/lib/spinebox/templates/app/{assets → app/assets}/javascripts/app/views/.gitignore +0 -0
  27. /data/lib/spinebox/templates/app/{assets → app/assets}/javascripts/app/views/root.jst.eco +0 -0
  28. /data/lib/spinebox/templates/app/{assets → app/assets}/javascripts/application.js.coffee +0 -0
  29. /data/lib/spinebox/templates/app/{assets → app/assets}/javascripts/lib/jquery.js +0 -0
  30. /data/lib/spinebox/templates/app/{assets → app/assets}/javascripts/lib/json2.js +0 -0
  31. /data/lib/spinebox/templates/app/{assets → app/assets}/javascripts/lib/spine/ajax.coffee +0 -0
  32. /data/lib/spinebox/templates/app/{assets → app/assets}/javascripts/lib/spine/list.coffee +0 -0
  33. /data/lib/spinebox/templates/app/{assets → app/assets}/javascripts/lib/spine/local.coffee +0 -0
  34. /data/lib/spinebox/templates/app/{assets → app/assets}/javascripts/lib/spine/manager.coffee +0 -0
  35. /data/lib/spinebox/templates/app/{assets → app/assets}/javascripts/lib/spine/relation.coffee +0 -0
  36. /data/lib/spinebox/templates/app/{assets → app/assets}/javascripts/lib/spine/route.coffee +0 -0
  37. /data/lib/spinebox/templates/app/{assets → app/assets}/javascripts/lib/spine/spine.coffee +0 -0
  38. /data/lib/spinebox/templates/app/{assets → app/assets}/stylesheets/application.css.scss +0 -0
  39. /data/lib/spinebox/templates/app/{views → app/views}/index.html.erb +0 -0
  40. /data/lib/spinebox/templates/{config → app/config}/config.rb +0 -0
  41. /data/lib/spinebox/templates/{config → app/config}/routes.rb +0 -0
  42. /data/lib/spinebox/templates/{config.ru → app/config.ru} +0 -0
data/Gemfile CHANGED
@@ -10,3 +10,4 @@ gem 'coffee_script'
10
10
  gem 'eco'
11
11
  gem 'sass'
12
12
  gem 'colorize'
13
+ gem 'active_support'
data/README.textile CHANGED
@@ -5,6 +5,7 @@ A ready to use spine.js rack skeleton builder with development server, routes, c
5
5
  * Ideal for single or few page applications
6
6
  * Fully setup, ready to go spine.js environment
7
7
  * Develop in coffee-script and sass with fantastic sprockets asset serving
8
+ * Use generators and scaffolding just like with rails
8
9
  * Compile assets and serve the whole app completely static
9
10
 
10
11
  h3. Installation
@@ -13,11 +14,27 @@ bc.. $ gem install spinebox
13
14
 
14
15
  h3. Usage
15
16
 
17
+ h4. Create new project
18
+
16
19
  bc.. # Create new project an start developing
17
20
  $ spinebox new blog
18
21
  $ cd blog
19
22
  $ spinebox server
20
23
 
24
+ h4. Generate models, views and controllers
25
+
26
+ bc.. # Generate a model view and a controller
27
+ $ spinebox generate model post title author body
28
+ $ spinebox generate controller posts
29
+ $ spinebox generate view post
30
+
31
+ h4. Scaffold
32
+
33
+ bc.. # Or scaffold all three of them
34
+ $ spinebox scaffold post title author body
35
+
36
+ h4. Compile project
37
+
21
38
  bc.. # Compile project for static serving
22
39
  $ spinebox compile
23
40
 
data/bin/spinebox CHANGED
@@ -19,7 +19,7 @@ Spinebox::Command.dispatch do
19
19
  # New application
20
20
  on "new APP", "Create a new APP", :if => proc { ['new', 'n'].include?(ARGV.first) }, :type => :action do
21
21
  ARGV.shift
22
- Spinebox::Generator.new(ARGV.first)
22
+ Spinebox::Generator::Application.new(ARGV.first)
23
23
  puts "Successfully created '#{ARGV.first}'".green
24
24
  exit(0)
25
25
  end
@@ -37,4 +37,44 @@ Spinebox::Command.dispatch do
37
37
  Rack::Handler::Thin.run(Spinebox.app, :Port => 3000)
38
38
  end
39
39
 
40
+
41
+ # Model Generator
42
+ on "generate model MODEL [attributes]", "Generate a model with attributes", :if => proc { ['generate', 'g'].include?(ARGV.first) and ['model', 'm'].include?(ARGV[1])}, :type => :generator do
43
+ ARGV.shift
44
+ ARGV.shift
45
+ name = ARGV.shift
46
+ model = Spinebox::Generator::Model.new(name, ARGV)
47
+ puts "Successfully created model '#{model.name}'".green
48
+ exit(0)
49
+ end
50
+
51
+ # Controller Generator
52
+ on "generate controller CONTROLLER", "Generate a controller", :if => proc { ['generate', 'g'].include?(ARGV.first) and ['controller', 'c'].include?(ARGV[1])}, :type => :generator do
53
+ ARGV.shift
54
+ ARGV.shift
55
+ controller = Spinebox::Generator::Controller.new(ARGV.first)
56
+ puts "Successfully created controller '#{controller.name}'".green
57
+ exit(0)
58
+ end
59
+
60
+ # View Generator
61
+ on "generate view VIEW", "Generate a view", :if => proc { ['generate', 'g'].include?(ARGV.first) and ['view', 'v'].include?(ARGV[1])}, :type => :generator do
62
+ ARGV.shift
63
+ ARGV.shift
64
+ view = Spinebox::Generator::View.new(ARGV.first)
65
+ puts "Successfully created view '#{view.name}'".green
66
+ exit(0)
67
+ end
68
+
69
+ # View Generator
70
+ on "scaffold MODEL [attributes]", "Scaffold a model, view and a controller", :if => proc { ['scaffold', 's'].include?(ARGV.first)}, :type => :scaffold do
71
+ ARGV.shift
72
+ name = ARGV.shift
73
+ model = Spinebox::Generator::Model.new(name, ARGV)
74
+ view = Spinebox::Generator::View.new(name)
75
+ controller = Spinebox::Generator::Controller.new(name)
76
+ puts "Successfully scaffolded model, view and controller '#{model.name}'".green
77
+ exit(0)
78
+ end
79
+
40
80
  end
@@ -37,6 +37,16 @@ module Spinebox
37
37
 
38
38
  puts "Actions:"
39
39
  @@commands.each { |command| printf "%-3s %-20s %s\n", "", command.command, command.desc if command.options[:type] == :action }
40
+
41
+ puts ""
42
+
43
+ puts "Generators:"
44
+ @@commands.each { |command| printf "%-3s %-40s %s\n", "", command.command, command.desc if command.options[:type] == :generator }
45
+
46
+ puts ""
47
+
48
+ puts "Scaffolds:"
49
+ @@commands.each { |command| printf "%-3s %-40s %s\n", "", command.command, command.desc if command.options[:type] == :scaffold }
40
50
  end
41
51
 
42
52
  # Encapsules a registered command
@@ -1,24 +1,105 @@
1
1
  module Spinebox
2
- class Generator
2
+ module Generator
3
+
4
+ # Generates an application skeleton
5
+ class Application
6
+ attr_reader :root
7
+
8
+ # Creates a new app and copies the templates to the newly created directory
9
+ def initialize app
10
+ @app = app
11
+ create_app_directory
12
+ copy_templates
13
+ end
14
+
15
+ private
16
+ def create_app_directory
17
+ FileUtils.mkdir @app
18
+ @root = File.realdirpath @app
19
+ end
20
+
21
+ def copy_templates
22
+ FileUtils.cp_r "#{Spinebox.root}/templates/app/.", @root
23
+ end
24
+ end
3
25
 
4
- attr_reader :root
5
26
 
6
- # Creates a new app and copies the templates to the newly created directory
7
- def initialize app
8
- @app = app
9
- create_app_directory
10
- copy_templates
27
+ # Generates a model
28
+ class Model
29
+
30
+ attr_reader :name
31
+ attr_reader :attributes
32
+ attr_reader :source
33
+ attr_reader :source_name
34
+
35
+ def initialize name, attributes = []
36
+ @name, @source_name, @attributes = name.camelize, name, attributes
37
+ compile_template
38
+ write_source
39
+ end
40
+
41
+ private
42
+ def compile_template
43
+ @source = ERB.new(File.open("#{Spinebox.root}/templates/model/model.js.coffee.erb").read).result(binding)
44
+ end
45
+
46
+ def write_source
47
+ File.open("app/assets/javascripts/app/models/#{@source_name}.js.coffee", "w"){ |file| file.write(@source) }
48
+ end
49
+
11
50
  end
12
51
 
13
- private
14
- def create_app_directory
15
- FileUtils.mkdir @app
16
- @root = File.realdirpath @app
52
+ # Generates a controller
53
+ class Controller
54
+
55
+ attr_reader :name
56
+ attr_reader :source
57
+ attr_reader :source_name
58
+
59
+
60
+ def initialize name
61
+ @name, @source_name, @view_name = name.pluralize.camelize, name.pluralize, name.singularize
62
+ compile_template
63
+ write_source
64
+ end
65
+
66
+ private
67
+ def compile_template
68
+ @source = ERB.new(File.open("#{Spinebox.root}/templates/controller/controller.js.coffee.erb").read).result(binding)
69
+ end
70
+
71
+ def write_source
72
+ File.open("app/assets/javascripts/app/controllers/#{@source_name}.js.coffee", "w"){ |file| file.write(@source) }
73
+ end
74
+
17
75
  end
18
76
 
19
- def copy_templates
20
- FileUtils.cp_r "#{Spinebox.root}/templates/.", @root
77
+
78
+ # Generates a view
79
+ class View
80
+
81
+ attr_reader :name
82
+ attr_reader :source
83
+ attr_reader :source_name
84
+
85
+
86
+ def initialize name
87
+ @name, @source_name = name.camelize, name
88
+ write_source
89
+ end
90
+
91
+ private
92
+ def compile_template
93
+ @source = ""
94
+ end
95
+
96
+ def write_source
97
+ File.open("app/assets/javascripts/app/views/#{@source_name}.jst.eco", "w"){ |file| file.write(@source) }
98
+ end
99
+
21
100
  end
22
101
 
102
+
103
+
23
104
  end
24
105
  end
@@ -0,0 +1,7 @@
1
+ class App.<%= @name %> extends Spine.Controller
2
+ constructor: ->
3
+ super
4
+ @render()
5
+
6
+ render: ->
7
+ @html JST['app/views/<%= @view_name %>'](@)
@@ -0,0 +1,3 @@
1
+ class App.<%= @name %> extends Spine.Model
2
+ @configure '<%= @name %>', <%= @attributes.map{ |attribute| "'#{attribute}'" }.join(", ") %>
3
+ @extend Spine.Model.Ajax
@@ -1,3 +1,3 @@
1
1
  module Spinebox
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
data/lib/spinebox.rb CHANGED
@@ -5,6 +5,8 @@ require 'eco'
5
5
  require 'sass'
6
6
  require "colorize"
7
7
  require "ostruct"
8
+ require 'active_support/all'
9
+ require 'erb'
8
10
 
9
11
  require "spinebox/version"
10
12
  require "spinebox/base"
data/spec/base_spec.rb CHANGED
@@ -7,7 +7,7 @@ describe Spinebox::Base do
7
7
  end
8
8
 
9
9
  it "should boot" do
10
- Dir.chdir "#{Spinebox.root}/templates"
10
+ Dir.chdir "#{Spinebox.root}/templates/app"
11
11
  lambda{ Spinebox.boot! }.should_not raise_exception
12
12
  end
13
13
 
@@ -3,7 +3,7 @@ require_relative "./helpers"
3
3
  describe Spinebox::Compiler do
4
4
 
5
5
  before(:each) do
6
- Dir.chdir "#{Spinebox.root}/templates"
6
+ Dir.chdir "#{Spinebox.root}/templates/app"
7
7
  Spinebox.boot!
8
8
  File.new("app/assets/images/test.png", "w")
9
9
  end
data/spec/config_spec.rb CHANGED
@@ -4,7 +4,7 @@ describe Spinebox do
4
4
 
5
5
  before(:each) do
6
6
  Spinebox::Config.reset!
7
- Dir.chdir "#{Spinebox.root}/templates"
7
+ Dir.chdir "#{Spinebox.root}/templates/app"
8
8
  end
9
9
 
10
10
  it "should offer a block style config method" do
@@ -3,7 +3,7 @@ require_relative "./helpers"
3
3
  describe Spinebox::ERBContext do
4
4
 
5
5
  before(:all) do
6
- Dir.chdir "#{Spinebox.root}/templates"
6
+ Dir.chdir "#{Spinebox.root}/templates/app"
7
7
  Spinebox.boot!
8
8
  end
9
9
 
@@ -2,24 +2,92 @@ require_relative "./helpers"
2
2
 
3
3
  describe Spinebox::Generator do
4
4
 
5
- before(:each) do
6
- Dir.chdir(File.dirname(__FILE__))
7
- FileUtils.rm_rf("tmp")
8
- FileUtils.mkdir("tmp")
9
- Dir.chdir "tmp"
5
+ context "app" do
6
+
7
+ before(:each) do
8
+ Dir.chdir(File.dirname(__FILE__))
9
+ FileUtils.rm_rf("tmp")
10
+ FileUtils.mkdir("tmp")
11
+ Dir.chdir "tmp"
12
+ end
13
+
14
+ after(:each) do
15
+ Dir.chdir ".."
16
+ FileUtils.rm_rf("tmp")
17
+ end
18
+
19
+ it "should be generated with name" do
20
+ File.directory?("box").should_not be_true
21
+
22
+ generator = Spinebox::Generator::Application.new "box"
23
+ File.directory?(generator.root).should be_true
24
+ Dir["#{generator.root}/**/*"].should have_at_least(5).files
25
+ end
26
+
10
27
  end
11
28
 
12
- after(:each) do
13
- Dir.chdir ".."
14
- FileUtils.rm_rf("tmp")
29
+ context "model" do
30
+
31
+ before(:each) do
32
+ Dir.chdir "#{Spinebox.root}/templates/app"
33
+ Spinebox.boot!
34
+ end
35
+
36
+ it "should be generated with attributes" do
37
+ File.exists?("app/assets/javascripts/app/models/post.js.coffee").should_not be_true
38
+
39
+ generator = Spinebox::Generator::Model.new "post", ["title", "date", "author"]
40
+ generator.source_name.should == "post"
41
+ generator.name.should == "Post"
42
+ generator.attributes.should == ["title", "date", "author"]
43
+ generator.source.include?("App.Post").should be_true
44
+ generator.source.include?("'title', 'date', 'author'").should be_true
45
+
46
+ File.exists?("app/assets/javascripts/app/models/post.js.coffee").should be_true
47
+ FileUtils.rm("app/assets/javascripts/app/models/post.js.coffee")
48
+ end
49
+
15
50
  end
16
51
 
17
- it "should generate app with name" do
18
- File.directory?("box").should_not be_true
52
+ context "controller" do
53
+
54
+ before(:each) do
55
+ Dir.chdir "#{Spinebox.root}/templates/app"
56
+ Spinebox.boot!
57
+ end
58
+
59
+ it "should be generated" do
60
+ File.exists?("app/assets/javascripts/app/controllers/posts.js.coffee").should_not be_true
61
+
62
+ generator = Spinebox::Generator::Controller.new "posts"
63
+ generator.source_name.should == "posts"
64
+ generator.name.should == "Posts"
65
+ generator.source.include?("App.Posts").should be_true
66
+
67
+ File.exists?("app/assets/javascripts/app/controllers/posts.js.coffee").should be_true
68
+ FileUtils.rm("app/assets/javascripts/app/controllers/posts.js.coffee")
69
+ end
70
+
71
+ end
72
+
73
+ context "view" do
74
+
75
+ before(:each) do
76
+ Dir.chdir "#{Spinebox.root}/templates/app"
77
+ Spinebox.boot!
78
+ end
79
+
80
+ it "should be generated" do
81
+ File.exists?("app/assets/javascripts/app/views/post.jst.eco").should_not be_true
82
+
83
+ generator = Spinebox::Generator::View.new "post"
84
+ generator.source_name.should == "post"
85
+ generator.name.should == "Post"
86
+
87
+ File.exists?("app/assets/javascripts/app/views/post.jst.eco").should be_true
88
+ FileUtils.rm("app/assets/javascripts/app/views/post.jst.eco")
89
+ end
19
90
 
20
- generator = Spinebox::Generator.new "box"
21
- File.directory?(generator.root).should be_true
22
- Dir["#{generator.root}/**/*"].should have_at_least(5).files
23
91
  end
24
92
 
25
93
  end
data/spec/routes_spec.rb CHANGED
@@ -3,7 +3,7 @@ require_relative "./helpers"
3
3
  describe Spinebox do
4
4
 
5
5
  before(:each) do
6
- Dir.chdir "#{Spinebox.root}/templates"
6
+ Dir.chdir "#{Spinebox.root}/templates/app"
7
7
  Spinebox::Routes.reset!
8
8
  end
9
9
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spinebox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -35,32 +35,34 @@ files:
35
35
  - lib/spinebox/generator.rb
36
36
  - lib/spinebox/routes.rb
37
37
  - lib/spinebox/templates/.DS_Store
38
- - lib/spinebox/templates/Gemfile
39
- - lib/spinebox/templates/Rakefile
40
- - lib/spinebox/templates/app/assets/images/.gitignore
41
- - lib/spinebox/templates/app/assets/javascripts/app/config/namespace.js.coffee
42
- - lib/spinebox/templates/app/assets/javascripts/app/config/routes.js.coffee
43
- - lib/spinebox/templates/app/assets/javascripts/app/controllers/.gitignore
44
- - lib/spinebox/templates/app/assets/javascripts/app/controllers/root.js.coffee
45
- - lib/spinebox/templates/app/assets/javascripts/app/index.js.coffee
46
- - lib/spinebox/templates/app/assets/javascripts/app/models/.gitignore
47
- - lib/spinebox/templates/app/assets/javascripts/app/views/.gitignore
48
- - lib/spinebox/templates/app/assets/javascripts/app/views/root.jst.eco
49
- - lib/spinebox/templates/app/assets/javascripts/application.js.coffee
50
- - lib/spinebox/templates/app/assets/javascripts/lib/jquery.js
51
- - lib/spinebox/templates/app/assets/javascripts/lib/json2.js
52
- - lib/spinebox/templates/app/assets/javascripts/lib/spine/ajax.coffee
53
- - lib/spinebox/templates/app/assets/javascripts/lib/spine/list.coffee
54
- - lib/spinebox/templates/app/assets/javascripts/lib/spine/local.coffee
55
- - lib/spinebox/templates/app/assets/javascripts/lib/spine/manager.coffee
56
- - lib/spinebox/templates/app/assets/javascripts/lib/spine/relation.coffee
57
- - lib/spinebox/templates/app/assets/javascripts/lib/spine/route.coffee
58
- - lib/spinebox/templates/app/assets/javascripts/lib/spine/spine.coffee
59
- - lib/spinebox/templates/app/assets/stylesheets/application.css.scss
60
- - lib/spinebox/templates/app/views/index.html.erb
61
- - lib/spinebox/templates/config.ru
62
- - lib/spinebox/templates/config/config.rb
63
- - lib/spinebox/templates/config/routes.rb
38
+ - lib/spinebox/templates/app/Gemfile
39
+ - lib/spinebox/templates/app/Rakefile
40
+ - lib/spinebox/templates/app/app/assets/images/.gitignore
41
+ - lib/spinebox/templates/app/app/assets/javascripts/app/config/namespace.js.coffee
42
+ - lib/spinebox/templates/app/app/assets/javascripts/app/config/routes.js.coffee
43
+ - lib/spinebox/templates/app/app/assets/javascripts/app/controllers/.gitignore
44
+ - lib/spinebox/templates/app/app/assets/javascripts/app/controllers/root.js.coffee
45
+ - lib/spinebox/templates/app/app/assets/javascripts/app/index.js.coffee
46
+ - lib/spinebox/templates/app/app/assets/javascripts/app/models/.gitignore
47
+ - lib/spinebox/templates/app/app/assets/javascripts/app/views/.gitignore
48
+ - lib/spinebox/templates/app/app/assets/javascripts/app/views/root.jst.eco
49
+ - lib/spinebox/templates/app/app/assets/javascripts/application.js.coffee
50
+ - lib/spinebox/templates/app/app/assets/javascripts/lib/jquery.js
51
+ - lib/spinebox/templates/app/app/assets/javascripts/lib/json2.js
52
+ - lib/spinebox/templates/app/app/assets/javascripts/lib/spine/ajax.coffee
53
+ - lib/spinebox/templates/app/app/assets/javascripts/lib/spine/list.coffee
54
+ - lib/spinebox/templates/app/app/assets/javascripts/lib/spine/local.coffee
55
+ - lib/spinebox/templates/app/app/assets/javascripts/lib/spine/manager.coffee
56
+ - lib/spinebox/templates/app/app/assets/javascripts/lib/spine/relation.coffee
57
+ - lib/spinebox/templates/app/app/assets/javascripts/lib/spine/route.coffee
58
+ - lib/spinebox/templates/app/app/assets/javascripts/lib/spine/spine.coffee
59
+ - lib/spinebox/templates/app/app/assets/stylesheets/application.css.scss
60
+ - lib/spinebox/templates/app/app/views/index.html.erb
61
+ - lib/spinebox/templates/app/config.ru
62
+ - lib/spinebox/templates/app/config/config.rb
63
+ - lib/spinebox/templates/app/config/routes.rb
64
+ - lib/spinebox/templates/controller/controller.js.coffee.erb
65
+ - lib/spinebox/templates/model/model.js.coffee.erb
64
66
  - lib/spinebox/version.rb
65
67
  - spec/base_spec.rb
66
68
  - spec/command_spec.rb
File without changes
File without changes