Permalink
Browse files

Initial commit

  • Loading branch information...
charly committed Feb 9, 2012
0 parents commit f6311f86113c6b9ad97086ac703791732411f762
Showing with 13,968 additions and 0 deletions.
  1. +6 −0 .gitignore
  2. +17 −0 Gemfile
  3. +20 −0 MIT-LICENSE
  4. +42 −0 README.md
  5. +39 −0 Rakefile
  6. +23 −0 backbonify.gemspec
  7. +79 −0 lib/assets/javascripts/backbone.filter.js
  8. +318 −0 lib/assets/javascripts/backbone.grid.js
  9. +1,143 −0 lib/assets/javascripts/backbone.js
  10. +21 −0 lib/assets/javascripts/backbone_datalink.js
  11. +68 −0 lib/assets/javascripts/backbone_rails_sync.js
  12. +131 −0 lib/assets/javascripts/formly.min.js
  13. +783 −0 lib/assets/javascripts/jquery-ui.js
  14. +9,266 −0 lib/assets/javascripts/jquery.js
  15. +79 −0 lib/assets/javascripts/jquery.notice.js
  16. +480 −0 lib/assets/javascripts/json2.js
  17. +981 −0 lib/assets/javascripts/underscore.js
  18. +4 −0 lib/backbonify.rb
  19. +5 −0 lib/backbonify/engine.rb
  20. +3 −0 lib/backbonify/version.rb
  21. +8 −0 lib/generators/backbonify/USAGE
  22. +29 −0 lib/generators/backbonify/hbs/hbs_generator.rb
  23. +6 −0 lib/generators/backbonify/hbs/templates/_form.haml
  24. +4 −0 lib/generators/backbonify/hbs/templates/_row.haml
  25. +1 −0 lib/generators/backbonify/hbs/templates/edit.haml
  26. +13 −0 lib/generators/backbonify/hbs/templates/index.haml
  27. +1 −0 lib/generators/backbonify/hbs/templates/new.haml
  28. +2 −0 lib/generators/backbonify/hbs/templates/page.haml
  29. +1 −0 lib/generators/backbonify/hbs/templates/show.haml
  30. +49 −0 lib/generators/backbonify/install/install_generator.rb
  31. +12 −0 lib/generators/backbonify/install/templates/app.js
  32. +20 −0 lib/generators/backbonify/model/model_generator.rb
  33. +21 −0 lib/generators/backbonify/model/templates/model.js
  34. +55 −0 lib/generators/backbonify/resource_helpers.rb
  35. +44 −0 lib/generators/backbonify/router/router_generator.rb
  36. +24 −0 lib/generators/backbonify/router/templates/router.js
  37. +2 −0 lib/generators/backbonify/router/templates/template.jst
  38. +8 −0 lib/generators/backbonify/router/templates/view.coffee
  39. +26 −0 lib/generators/backbonify/scaffold/scaffold_generator.rb
  40. +25 −0 lib/generators/backbonify/views/templates/edit_view.js
  41. +15 −0 lib/generators/backbonify/views/templates/index_view.js
  42. +26 −0 lib/generators/backbonify/views/templates/new_view.js
  43. +22 −0 lib/generators/backbonify/views/templates/page_view.js
  44. +19 −0 lib/generators/backbonify/views/templates/show_view.js
  45. +21 −0 lib/generators/backbonify/views/views_generator.rb
  46. +6 −0 script/rails
