pastur 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +82 -0
- data/Rakefile +34 -0
- data/lib/pastur.rb +4 -0
- data/lib/pastur/engine.rb +4 -0
- data/lib/pastur/version.rb +3 -0
- data/vendor/assets/javascripts/pastur.js +30 -0
- metadata +94 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 87a758e852fca53942f487a0817f8f3e297413fd
|
4
|
+
data.tar.gz: cbfeaf3c3776a785b9c1523c0817ca2bbca54dab
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: af971dba2f17b78245d89641faf5d84aab0f07e7c7a56d7470fe0928fd6810affab47ccb319de6fd83c7292ab18f57506d6ce6e39996e390d15da72ffb5c71f6
|
7
|
+
data.tar.gz: ca7b5d8494ba66af8a5ab898b0ad09ac481d9d596a2bb82e339e7d6477c832b49ef2d9bf8cb44dbd54d6d6c5769eb052a3a9cca1f7c1f5b2410dc84cf5cc243c
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2017 Josh Greenberg
|
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,82 @@
|
|
1
|
+
# Pastur
|
2
|
+
|
3
|
+
**Pastur** provides a JavaScript pattern that lets you easily write and organize page-specific code that works properly with Turbolinks. Or, **pa**ge-**s**pecific JS for **tur**bolinks!
|
4
|
+
|
5
|
+
Inspired by [Brandon Hilkert](http://brandonhilkert.com/blog/organizing-javascript-in-rails-application-with-turbolinks/).
|
6
|
+
|
7
|
+
## How it works
|
8
|
+
|
9
|
+
When navigating between pages in Rails, Turbolinks only reloads the parts of the page that change. In the typical setup, JavaScript is often only loaded when a visitor first accesses the web app, and not on every page load. This is great for page load speed while navigating around an app, but it can cause problems for things like event binding, widget initialization, etc.
|
10
|
+
|
11
|
+
Pastur provides a clean pattern to define _all_ of the app's event bindings on a full load, then only fire them on the proper pages. It's a really simple abstraction - seriously, the readme is longer than the code.
|
12
|
+
|
13
|
+
## Dependencies
|
14
|
+
|
15
|
+
- jQuery
|
16
|
+
- Turbolinks
|
17
|
+
|
18
|
+
Pastur is intended to enhance an out-of-the-box Rails setup with a Sprockets asset pipeline, but there's nothing in the code base that depends on them.
|
19
|
+
|
20
|
+
## Installation
|
21
|
+
|
22
|
+
You've seen this before:
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
# Gemfile
|
26
|
+
gem 'pastur'
|
27
|
+
```
|
28
|
+
```bash
|
29
|
+
$ bundle install
|
30
|
+
```
|
31
|
+
|
32
|
+
Or:
|
33
|
+
|
34
|
+
```bash
|
35
|
+
$ gem install pastur
|
36
|
+
```
|
37
|
+
|
38
|
+
Add to your JavaScript manifest, after jQuery and Turbolinks:
|
39
|
+
|
40
|
+
```javascript
|
41
|
+
//= require pastur
|
42
|
+
//= require_tree ./pages
|
43
|
+
```
|
44
|
+
|
45
|
+
You can organize and include the `require_tree` however you want, as long as Sprockets loads it after `pastur`.
|
46
|
+
|
47
|
+
## Usage
|
48
|
+
|
49
|
+
```javascript
|
50
|
+
// app/assets/javascripts/pages/whatever.js
|
51
|
+
App.page('.controller.action', [
|
52
|
+
App.event('turbolinks:load', function(e) {
|
53
|
+
// page-specific code goes here
|
54
|
+
}),
|
55
|
+
App.event('click', '#selector', function(e) {
|
56
|
+
// page-specific code goes here
|
57
|
+
}),
|
58
|
+
// ...
|
59
|
+
]);
|
60
|
+
```
|
61
|
+
|
62
|
+
`App.page()` takes two arguments:
|
63
|
+
|
64
|
+
1. Any valid jQuery selector
|
65
|
+
2. An array of `App.event()`s, mirroring the syntax of `$(document).on()`
|
66
|
+
|
67
|
+
Basically all this does is inject a check for the presence of `$('.controller.action')` on the page before running event code. The recommended convention is to set `<body class="controller action">` and define the page selector as `.controller.action`, but this is very flexible. Page selectors don't even have to be page-specific and should also work with partials.
|
68
|
+
|
69
|
+
Event bindings are only defined once, and all page-specific JS should _only_ be run in an event context. Reusable components should be defined elsewhere, outside of Pastur (but called from within Pastur).
|
70
|
+
|
71
|
+
Pastur also works with CoffeeScript:
|
72
|
+
|
73
|
+
```coffee
|
74
|
+
App.page '.controller.action', [
|
75
|
+
App.event 'turbolinks:load', (e) ->
|
76
|
+
# awesome
|
77
|
+
]
|
78
|
+
```
|
79
|
+
|
80
|
+
## TODO
|
81
|
+
|
82
|
+
- Generator
|
data/Rakefile
ADDED
@@ -0,0 +1,34 @@
|
|
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 = 'DynamicForm'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
require 'bundler/gem_tasks'
|
23
|
+
|
24
|
+
require 'rake/testtask'
|
25
|
+
|
26
|
+
Rake::TestTask.new(:test) do |t|
|
27
|
+
t.libs << 'lib'
|
28
|
+
t.libs << 'test'
|
29
|
+
t.pattern = 'test/**/*_test.rb'
|
30
|
+
t.verbose = false
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
task default: :test
|
data/lib/pastur.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
window.App || (window.App = {});
|
2
|
+
|
3
|
+
App.Event = (function() {
|
4
|
+
function Event(event1, selector1, code1) {
|
5
|
+
this.event = event1;
|
6
|
+
this.selector = selector1;
|
7
|
+
this.code = code1;
|
8
|
+
}
|
9
|
+
|
10
|
+
return Event;
|
11
|
+
|
12
|
+
})();
|
13
|
+
|
14
|
+
App.event = function(event, selector, code) {
|
15
|
+
if (!code) {
|
16
|
+
code = selector;
|
17
|
+
selector = null;
|
18
|
+
}
|
19
|
+
return new App.Event(event, selector, code);
|
20
|
+
};
|
21
|
+
|
22
|
+
App.page = function(selector, events) {
|
23
|
+
return events.forEach(function(e) {
|
24
|
+
return $(document).on(e.event, e.selector, function(event) {
|
25
|
+
if ($(selector).length > 0) {
|
26
|
+
return e.code(event);
|
27
|
+
}
|
28
|
+
});
|
29
|
+
});
|
30
|
+
};
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pastur
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Josh Greenberg
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-05-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: turbolinks
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: jquery-rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: jquery-turbolinks
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Super simple pattern to effectively organize page-specific JS within
|
56
|
+
Rails for use with Turbolinks
|
57
|
+
email:
|
58
|
+
- joshgreenberg91@gmail.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- MIT-LICENSE
|
64
|
+
- README.md
|
65
|
+
- Rakefile
|
66
|
+
- lib/pastur.rb
|
67
|
+
- lib/pastur/engine.rb
|
68
|
+
- lib/pastur/version.rb
|
69
|
+
- vendor/assets/javascripts/pastur.js
|
70
|
+
homepage: https://bitbucket.org/josh_greenberg/pastur
|
71
|
+
licenses:
|
72
|
+
- MIT
|
73
|
+
metadata: {}
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
requirements: []
|
89
|
+
rubyforge_project:
|
90
|
+
rubygems_version: 2.6.8
|
91
|
+
signing_key:
|
92
|
+
specification_version: 4
|
93
|
+
summary: PAge-Specific TURbolinks
|
94
|
+
test_files: []
|