sumatra-rails 0.0.4.1 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. data/Gemfile.lock +4 -5
  2. data/lib/sumatra/rails/version.rb +1 -1
  3. data/vendor/assets/javascripts/sumatra.js.coffee +122 -1
  4. metadata +19 -30
  5. checksums.yaml +0 -15
  6. data/vendor/assets/javascripts/sumatra/.env.example +0 -1
  7. data/vendor/assets/javascripts/sumatra/.gitignore +0 -2
  8. data/vendor/assets/javascripts/sumatra/Cakefile +0 -27
  9. data/vendor/assets/javascripts/sumatra/LICENSE.md +0 -20
  10. data/vendor/assets/javascripts/sumatra/README.md +0 -183
  11. data/vendor/assets/javascripts/sumatra/component.json +0 -30
  12. data/vendor/assets/javascripts/sumatra/docs/docco.css +0 -500
  13. data/vendor/assets/javascripts/sumatra/docs/index.html +0 -177
  14. data/vendor/assets/javascripts/sumatra/docs/index.md +0 -0
  15. data/vendor/assets/javascripts/sumatra/docs/plugin.js.html +0 -207
  16. data/vendor/assets/javascripts/sumatra/docs/public/fonts/aller-bold.eot +0 -0
  17. data/vendor/assets/javascripts/sumatra/docs/public/fonts/aller-bold.ttf +0 -0
  18. data/vendor/assets/javascripts/sumatra/docs/public/fonts/aller-bold.woff +0 -0
  19. data/vendor/assets/javascripts/sumatra/docs/public/fonts/aller-light.eot +0 -0
  20. data/vendor/assets/javascripts/sumatra/docs/public/fonts/aller-light.ttf +0 -0
  21. data/vendor/assets/javascripts/sumatra/docs/public/fonts/aller-light.woff +0 -0
  22. data/vendor/assets/javascripts/sumatra/docs/public/fonts/fleurons.eot +0 -0
  23. data/vendor/assets/javascripts/sumatra/docs/public/fonts/fleurons.ttf +0 -0
  24. data/vendor/assets/javascripts/sumatra/docs/public/fonts/fleurons.woff +0 -0
  25. data/vendor/assets/javascripts/sumatra/docs/public/fonts/novecento-bold.eot +0 -0
  26. data/vendor/assets/javascripts/sumatra/docs/public/fonts/novecento-bold.ttf +0 -0
  27. data/vendor/assets/javascripts/sumatra/docs/public/fonts/novecento-bold.woff +0 -0
  28. data/vendor/assets/javascripts/sumatra/docs/public/images/gray.png +0 -0
  29. data/vendor/assets/javascripts/sumatra/docs/public/stylesheets/normalize.css +0 -375
  30. data/vendor/assets/javascripts/sumatra/docs/runtime.js.html +0 -111
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sumatra-rails (0.0.4.1)
4
+ sumatra-rails (0.0.5)
5
5
  coffee-rails
6
6
  jquery-rails
7
7
  rails (~> 3.2)
@@ -44,7 +44,7 @@ GEM
44
44
  coffee-script (2.2.0)
45
45
  coffee-script-source
46
46
  execjs
47
- coffee-script-source (1.6.1)
47
+ coffee-script-source (1.6.2)
48
48
  erubis (2.7.0)
49
49
  execjs (1.4.0)
50
50
  multi_json (~> 1.0)
@@ -55,11 +55,10 @@ GEM
55
55
  railties (>= 3.0, < 5.0)
56
56
  thor (>= 0.14, < 2.0)
57
57
  json (1.7.7)
58
- mail (2.5.3)
59
- i18n (>= 0.4.0)
58
+ mail (2.5.4)
60
59
  mime-types (~> 1.16)
61
60
  treetop (~> 1.4.8)
62
- mime-types (1.21)
61
+ mime-types (1.23)
63
62
  multi_json (1.7.1)
64
63
  polyglot (0.3.3)
65
64
  rack (1.4.5)
