bullseye 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -33,6 +33,7 @@ becomes `admin/users`).
33
33
  Then, in `application.js`:
34
34
 
35
35
  ``` javascript
36
+ //= require jquery
36
37
  //= require bullseye
37
38
  ```
38
39
 
@@ -61,6 +62,24 @@ Want to target that page in your Sass? Use a little string interpolation and a f
61
62
 
62
63
  Piece of cake.
63
64
 
65
+ ### Fuzzy search
66
+
67
+ Plugging Bullseye into an existing app may require making Bullseye work a little harder to target pages.
68
+ For instance, you can use Bullseye with ActiveAdmin to target particular actions on models.
69
+ However, you can't really add your own `body` tag to their templates. Luckily, they do put in both
70
+ the action and controller names in the `class` attribute of the `body` tag.
71
+
72
+ Create an initializer, like `config/initializers/bullseye.rb` and add the following:
73
+
74
+ ``` ruby
75
+ Bullseye.configure do |config|
76
+ config.fuzzy_search = %{$('body').get(0).classNames.split(/\\s+/)}
77
+ config.css_selector = 'body.:action.:controller'
78
+ end
79
+ ```
80
+
81
+ Then you can make your `controller/action.bullseye` files and everything should just work.
82
+
64
83
  ## Hacking
65
84
 
66
85
  _You'll need to install [Penchant](http://github.com/johnbintz/penchant) to mess with the Gemfile
@@ -0,0 +1,54 @@
1
+ this.Bullseye = {
2
+ target: function(controller, action, callback) {
3
+ this.targets[controller] = (this.targets[controller] || {});
4
+ this.targets[controller][action] = callback;
5
+ },
6
+
7
+ targets: {},
8
+
9
+ exec: function() {
10
+ var controller, action;
11
+
12
+ switch (arguments.length) {
13
+ case 2:
14
+ controller = arguments[0];
15
+ action = arguments[1];
16
+ break;
17
+
18
+ case 1:
19
+ choices = arguments[0];
20
+
21
+ choice_loop:
22
+ for (controller_i = 0; controller_i < choices.length; ++controller_i) {
23
+ controller = choices[controller_i];
24
+ if (this.targets[controller]) {
25
+ for (action_i = 0; action_i < choices.length; ++action_i) {
26
+ action = choices[action_i];
27
+
28
+ if (this.targets[controller][action]) {
29
+ break choice_loop;
30
+ }
31
+ }
32
+ }
33
+ }
34
+ break;
35
+ }
36
+
37
+ if (this.targets[controller] && this.targets[controller][action]) {
38
+ this.targets[controller][action].apply(this.context);
39
+ }
40
+ }
41
+ };
42
+
43
+ Bullseye.context = this;
44
+
45
+ $(function() {
46
+ Bullseye.exec(
47
+ <% if Bullseye.config.fuzzy_search %>
48
+ <%= Bullseye.config.fuzzy_search %>
49
+ <% else %>
50
+ <%= Bullseye.config.js_controller_search %>,
51
+ <%= Bullseye.config.js_action_search %>
52
+ <% end %>
53
+ );
54
+ });
@@ -2,3 +2,28 @@ require "bullseye/version"
2
2
  require 'bullseye/engine' if defined?(Rails::Engine)
3
3
  require 'bullseye/tilt/bullseye_template'
4
4
  require 'bullseye/sass/bullseye_functions'
5
+
6
+ module Bullseye
7
+ class Configuration
8
+ attr_accessor :js_controller_search, :js_action_search, :css_selector, :fuzzy_search
9
+
10
+ def initialize
11
+ @js_controller_search = %{$('body').data('controller')}
12
+ @js_action_search = %{$('body').data('action')}
13
+
14
+ @css_selector = %{body[data-action=':action'][data-controller=':controller']}
15
+
16
+ @fuzzy_search = false
17
+ end
18
+ end
19
+
20
+ class << self
21
+ def config
22
+ @config ||= Configuration.new
23
+ end
24
+
25
+ def configure
26
+ block_given? ? yield(config) : config
27
+ end
28
+ end
29
+ end
@@ -8,7 +8,7 @@ module Sass::Script::Functions
8
8
  action = parts.pop
9
9
  controller = parts.join('/')
10
10
 
11
- Sass::Script::String.new("body[data-action='#{action}'][data-controller='#{controller}']")
11
+ Sass::Script::String.new(Bullseye.config.css_selector.gsub(':action', action).gsub(':controller', controller))
12
12
  end
13
13
  end
14
14
 
@@ -1,3 +1,3 @@
1
1
  module Bullseye
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bullseye
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-27 00:00:00.000000000 Z
12
+ date: 2012-08-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: tilt
@@ -72,7 +72,7 @@ files:
72
72
  - LICENSE
73
73
  - README.md
74
74
  - Rakefile
75
- - app/assets/javascripts/bullseye.js
75
+ - app/assets/javascripts/bullseye.js.erb
76
76
  - bullseye.gemspec
77
77
  - lib/bullseye.rb
78
78
  - lib/bullseye/engine.rb
@@ -99,18 +99,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
99
99
  - - ! '>='
100
100
  - !ruby/object:Gem::Version
101
101
  version: '0'
102
- segments:
103
- - 0
104
- hash: 2003828615834542640
105
102
  required_rubygems_version: !ruby/object:Gem::Requirement
106
103
  none: false
107
104
  requirements:
108
105
  - - ! '>='
109
106
  - !ruby/object:Gem::Version
110
107
  version: '0'
111
- segments:
112
- - 0
113
- hash: 2003828615834542640
114
108
  requirements: []
115
109
  rubyforge_project:
116
110
  rubygems_version: 1.8.23
@@ -118,3 +112,4 @@ signing_key:
118
112
  specification_version: 3
119
113
  summary: Implement DOM-ready execution in Rails using the Asset Pipeline.
120
114
  test_files: []
115
+ has_rdoc:
@@ -1,22 +0,0 @@
1
- #= require jquery
2
-
3
- this.Bullseye = {
4
- target: function(controller, action, callback) {
5
- this.targets[controller] = (this.targets[controller] || {});
6
- this.targets[controller][action] = callback;
7
- },
8
-
9
- targets: {},
10
-
11
- exec: function(controller, action) {
12
- if (this.targets[controller] && this.targets[controller][action]) {
13
- this.targets[controller][action].apply(this.context);
14
- }
15
- }
16
- };
17
-
18
- Bullseye.context = this;
19
-
20
- $(function() {
21
- Bullseye.exec($('body').data('controller'), $('body').data('action'));
22
- });