spine-rails 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -31,7 +31,7 @@ Running `rails g spine:new` will create the following directory structure:
31
31
  app/assets/javascripts/app/models/
32
32
  app/assets/javascripts/app/views/
33
33
  app/assets/javascripts/app/controllers/
34
- app/assets/javascripts/app/index.coffee
34
+ app/assets/javascripts/app/index.js.coffee
35
35
 
36
36
  By default your application will be namespaced by the `app` directory. You can specify a different namespace with the `--app` option:
37
37
 
@@ -39,7 +39,7 @@ By default your application will be namespaced by the `app` directory. You can s
39
39
 
40
40
  **NOTE:** If you use the `--app` option here, then you will also have to specify it with other generators.
41
41
 
42
- Use the top-level level `index.coffee` file to setup namespacing and initial controller instantiation.
42
+ Use the top-level level `index.js.coffee` file to setup namespacing and initial controller instantiation.
43
43
 
44
44
  ## Generators
45
45
 
@@ -328,6 +328,10 @@
328
328
  return new this(objects);
329
329
  }
330
330
  };
331
+ Model.fromForm = function() {
332
+ var _ref;
333
+ return (_ref = new this).fromForm.apply(_ref, arguments);
334
+ };
331
335
  Model.recordsValues = function() {
332
336
  var key, result, value, _ref;
333
337
  result = [];
@@ -363,13 +367,16 @@
363
367
  };
364
368
  Model.prototype.validate = function() {};
365
369
  Model.prototype.load = function(atts) {
366
- var key, value, _results;
367
- _results = [];
370
+ var key, value;
368
371
  for (key in atts) {
369
372
  value = atts[key];
370
- _results.push(typeof this[key] === 'function' ? this[key](value) : this[key] = value);
373
+ if (typeof this[key] === 'function') {
374
+ this[key](value);
375
+ } else {
376
+ this[key] = value;
377
+ }
371
378
  }
372
- return _results;
379
+ return this;
373
380
  };
374
381
  Model.prototype.attributes = function() {
375
382
  var key, result, _i, _len, _ref;
@@ -460,6 +467,16 @@
460
467
  Model.prototype.toString = function() {
461
468
  return "<" + this.constructor.className + " (" + (JSON.stringify(this)) + ")>";
462
469
  };
470
+ Model.prototype.fromForm = function(form) {
471
+ var key, result, _i, _len, _ref;
472
+ result = {};
473
+ _ref = $(form).serializeArray();
474
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
475
+ key = _ref[_i];
476
+ result[key.name] = key.value;
477
+ }
478
+ return this.load(result);
479
+ };
463
480
  Model.prototype.exists = function() {
464
481
  return this.id && this.id in this.constructor.records;
465
482
  };
@@ -229,4 +229,4 @@
229
229
  if (typeof module !== "undefined" && module !== null) {
230
230
  module.exports = Ajax;
231
231
  }
232
- }).call(this);
232
+ }).call(this);
@@ -81,6 +81,49 @@
81
81
  return this;
82
82
  }
83
83
  });
84
+ Spine.Stack = (function() {
85
+ __extends(Stack, Spine.Controller);
86
+ Stack.prototype.controllers = {};
87
+ Stack.prototype.routes = {};
88
+ Stack.prototype.className = 'spine stack';
89
+ function Stack() {
90
+ var key, value, _fn, _ref, _ref2;
91
+ Stack.__super__.constructor.apply(this, arguments);
92
+ this.manager = new Spine.Manager;
93
+ _ref = this.controllers;
94
+ for (key in _ref) {
95
+ value = _ref[key];
96
+ this[key] = new value({
97
+ stack: this
98
+ });
99
+ this.add(this[key]);
100
+ }
101
+ _ref2 = this.routes;
102
+ _fn = __bind(function(key, value) {
103
+ var callback;
104
+ if (typeof value === 'function') {
105
+ callback = value;
106
+ }
107
+ callback || (callback = __bind(function() {
108
+ var _ref3;
109
+ return (_ref3 = this[value]).active.apply(_ref3, arguments);
110
+ }, this));
111
+ return this.route(key, callback);
112
+ }, this);
113
+ for (key in _ref2) {
114
+ value = _ref2[key];
115
+ _fn(key, value);
116
+ }
117
+ if (this["default"]) {
118
+ this[this["default"]].active();
119
+ }
120
+ }
121
+ Stack.prototype.add = function(controller) {
122
+ this.manager.add(controller);
123
+ return this.append(controller);
124
+ };
125
+ return Stack;
126
+ })();
84
127
  if (typeof module !== "undefined" && module !== null) {
85
128
  module.exports = Spine.Manager;
86
129
  }