@@ -1,5 +1,5 @@
1
1
  module Sumatra
2
2
  module Rails
3
- VERSION = "0.0.4.1"
3
+ VERSION = "0.0.5"
4
4
  end
5
5
  end
@@ -1 +1,122 @@
1
- #= require_tree ./sumatra/pkg
1
+ # SumatraPlugin
2
+ # -------------
3
+ #
4
+ # A prototype object for common actions when defining jQuery plugins
5
+ # in the Sumatra framework. It is designed so that you never have to
6
+ # override the constructor. Instead, the constructor sets up a common
7
+ # method interface for both initialization (which would happen after
8
+ # construction) and the binding of events, a common task in jQuery
9
+ # plugins. This prototype even handles some of that for you, with
10
+ # the default `bindEvents()` being bound to call the `perform()`
11
+ # method (which must be defined by the object extending `SumatraPlugin`)
12
+ # whenever the element it was constructed with triggers the event
13
+ # defined by `action`.
14
+ #
15
+ # So essentially, you can define almost any jQuery plugin using this
16
+ # interface, even though the only thing binding it to the `sumatra`
17
+ # function is its constructor that takes 3 parameters.
18
+ #
19
+ # `SumatraPlugin` also has facilities for dealing with an options hash
20
+ # and merging said options with defaults. You can define the default
21
+ # options for your plugin like so:
22
+ #
23
+ # sumatra 'clickToGo', ->
24
+ # class ClickToGo extends SumatraPlugin
25
+ # action: 'click'
26
+ # defaults: { to: 'http://google.com' }
27
+ # perform: (event) =>
28
+ # if confirm "Are you sure you want to go to #{@options.goTo}?"
29
+ # window.location = @options.goTo
30
+ #
31
+ # Then, when instantiating, just override them.
32
+ #
33
+ # $('a').clickToGo(to: 'http://yahoo.com');
34
+ #
35
+ # This removes the need for writing that boilerplate options hash extend
36
+ # code every time you write a jQuery plugin that takes options. All
37
+ # plugins defined with `sumatra()` take an optional options hash, which is
38
+ # `{}` by default, in case your plugin doesn't require options.
39
+ class @SumatraPlugin
40
+ # The event to bind to if `perform()` is defined.
41
+ action: 'one'
42
+
43
+ # A hash of attributes that are extended with an options hash passed
44
+ # into the jQuery plugin upon instantiation. Useful for setting up
45
+ # data that is required.
46
+ defaults: {}
47
+
48
+ # Instantiate a `SumatraPlugin` and bind it to the current element
49
+ # with options. This also initiates the workflow.
50
+ #
51
+ # **DO NOT OVERRIDE!!**
52
+ constructor: (current_element, index_of_query, init_options) ->
53
+ @element = $(current_element)
54
+ @index = index_of_query
55
+ @options = @mergeDefaultsWith init_options
56
+ @element.data 'serviceObject', this
57
+ @initialize() and @bindEvents()
58
+
59
+ # Merge `options` hash with the `defaults` as set in the definition
60
+ # of this object.
61
+ mergeDefaultsWith: (options) ->
62
+ _.extend @defaults, @options
63
+
64
+ # Run custom constructor code, but blocks instantiation if this method
65
+ # returns `false`. This method was pretty much designed to be overridden.
66
+ initialize: ->
67
+ true
68
+
69
+ # Bind the `perform()` method to the `action` as set in the definition
70
+ # of this plugin. Overriding this method removes the guarantee that
71
+ # perform() will be called at all...
72
+ bindEvents: ->
73
+ if @action?
74
+ @element.on @action, @perform
75
+
76
+ # The event binding that handles `action`. Override this with your own
77
+ # method. You must override this method or the `bindEvents` method to
78
+ # get this plugin to do anything. It takes a single argument, `event`,
79
+ # which represents the given DOMEvent represented by `action` as passed
80
+ # in by `jQuery.on`.
81
+ perform: null
82
+
83
+ # SumatraRuntime
84
+ # --------------
85
+ #
86
+ # Defines a jQuery plugin using a service object with a nice,
87
+ # consistent, CoffeeScript-style interface. Plugins can extend
88
+ # `SumatraPlugin`, a prototype that makes defining plugins with
89
+ # Sumatra easier.
90
+ #
91
+ # The runtime function returns the generated jQuery plugin to the
92
+ # global scope so it can be used in your application code.
93
+ #
94
+ # Arguments:
95
+ #
96
+ # - **plugin_name:** The jQuery plugin name, called like `$('div').myPlugin();`
97
+ # - **plugin_code:** A function that will be executed immediately and must return
98
+ # a single object that takes 3 parameters in its constructor. These parameters
99
+ # are the `element` being targeted by jQuery, the `index` at which it appears
100
+ # in the query, and the `options` hash passed during the instantiation of the
101
+ # jQuery plugin.
102
+ #
103
+ # Example:
104
+ #
105
+ # sumatra 'myPlugin', ->
106
+ # class MyPlugin extends SumatraPlugin
107
+ # action: null
108
+ # initialize:
109
+ # alert 'loaded'
110
+ #
111
+ @sumatra = (plugin_name, plugin_code) ->
112
+ # Instantiate a PluginHelper and apply the current scope. This can
113
+ # be any object that responds to 3 parameters in its constructor
114
+ # and will be set to whatever is returned by `plugin_code()`.
115
+ PluginHelper = plugin_code.apply this
116
+
117
+ jQuery.fn[plugin_name] = (options={}) ->
118
+ @each (index, element) ->
119
+ # For each element, create a `PluginHelper` instance
120
+ # of the passed-in `plugin_code` and apply the jQuery
121
+ # plugin parameters to the constructor.
122
+ new PluginHelper(element, index, options)
metadata CHANGED
@@ -1,18 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sumatra-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4.1
4
+ version: 0.0.5
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Tom Scott
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2013-03-19 00:00:00.000000000 Z
12
+ date: 2013-05-24 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: rails
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
19
  - - ~>
18
20
  - !ruby/object:Gem::Version
@@ -20,6 +22,7 @@ dependencies:
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
27
  - - ~>
25
28
  - !ruby/object:Gem::Version
@@ -27,6 +30,7 @@ dependencies:
27
30
  - !ruby/object:Gem::Dependency
28
31
  name: jquery-rails
29
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
30
34
  requirements:
31
35
  - - ! '>='
32
36
  - !ruby/object:Gem::Version
@@ -34,6 +38,7 @@ dependencies:
34
38
  type: :runtime
35
39
  prerelease: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
37
42
  requirements:
38
43
  - - ! '>='
39
44
  - !ruby/object:Gem::Version
@@ -41,6 +46,7 @@ dependencies:
41
46
  - !ruby/object:Gem::Dependency
42
47
  name: coffee-rails
43
48
  requirement: !ruby/object:Gem::Requirement
49
+ none: false
44
50
  requirements:
45
51
  - - ! '>='
46
52
  - !ruby/object:Gem::Version
@@ -48,6 +54,7 @@ dependencies:
48
54
  type: :runtime
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
51
58
  requirements:
52
59
  - - ! '>='
53
60
  - !ruby/object:Gem::Version
@@ -108,53 +115,35 @@ files:
108
115
  - test/sumatra_test.rb
109
116
  - test/test_helper.rb
110
117
  - vendor/assets/javascripts/sumatra.js.coffee
