rails-backbone-sp 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.md +89 -0
  3. data/Rakefile +48 -0
  4. data/lib/backbone-rails.rb +6 -0
  5. data/lib/generators/backbone/install/install_generator.rb +34 -0
  6. data/lib/generators/backbone/install/templates/app.coffee +11 -0
  7. data/lib/generators/backbone/model/model_generator.rb +19 -0
  8. data/lib/generators/backbone/model/templates/model.coffee +11 -0
  9. data/lib/generators/backbone/resource_helpers.rb +55 -0
  10. data/lib/generators/backbone/router/router_generator.rb +51 -0
  11. data/lib/generators/backbone/router/templates/router-sp.coffee +14 -0
  12. data/lib/generators/backbone/router/templates/router.coffee +14 -0
  13. data/lib/generators/backbone/router/templates/template.jst +2 -0
  14. data/lib/generators/backbone/router/templates/view.coffee +8 -0
  15. data/lib/generators/backbone/scaffold/scaffold_generator.rb +52 -0
  16. data/lib/generators/backbone/scaffold/templates/model.coffee +11 -0
  17. data/lib/generators/backbone/scaffold/templates/router-sp.coffee +31 -0
  18. data/lib/generators/backbone/scaffold/templates/router.coffee +31 -0
  19. data/lib/generators/backbone/scaffold/templates/templates/edit.jst +17 -0
  20. data/lib/generators/backbone/scaffold/templates/templates/index.jst +16 -0
  21. data/lib/generators/backbone/scaffold/templates/templates/model.jst +7 -0
  22. data/lib/generators/backbone/scaffold/templates/templates/new.jst +17 -0
  23. data/lib/generators/backbone/scaffold/templates/templates/show.jst +9 -0
  24. data/lib/generators/backbone/scaffold/templates/templates-sp/edit.jst +17 -0
  25. data/lib/generators/backbone/scaffold/templates/templates-sp/index.jst +16 -0
  26. data/lib/generators/backbone/scaffold/templates/templates-sp/model.jst +7 -0
  27. data/lib/generators/backbone/scaffold/templates/templates-sp/new.jst +17 -0
  28. data/lib/generators/backbone/scaffold/templates/templates-sp/show.jst +9 -0
  29. data/lib/generators/backbone/scaffold/templates/views/edit_view.coffee +24 -0
  30. data/lib/generators/backbone/scaffold/templates/views/index_view.coffee +22 -0
  31. data/lib/generators/backbone/scaffold/templates/views/model_view.coffee +19 -0
  32. data/lib/generators/backbone/scaffold/templates/views/new_view.coffee +37 -0
  33. data/lib/generators/backbone/scaffold/templates/views/show_view.coffee +8 -0
  34. data/lib/generators/backbone/scaffold/templates/views-sp/edit_view.coffee +24 -0
  35. data/lib/generators/backbone/scaffold/templates/views-sp/index_view.coffee +22 -0
  36. data/lib/generators/backbone/scaffold/templates/views-sp/model_view.coffee +19 -0
  37. data/lib/generators/backbone/scaffold/templates/views-sp/new_view.coffee +37 -0
  38. data/lib/generators/backbone/scaffold/templates/views-sp/show_view.coffee +8 -0
  39. data/lib/rails-backbone.rb +2 -0
  40. data/lib/tasks/backbone-rails_tasks.rake +4 -0
  41. data/vendor/assets/javascripts/backbone.js +1158 -0
  42. data/vendor/assets/javascripts/backbone_datalink.js +21 -0
  43. data/vendor/assets/javascripts/backbone_rails_sync.js +59 -0
  44. data/vendor/assets/javascripts/underscore.js +845 -0
  45. metadata +157 -0
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2011 Ryan Fitzgerald
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,89 @@
1
+ # Backbone-Rails [![Build Status](https://secure.travis-ci.org/codebrew/backbone-rails.png)](http://travis-ci.org/codebrew/backbone-rails)
2
+
3
+ Easily setup and use backbone.js (0.5.0) with rails 3.1
4
+
5
+ ## Rails 3.1 setup
6
+ This gem requires the use of rails 3.1, coffeescript and the new rails asset pipeline provided by sprockets.
7
+
8
+ This gem vendors the latest version of underscore.js and backbone.js for Rails 3.1 and greater. The files will be added to the asset pipeline and available for you to use.
9
+
10
+ ### Installation
11
+
12
+ In your Gemfile, add this line:
13
+
14
+ gem "rails-backbone"
15
+
16
+ Then run the following commands:
17
+
18
+ bundle install
19
+ rails g backbone:install
20
+
21
+ ### Layout and namespacing
22
+
23
+ Running `rails g backbone:install` will create the following directory structure under `app/assets/javascripts/backbone`:
24
+
25
+ routers/
26
+ models/
27
+ templates/
28
+ views/
29
+
30
+ It will also create a toplevel app_name.coffee file to setup namespacing and setup initial requires.
31
+
32
+ ## Generators
33
+ backbone-rails provides 3 simple generators to help get you started using backbone.js with rails 3.1.
34
+ The generators will only create client side code (javascript).
35
+
36
+ ### Model Generator
37
+
38
+ rails g backbone:model
39
+
40
+ This generator creates a backbone model and collection inside `app/assets/javascript/backbone/models` to be used to talk to the rails backend.
41
+
42
+ ### Routers
43
+
44
+ rails g backbone:router
45
+
46
+ This generator creates a backbone router with corresponding views and templates for the given actions provided.
47
+
48
+ ### Scaffolding
49
+
50
+ rails g backbone:scaffold
51
+
52
+ This generator creates a router, views, templates, model and collection to create a simple crud single page app
53
+
54
+ ## Example Usage
55
+
56
+ Created a new rails 3.1 application called `blog`.
57
+
58
+ rails new blog
59
+
60
+ Edit your Gemfile and add
61
+
62
+ gem 'rails-backbone'
63
+
64
+ Install the gem and generate scaffolding.
65
+
66
+ bundle install
67
+ rails g backbone:install
68
+ rails g scaffold Post title:string content:string
69
+ rake db:migrate
70
+ rails g backbone:scaffold Post title:string content:string
71
+
72
+ You now have installed the backbone-rails gem, setup a default directory structure for your frontend backbone code.
73
+ Then you generated the usual rails server side crud scaffolding and finally generated backbone.js code to provide a simple single page crud app.
74
+ You have one last step:
75
+
76
+ Edit your posts index view `app/views/posts/index.html.erb` with the following contents:
77
+
78
+ <div id="posts"></div>
79
+
80
+ <script type="text/javascript">
81
+ $(function() {
82
+ // Blog is the app name
83
+ window.router = new Blog.Routers.PostsRouter({posts: <%= @posts.to_json.html_safe -%>});
84
+ Backbone.history.start();
85
+ });
86
+ </script>
87
+
88
+ Now start your server `rails s` and browse to [localhost:3000/posts](http://localhost:3000/posts)
89
+ You should now have a fully functioning single page crud app for Post models.
data/Rakefile ADDED
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+
8
+ require 'bundler/gem_tasks'
9
+ require 'rdoc/task'
10
+
11
+ RDoc::Task.new(:rdoc) do |rdoc|
12
+ rdoc.rdoc_dir = 'rdoc'
13
+ rdoc.title = 'BackboneRails'
14
+ rdoc.options << '--line-numbers' << '--inline-source'
15
+ rdoc.rdoc_files.include('README.md')
16
+ rdoc.rdoc_files.include('lib/**/*.rb')
17
+ end
18
+
19
+ require 'rake/testtask'
20
+
21
+ Rake::TestTask.new(:test) do |t|
22
+ t.libs << 'lib'
23
+ t.libs << 'test'
24
+ t.pattern = 'test/**/*_test.rb'
25
+ t.verbose = false
26
+ end
27
+
28
+ task :default => :test
29
+
30
+ namespace :backbone do
31
+ desc "Download the latest versions of underscore and backbone.js from git"
32
+ task :download_latest do
33
+ files = {
34
+ 'underscore.js'=>'https://github.com/documentcloud/underscore/raw/master/underscore.js',
35
+ 'backbone.js' => 'https://github.com/documentcloud/backbone/raw/master/backbone.js'
36
+ }
37
+
38
+ vendor_dir = "vendor/assets/javascripts"
39
+
40
+ require 'open-uri'
41
+ files.each do |local,remote|
42
+ puts "Downloading #{local}"
43
+ File.open "#{vendor_dir}/#{local}", 'w' do |f|
44
+ f.write open(remote).read
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,6 @@
1
+ require 'rails'
2
+
3
+ module BackboneRails
4
+ class Engine < Rails::Engine
5
+ end
6
+ end
@@ -0,0 +1,34 @@
1
+ require 'generators/backbone/resource_helpers'
2
+
3
+ module Backbone
4
+ module Generators
5
+ class InstallGenerator < Rails::Generators::Base
6
+ include Backbone::Generators::ResourceHelpers
7
+
8
+ source_root File.expand_path("../templates", __FILE__)
9
+
10
+ desc "This generator installs backbone.js with a default folder layout in app/assets/javascripts/backbone"
11
+
12
+ class_option :skip_git, :type => :boolean, :aliases => "-G", :default => false,
13
+ :desc => "Skip Git ignores and keeps"
14
+
15
+ def inject_backbone
16
+ inject_into_file "app/assets/javascripts/application.js", :before => "//= require_tree" do
17
+ "//= require underscore\n//= require backbone\n//= require backbone_rails_sync\n//= require backbone_datalink\n//= require backbone/#{application_name.underscore}\n"
18
+ end
19
+ end
20
+
21
+ def create_dir_layout
22
+ %W{routers models views templates}.each do |dir|
23
+ empty_directory "app/assets/javascripts/backbone/#{dir}"
24
+ create_file "app/assets/javascripts/backbone/#{dir}/.gitkeep" unless options[:skip_git]
25
+ end
26
+ end
27
+
28
+ def create_app_file
29
+ template "app.coffee", "app/assets/javascripts/backbone/#{application_name.underscore}.js.coffee"
30
+ end
31
+
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,11 @@
1
+ #= require_self
2
+ #= require_tree ./templates
3
+ #= require_tree ./models
4
+ #= require_tree ./views
5
+ #= require_tree ./routers
6
+
7
+ window.<%= js_app_name %> =
8
+ Models: {}
9
+ Collections: {}
10
+ Routers: {}
11
+ Views: {}
@@ -0,0 +1,19 @@
1
+ require 'generators/backbone/resource_helpers'
2
+
3
+ module Backbone
4
+ module Generators
5
+ class ModelGenerator < Rails::Generators::NamedBase
6
+ include Backbone::Generators::ResourceHelpers
7
+
8
+ source_root File.expand_path("../templates", __FILE__)
9
+ desc "This generator creates a backbone model"
10
+
11
+ argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
12
+
13
+ def create_backbone_model
14
+ template "model.coffee", "#{backbone_path}/models/#{file_name}.js.coffee"
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,11 @@
1
+ class <%= model_namespace %> extends Backbone.Model
2
+ paramRoot: '<%= singular_table_name %>'
3
+
4
+ defaults:
5
+ <% attributes.each do |attribute| -%>
6
+ <%= attribute.name %>: null
7
+ <% end -%>
8
+
9
+ class <%= collection_namespace %>Collection extends Backbone.Collection
10
+ model: <%= model_namespace %>
11
+ url: '<%= route_url %>'
@@ -0,0 +1,55 @@
1
+ module Backbone
2
+ module Generators
3
+ module ResourceHelpers
4
+
5
+ def backbone_path
6
+ "app/assets/javascripts/backbone"
7
+ end
8
+
9
+ def model_namespace
10
+ [js_app_name, "Models", class_name].join(".")
11
+ end
12
+
13
+ def singular_model_name
14
+ uncapitalize singular_name.camelize
15
+ end
16
+
17
+ def plural_model_name
18
+ uncapitalize(plural_name.camelize)
19
+ end
20
+
21
+ def collection_namespace
22
+ [js_app_name, "Collections", plural_name.camelize].join(".")
23
+ end
24
+
25
+ def view_namespace
26
+ [js_app_name, "Views", plural_name.camelize].join(".")
27
+ end
28
+
29
+ def router_namespace
30
+ [js_app_name, "Routers", plural_name.camelize].join(".")
31
+ end
32
+
33
+ def jst(action)
34
+ "backbone/templates/#{plural_name}/#{action}"
35
+ end
36
+
37
+ def js_app_name
38
+ application_name.camelize
39
+ end
40
+
41
+ def application_name
42
+ if defined?(Rails) && Rails.application
43
+ Rails.application.class.name.split('::').first
44
+ else
45
+ "application"
46
+ end
47
+ end
48
+
49
+ def uncapitalize(str)
50
+ str[0, 1].downcase + str[1..-1]
51
+ end
52
+
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,51 @@
1
+ require 'generators/backbone/resource_helpers'
2
+
3
+ module Backbone
4
+ module Generators
5
+ class RouterGenerator < Rails::Generators::NamedBase
6
+ include Backbone::Generators::ResourceHelpers
7
+
8
+ source_root File.expand_path("../templates", __FILE__)
9
+ desc "This generator creates a backbone router with views and templates for the provided actions"
10
+
11
+ class_option :single, :type => :boolean, :aliases => "-S", :default => false,
12
+ :desc => "Single Page Mode"
13
+
14
+ argument :actions, :type => :array, :default => [], :banner => "action action"
15
+
16
+ RESERVED_JS_WORDS = %W{
17
+ break case catch continue debugger default delete do else finally for
18
+ function if in instanceof new return switch this throw try typeof var void while with
19
+ }
20
+
21
+ def validate_no_reserved_words
22
+ actions.each do |action|
23
+ if RESERVED_JS_WORDS.include? action
24
+ raise Thor::Error, "The name '#{action}' is reserved by javascript " <<
25
+ "Please choose an alternative action name and run this generator again."
26
+ end
27
+ end
28
+ end
29
+
30
+ def create_router_files
31
+ if options[:single]
32
+ template 'router-sp.coffee', File.join(backbone_path, "routers", class_path, "#{file_name}_router.js.coffee")
33
+ else
34
+ template 'router.coffee', File.join(backbone_path, "routers", class_path, "#{file_name}_router.js.coffee")
35
+ end
36
+ end
37
+
38
+ def create_view_files
39
+ actions.each do |action|
40
+ @action = action
41
+ @view_path = File.join(backbone_path, "views", plural_name, "#{action}_view.js.coffee")
42
+ @jst_path = File.join(backbone_path,"templates", plural_name, "#{action}.jst.ejs")
43
+
44
+ template "view.coffee", @view_path
45
+ template "template.jst", @jst_path
46
+ end
47
+ end
48
+
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,14 @@
1
+ class <%= router_namespace %>Router extends Backbone.Router
2
+ initialize: (options) ->
3
+
4
+ routes:
5
+ <% actions.each do |action| -%>
6
+ "/<%= plural_name %>/<%= action %>": "<%= action %>"
7
+ <% end -%>
8
+
9
+ <% actions.each do |action| -%>
10
+ <%= action %>: ->
11
+ @view = new <%= "#{view_namespace}.#{action.camelize}View()" %>
12
+ $("#<%= plural_name %>").html(@view.render().el)
13
+
14
+ <% end -%>
@@ -0,0 +1,14 @@
1
+ class <%= router_namespace %>Router extends Backbone.Router
2
+ initialize: (options) ->
3
+
4
+ routes:
5
+ <% actions.each do |action| -%>
6
+ "/<%= action %>": "<%= action %>"
7
+ <% end -%>
8
+
9
+ <% actions.each do |action| -%>
10
+ <%= action %>: ->
11
+ @view = new <%= "#{view_namespace}.#{action.camelize}View()" %>
12
+ $("#<%= plural_name %>").html(@view.render().el)
13
+
14
+ <% end -%>
@@ -0,0 +1,2 @@
1
+ <h1><%= class_name %>#<%= @action %></h1>
2
+ <p>Find me in <%= @jst_path %></p>
@@ -0,0 +1,8 @@
1
+ <%= view_namespace %> ||= {}
2
+
3
+ class <%= view_namespace %>.<%= @action.camelize %>View extends Backbone.View
4
+ template: JST["<%= jst @action %>"]
5
+
6
+ render: ->
7
+ $(@el).html(@template())
8
+ return this
@@ -0,0 +1,52 @@
1
+ require 'generators/backbone/model/model_generator'
2
+
3
+ module Backbone
4
+ module Generators
5
+ class ScaffoldGenerator < ModelGenerator
6
+
7
+ source_root File.expand_path("../templates", __FILE__)
8
+ desc "This generator creates the client side crud scaffolding"
9
+
10
+ class_option :single, :type => :boolean, :aliases => "-S", :default => false,
11
+ :desc => "Single Page Mode"
12
+
13
+ def create_router_files
14
+ if options[:single]
15
+ template 'router-sp.coffee', File.join(backbone_path, "routers", class_path, "#{plural_name}_router.js.coffee")
16
+ else
17
+ template 'router.coffee', File.join(backbone_path, "routers", class_path, "#{plural_name}_router.js.coffee")
18
+ end
19
+ end
20
+
21
+ def create_view_files
22
+ available_views.each do |view|
23
+ template "views/#{view}_view.coffee", File.join(backbone_path, "views", plural_name, "#{view}_view.js.coffee")
24
+ template "templates/#{view}.jst", File.join(backbone_path, "templates", plural_name, "#{view}.jst.ejs")
25
+ end
26
+ if options[:single]
27
+ available_views.each do |view|
28
+ template "views-sp/#{view}_view.coffee", File.join(backbone_path, "views", plural_name, "#{view}_view.js.coffee")
29
+ template "templates-sp/#{view}.jst", File.join(backbone_path, "templates", plural_name, "#{view}.jst.ejs")
30
+ end
31
+
32
+ template "views-sp/model_view.coffee", File.join(backbone_path, "views", plural_name, "#{singular_name}_view.js.coffee")
33
+ template "templates-sp/model.jst", File.join(backbone_path, "templates", plural_name, "#{singular_name}.jst.ejs")
34
+ else
35
+ available_views.each do |view|
36
+ template "views/#{view}_view.coffee", File.join(backbone_path, "views", plural_name, "#{view}_view.js.coffee")
37
+ template "templates/#{view}.jst", File.join(backbone_path, "templates", plural_name, "#{view}.jst.ejs")
38
+ end
39
+
40
+ template "views/model_view.coffee", File.join(backbone_path, "views", plural_name, "#{singular_name}_view.js.coffee")
41
+ template "templates/model.jst", File.join(backbone_path, "templates", plural_name, "#{singular_name}.jst.ejs")
42
+ end
43
+ end
44
+
45
+ protected
46
+ def available_views
47
+ %w(index show new edit)
48
+ end
49
+
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,11 @@
1
+ class <%= model_namespace %> extends Backbone.Model
2
+ paramRoot: '<%= singular_table_name %>'
3
+
4
+ defaults:
5
+ <% attributes.each do |attribute| -%>
6
+ <%= attribute.name %>: null
7
+ <% end -%>
8
+
9
+ class <%= collection_namespace %>Collection extends Backbone.Collection
10
+ model: <%= model_namespace %>
11
+ url: '<%= route_url %>'
@@ -0,0 +1,31 @@
1
+ class <%= router_namespace %>Router extends Backbone.Router
2
+ initialize: (options) ->
3
+ @<%= plural_model_name %> = new <%= collection_namespace %>Collection()
4
+ @<%= plural_model_name %>.reset options.<%= plural_model_name %>
5
+
6
+ routes:
7
+ "/<%= plural_name %>/new" : "new<%= class_name %>"
8
+ "/<%= plural_name %>/index" : "index"
9
+ "/<%= plural_name %>/:id/edit" : "edit"
10
+ "/<%= plural_name %>/:id" : "show"
11
+ "/<%= plural_name %>/.*" : "index"
12
+
13
+ new<%= class_name %>: ->
14
+ @view = new <%= "#{view_namespace}.NewView(collection: @#{plural_name})" %>
15
+ $("#<%= plural_name %>").html(@view.render().el)
16
+
17
+ index: ->
18
+ @view = new <%= "#{view_namespace}.IndexView(#{plural_name}: @#{plural_name})" %>
19
+ $("#<%= plural_name %>").html(@view.render().el)
20
+
21
+ show: (id) ->
22
+ <%= singular_name %> = @<%= plural_name %>.get(id)
23
+
24
+ @view = new <%= "#{view_namespace}.ShowView(model: #{singular_name})" %>
25
+ $("#<%= plural_name %>").html(@view.render().el)
26
+
27
+ edit: (id) ->
28
+ <%= singular_name %> = @<%= plural_name %>.get(id)
29
+
30
+ @view = new <%= "#{view_namespace}.EditView(model: #{singular_name})" %>
31
+ $("#<%= plural_name %>").html(@view.render().el)
@@ -0,0 +1,31 @@
1
+ class <%= router_namespace %>Router extends Backbone.Router
2
+ initialize: (options) ->
3
+ @<%= plural_model_name %> = new <%= collection_namespace %>Collection()
4
+ @<%= plural_model_name %>.reset options.<%= plural_model_name %>
5
+
6
+ routes:
7
+ "/new" : "new<%= class_name %>"
8
+ "/index" : "index"
9
+ "/:id/edit" : "edit"
10
+ "/:id" : "show"
11
+ ".*" : "index"
12
+
13
+ new<%= class_name %>: ->
14
+ @view = new <%= "#{view_namespace}.NewView(collection: @#{plural_name})" %>
15
+ $("#<%= plural_name %>").html(@view.render().el)
16
+
17
+ index: ->
18
+ @view = new <%= "#{view_namespace}.IndexView(#{plural_name}: @#{plural_name})" %>
19
+ $("#<%= plural_name %>").html(@view.render().el)
20
+
21
+ show: (id) ->
22
+ <%= singular_name %> = @<%= plural_name %>.get(id)
23
+
24
+ @view = new <%= "#{view_namespace}.ShowView(model: #{singular_name})" %>
25
+ $("#<%= plural_name %>").html(@view.render().el)
26
+
27
+ edit: (id) ->
28
+ <%= singular_name %> = @<%= plural_name %>.get(id)
29
+
30
+ @view = new <%= "#{view_namespace}.EditView(model: #{singular_name})" %>
31
+ $("#<%= plural_name %>").html(@view.render().el)
@@ -0,0 +1,17 @@
1
+ <h1>Edit <%= singular_table_name %></h1>
2
+
3
+ <form id="edit-<%= singular_table_name %>" name="<%= singular_table_name %>">
4
+ <% attributes.each do |attribute| -%>
5
+ <div class="field">
6
+ <label for="<%= attribute.name %>"> <%= attribute.name %>:</label>
7
+ <input type="text" name="<%= attribute.name %>" id="<%= attribute.name %>" value=<%%= <%= attribute.name %> %> >
8
+ </div>
9
+
10
+ <% end -%>
11
+ <div class="actions">
12
+ <input type="submit" value="Update <%= human_name %>" />
13
+ </div>
14
+
15
+ </form>
16
+
17
+ <a href="#/index">Back</a>
@@ -0,0 +1,16 @@
1
+ <h1>Listing <%= plural_table_name %></h1>
2
+
3
+ <table id="<%= plural_name %>-table">
4
+ <tr>
5
+ <% attributes.each do |attribute| -%>
6
+ <th><%= attribute.human_name %></th>
7
+ <% end -%>
8
+ <th></th>
9
+ <th></th>
10
+ <th></th>
11
+ </tr>
12
+ </table>
13
+
14
+ <br/>
15
+
16
+ <a href="#/new">New <%= human_name %></a>
@@ -0,0 +1,7 @@
1
+ <% attributes.each do |attribute| -%>
2
+ <td><%%= <%= attribute.name %> %></td>
3
+ <% end -%>
4
+
5
+ <td><a href="#/<%%= id %>">Show</td>
6
+ <td><a href="#/<%%= id %>/edit">Edit</td>
7
+ <td><a href="#/<%%= id %>/destroy" class="destroy">Destroy</a></td>
@@ -0,0 +1,17 @@
1
+ <h1>New <%= singular_table_name %></h1>
2
+
3
+ <form id="new-<%= singular_table_name %>" name="<%= singular_table_name %>">
4
+ <% attributes.each do |attribute| -%>
5
+ <div class="field">
6
+ <label for="<%= attribute.name %>"> <%= attribute.name %>:</label>
7
+ <input type="text" name="<%= attribute.name %>" id="<%= attribute.name %>" value=<%%= <%= attribute.name %> %> >
8
+ </div>
9
+
10
+ <% end -%>
11
+ <div class="actions">
12
+ <input type="submit" value="Create <%= human_name %>" />
13
+ </div>
14
+
15
+ </form>
16
+
17
+ <a href="#/index">Back</a>
@@ -0,0 +1,9 @@
1
+ <% attributes.each do |attribute| -%>
2
+ <p>
3
+ <b><%= attribute.human_name %>:</b>
4
+ <%%= <%= attribute.name %> %>
5
+ </p>
6
+
7
+ <% end -%>
8
+
9
+ <a href="#/index">Back</a>
@@ -0,0 +1,17 @@
1
+ <h1>Edit <%= singular_table_name %></h1>
2
+
3
+ <form id="edit-<%= singular_table_name %>" name="<%= singular_table_name %>">
4
+ <% attributes.each do |attribute| -%>
5
+ <div class="field">
6
+ <label for="<%= attribute.name %>"> <%= attribute.name %>:</label>
7
+ <input type="text" name="<%= attribute.name %>" id="<%= attribute.name %>" value=<%%= <%= attribute.name %> %> >
8
+ </div>
9
+
10
+ <% end -%>
11
+ <div class="actions">
12
+ <input type="submit" value="Update <%= human_name %>" />
13
+ </div>
14
+
15
+ </form>
16
+
17
+ <a href="#/<%= plural_name %>/index">Back</a>
@@ -0,0 +1,16 @@
1
+ <h1>Listing <%= plural_table_name %></h1>
2
+
3
+ <table id="<%= plural_name %>-table">
4
+ <tr>
5
+ <% attributes.each do |attribute| -%>
6
+ <th><%= attribute.human_name %></th>
7
+ <% end -%>
8
+ <th></th>
9
+ <th></th>
10
+ <th></th>
11
+ </tr>
12
+ </table>
13
+
14
+ <br/>
15
+
16
+ <a href="#/<%= plural_name %>/new">New <%= human_name %></a>
@@ -0,0 +1,7 @@
1
+ <% attributes.each do |attribute| -%>
2
+ <td><%%= <%= attribute.name %> %></td>
3
+ <% end -%>
4
+
5
+ <td><a href="#/<%= plural_name %>/<%%= id %>">Show</td>
6
+ <td><a href="#/<%= plural_name %>/<%%= id %>/edit">Edit</td>
7
+ <td><a href="#/<%= plural_name %>/<%%= id %>/destroy" class="destroy">Destroy</a></td>