@@ -36,7 +36,7 @@
36
36
  }
37
37
  return _results;
38
38
  } else {
39
- return this.routes.unshift(new this(path, callback));
39
+ return this.routes.push(new this(path, callback));
40
40
  }
41
41
  };
42
42
  Route.setup = function(options) {
@@ -15,24 +15,24 @@
15
15
  Spine.Tabs = (function() {
16
16
  __extends(Tabs, Spine.Controller);
17
17
  Tabs.prototype.events = {
18
- "click [data-name]": "click"
18
+ 'click [data-name]': 'click'
19
19
  };
20
20
  function Tabs() {
21
21
  this.change = __bind(this.change, this); Tabs.__super__.constructor.apply(this, arguments);
22
- this.bind("change", this.change);
22
+ this.bind('change', this.change);
23
23
  }
24
24
  Tabs.prototype.change = function(name) {
25
25
  if (!name) {
26
26
  return;
27
27
  }
28
28
  this.current = name;
29
- this.children().removeClass("active");
30
- return this.children("[data-name='" + this.current + "']").addClass("active");
29
+ this.children().removeClass('active');
30
+ return this.children("[data-name=" + this.current).addClass('active');
31
31
  };
32
32
  Tabs.prototype.render = function() {
33
33
  this.change(this.current);
34
- if (!(this.children(".active").length || this.current)) {
35
- return this.children(":first").click();
34
+ if (!(this.children('.active').length || this.current)) {
35
+ return this.children(':first').click();
36
36
  }
37
37
  };
38
38
  Tabs.prototype.children = function(sel) {
@@ -40,11 +40,11 @@
40
40
  };
41
41
  Tabs.prototype.click = function(e) {
42
42
  var name;
43
- name = $(e.target).attr("data-name");
44
- return this.trigger("change", name);
43
+ name = $(e.target).attr('data-name');
44
+ return this.trigger('change', name);
45
45
  };
46
46
  Tabs.prototype.connect = function(tabName, controller) {
47
- return this.bind("change", function(name) {
47
+ return this.bind('change', function(name) {
48
48
  if (name === tabName) {
49
49
  return controller.active();
50
50
  }
@@ -11,7 +11,7 @@ module Spine
11
11
  template "controller.coffee.erb", File.join(
12
12
  "app/assets/javascripts",
13
13
  app_name, "controllers",
14
- class_path, file_name.pluralize + ".coffee"
14
+ class_path, file_name.pluralize + ".js.coffee"
15
15
  )
16
16
  end
17
17
  end
@@ -10,7 +10,7 @@ module Spine
10
10
  argument :fields, :desc => 'List of model attributes', :type => :array, :banner => 'field1 field2'
11
11
 
12
12
  def create_model
13
- template "model.coffee.erb", "app/assets/javascripts/#{app_name}/models/#{file_name}.coffee"
13
+ template "model.coffee.erb", "app/assets/javascripts/#{app_name}/models/#{file_name}.js.coffee"
14
14
  end
15
15
  end
16
16
  end
@@ -25,7 +25,7 @@ module Spine
25
25
  end
26
26
 
27
27
  def create_app_file
28
- template "index.coffee.erb", "app/assets/javascripts/#{app_name}/index.coffee"
28
+ template "index.coffee.erb", "app/assets/javascripts/#{app_name}/index.js.coffee"
29
29
  end
30
30
 
31
31
  def add_spine_app_to_application
@@ -0,0 +1,42 @@
1
+ require "rails"
2
+ require "spine/generators"
3
+
4
+ module Spine
5
+ module Generators
6
+ class ScaffoldGenerator < Base
7
+ source_root File.expand_path("../templates", __FILE__)
8
+ desc "Generate a Spine scaffold with configured fields"
9
+
10
+ argument :fields, :desc => "List of model attributes", :type => :array, :banner => "field1 field2"
11
+
12
+ def create_scaffold
13
+ raise("The 'eco' gem is required; add it to the Gemfile") unless defined?(::Eco)
14
+
15
+ generate "spine:model #{model_name} #{fields.join(" ")} --app #{app_name}"
16
+ template "controller.coffee.erb", "app/assets/javascripts/#{app_name}/controllers/#{controller_name}.js.coffee"
17
+ template "edit.jst.erb", "app/assets/javascripts/#{app_name}/views/#{controller_name}/edit.jst.eco"
18
+ template "index.jst.erb", "app/assets/javascripts/#{app_name}/views/#{controller_name}/index.jst.eco"
19
+ template "new.jst.erb", "app/assets/javascripts/#{app_name}/views/#{controller_name}/new.jst.eco"
20
+ template "show.jst.erb", "app/assets/javascripts/#{app_name}/views/#{controller_name}/show.jst.eco"
21
+ end
22
+
23
+ protected
24
+
25
+ def model_name
26
+ file_name.singularize
27
+ end
28
+
29
+ def model_class
30
+ class_name.singularize
31
+ end
32
+
33
+ def controller_name
34
+ file_name.pluralize
35
+ end
36
+
37
+ def controller_class
38
+ class_name.pluralize
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,110 @@
1
+ $ = jQuery.sub()
2
+ <%= model_class %> = <%= app_class %>.<%= model_class %>
3
+
4
+ $.fn.item = ->
5
+ elementID = $(@).data('id')
6
+ elementID or= $(@).parents('[data-id]').data('id')
7
+ <%= model_class %>.find(elementID)
8
+
9
+ class New extends Spine.Controller
10
+ events:
11
+ 'submit form': 'submit'
12
+
13
+ constructor: ->
14
+ super
15
+ @active @render
16
+
17
+ render: ->
18
+ @html App.view('<%= controller_name %>/new')
19
+
20
+ submit: (e) ->
21
+ e.preventDefault()
22
+ <%= model_name %> = <%= model_class %>.fromForm(e.target).save()
23
+ @navigate '/<%= controller_name %>', <%= model_name %>.id if <%= model_name %>
24
+
25
+ class Edit extends Spine.Controller
26
+ events:
27
+ 'submit form': 'submit'
28
+
29
+ constructor: ->
30
+ super
31
+ @active (params) ->
32
+ @change(params.id)
33
+
34
+ change: (id) ->
35
+ @item = <%= model_class %>.find(id)
36
+ @render()
37
+
38
+ render: ->
39
+ @html App.view('<%= controller_name %>/edit')(@item)
40
+
41
+ submit: (e) ->
42
+ e.preventDefault()
43
+ @item.fromForm(e.target).save()
44
+ @navigate '/<%= controller_name %>'
45
+
46
+ class Show extends Spine.Controller
47
+ events:
48
+ 'click [data-type=back]': 'back'
49
+
50
+ constructor: ->
51
+ super
52
+ @active (params) ->
53
+ @change(params.id)
54
+
55
+ change: (id) ->
56
+ @item = <%= model_class %>.find(id)
57
+ @render()
58
+
59
+ render: ->
60
+ @html App.view('<%= controller_name %>/show')(@item)
61
+
62
+ back: ->
63
+ @navigate '/<%= controller_name %>'
64
+
65
+ class Index extends Spine.Controller
66
+ events:
67
+ 'click [data-type=edit]': 'edit'
68
+ 'click [data-type=destroy]': 'destroy'
69
+ 'click [data-type=show]': 'show'
70
+ 'click [data-type=new]': 'new'
71
+
72
+ constructor: ->
73
+ super
74
+ <%= model_class %>.bind 'refresh change', @render
75
+ <%= model_class %>.fetch()
76
+
77
+ render: =>
78
+ <%= controller_name %> = <%= model_class %>.all()
79
+ @html App.view('<%= controller_name %>/index')(<%= controller_name %>: <%= controller_name %>)
80
+
81
+ edit: (e) ->
82
+ item = $(e.target).item()
83
+ @navigate '/<%= controller_name %>', item.id, 'edit'
84
+
85
+ destroy: (e) ->
86
+ item = $(e.target).item()
87
+ item.destroy() if confirm('Sure?')
88
+
89
+ show: (e) ->
90
+ item = $(e.target).item()
91
+ @navigate '/<%= controller_name %>', item.id
92
+
93
+ new: ->
94
+ @navigate '/<%= controller_name %>/new'
95
+
96
+ class App.<%= controller_class %> extends Spine.Stack
97
+ controllers:
98
+ index: Index
99
+ edit: Edit
100
+ show: Show
101
+ new: New
102
+
103
+ routes:
104
+ '/<%= controller_name %>/new': 'new'
105
+ '/<%= controller_name %>/:id/edit': 'edit'
106
+ '/<%= controller_name %>/:id': 'show'
107
+ '/<%= controller_name %>': 'index'
108
+
109
+ default: 'index'
110
+ className: 'stack <%= controller_name %>'
@@ -0,0 +1,15 @@
1
+ <h1>Edit <%= model_class %></h1>
2
+
3
+ <form>
4
+ <% fields.each do |field| %>
5
+ <label>
6
+ <span><%= field.titleize %></span>
7
+ <input
8
+ type="text" name="<%= field %>"
9
+ value="<%%= @<%= field %> %>" required
10
+ <%- if field == fields[0] %> autofocus<% end %>>
11
+ </label>
12
+ <% end %>
13
+ <button>Edit</button>
14
+
15
+ </form>
@@ -0,0 +1,12 @@
1
+ <h1>Listing <%= model_class.pluralize %></h1>
2
+
3
+ <%% for <%= model_name %> in @<%= controller_name %>: %>
4
+ <div class="item" data-id="<%%= <%= model_name %>.id %>">
5
+ <a data-type="show"><%%= <%= model_name %>.<%= fields[0] %> %></a>
6
+
7
+ <a data-type="edit">Edit</a>
8
+ <a data-type="destroy">Destroy</a>
9
+ </div>
10
+ <%% end %>
11
+
12
+ <p><a data-type="new">New <%= model_class %></a></p>
@@ -0,0 +1,15 @@
1
+ <h1>New <%= model_class %></h1>
2
+
3
+ <form>
4
+ <% fields.each do |field| %>
5
+ <label>
6
+ <span><%= field.titleize %></span>
7
+ <input
8
+ type="text" name="<%= field %>"
9
+ value="<%%= @<%= field %> %>" required
10
+ <%- if field == fields[0] %> autofocus<% end %>>
11
+ </label>
12
+ <% end %>
13
+ <button>Create</button>
14
+
15
+ </form>
@@ -0,0 +1,7 @@
1
+ <h1>Show <%= model_class %></h1>
2
+
3
+ <a data-type="back">Back</a>
4
+
5
+ <%- fields.each do |field| -%>
6
+ <p><%= field.titleize %>: <%%= @<%= field %> %></p>
7
+ <%- end -%>
@@ -3,17 +3,19 @@ module Spine
3
3
  class Base < ::Rails::Generators::NamedBase
4
4
  class_option :app, :type => :string, :default => "app", :desc => "app name"
5
5
 
6
- def class_name
7
- (class_path + [file_name]).map!{ |m| m.camelize }.join('')
8
- end
6
+ protected
9
7
 
10
- def app_name
11
- options[:app]
12
- end
8
+ def class_name
9
+ (class_path + [file_name]).map!{ |m| m.camelize }.join('')
10
+ end
13
11
 
14
- def app_class
15
- app_name.camelize
16
- end
12
+ def app_name
13
+ options[:app]
14
+ end
15
+
16
+ def app_class
17
+ app_name.camelize
18
+ end
17
19
  end
18
20
  end
19
21
  end
@@ -1,6 +1,6 @@
1
1
  module Spine
2
2
  module Rails
3
- VERSION = "0.0.7"
3
+ VERSION = "0.0.8"
4
4
  SPINE_VERSION = "1.0.3"
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spine-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-22 00:00:00.000000000Z
12
+ date: 2011-10-23 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &70168718472840 !ruby/object:Gem::Requirement
16
+ requirement: &70224443989420 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 3.1.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70168718472840
24
+ version_requirements: *70224443989420
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: bundler
27
- requirement: &70168718516220 !ruby/object:Gem::Requirement
27
+ requirement: &70224443988460 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70168718516220
35
+ version_requirements: *70224443988460
36
36
  description: This gem provides Spine for your Rails 3 application.
37
37
  email:
38
38
  - info@eribium.org
@@ -61,6 +61,12 @@ files:
61
61
  - lib/generators/spine/model/templates/model.coffee.erb
62
62
  - lib/generators/spine/new/new_generator.rb
63
63
  - lib/generators/spine/new/templates/index.coffee.erb
64
+ - lib/generators/spine/scaffold/scaffold_generator.rb
65
+ - lib/generators/spine/scaffold/templates/controller.coffee.erb
66
+ - lib/generators/spine/scaffold/templates/edit.jst.erb
67
+ - lib/generators/spine/scaffold/templates/index.jst.erb
68
+ - lib/generators/spine/scaffold/templates/new.jst.erb
69
+ - lib/generators/spine/scaffold/templates/show.jst.erb
64
70
  - lib/generators/spine/view/templates/view.eco.erb
65
71
  - lib/generators/spine/view/templates/view.ejs.erb
66
72
  - lib/generators/spine/view/templates/view.hamljs.erb
@@ -96,3 +102,4 @@ signing_key:
96
102
  specification_version: 3
97
103
  summary: Use Spine with Rails 3
98
104
  test_files: []
105
+ has_rdoc: