vertebra 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9570222ad06676f9caa91978cd25c518fb5d9299
4
+ data.tar.gz: cbcecb3c43d1244bb0375023654978fb11bf8725
5
+ SHA512:
6
+ metadata.gz: b6ab678cd94743dcf64a14e29316dcfcfdd355442420d78a53dfa9505b9d1ccd1266592c6cd4781fe68bcaa9c667b53d52dc50b895d0cba44ae1033a4d687c09
7
+ data.tar.gz: 03498b133b4a51449b491b29300e331dd99cbfb719ae020cba0b8e8296a6938efe528e37b293faef62fdc9ca33bedb9871bef58cc599e3ab9eff032ca1bec3c2
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2016 vala
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,61 @@
1
+ # Vertebra
2
+
3
+ Micro Coffeescript framework for use instead of Backbone.View to avoid requiring
4
+ underscore and the whole backbone framework.
5
+
6
+ Supported Backbone.View features :
7
+
8
+ - DOM Events delegation (with prototype.events property)
9
+ - Class-level events API (listenTo / stopListening / on / off / trigger)
10
+ - Automatic element assignation (this.$el) and scoped finders (this.$(selector))
11
+
12
+ ## Installation
13
+
14
+ Add to your Gemfile and bundle :
15
+
16
+ ```ruby
17
+ gem 'vertebra'
18
+ ```
19
+
20
+ Require the framework :
21
+
22
+ ```javascript
23
+ //= require vertebra
24
+ ```
25
+
26
+ ## Usage
27
+
28
+ Here's a simple example API usage covering most of the Vertebra supported
29
+ features.
30
+
31
+ ```coffeescript
32
+ class MyPanel extends Vertebra.View
33
+ events:
34
+ 'click .trigger-button': 'buttonClicked'
35
+
36
+ # Like for Backbone, use the `#initialize` method isteand of `#constructor`
37
+ # to hook into class instanciation
38
+ #
39
+ initialize: ->
40
+ @form = new MyForm(el: @$('form'))
41
+ # Class-level events API
42
+ @listenTo(@form, 'submit', @onFormSubmit)
43
+
44
+ buttonClicked: ->
45
+ # Button clicked here
46
+
47
+ onFormSubmit: ->
48
+ # Form submitted here
49
+
50
+
51
+ class MyButton extends Vertebra.View
52
+ events:
53
+ 'submit': 'onSubmit'
54
+
55
+ onSubmit: ->
56
+ @trigger('submit')
57
+ ```
58
+
59
+ # Licence
60
+
61
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,26 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Vertebra'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+ load 'rails/tasks/statistics.rake'
22
+
23
+
24
+
25
+ Bundler::GemHelper.install_tasks
26
+
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,88 @@
1
+ # Global Vertebra namespace
2
+ @Vertebra = {}
3
+
4
+ # Allows assigning unique ids to views
5
+ lastUniqueId = 0
6
+ uniqueId = (prefix) ->
7
+ [prefix, ++lastUniqueId].join('-')
8
+
9
+ # Regex to split delegated events string
10
+ delegateEventSplitter = /^(\S+)\s*(.*)$/
11
+
12
+ @camelize = (str) ->
13
+ str.replace(/(^|[-_])(.)/g, (match) -> return match.toUpperCase()).replace(/[-_]/g, '')
14
+
15
+ # Minimalist Backbon.View with support for view element, this.$ and delegated
16
+ # events on initialization.
17
+ #
18
+ # Only depends on jQuery, and not underscore.js
19
+ class Vertebra.View
20
+ $: (selector) ->
21
+ @$el.find(selector)
22
+
23
+ constructor: (options) ->
24
+ @setElement(options.el) if options.el
25
+ @_eventListeners = {}
26
+ @_listeningTo = {}
27
+ @cid = uniqueId('view')
28
+ @initialize?.apply(this, arguments)
29
+
30
+ setElement: (el) ->
31
+ @$el = if el instanceof $ then el else $(el)
32
+ @el = @$el[0]
33
+ @delegateEvents()
34
+
35
+ delegateEvents: ->
36
+ return unless @events
37
+ @_undelegateEvents()
38
+
39
+ for key, method of @events
40
+ method = @[method]
41
+ continue unless method
42
+ match = key.match(delegateEventSplitter)
43
+ @delegate(match[1], match[2], $.proxy(method, this))
44
+
45
+ delegate: (eventName, selector, listener) ->
46
+ @$el?.on(eventName + '.delegateEvents' + @cid, selector, listener)
47
+
48
+ _undelegateEvents: ->
49
+ @$el?.off('.delegateEvents' + @cid)
50
+
51
+ listenTo: (object, eventName, listener) ->
52
+ @_listeningTo[object.cid] ?= {}
53
+ @_listeningTo[object.cid][eventName] ?= []
54
+ @_listeningTo[object.cid][eventName].push(listener)
55
+
56
+ object.on(eventName, (=> listener.apply(this, arguments)))
57
+
58
+ on: (eventName, listener) ->
59
+ @_eventListeners[eventName] ?= []
60
+ @_eventListeners[eventName].push(listener)
61
+
62
+ off: (eventName, listener) ->
63
+ return unless (listeners = @_eventListeners[eventName])
64
+
65
+ if listener
66
+ listeners.splice(index, 1) for index of listeners when listeners[index] is listener
67
+ else
68
+ @_eventListeners[eventName] = []
69
+
70
+ trigger: (eventName, args...) ->
71
+ if (listeners = @_eventListeners[eventName])
72
+ listener.apply(this, args) for listener in listeners
73
+
74
+ stopListeningTo: (object, eventName, listener) ->
75
+ if (listenersHash = @_listeningTo[object.cid]) and (listeners = listenersHash[eventName])
76
+ object.off(eventName, listener) for listener in listeners
77
+
78
+ stopListening: ->
79
+ return unless @_listeningTo
80
+
81
+ for object, events of @_listeningTo
82
+ for eventName, listeners of events
83
+ @stopListeningTo(object, eventName, listener)
84
+
85
+ destroy: ->
86
+ @stopListening()
87
+
88
+
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,4 @@
1
+ module Vertebra
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Vertebra
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Vertebra</title>
5
+ <%= stylesheet_link_tag "vertebra/application", media: "all" %>
6
+ <%= javascript_include_tag "vertebra/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
data/config/routes.rb ADDED
@@ -0,0 +1,2 @@
1
+ Vertebra::Engine.routes.draw do
2
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :vertebra do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,5 @@
1
+ module Vertebra
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace Vertebra
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module Vertebra
2
+ VERSION = "0.1.0"
3
+ end
data/lib/vertebra.rb ADDED
@@ -0,0 +1,4 @@
1
+ require "vertebra/engine"
2
+
3
+ module Vertebra
4
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vertebra
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - vala
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.1'
20
+ - - "<="
21
+ - !ruby/object:Gem::Version
22
+ version: '5.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '3.1'
30
+ - - "<="
31
+ - !ruby/object:Gem::Version
32
+ version: '5.0'
33
+ description: Mico-JS Framework based on the Backbone.View API
34
+ email:
35
+ - vala@glyph.fr
36
+ executables: []
37
+ extensions: []
38
+ extra_rdoc_files: []
39
+ files:
40
+ - MIT-LICENSE
41
+ - README.md
42
+ - Rakefile
43
+ - app/assets/javascripts/vertebra.coffee
44
+ - app/assets/javascripts/vertebra/application.js
45
+ - app/assets/stylesheets/vertebra/application.css
46
+ - app/controllers/vertebra/application_controller.rb
47
+ - app/helpers/vertebra/application_helper.rb
48
+ - app/views/layouts/vertebra/application.html.erb
49
+ - config/routes.rb
50
+ - lib/tasks/vertebra_tasks.rake
51
+ - lib/vertebra.rb
52
+ - lib/vertebra/engine.rb
53
+ - lib/vertebra/version.rb
54
+ homepage: https://github.com/glyph-fr/vertebra
55
+ licenses:
56
+ - MIT
57
+ metadata: {}
58
+ post_install_message:
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ requirements: []
73
+ rubyforge_project:
74
+ rubygems_version: 2.5.1
75
+ signing_key:
76
+ specification_version: 4
77
+ summary: Mico-JS Framework based on the Backbone.View API
78
+ test_files: []