jazz-jss 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,19 +1,51 @@
1
- = jazz
1
+ jazz jss
2
+ =======
2
3
 
3
- Description goes here.
4
+ It's a simple rapid prototyping JSS framework
4
5
 
5
- == Contributing to jazz
6
-
7
- * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
- * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
- * Fork the project
10
- * Start a feature/bugfix branch
11
- * Commit and push until you are happy with your contribution
12
- * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
- * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
6
 
15
- == Copyright
7
+ Install
8
+ -------
16
9
 
17
- Copyright (c) 2011 Florian Schade. See LICENSE.txt for
18
- further details.
19
10
 
11
+ Usage
12
+ -----
13
+
14
+ in shell
15
+ jazz new todo
16
+ cd todo
17
+ jazz generate scaffold item title state
18
+
19
+ add route to config/routes.js
20
+ Jazz.Route.draw(
21
+ {
22
+ '': 'items_controller#index',
23
+ '/items': 'items_controller#index'
24
+ }
25
+ );
26
+
27
+ open app/controllers/items_controller.js and add this to index action
28
+ milk = new Item({title: 'milk', state: false});
29
+ milk.save();
30
+
31
+ bread = new Item({title: 'bread', state: false});
32
+ bread.save();
33
+
34
+ open_cart = Item.findBy({state: false});
35
+ console.log(open_cart);
36
+
37
+ bread.set({state: true});
38
+ bread.save();
39
+ open_cart = Item.findBy({state: false});
40
+ console.log(open_cart);
41
+
42
+ Todo
43
+ ----
44
+
45
+ Coming soon
46
+
47
+
48
+ Credits
49
+ -------
50
+
51
+ Copyright (c) 2011 Florian Schade. All rights reserved.
data/bin/jazz CHANGED
@@ -4,6 +4,7 @@ require 'jazz'
4
4
 
5
5
  if(ARGV.include?('generate'))
6
6
  Jazz::CLI.start
7
- else
7
+ elsif(ARGV.include?('new'))
8
+ ARGV.delete('new')
8
9
  Jazz::AppGenerator.start
9
10
  end