111
- - vendor/assets/javascripts/sumatra/.env.example
112
- - vendor/assets/javascripts/sumatra/.gitignore
113
- - vendor/assets/javascripts/sumatra/Cakefile
114
- - vendor/assets/javascripts/sumatra/LICENSE.md
115
- - vendor/assets/javascripts/sumatra/README.md
116
- - vendor/assets/javascripts/sumatra/component.json
117
- - vendor/assets/javascripts/sumatra/docs/docco.css
118
- - vendor/assets/javascripts/sumatra/docs/index.html
119
- - vendor/assets/javascripts/sumatra/docs/index.md
120
- - vendor/assets/javascripts/sumatra/docs/plugin.js.html
121
- - vendor/assets/javascripts/sumatra/docs/public/fonts/aller-bold.eot
122
- - vendor/assets/javascripts/sumatra/docs/public/fonts/aller-bold.ttf
123
- - vendor/assets/javascripts/sumatra/docs/public/fonts/aller-bold.woff
124
- - vendor/assets/javascripts/sumatra/docs/public/fonts/aller-light.eot
125
- - vendor/assets/javascripts/sumatra/docs/public/fonts/aller-light.ttf
126
- - vendor/assets/javascripts/sumatra/docs/public/fonts/aller-light.woff
127
- - vendor/assets/javascripts/sumatra/docs/public/fonts/fleurons.eot
128
- - vendor/assets/javascripts/sumatra/docs/public/fonts/fleurons.ttf
129
- - vendor/assets/javascripts/sumatra/docs/public/fonts/fleurons.woff
130
- - vendor/assets/javascripts/sumatra/docs/public/fonts/novecento-bold.eot
131
- - vendor/assets/javascripts/sumatra/docs/public/fonts/novecento-bold.ttf
132
- - vendor/assets/javascripts/sumatra/docs/public/fonts/novecento-bold.woff
133
- - vendor/assets/javascripts/sumatra/docs/public/images/gray.png
134
- - vendor/assets/javascripts/sumatra/docs/public/stylesheets/normalize.css
135
- - vendor/assets/javascripts/sumatra/docs/runtime.js.html
136
118
  homepage: http://github.com/tubbo/sumatra-rails
137
119
  licenses: []
138
- metadata: {}
139
120
  post_install_message:
140
121
  rdoc_options: []
141
122
  require_paths:
142
123
  - lib
143
124
  required_ruby_version: !ruby/object:Gem::Requirement
125
+ none: false
144
126
  requirements:
145
127
  - - ! '>='
146
128
  - !ruby/object:Gem::Version
147
129
  version: '0'
130
+ segments:
131
+ - 0
132
+ hash: 1720138496632790677
148
133
  required_rubygems_version: !ruby/object:Gem::Requirement
134
+ none: false
149
135
  requirements:
150
136
  - - ! '>='
151
137
  - !ruby/object:Gem::Version
152
138
  version: '0'
139
+ segments:
140
+ - 0
141
+ hash: 1720138496632790677
153
142
  requirements: []
154
143
  rubyforge_project:
155
- rubygems_version: 2.0.0
144
+ rubygems_version: 1.8.23
156
145
  signing_key:
157
- specification_version: 4
146
+ specification_version: 3
158
147
  summary: Sumatra is a CoffeeScript framework for writing beautiful jQuery plugins.
159
148
  test_files:
160
149
  - test/dummy/app/assets/javascripts/application.js