@@ -0,0 +1,6 @@
+.bundle/
+log/*.log
+pkg/
+test/dummy/db/*.sqlite3
+test/dummy/log/*.log
+test/dummy/tmp/
17 Gemfile
@@ -0,0 +1,17 @@
+source "http://rubygems.org"
+
+# Declare your gem's dependencies in backbonify.gemspec.
+# Bundler will treat runtime dependencies like base dependencies, and
+# development dependencies will be added by default to the :development group.
+gemspec
+
+# jquery-rails is used by the dummy application
+gem "jquery-rails"
+
+# Declare any dependencies that are still in development here instead of in
+# your gemspec. These might include edge Rails or gems from your path or
+# Git. Remember to move these dependencies to your gemspec before releasing
+# your gem to rubygems.org.
+
+# To use debugger
+# gem 'ruby-debug'
@@ -0,0 +1,20 @@
+Copyright 2011 Charles Sistovaris
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,42 @@
+# Backbonify
+A generator for Backbone in Rails >= 3.1. The Language is javascript (no coffee)
+and the template engine is (only) handlebars wraped in haml! However this generator takes advantage of hooks (brought by yehuda in rails 3) so it is easy to add other template
+engines and so on...
+
+## Warning
+This is not a general purpose generator. I made it to fit my needs. And its quit beta.
+But hey it's just generators, not code...
+
+## Install with Rails 3.1
+In your Gemfile
+ gem "backbonify", :git => "http://github.com/charly/backbonify"
+
+## Usage
+In your console
+ rails g backbonify:install
+ rails g backbonify:scaffold Model field:type field:type
+
+## More Usage
+backbonify:scaffold hooks on those (sub) generators. You can also cherry pick them!
+ rails g backbonify:model Model field:type ...
+ rails g backbonify:router Model
+ rails g backbonify:view Model
+ rails g backbonify:template Model field:type ...
+
+## TODO
+test!!! options & more doc on what files it generates....
+
+## Dependencies for haml and handlebars
+Include them in your Gemfile
+ gem 'handlebars_assets'
+ gem 'haml_assets', :git => "http://github.com/infbio/haml_assets"
+
+
+## Thanks to
+Originally I wanted to fork [backbone-rails][1] to add javascript version
+(instead of cofeescript only). But it was too far a part.
+
+## License
+This project rocks and uses MIT-LICENSE.
+
+[1]: https://github.com/codebrew/backbone-rails
@@ -0,0 +1,39 @@
+#!/usr/bin/env rake
+begin
+ require 'bundler/setup'
+rescue LoadError
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
+end
+begin
+ require 'rdoc/task'
+rescue LoadError
+ require 'rdoc/rdoc'
+ require 'rake/rdoctask'
+ RDoc::Task = Rake::RDocTask
+end
+
+RDoc::Task.new(:rdoc) do |rdoc|
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = 'Backbonify'
+ rdoc.options << '--line-numbers'
+ rdoc.rdoc_files.include('README.rdoc')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
+
+APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
+load 'rails/tasks/engine.rake'
+
+
+Bundler::GemHelper.install_tasks
+
+require 'rake/testtask'
+
+Rake::TestTask.new(:test) do |t|
+ t.libs << 'lib'
+ t.libs << 'test'
+ t.pattern = 'test/**/*_test.rb'
+ t.verbose = false
+end
+
+
+task :default => :test
@@ -0,0 +1,23 @@
+$:.push File.expand_path("../lib", __FILE__)
+
+# Maintain your gem's version:
+require "backbonify/version"
+
+# Describe your gem and declare its dependencies:
+Gem::Specification.new do |s|
+ s.name = "backbonify"
+ s.version = Backbonify::VERSION
+ s.authors = ["Charles Sistovaris"]
+ s.email = ["TODO: Your email"]
+ s.homepage = "http://ruby.simapse.com/"
+ s.summary = "Backbone Generator for Rails >= 3.1"
+ s.description = "TODO: Description of Backbonify."
+
+ s.files = Dir["{lib}/**/*"] + ["MIT-LICENSE", "Rakefile", "README.rdoc"]
+ s.test_files = Dir["test/**/*"]
+
+ s.add_dependency "rails", "~> 3.1"
+ # s.add_dependency "jquery-rails"
+
+ s.add_development_dependency "sqlite3"
+end
@@ -0,0 +1,79 @@
+// TODO : a mixin for pageViewfiltering
+//var pageViewfiltering = {
+// filter: function(event) {
+// if (event.which == 13) {
+// var a = this.getAttrValue(event)
+// this.collection.filterAttr(a[0], a[1])
+// }
+// },
+//
+// showLength:function() {
+// this.$("#collectionLength").text(this.collection.length)
+// },
+//
+// // helper to get the attr 'film' out of name='performance[film]'
+// getAttrValue: function(event) {
+// var $target = $(event.currentTarget),
+// query = $target.val(),
+// attr = $target.prop("name").replace(/[a-z_].*\[([a-z].*)\]/, "$1")
+// return [attr, query]
+// }
+//}
+
+
+var Filter = {
+ // ADD this in the collection
+ //initialize: function() {
+ // this._prepareFiltering();
+ //}
+
+ //
+ // FILTERING
+ //
+ _prepareFiltering: function() {
+ this.originalCollection = new Backbone.Collection;
+ this.previousCollection = new Backbone.Collection;
+ this.filterCollection = this;
+ this.bind("reset", this.setOriginalCollection, this)
+ },
+
+ //filterAttr("film", "city") instead of filterFilms("city")
+ filterAttr: function(attribute, query) {
+ this.handleFilters(attribute, query);
+
+ var reg = new RegExp(query,"i");
+ this.filtering(function(model){
+ var attrValue = model.get(attribute);
+ if(attrValue && attrValue.match(reg)) return model;
+ })
+ },
+
+ // previousCollection keeps track of the previous result so
+ // it can refilter on that one (it should be an array actually)
+ // TODO : consider having a filter for each attribute......
+ handleFilters: function(attribute, query) {
+ if(query == "") {
+ this.filterCollection = this.originalCollection
+ }
+ else if(this.previousAttr==attribute) {
+ this.filterCollection = this.previousCollection
+ }
+ else {
+ this.filterCollection = this;
+ }
+ this.previousCollection.reset(this.filterCollection.models);
+ this.previousAttr = attribute;
+ },
+
+ filtering: function(criteria) {
+ this.reset(this.filterCollection.select(criteria), {silent: true})
+ this.trigger("filter");
+ },
+
+ // loadedCollection is a copy of this collection to store
+ // the original models before they get filtered
+ setOriginalCollection: function(event) {
+ this.originalCollection.reset(this.models)
+ }
+
+}
Oops, something went wrong.

0 comments on commit f6311f8

Please sign in to comment.