data/dist/jazz/lib/db.js CHANGED
@@ -16,7 +16,7 @@ _.extend(
16
16
  add:function (model) {
17
17
  obj = jQuery.extend(true, {}, model);
18
18
  obj._config.persist = true;
19
- this.models[obj.uid()] = obj;
19
+ this.models[obj.uid] = obj;
20
20
  },
21
21
 
22
22
  all:function () {
@@ -1,23 +1,14 @@
1
1
  _.extend(
2
2
  Jazz.Helper,
3
3
  {
4
- loadView: function (name) {
5
- return $.ajax({
6
- url:'./app/assets/templates/' + name + '.html',
7
- type:'GET',
8
- cache:false,
9
- async:false
10
- }).responseText;
11
- },
12
4
  extend: function (protoProps, classProps) {
13
5
  var child = Jazz.Helper.inherits(this, protoProps, classProps);
14
- //var child = jQuery.extend(true, this, protoProps, classProps);
15
6
  child.extend = this.extend;
16
7
  return child;
17
8
  },
18
-
9
+
19
10
  ctor: function(){},
20
-
11
+
21
12
  inherits: function(parent, protoProps, staticProps) {
22
13
  var child;
23
14
  if (protoProps && protoProps.hasOwnProperty('constructor')) {
@@ -25,31 +16,22 @@ _.extend(
25
16
  } else {
26
17
  child = function(){ return parent.apply(this, arguments); };
27
18
  }
28
-
19
+
29
20
  _.extend(child, parent);
30
-
21
+
31
22
  Jazz.Helper.ctor.prototype = parent.prototype;
32
23
  child.prototype = new Jazz.Helper.ctor();
33
-
24
+
34
25
  if (protoProps) _.extend(child.prototype, protoProps);
35
-
26
+
36
27
  if (staticProps) _.extend(child, staticProps);
37
-
28
+
38
29
  child.prototype.constructor = child;
39
-
30
+
40
31
  child.__super__ = parent.prototype;
41
-
32
+
42
33
  return child;
43
- },
44
-
45
- showError: function (message) {
46
- alert(message);
47
- },
48
-
49
- getApp: function(){
50
- return eval(Jazz.Config.appName);
51
34
  }
52
-
53
35
  }
54
36
  );
55
37
 
@@ -1,122 +1,88 @@
1
- Jazz.Model = function(attributes, options){
2
-
3
- this._prepare(attributes);
4
- this.initialize();
1
+ Jazz.Model = function (attributes, options) {
2
+ this.initialize(attributes);
5
3
  };
6
4
 
7
- Jazz.Model.extend = Jazz.Model.create = Jazz.Helper.extend;
8
-
9
- _.extend(
10
- Jazz.Model.prototype,
11
- {
12
- //initialize function
13
- initialize: function(){},
14
-
15
- //
16
- _prepare: function(attributes){
17
-
18
- //Resets the attributes per OBJ
19
- this.attributes = {};
20
-
21
- //Resets the _config and combine per OBJ
22
- _config = {
23
- uid: _.uniqueId(),
24
- persist: false
25
- }
26
- this._config = _.extend({}, this._config, _config);
27
-
28
- //Prepopulate OBJ
29
- defaults = {};
30
-
31
- for(var attr in window[this._config.table].columns){
32
- defaults[attr] = window[this._config.table].columns[attr].value;
33
- }
34
-
35
- _.extend(defaults, attributes);
36
-
37
- this.set(defaults);
38
-
39
- },
40
-
41
- //
42
- toJson : function() {
43
- return _.clone(this.attributes);
44
- },
45
-
46
- //
47
- has : function(attr) {
48
- return this.attributes[attr] != null;
49
- },
50
-
51
- //
52
- hasPropertiesWithValues : function(query) {
53
-
54
- size = _.size(query);
55
- i = 0;
56
-
57
- for (var key in query) {
58
- if (!this.has(key)) continue;
59
- if (this.get(key) != query[key]) continue;
60
- i++;
61
- }
62
-
63
- return i == size ? true : false;
64
-
65
- },
66
-
67
- //
68
- set: function(attrs){
69
- if (!attrs) return this;
70
-
71
- var now = this.attributes;
72
- var can = _.keys(window[this._config.table].columns);
73
-
74
- for (var attr in attrs) {
75
- if (_.contains(can, attr) ) {
76
- now[attr] = attrs[attr];
77
- } else {
78
- Jazz.Helper.showError('Cannot add ' + attr);
79
- }
5
+
6
+ Jazz.Model._config = {}
7
+
8
+ Jazz.Model.create = function (settings, model, object) {
9
+ _.extend(this._config, settings);
10
+ _.extend(this, model);
11
+
12
+ obj = {};
13
+ obj._config = {}
14
+ _.extend(obj._config, settings);
15
+ _.extend(obj, object);
16
+
17
+
18
+
19
+ var child = Jazz.Helper.inherits(this, obj);
20
+ child.extend = this.extend;
21
+ return child;
22
+ }
23
+
24
+ Jazz.Model.findBy = function (attributes) {
25
+ var objs = [];
26
+ _.each(
27
+ this._config.table.models,
28
+ function (model) {
29
+
30
+ var add = false;
31
+
32
+ for (var attribute in attributes) {
33
+ if (!model.has(attribute)) continue;
34
+ if (model.get(attribute) != attributes[attribute]) continue;
35
+ add = true;
80
36
  }
81
-
82
- return this;
83
- },
84
-
85
- //
86
- get: function(key){
87
- if (!this.attributes) return this;
88
- if (!key) return this.attributes;
89
- return this.attributes[key];
90
- },
91
-
92
- uid: function(){
93
- return this._config.uid;
94
- },
95
-
96
- //
97
- remove: function(key){
98
- if (!key) return this;
99
- delete this.attributes[key];
100
- return this;
101
- },
102
-
103
- //
104
- create: function(attributes){
105
- this.validate.atCreate();
106
- this.set(attributes);
107
- window[this._config.table].add(this);
108
- },
109
-
110
- update: function(attributes){
111
- this.validate.atUpdate();
112
- this.set(attributes);
113
- window[this._config.table].add(this);
114
- },
115
-
116
- validate: {
117
- atCreate: function(){},
118
- atUpdate: function(){},
37
+
38
+ if (add) objs.push(model);
39
+
119
40
  }
41
+ );
42
+ return objs
43
+ }
44
+
45
+ Jazz.Model.prototype.initialize = function (attributes) {
46
+ this.attributes = {};
47
+ this.uid = _.uniqueId();
48
+
120
49
 
50
+
51
+
52
+ //Prepopulate OBJ
53
+ defaults = {};
54
+
55
+ for (var attribute in this._config.table.columns) {
56
+ defaults[attribute] = this._config.table.columns[attribute].value;
57
+ }
58
+
59
+ _.extend(defaults, attributes);
60
+
61
+ this.set(defaults);
62
+
63
+ }
64
+
65
+ Jazz.Model.prototype.set = function (attributes) {
66
+ var can = _.keys(this._config.table.columns);
67
+
68
+ for (var attribute in attributes) {
69
+
70
+ if (_.contains(can, attribute)) {
71
+ this.attributes[attribute] = attributes[attribute];
72
+ }
121
73
  }
122
- );
74
+ }
75
+
76
+ Jazz.Model.prototype.get = function (key) {
77
+ if (!this.attributes) return this;
78
+ if (!key) return this.attributes;
79
+ return this.attributes[key];
80
+ }
81
+
82
+ Jazz.Model.prototype.has = function (attribute) {
83
+ return this.attributes[attribute] != null;
84
+ }
85
+
86
+ Jazz.Model.prototype.save = function () {
87
+ this._config.table.add(this);
88
+ }
@@ -1,5 +1,6 @@
1
1
  Jazz.Route = {
2
2
  routes: {},
3
+
3
4
  initialize: function(){
4
5
  Jazz.Route.navigate();
5
6
  $(window).hashchange(
data/dist/jazz/main.js CHANGED
@@ -1,6 +1,7 @@
1
1
  var Jazz = {
2
2
  _:{
3
- requires:[
3
+ _app: "",
4
+ _files: [
4
5
  'vendor/jquery/jquery.js',
5
6
  'vendor/hashchange/jquery.ba-hashchange.js',
6
7
  'vendor/mustache/mustache.js',
@@ -12,65 +13,53 @@ var Jazz = {
12
13
  'lib/jazz/lib/view.js',
13
14
  'lib/jazz/lib/controller.js',
14
15
  'config/application.js',
15
- 'config/routes.js',
16
- 'config/glue.js'
16
+ 'config/glue.js',
17
+ 'config/routes.js'
17
18
  ]
18
19
  },
19
- Helper:{
20
- addOrderToRequires:function (collection, path) {
21
- path = path ? path : '';
22
- //Load order is importent so add it by default
23
- for (file in collection) {
24
- collection[file] = collection[file] != "" ? 'vendor/require/order!' + path + collection[file] : "";
20
+
21
+ Helper: function(){},
22
+ Now: {},
23
+ initialize: function(){
24
+ this.load(
25
+ glue,
26
+ function(){
27
+ window[Jazz._._app].initialize();
28
+ Jazz.Route.initialize();
25
29
  }
26
- return collection;
30
+ );
31
+ },
32
+
33
+ load: function(path, callback){
34
+
35
+ if (!path) return this;
36
+
37
+ files = [];
38
+
39
+ if (typeof path == "string")
40
+ files.push(path);
41
+ else
42
+ files = path;
43
+
44
+ for (file in files) {
45
+ files[file] = 'vendor/require/order!' + files[file];
27
46
  }
47
+
48
+ require(
49
+ {
50
+ baseUrl:""
51
+ },
52
+ files,
53
+ callback
54
+ );
28
55
  },
29
- Now:{},
30
- Config:{}
56
+
57
+ setup: function(name){
58
+ //Set Appname
59
+ this._._app = name;
60
+ }
31
61
  }
32
62
 
33
-
34
- require(
35
- {
36
- baseUrl:""
37
- },
38
- Jazz.Helper.addOrderToRequires(Jazz._.requires),
39
- function () {
40
- _.extend(
41
- Jazz.Helper.getApp(),
42
- {
43
- _:{
44
- requires:[]
45
- }
46
- }
47
- );
48
-
49
- _.each(
50
- Glue,
51
- function (val, key) {
52
- var path;
53
- switch (key) {
54
- case "Db":
55
- path = "db/"
56
- break;
57
- default:
58
- path = "app/" + key + '/'
59
- break;
60
- }
61
-
62
- Jazz.Helper.getApp()._.requires.push(Jazz.Helper.addOrderToRequires(val, path));
63
- }
64
- );
65
-
66
- Jazz.Helper.getApp()._.requires = _.flatten(Jazz.Helper.getApp()._.requires);
67
-
68
- require(
69
- Jazz.Helper.getApp()._.requires,
70
- function () {
71
- eval(Jazz.Config.appName + '.initialize()');
72
- Jazz.Route.initialize();
73
- }
74
- );
75
- }
76
- );
63
+ Jazz.load(Jazz._._files, function(){
64
+ Jazz.initialize();
65
+ });
@@ -36,6 +36,32 @@ module Jazz
36
36
  File.exists?('public')
37
37
  end
38
38
 
39
+ def generate_controller
40
+ template "templates/controller.js", "#{app_path}/app/controllers/#{name.downcase.pluralize}_controller.js"
41
+ end
42
+
43
+ def generate_model
44
+ template "templates/model.js", "#{app_path}/app/models/#{name.downcase}.js"
45
+ end
46
+
47
+ def generate_db
48
+ template "templates/db.js", "#{app_path}/db/create_#{name.downcase.pluralize}.js"
49
+ end
50
+
51
+ def generate_views
52
+ empty_directory "#{app_path}/app/views/#{name.downcase.pluralize}"
53
+ template "templates/view_create.html", "#{app_path}/app/views/#{name.downcase.pluralize}/create.html"
54
+ template "templates/view_index.html", "#{app_path}/app/views/#{name.downcase.pluralize}/index.html"
55
+ template "templates/view_show.html", "#{app_path}/app/views/#{name.downcase.pluralize}/show.html"
56
+ template "templates/view_update.html", "#{app_path}/app/views/#{name.downcase.pluralize}/update.html"
57
+ end
58
+
59
+ def generate_glue
60
+ @files = Dir.glob('db/*') + Dir.glob('app/models/*') + Dir.glob('app/controllers/*')
61
+ puts @files
62
+ template "templates/glue.js", "#{app_path}/config/glue.js", {:force => true}
63
+ end
64
+
39
65
  end
40
66
 
41
67
  end
@@ -23,7 +23,7 @@ module Jazz
23
23
  directory 'dist/mustache', "#{new_app_path}/vendor/mustache"
24
24
  directory 'dist/require', "#{new_app_path}/vendor/require"
25
25
  directory 'dist/underscore', "#{new_app_path}/vendor/underscore"
26
-
26
+
27
27
  template "templates/application.js", "#{new_app_path}/config/application.js"
28
28
  template "templates/index.html", "#{new_app_path}/index.html"
29
29
 
data/lib/jazz/cli.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Jazz
2
2
  class CLI < Thor
3
-
3
+
4
4
  desc "Jazz generate [generator] [name]", "call a generator"
5
5
  def generate(requested_generator, name, *args)
6
6
  ARGV.delete('generate')
@@ -16,8 +16,15 @@ module Jazz
16
16
  end
17
17
 
18
18
  def build_the_controller
19
- template "templates/controller.js", "#{app_path}/app/controllers/#{name.downcase}_controller.js"
20
- empty_directory "#{app_path}/app/views/#{name.downcase}"
19
+ generate_controller
20
+ end
21
+
22
+ def build_the_views
23
+ generate_views
24
+ end
25
+
26
+ def build_the_glue
27
+ generate_glue
21
28
  end
22
29
 
23
30
  def farewell
@@ -16,8 +16,8 @@ module Jazz
16
16
  end
17
17
 
18
18
  def build_the_model
19
- template "templates/model.js", "#{app_path}/app/models/#{name.downcase}.js"
20
- template "templates/db.js", "#{app_path}/db/create_#{name.downcase.pluralize}.js"
19
+ generate_model
20
+ generate_db
21
21
  end
22
22
 
23
23
  def farewell
@@ -21,19 +21,21 @@ module Jazz
21
21
  end
22
22
 
23
23
  def build_the_model
24
- template "templates/model.js", "#{app_path}/app/models/#{name.downcase}.js"
25
- template "templates/db.js", "#{app_path}/db/create_#{name.downcase.pluralize}.js"
24
+ generate_model
25
+ generate_db
26
26
  end
27
27
 
28
28
  def build_the_controller
29
- template "templates/scaffold_controller.js", "#{app_path}/app/controllers/#{name.downcase.pluralize}_controller.js"
29
+ generate_controller
30
30
  end
31
31
 
32
- # def build_the_views
33
- # template "templates/scaffold_index.html", "#{public_path}/#{name.downcase.pluralize}.html"
34
- # template "templates/scaffold_partial.html.mustache", "#{app_path}/app/views/#{name.downcase.pluralize}/_#{name.downcase}.html.mustache"
35
- # template "templates/scaffold_edit.html.mustache", "#{app_path}/app/views/#{name.downcase.pluralize}/edit.html.mustache"
36
- # end
32
+ def build_the_views
33
+ generate_views
34
+ end
35
+
36
+ def build_the_glue
37
+ generate_glue
38
+ end
37
39
 
38
40
  def farewell
39
41
  $stdout.puts "Your scaffold is ready to rumble!"
data/lib/jazz.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'rubygems'
2
+ require 'json'
2
3
  require 'thor'
3
4
  require 'thor/group'
4
5
  require 'active_support/inflector'
@@ -1,4 +1,6 @@
1
- Jazz.Config.appName = '<%= name %>';
1
+ Jazz.setup('<%= name %>');
2
+
2
3
  <%= name %> = {
3
- initialize: function(){}
4
+ initialize: function(){
5
+ }
4
6
  }
@@ -1,4 +1,4 @@
1
- var <%= name.capitalize %>Controller = Jazz.Controller.create(
1
+ var <%= name.capitalize.pluralize %>Controller = Jazz.Controller.create(
2
2
  {
3
3
 
4
4
  initialize: function(){},
@@ -16,4 +16,4 @@ var <%= name.capitalize %>Controller = Jazz.Controller.create(
16
16
  }
17
17
  );
18
18
 
19
- <%= name %>_controller = new <%= name.capitalize %>Controller;
19
+ <%= name.downcase.pluralize -%>_controller = new <%= name.capitalize.pluralize -%>Controller;
data/templates/db.js CHANGED
@@ -11,4 +11,4 @@ var Create<%= name.capitalize.pluralize %> = Jazz.Db.create(
11
11
  }
12
12
  );
13
13
 
14
- <%= name.pluralize %> = new Create<%= name.capitalize.pluralize %>;
14
+ create_<%= name.downcase.pluralize %> = new Create<%= name.capitalize.pluralize %>;
data/templates/glue.js ADDED
@@ -0,0 +1,4 @@
1
+ var glue = [
2
+ <% @files.each_with_index do |file, index| %>'<%= file %>'<% unless @files.length == index + 1 %>,
3
+ <% end %><% end %>
4
+ ]
data/templates/model.js CHANGED
@@ -1,9 +1,16 @@
1
- var <%= name.capitalize %>Model = Jazz.Model.create(
2
- {
3
- _config: {
4
-
5
- table: '<%= name.pluralize %>'
6
-
7
- }
8
- }
1
+ var <%= name.singularize.capitalize %> = Jazz.Model.create(
2
+
3
+ //configuration
4
+ {
5
+ table: create_<%= name.downcase.pluralize %>
6
+ },
7
+
8
+ //modelActions
9
+ {
10
+ },
11
+
12
+ //objectActions
13
+ {
14
+ }
15
+
9
16
  );
@@ -1,5 +1,6 @@
1
- var <%= name.capitalize.pluralize -%>Controller = Jazz.Controller.create(
1
+ var <%= name.capitalize.pluralize %>Controller = Jazz.Controller.create(
2
2
  {
3
+
3
4
  initialize: function(){},
4
5
 
5
6
  index: function(){},
@@ -8,11 +9,11 @@ var <%= name.capitalize.pluralize -%>Controller = Jazz.Controller.create(
8
9
 
9
10
  create: function(){},
10
11
 
11
- edit: function(){},
12
+ update: function(){},
12
13
 
13
- destroy: function(){},
14
+ destroy: function(){}
14
15
 
15
16
  }
16
17
  );
17
18
 
18
- <%= name.pluralize -%>_controller = new <%= name.capitalize.pluralize -%>Controller;
19
+ <%= name.downcase.pluralize -%>_controller = new <%= name.capitalize.pluralize -%>Controller;
File without changes
File without changes
File without changes
File without changes
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jazz-jss
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Florian Schade
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-12-14 00:00:00 Z
18
+ date: 2011-12-20 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  version_requirements: &id001 !ruby/object:Gem::Requirement
@@ -138,14 +138,18 @@ files:
138
138
  - lib/jazz/scaffold_generator.rb
139
139
  - templates/app_root/app/assets/javascripts/application.js
140
140
  - templates/app_root/app/assets/stylesheets/application.css
141
- - templates/app_root/config/glue.js
142
141
  - templates/app_root/config/routes.js
143
142
  - templates/application.js
144
143
  - templates/controller.js
145
144
  - templates/db.js
145
+ - templates/glue.js
146
146
  - templates/index.html
147
147
  - templates/model.js
148
148
  - templates/scaffold_controller.js
149
+ - templates/view_create.html
150
+ - templates/view_index.html
151
+ - templates/view_show.html
152
+ - templates/view_update.html
149
153
  - LICENSE.txt
150
154
  - README.rdoc
151
155
  homepage: https://github.com/purpled/jazz
@@ -1,7 +0,0 @@
1
- var Glue = {
2
- Db: [],
3
- Helpers: [],
4
- Models: [],
5
- Views: [],
6
- Controllers: []
7
- };