checksums.yaml DELETED
@@ -1,15 +0,0 @@
1
- ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ODkxYTU2MjY5YjZlN2RmYjQ3OWJjMDQyMDM1Mjg3ZmRlNzlmNmM1ZQ==
5
- data.tar.gz: !binary |-
6
- ODI5MDY2OWRlMWIxZjZkYTQ4N2MxODAzYzFlOTI5MzEyMTI2Yjk2YQ==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- NDA3OTZiMjgzNzAzMjMyOTRhYmY1ZjQwMmNiMGUyOGFmNjFiMTA5ZTBjNmY3
10
- MjgyYjU5NGJmMDFjNjYzMzg2YzE1Y2E1ODJkNDc4OTBmY2NlZjhlNDE2Nzkx
11
- OTI1Y2JkZDYxNDIyNzRhZmEwZGIyYjM5MDk3ZTgwNTIxNDlmZTY=
12
- data.tar.gz: !binary |-
13
- MzNlMjZhM2QyMDAyZmY3MjMzZjgzZTBhMDRkZTRlYjgwZWNjOThiYzdlMzc0
14
- NzhlZTg1MzZmY2U4NWVlMGRjZjdhNzdiZmYxY2E1MzliZDI0NzJjMDBkYTVj
15
- ZGI3NmJmNjQ4NjY0MmFkZmNmZjI0OTdhMjg5Yjg3YjA2OGEzYWQ=
@@ -1 +0,0 @@
1
- PATH=node_modules/.bin:$PATH
@@ -1,2 +0,0 @@
1
- node_modules
2
- components/sumatra/
@@ -1,27 +0,0 @@
1
- {exec} = require 'child_process'
2
-
3
- task 'build:javascript', "Compile Sumatra into JavaScript", ->
4
- exec 'coffee --join pkg/sumatra.js --compile lib/sumatra/*.coffee'
5
-
6
- task 'build:coffeescript', "Compile Sumatra into CoffeeScript", ->
7
- fs = require 'fs'
8
- src = fs.readFileSync 'lib/sumatra/plugin.js.coffee'
9
- src += fs.readFileSync 'lib/sumatra/runtime.js.coffee'
10
- fs.writeFile 'pkg/sumatra.coffee', src, (err) ->
11
- throw err if err
12
- true
13
-
14
- task 'build', "Compile Sumatra into both languages", ->
15
- invoke 'build:coffeescript'
16
- invoke 'build:javascript'
17
-
18
- task 'test', "Run all tests", ->
19
- exec "NODE_ENV=test
20
- mocha
21
- --compilers coffee:coffee-script
22
- --require coffee-script
23
- --require test/test_helper.js.coffee
24
- --colors
25
- ", (err, output) ->
26
- throw err if err
27
- console.log output
@@ -1,20 +0,0 @@
1
- Copyright 2013 Tom Scott
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.
@@ -1,183 +0,0 @@
1
- # Sumatra
2
-
3
- Sumatra is a CoffeeScript framework for writing jQuery plugins harder,
4
- better, faster, stronger.
5
-
6
- You should use Sumatra if you...
7
-
8
- - Encapsulate complex jQuery plugins in a service object and call an
9
- instance of that service object for each DOM element the plugin
10
- selector is passed
11
- - Enjoy test-driven development, clear code, and convention over
12
- configuration
13
- - Believe unicorns are real
14
-
15
- ## Why?
16
-
17
- A lot of jQuery plugins are written to encapsulate a simple bit of
18
- functionality used throughout the application. But jQuery's syntax was
19
- designed to improve the way people write JavaScript. CoffeeScript has a
20
- similar goal, but approaches it from a different angle, it compiles its
21
- syntax into JavaScript but does so in a safe, syntactically correct and
22
- (mostly) readable way. This framework unites the two, and finally allows
23
- jQuery developers to build plugins in CoffeeScript without making their
24
- code look, well, downright ugly!
25
-
26
- ## Installation
27
-
28
- ### Requirements
29
-
30
- - jQuery
31
- - CoffeeScript if you want to develop it..
32
-
33
- We recommend Bower for installing Sumatra as a component:
34
-
35
- ```bash
36
- $ bower install sumatra
37
- ```
38
-
39
- However, you can also install Sumatra manually by just including the
40
- `pkg/sumatra.js` file in your javascripts directory.
41
-
42
- ## Usage
43
-
44
- Sumatra values convention over configuration, and its usage revolves
45
- around an established pattern that hopefully others will find useful.
46
-
47
- ### Defining a Basic Plugin
48
-
49
- After loading Sumatra, you can build jQuery plugins that are both clear
50
- and superbly terse:
51
-
52
- ```coffeescript
53
- sumatra 'clickMe', ->
54
- class ClickMe extends SumatraPlugin
55
- action: 'click'
56
- perform: (event) =>
57
- element_id = @element.attr('id') || '<div>'
58
- alert "You just clicked #{element_id}!"
59
- ```
60
-
61
- All this plugin does is show an `alert()` when the element is clicked.
62
- You can define a single action with `action:` and then define the
63
- `perform()` event handler that binds to whatever action you've set
64
- on the element.
65
-
66
- To bind an element to this event, just call it like any normal
67
- jQuery plugin:
68
-
69
- ```coffeescript
70
- $('#my_element').clickMe();
71
- ```
72
-
73
- ### Parameters
74
-
75
- You can also make plugins that pass in options. All Sumatra plugins
76
- take an `options` hash as their only argument, regardless of whether
77
- the service object uses them or not.
78
-
79
- ```coffeescript
80
- sumatra 'ajaxSubmit', ->
81
- class AjaxSubmit extends SumatraPlugin
82
- action: 'submit'
83
- mergeOptions: ->
84
- @defaults = @_getFormDefaults()
85
- _.extend(@options, @defaults)
86
-
87
- perform: (event) =>
88
- event.preventDefault()
89
- event.stopPropagation()
90
- $.ajax @options
91
-
92
- _getFormDefaults: ->
93
- {
94
- url: @element.attr('action')
95
- type: @element.attr('method')
96
- error: (message, status, xhr) ->
97
- console.log status, message, xhr
98
- alert "#{status}: #{message}"
99
- }
100
- ```
101
-
102
- This is an example of [ajaxSubmit from the jQuery.form plugin][jqform],
103
- implemented using Sumatra. It would especially be useful when rendering
104
- an inline response with JSON, using something such as Handlebars to
105
- compile the JSON data into a logic-less client-side template...
106
-
107
- ```coffeescript
108
- $('form').ajaxSubmit \
109
- dataType: 'json'
110
- success: (context) =>
111
- template = Handlebars.compile $('#response_template')
112
- response = template(context)
113
- @element.html response
114
- ```
115
-
116
- ### Basic Properties
117
-
118
- As a by-product of the jQuery instantation process, each `SumatraPlugin`
119
- comes with the following three properties, for free:
120
-
121
- - **element:** References a single jQuery DOM Object, which can perform
122
- basic functionality on the page. It is obtained from the collection of
123
- objects which matched the plugin's selector upon instantiation.
124
- - **index:** The index of the jQuery DOM Object in the collection of
125
- objects which matched the plugin's selector upon instantiation.
126
- - **options:** A Hash-notated Object obtained as the only argument in
127
- the jQuery plugin when instantiated. This object is then merged with
128
- the `defaults` hash, which are default params in the plugin's
129
- definition, before initialization occurs.
130
-
131
- ### Workflow
132
-
133
- Each SumatraPlugin has a "workflow" that is expressed as a series of
134
- methods, all run in the `constructor` of the object. The constructor
135
- is responsible for setup of the object's basic properties. This method
136
- should never be overridden, instead, each step of the instantiation
137
- process can be controlled by overriding one of the following methods:
138
-
139
- - **mergeOptions:** Merge the options with the defaults hash. You can
140
- override this to use attributes from `@element` as defaults instead.
141
- - **initialize:** The main override of the constructor method, this is
142
- where one would actually "construct" the objects they are going to be
143
- using in this plugin instance, bind events, and call helper methods.
144
- - **bindEvents:** This is where the `action:` event should be bound in
145
- some way. In many cases, this is overridden to bind other events as
146
- well as the `action:`, or binding the event as a `$(document).on`.
147
- - **perform:** The event handler of the plugin, this is normally called
148
- when the `action:` event is fired, but it must be defined if it is
149
- called or it will throw an error.
150
-
151
- You can define more methods, but these are the only public methods that
152
- should be overridden. Any method beginning with `_` is considered
153
- "private" and should not be overridden. Please carry this convention
154
- to your own code as well.
155
-
156
- ## Development
157
-
158
- You can build this code into JavaScript by running the following
159
- command at the root dir:
160
-
161
- ```bash
162
- $ npm install && cake build
163
- ```
164
-
165
- ### Contributions
166
-
167
- Contributions will be accepted via Git/GitHub pull requests, as long as
168
- you write tests that prove your contributions work. We use Jasmine to
169
- write tests in CoffeeScript (you know, for the actual framework?) and
170
- RSpec to write tests for the Rails helpers.
171
-
172
- ### Releases
173
-
174
- All releases will be made in both CoffeeScript and JavaScript, and
175
- available simultaneously on the Bower and RubyGems package managers.
176
- We use Bower to manage the standalone JavaScript code which has no
177
- dependency on Sprockets, Rails, or anything Ruby.
178
-
179
- This code is released under the [MIT License][LICENSE].
180
-
181
- [jqform]: http://jquery.malsup.com/form
182
- [LICENSE]: https://github.com/tubbo/sumatra/blob/master/LICENSE.md
183
- [engine]: http://github.com/tubbo/sumatra-rails
@@ -1,30 +0,0 @@
1
- {
2
- "name": "sumatra",
3
- "version": "0.0.0",
4
- "main": "./pkg/sumatra.js",
5
- "dependencies": {
6
- "jquery": "~1.9.1",
7
- "underscore": "~1.4.4",
8
- "bootstrap.css": "~2.1.1"
9
- },
10
- "devDependencies": {
11
- "coffee-script": "~1.6.2"
12
- },
13
- "ignore": [
14
- "components/**",
15
- "test/**",
16
- "lib/**",
17
- "package.json",
18
- "index.html"
19
- ],
20
- "gitHead": "c7f52b1ad87c6d4c516eafc8307d8ecb5b132e9b",
21
- "readme": "# Sumatra\n\nSumatra is a CoffeeScript framework for writing jQuery plugins harder,\nbetter, faster, stronger.\n\nYou should use Sumatra if you...\n\n- Encapsulate complex jQuery plugins in a service object and call an\n instance of that service object for each DOM element the plugin\n selector is passed\n- Enjoy test-driven development, clear code, and convention over\n configuration\n- Believe unicorns are real\n\n## Why?\n\nA lot of jQuery plugins are written to encapsulate a simple bit of\nfunctionality used throughout the application. But jQuery's syntax was\ndesigned to improve the way people write JavaScript. CoffeeScript has a\nsimilar goal, but approaches it from a different angle, it compiles its\nsyntax into JavaScript but does so in a safe, syntactically correct and\n(mostly) readable way. This framework unites the two, and finally allows\njQuery developers to build plugins in CoffeeScript without making their\ncode look, well, downright ugly!\n\n## Installation\n\n### Requirements\n\n- jQuery\n- CoffeeScript if you want to develop it..\n\nWe recommend Bower for installing Sumatra as a component:\n\n```bash\n$ bower install sumatra\n```\n\nHowever, you can also install Sumatra manually by just including the\n`pkg/sumatra.js` file in your javascripts directory.\n\n## Usage\n\nSumatra values convention over configuration, and its usage revolves\naround an established pattern that hopefully others will find useful.\n\n### Defining a Basic Plugin\n\nAfter loading Sumatra, you can build jQuery plugins that are both clear\nand superbly terse:\n\n```coffeescript\nsumatra 'clickMe', ->\n class ClickMe extends SumatraPlugin\n action: 'click'\n perform: (event) =>\n element_id = @element.attr('id') || '<div>'\n alert \"You just clicked #{element_id}!\"\n```\n\nAll this plugin does is show an `alert()` when the element is clicked.\nYou can define a single action with `action:` and then define the\n`perform()` event handler that binds to whatever action you've set\non the element.\n\nTo bind an element to this event, just call it like any normal\njQuery plugin:\n\n```coffeescript\n$('#my_element').clickMe();\n```\n\n### Parameters\n\nYou can also make plugins that pass in options. All Sumatra plugins\ntake an `options` hash as their only argument, regardless of whether\nthe service object uses them or not.\n\n```coffeescript\nsumatra 'ajaxSubmit', ->\n class AjaxSubmit extends SumatraPlugin\n action: 'submit'\n mergeOptions: ->\n @defaults = @_getFormDefaults()\n _.extend(@options, @defaults)\n\n perform: (event) =>\n event.preventDefault()\n event.stopPropagation()\n $.ajax @options\n\n _getFormDefaults: ->\n {\n url: @element.attr('action')\n type: @element.attr('method')\n error: (message, status, xhr) ->\n console.log status, message, xhr\n alert \"#{status}: #{message}\"\n }\n```\n\nThis is an example of [ajaxSubmit from the jQuery.form plugin][jqform],\nimplemented using Sumatra. It would especially be useful when rendering\nan inline response with JSON, using something such as Handlebars to\ncompile the JSON data into a logic-less client-side template...\n\n```coffeescript\n$('form').ajaxSubmit \\\n dataType: 'json'\n success: (context) =>\n template = Handlebars.compile $('#response_template')\n response = template(context)\n @element.html response\n```\n\n### Basic Properties\n\nAs a by-product of the jQuery instantation process, each `SumatraPlugin`\ncomes with the following three properties, for free:\n\n- **element:** References a single jQuery DOM Object, which can perform\n basic functionality on the page. It is obtained from the collection of\n objects which matched the plugin's selector upon instantiation.\n- **index:** The index of the jQuery DOM Object in the collection of\n objects which matched the plugin's selector upon instantiation.\n- **options:** A Hash-notated Object obtained as the only argument in\n the jQuery plugin when instantiated. This object is then merged with\n the `defaults` hash, which are default params in the plugin's\n definition, before initialization occurs.\n\n### Workflow\n\nEach SumatraPlugin has a \"workflow\" that is expressed as a series of\nmethods, all run in the `constructor` of the object. The constructor\nis responsible for setup of the object's basic properties. This method\nshould never be overridden, instead, each step of the instantiation\nprocess can be controlled by overriding one of the following methods:\n\n- **mergeOptions:** Merge the options with the defaults hash. You can\n override this to use attributes from `@element` as defaults instead.\n- **initialize:** The main override of the constructor method, this is\n where one would actually \"construct\" the objects they are going to be\n using in this plugin instance, bind events, and call helper methods.\n- **bindEvents:** This is where the `action:` event should be bound in\n some way. In many cases, this is overridden to bind other events as\n well as the `action:`, or binding the event as a `$(document).on`.\n- **perform:** The event handler of the plugin, this is normally called\n when the `action:` event is fired, but it must be defined if it is\n called or it will throw an error.\n\nYou can define more methods, but these are the only public methods that\nshould be overridden. Any method beginning with `_` is considered\n\"private\" and should not be overridden. Please carry this convention\nto your own code as well.\n\n## Development\n\nYou can build this code into JavaScript by running the following\ncommand at the root dir:\n\n```bash\n$ npm install && cake build\n```\n\n### Contributions\n\nContributions will be accepted via Git/GitHub pull requests, as long as\nyou write tests that prove your contributions work. We use Jasmine to\nwrite tests in CoffeeScript (you know, for the actual framework?) and\nRSpec to write tests for the Rails helpers.\n\n### Releases\n\nAll releases will be made in both CoffeeScript and JavaScript, and\navailable simultaneously on the Bower and RubyGems package managers.\nWe use Bower to manage the standalone JavaScript code which has no\ndependency on Sprockets, Rails, or anything Ruby.\n\nThis code is released under the [MIT License][LICENSE].\n\n[jqform]: http://jquery.malsup.com/form\n[LICENSE]: https://github.com/tubbo/sumatra/blob/master/LICENSE.md\n[engine]: http://github.com/tubbo/sumatra-rails\n",
22
- "readmeFilename": "README.md",
23
- "_id": "sumatra@0.0.4",
24
- "description": "Sumatra is a CoffeeScript framework for writing jQuery plugins harder, better, faster, stronger.",
25
- "commit": "c7f52b1ad87c6d4c516eafc8307d8ecb5b132e9b",
26
- "repository": {
27
- "type": "git",
28
- "url": "git://github.com/tubbo/sumatra.git"
29
- }
30
- }