bullseye 0.0.1

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.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bullseye.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 John Bintz
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # Bullseye!
2
+
3
+ An *extremely quickly written* shoot-from-the-hip implementation of [so-called Garber-Irish DOM-ready execution](http://viget.com/inspire/extending-paul-irishs-comprehensive-dom-ready-execution)
4
+ for the Rails asset pipeline. Could work with other Sprockets stuff down the road, too. But for now, it's
5
+ pretty married to Rails. Also, needs tests for the exactly four things that it does. Anyone wanna add exactly four Cucumber features?
6
+
7
+ ## Why?
8
+
9
+ I got sick of on-page JavaScript. Also I like using the Asset Pipeline for what it's actually intended for,
10
+ reducing the number of HTTP requests.
11
+
12
+ ## How?
13
+
14
+ Add the gem:
15
+
16
+ ``` ruby
17
+ gem 'bullseye'
18
+ ```
19
+
20
+ Replace your `body` tag in your layout with:
21
+
22
+ ``` haml
23
+ !!!
24
+ %html
25
+ = bullseye_body do
26
+ = yield
27
+ ```
28
+
29
+ That adds `data-action` and `data-controller` attributes to your `body` tag automagically. The controller
30
+ comes from `ActionController::Base.controller_path`, so it's the full namespaced underscored path (`Admin::UsersController`
31
+ becomes `admin/users`).
32
+
33
+ Then, in `application.js`:
34
+
35
+ ``` javascript
36
+ //= require bullseye
37
+ ```
38
+
39
+ Finally, create some controller/actions-specific files within `app/assets/javascripts/bullseye`
40
+ and give them the extenstion `.bullseye`. For instance, target `SitesController#show` in JS and CoffeeScript:
41
+
42
+ ``` javascript
43
+ // app/assets/javascripts/bullseye/sites/show.bullseye
44
+
45
+ alert("I am showing a site");
46
+ ```
47
+
48
+ ``` coffeescript
49
+ # app/assets/javascripts/bullseye/sites/show.bullseye.coffee
50
+
51
+ alert "I am also showing a site"
52
+ ```
53
+
54
+ Piece of cake.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,24 @@
1
+ #= require jquery
2
+
3
+ this.Bullseye = {
4
+ target: function(controller, action, callback) {
5
+ this.targets = (this.targets || {});
6
+ this.targets[controller] = (this.targets[controller] || {});
7
+ this.targets[controller][action] = callback;
8
+ },
9
+
10
+ exec: function(controller, action) {
11
+ if (this.targets[controller] && this.targets[controller][action]) {
12
+ this.targets[controller][action].apply(this.context);
13
+ }
14
+ }
15
+ };
16
+
17
+ Bullseye.context = this;
18
+
19
+ $(function() {
20
+ var controller = $('body').data('controller');
21
+ var action = $('body').data('action');
22
+
23
+ Bullseye.exec(controller, action);
24
+ });
data/bullseye.gemspec ADDED
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/bullseye/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["John Bintz"]
6
+ gem.email = ["john@coswellproductions.com"]
7
+ gem.description = %q{Implement DOM-ready execution in Rails using the Asset Pipeline.}
8
+ gem.summary = %q{Implement DOM-ready execution in Rails using the Asset Pipeline.}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "bullseye"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Bullseye::VERSION
17
+
18
+ gem.add_dependency 'tilt'
19
+ gem.add_dependency 'sprockets'
20
+ end
data/lib/bullseye.rb ADDED
@@ -0,0 +1,3 @@
1
+ require "bullseye/version"
2
+ require 'bullseye/engine' if defined?(Rails::Engine)
3
+ require 'bullseye/tilt/bullseye_template'
@@ -0,0 +1,14 @@
1
+ require 'bullseye/helpers/bullseye_helper'
2
+
3
+ module Bullseye
4
+ class Engine < ::Rails::Engine
5
+ initializer 'bullseye.view_helpers' do
6
+ ActionView::Base.send(:include, Bullseye::Helpers::BullseyeHelper)
7
+ end
8
+
9
+ initializer 'bullseye.sprockets', :after => 'sprockets.environment' do |app|
10
+ app.assets.register_engine '.bullseye', Bullseye::Tilt::BullseyeTemplate
11
+ end
12
+ end
13
+ end
14
+
@@ -0,0 +1,10 @@
1
+ module Bullseye
2
+ module Helpers
3
+ module BullseyeHelper
4
+ def bullseye_body(options = {}, &block)
5
+ content_tag(:body, capture(&block), { 'data-action' => action_name, 'data-controller' => controller_path }.merge(options)).html_safe
6
+ end
7
+ end
8
+ end
9
+ end
10
+
@@ -0,0 +1,28 @@
1
+ require 'tilt'
2
+ require 'sprockets'
3
+
4
+ module Bullseye
5
+ module Tilt
6
+ class BullseyeTemplate < ::Tilt::Template
7
+ def self.default_mime_type
8
+ 'application/javascript'
9
+ end
10
+
11
+ def prepare
12
+ end
13
+
14
+ def evaluate(scope, locals, &block)
15
+ parts = scope.logical_path.split('/')
16
+ action = parts.pop
17
+ controller = parts[1..-1].join('/')
18
+
19
+ <<-JS
20
+ Bullseye.target('#{controller}', '#{action}', function() {
21
+ #{data}
22
+ });
23
+ JS
24
+ end
25
+ end
26
+ end
27
+ end
28
+
@@ -0,0 +1,3 @@
1
+ module Bullseye
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bullseye
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - John Bintz
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-23 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: tilt
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: sprockets
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Implement DOM-ready execution in Rails using the Asset Pipeline.
47
+ email:
48
+ - john@coswellproductions.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - LICENSE
56
+ - README.md
57
+ - Rakefile
58
+ - app/assets/javascripts/bullseye.js
59
+ - bullseye.gemspec
60
+ - lib/bullseye.rb
61
+ - lib/bullseye/engine.rb
62
+ - lib/bullseye/helpers/bullseye_helper.rb
63
+ - lib/bullseye/tilt/bullseye_template.rb
64
+ - lib/bullseye/version.rb
65
+ homepage: ''
66
+ licenses: []
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 1.8.23
86
+ signing_key:
87
+ specification_version: 3
88
+ summary: Implement DOM-ready execution in Rails using the Asset Pipeline.
89
+ test_files: []