amoeba-js-rails 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm gemset use amoeba-js-rails --create
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "http://rubygems.org"
2
+
3
+ group :development do
4
+ gem "jeweler", "~> 1.8.4"
5
+ end
@@ -0,0 +1,19 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ jeweler (1.8.4)
6
+ bundler (~> 1.0)
7
+ git (>= 1.2.5)
8
+ rake
9
+ rdoc
10
+ json (1.7.6)
11
+ rake (10.0.3)
12
+ rdoc (3.12)
13
+ json (~> 1.4)
14
+
15
+ PLATFORMS
16
+ ruby
17
+
18
+ DEPENDENCIES
19
+ jeweler (~> 1.8.4)
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Chris Barton
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.
@@ -0,0 +1,19 @@
1
+ = amoeba-core
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to amoeba-core
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
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2013 Chris Barton. See LICENSE.txt for
18
+ further details.
19
+
@@ -0,0 +1,34 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ gem.name = "amoeba-js-rails"
17
+ gem.homepage = "http://github.com/AmoebaConsulting/amoeba-js-rails"
18
+ gem.license = "MIT"
19
+ gem.summary = %Q{A lightweight JS framework designed to help organize your client-side code when working with Rails}
20
+ gem.description = "Amoeba.js is a lightweight JS framework designed to work with Rails" +
21
+ " (but potentially any MVC framework) and provide JS organization, routing, models, and views."
22
+ gem.email = "sayhi@amoe.ba"
23
+ gem.authors = ["Chris Barton"]
24
+ end
25
+ Jeweler::RubygemsDotOrgTasks.new
26
+
27
+ require 'rake/testtask'
28
+ Rake::TestTask.new(:test) do |test|
29
+ test.libs << 'lib' << 'test'
30
+ test.pattern = 'test/**/test_*.rb'
31
+ test.verbose = true
32
+ end
33
+
34
+ task :default => :test
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,64 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "amoeba-js-rails"
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Chris Barton"]
12
+ s.date = "2013-01-09"
13
+ s.description = "Amoeba.js is a lightweight JS framework designed to work with Rails (but potentially any MVC framework) and provide JS organization, routing, models, and views."
14
+ s.email = "sayhi@amoe.ba"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".rvmrc",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE.txt",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "amoeba-js-rails.gemspec",
28
+ "lib/amoeba-js-rails.rb",
29
+ "lib/amoeba_js_rails.rb",
30
+ "lib/amoeba_js_rails/version.rb",
31
+ "test/helper.rb",
32
+ "test/test_amoeba-core.rb",
33
+ "vendor/assets/javascripts/amoeba.js",
34
+ "vendor/assets/javascripts/amoeba/app.js.coffee",
35
+ "vendor/assets/javascripts/amoeba/helpers.js.coffee",
36
+ "vendor/assets/javascripts/amoeba/lib/events.js.coffee",
37
+ "vendor/assets/javascripts/amoeba/lib/lookup_context.js.coffee",
38
+ "vendor/assets/javascripts/amoeba/lib/route_set.js.coffee",
39
+ "vendor/assets/javascripts/amoeba/models/base.js.coffee",
40
+ "vendor/assets/javascripts/amoeba/routers/base.js.coffee",
41
+ "vendor/assets/javascripts/amoeba/views/base.js.coffee",
42
+ "vendor/assets/javascripts/lib/ext/coffeescript.js.coffee",
43
+ "vendor/assets/javascripts/lib/lib.js",
44
+ "vendor/assets/javascripts/lib/polyfills.js"
45
+ ]
46
+ s.homepage = "http://github.com/AmoebaConsulting/amoeba-js-rails"
47
+ s.licenses = ["MIT"]
48
+ s.require_paths = ["lib"]
49
+ s.rubygems_version = "1.8.24"
50
+ s.summary = "A lightweight JS framework designed to help organize your client-side code when working with Rails"
51
+
52
+ if s.respond_to? :specification_version then
53
+ s.specification_version = 3
54
+
55
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
56
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
57
+ else
58
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
59
+ end
60
+ else
61
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
62
+ end
63
+ end
64
+
@@ -0,0 +1 @@
1
+ require 'amoeba_js_rails'
@@ -0,0 +1,10 @@
1
+ module AmoebaJs
2
+ module Rails
3
+ if defined?(Rails) && ::Rails.version >= "3.1"
4
+ class Engine < ::Rails::Engine
5
+ end
6
+ end
7
+ end
8
+ end
9
+
10
+ require 'amoeba_js_rails/version'
@@ -0,0 +1,3 @@
1
+ module AmoebaJs::Rails
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'amoeba-core'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestAmoebaCore < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ //= require_self
2
+ //= require_tree ./lib
3
+ //= require amoeba/app
4
+
5
+ ;var Amoeba = (function(){
6
+ return {
7
+ Routers: {},
8
+ Models: {},
9
+ Views: {}
10
+ };
11
+ })();
@@ -0,0 +1,22 @@
1
+ #= require_directory ./lib
2
+ #= require ./helpers
3
+ #= require_directory ./routers
4
+ #= require_directory ./models
5
+ #= require_directory ./views
6
+ #= require_self
7
+
8
+ class Amoeba.App extends Module
9
+ @include Amoeba.Events
10
+
11
+ constructor: (@options = {}) ->
12
+ @helpers = new Amoeba.Helpers()
13
+ @routes = new Amoeba.RouteSet()
14
+
15
+ @initialize()
16
+ @start() if @options.start
17
+ @
18
+
19
+ start: ->
20
+ @currentView = @routes.route(window.location.pathname).currentView
21
+
22
+ initialize: ->
@@ -0,0 +1,9 @@
1
+ class Amoeba.Helpers
2
+ constructor: ->
3
+ @extractHelper methods for methods in @constructor.helpers
4
+
5
+ extractHelper: (methods) ->
6
+ (@[name] = method.bind(@)) for name, method of methods
7
+
8
+ @register: (helper) ->
9
+ (@helpers ?= []).push helper
@@ -0,0 +1,23 @@
1
+ Amoeba.Events = {
2
+ on: (events, callback) ->
3
+ if typeof events is 'string'
4
+ return this if not callback
5
+ e = {}
6
+ e[events] = callback
7
+ events = e
8
+ callbacks = @_callbacks or (@_callbacks = {})
9
+
10
+ for event, _callback of events
11
+ (callbacks[event] or (callbacks[event] = [])).push(_callback)
12
+ @
13
+ trigger: ->
14
+ event = arguments[0]
15
+ eventArgs = Array::slice.call(arguments, 1)
16
+
17
+ return this if not (@_callbacks and (callbacks = @_callbacks[event]))
18
+
19
+ for callback in callbacks
20
+ do (callback) ->
21
+ callback.apply(@, eventArgs)
22
+ @
23
+ }
@@ -0,0 +1,10 @@
1
+ class Amoeba.LookupContext
2
+ constructor: (@viewPath) ->
3
+ throw "Cannot find view path" unless @viewPath
4
+
5
+ find: (template) ->
6
+ view = @viewPath
7
+ namespaces = template.split('.')
8
+
9
+ (view = view[namespace]) for namespace in namespaces
10
+ view
@@ -0,0 +1,20 @@
1
+ class Amoeba.RouteSet
2
+ @GLOB_ROUTE = /.*/
3
+ constructor: (@routes = {}) ->
4
+ add: (router, regex, route) ->
5
+ if regex.source is @constructor.GLOB_ROUTE.source
6
+ @glob = [router, route]
7
+ else
8
+ @routes[route] = [router, regex]
9
+ route: (path) ->
10
+ routed = false
11
+ for action, route of @routes
12
+ router = route[0]
13
+ regex = route[1]
14
+
15
+ if regex.test(path)
16
+ routed = true
17
+ @execute(router, action)
18
+ @execute.apply(@, @glob) if @glob
19
+ execute: (router, action) ->
20
+ router.execute.call(router, action)
@@ -0,0 +1,22 @@
1
+ class Amoeba.Models.Base
2
+ constructor: ->
3
+ @attributes = {}
4
+ @initialize()
5
+ @
6
+
7
+ initialize: ->
8
+
9
+ set: (attributes) ->
10
+ @attributes[attribute] = value for attribute, value of attributes
11
+
12
+ get: (attribute) ->
13
+ @attributes[attribute]
14
+
15
+ toJson: (includeRoot = false) ->
16
+ base = {}
17
+ if includeRoot
18
+ throw 'There is no root association' unless @root
19
+ (base[@root] ?= {})[attribute] = value for attribute, value of @attributes
20
+ else
21
+ base[attribute] = value for attribute, value of @attributes
22
+ base
@@ -0,0 +1,22 @@
1
+ class Amoeba.Routers.Base extends Module
2
+ @include Amoeba.Events
3
+
4
+ constructor: (@app) ->
5
+ @helpers = @app.helpers
6
+ @lookupContext = new Amoeba.LookupContext(@app.options.viewLookupPath)
7
+ @initialize()
8
+ @
9
+
10
+ initialize: ->
11
+ route: (regex, action) ->
12
+ @app.routes.add @, regex, action
13
+ execute: (action) ->
14
+ @currentView = null
15
+ @[action]()
16
+ @
17
+ render: (partial) ->
18
+ throw "Render already called with #{@currentView}" if @currentView?
19
+
20
+ view = @lookupContext.find(partial)
21
+
22
+ @currentView = new view(@)
@@ -0,0 +1,38 @@
1
+ class Amoeba.Views.Base extends Module
2
+ @include Amoeba.Events
3
+
4
+ eventRegex: /([:\w]+)\s+([#-\.\w]+)/
5
+ constructor: (@controller, @parent, @options = {}) ->
6
+ @[key] = option for key, option of @options
7
+ @app = @controller.app
8
+ @lookupContext = @controller.lookupContext
9
+ @helpers = @controller.helpers
10
+
11
+ @rebind()
12
+ @events ?= {}
13
+
14
+ @delegateEvents()
15
+ @initialize()
16
+ @
17
+
18
+ initialize: ->
19
+ rebind: ->
20
+ @$ = $(@el or document)
21
+ delegateEvents: ->
22
+ for event, handler of @events
23
+ throw "Handler #{handler} does not exist for event delegation" unless @[handler]?
24
+
25
+ match = event.match(@eventRegex)
26
+ @[handler] = @[handler].bind(@)
27
+
28
+ @$.on(match[1], match[2], @[handler])
29
+ undelegateEvents: ->
30
+ for event, handler of @events
31
+ match = event.match(@eventRegex)
32
+
33
+ @$.off(match[1], match[2], @[handler])
34
+ render: (partial, options = {}) ->
35
+ view = @lookupContext.find(partial)
36
+ new view(@controller, @, options)
37
+ remove: ->
38
+ @$.remove()
@@ -0,0 +1,16 @@
1
+ moduleKeywords = ['extended', 'included']
2
+
3
+ class window.Module
4
+ @extend: (obj) ->
5
+ for key, value of obj when key not in moduleKeywords
6
+ @[key] = value
7
+
8
+ obj.extended?.apply(@)
9
+ @
10
+
11
+ @include: (obj) ->
12
+ for key, value of obj when key not in moduleKeywords
13
+ @::[key] = value
14
+
15
+ obj.included?.apply(@)
16
+ @
@@ -0,0 +1,2 @@
1
+ //= require_tree ./ext
2
+ //= require_directory .
@@ -0,0 +1,20 @@
1
+ (function(){
2
+ Object.keys || (Object.keys = function(object){
3
+ var keys = [];
4
+
5
+ for (var key in object) {
6
+ if (object.hasOwnProperty(key)) {
7
+ keys.push(key);
8
+ }
9
+ }
10
+
11
+ return keys;
12
+ });
13
+
14
+ Function.bind || (Function.bind = function(ctx){
15
+ var fn = this;
16
+ return function(){
17
+ return fn.apply(ctx, arguments);
18
+ };
19
+ });
20
+ })();
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: amoeba-js-rails
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.0
6
+ platform: ruby
7
+ authors:
8
+ - Chris Barton
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-09 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ prerelease: false
16
+ type: :development
17
+ name: jeweler
18
+ requirement: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: 1.8.4
23
+ none: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ version: 1.8.4
29
+ none: false
30
+ description: Amoeba.js is a lightweight JS framework designed to work with Rails (but
31
+ potentially any MVC framework) and provide JS organization, routing, models, and
32
+ views.
33
+ email: sayhi@amoe.ba
34
+ executables: []
35
+ extensions: []
36
+ extra_rdoc_files:
37
+ - LICENSE.txt
38
+ - README.rdoc
39
+ files:
40
+ - .rvmrc
41
+ - Gemfile
42
+ - Gemfile.lock
43
+ - LICENSE.txt
44
+ - README.rdoc
45
+ - Rakefile
46
+ - VERSION
47
+ - amoeba-js-rails.gemspec
48
+ - lib/amoeba-js-rails.rb
49
+ - lib/amoeba_js_rails.rb
50
+ - lib/amoeba_js_rails/version.rb
51
+ - test/helper.rb
52
+ - test/test_amoeba-core.rb
53
+ - vendor/assets/javascripts/amoeba.js
54
+ - vendor/assets/javascripts/amoeba/app.js.coffee
55
+ - vendor/assets/javascripts/amoeba/helpers.js.coffee
56
+ - vendor/assets/javascripts/amoeba/lib/events.js.coffee
57
+ - vendor/assets/javascripts/amoeba/lib/lookup_context.js.coffee
58
+ - vendor/assets/javascripts/amoeba/lib/route_set.js.coffee
59
+ - vendor/assets/javascripts/amoeba/models/base.js.coffee
60
+ - vendor/assets/javascripts/amoeba/routers/base.js.coffee
61
+ - vendor/assets/javascripts/amoeba/views/base.js.coffee
62
+ - vendor/assets/javascripts/lib/ext/coffeescript.js.coffee
63
+ - vendor/assets/javascripts/lib/lib.js
64
+ - vendor/assets/javascripts/lib/polyfills.js
65
+ homepage: http://github.com/AmoebaConsulting/amoeba-js-rails
66
+ licenses:
67
+ - MIT
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ segments:
78
+ - 0
79
+ hash: 3139468140220277540
80
+ none: false
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ none: false
87
+ requirements: []
88
+ rubyforge_project:
89
+ rubygems_version: 1.8.24
90
+ signing_key:
91
+ specification_version: 3
92
+ summary: A lightweight JS framework designed to help organize your client-side code
93
+ when working with Rails
94
+ test_files: []