bullseye 0.0.4 → 0.0.7

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/README.md CHANGED
@@ -52,6 +52,14 @@ alert("I am showing a site");
52
52
  alert "I am also showing a site"
53
53
  ```
54
54
 
55
+ Want to use the same JavaScript for two actions, say `new` and `edit`? Put both actions in the filename separated by a dash:
56
+
57
+ ``` coffeescript
58
+ # app/assets/javascripts/bullseye/sites/new-edit.bullseye.coffee
59
+
60
+ alert "I appear on both the new and edit actions"
61
+ ```
62
+
55
63
  Want to target that page in your Sass? Use a little string interpolation and a function that generates a selector:
56
64
 
57
65
  ``` sass
@@ -75,13 +83,30 @@ Create an initializer, like `config/initializers/bullseye.rb` and add the follow
75
83
  Bullseye.configure do |config|
76
84
  config.fuzzy_search = %{$('body').get(0).classNames.split(/\\s+/)}
77
85
  config.css_selector = 'body.:action.:controller'
86
+ config.html_tag = { 'class' => ':action :controller' }
78
87
  end
79
88
  ```
80
89
 
81
90
  Then you can make your `controller/action.bullseye` files and everything should just work.
82
91
 
92
+ ## Force the name of the controller/action
93
+
94
+ For things like error handling in `rescue_from`, you can force the `action` and `controller` that
95
+ Bullseye will use:
96
+
97
+ ``` ruby
98
+ rescue_from StandardError do |e|
99
+ bullseye_target 'application/errors/http_500'
100
+
101
+ render 'http_500'
102
+ end
103
+ ```
104
+
105
+ This will resolve to the controller `application/errors` and the action `http_500` in the Bullseye
106
+ HTML `body` tag for that page.
107
+
83
108
  ## Hacking
84
109
 
85
110
  _You'll need to install [Penchant](http://github.com/johnbintz/penchant) to mess with the Gemfile
86
- during development._
111
+ during development.
87
112
 
@@ -1,7 +1,11 @@
1
1
  this.Bullseye = {
2
- target: function(controller, action, callback) {
2
+ target: function(controller, actions, callback) {
3
3
  this.targets[controller] = (this.targets[controller] || {});
4
- this.targets[controller][action] = callback;
4
+
5
+ var actions_i;
6
+ for (actions_i = 0; actions_i < actions.length; ++actions_i) {
7
+ this.targets[controller][actions[actions_i]] = callback;
8
+ }
5
9
  },
6
10
 
7
11
  targets: {},
@@ -34,6 +38,8 @@ this.Bullseye = {
34
38
  break;
35
39
  }
36
40
 
41
+ controller = controller.replace('/', '-');
42
+
37
43
  if (this.targets[controller] && this.targets[controller][action]) {
38
44
  this.targets[controller][action].apply(this.context);
39
45
  }
data/lib/bullseye.rb CHANGED
@@ -5,16 +5,7 @@ require 'bullseye/sass/bullseye_functions'
5
5
 
6
6
  module Bullseye
7
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
8
+ attr_accessor :js_controller_search, :js_action_search, :css_selector, :html_tag, :fuzzy_search
18
9
  end
19
10
 
20
11
  class << self
@@ -27,3 +18,4 @@ module Bullseye
27
18
  end
28
19
  end
29
20
  end
21
+
@@ -1,14 +1,34 @@
1
1
  require 'bullseye/helpers/bullseye_helper'
2
+ require 'bullseye/helpers/bullseye_controller_helper'
2
3
 
3
4
  module Bullseye
4
5
  class Engine < ::Rails::Engine
5
6
  initializer 'bullseye.view_helpers' do
6
7
  ActionView::Base.send(:include, Bullseye::Helpers::BullseyeHelper)
8
+ ActionController::Base.send(:include, Bullseye::Helpers::BullseyeControllerHelper)
7
9
  end
8
10
 
9
11
  initializer 'bullseye.sprockets', :after => 'sprockets.environment' do |app|
10
12
  app.assets.register_engine '.bullseye', Bullseye::Tilt::BullseyeTemplate
11
13
  end
12
14
  end
15
+
16
+ class InstallGenerator < ::Rails::Generators::Base
17
+ source_root File.expand_path('../../../skel', __FILE__)
18
+
19
+ def create_initializer_file
20
+ copy_file "config/initializers/bullseye.rb", "config/initializers/bullseye.rb"
21
+
22
+ puts
23
+ puts "Add to your main application.js file:"
24
+ puts
25
+ puts "//= require bullseye"
26
+ puts
27
+ puts "and replace your body tag layouts/application.html with a call to bullseye_body:"
28
+ puts
29
+ puts "= bullseye_body do"
30
+ puts
31
+ end
32
+ end
13
33
  end
14
34
 
@@ -0,0 +1,26 @@
1
+ module Bullseye
2
+ module FindParts
3
+ SEPARATOR = '-'
4
+
5
+ def actions
6
+ parts.last.split(SEPARATOR)
7
+ end
8
+
9
+ def controller
10
+ parts[0..-2].join(SEPARATOR)
11
+ end
12
+
13
+ def parts
14
+ @parts ||= @source.split('/')
15
+ end
16
+
17
+ class PartFinder
18
+ include Bullseye::FindParts
19
+
20
+ def initialize(source)
21
+ @source = source
22
+ end
23
+ end
24
+ end
25
+ end
26
+
@@ -0,0 +1,14 @@
1
+ require 'bullseye/find_parts'
2
+
3
+ module Bullseye
4
+ module Helpers
5
+ module BullseyeControllerHelper
6
+ def bullseye_target(target)
7
+ part_finder = Bullseye::FindParts::PartFinder.new(target)
8
+
9
+ @__bullseye_action = part_finder.actions.first
10
+ @__bullseye_controller = part_finder.controller
11
+ end
12
+ end
13
+ end
14
+ end
@@ -2,7 +2,20 @@ module Bullseye
2
2
  module Helpers
3
3
  module BullseyeHelper
4
4
  def bullseye_body(options = {}, &block)
5
- content_tag(:body, capture(&block), { 'data-action' => action_name, 'data-controller' => controller_path }.merge(options)).html_safe
5
+ attributes = Bullseye.config.html_tag.collect do |key, value|
6
+ [ key, value.gsub(':action', __bullseye_action).gsub(':controller', __bullseye_controller) ]
7
+ end
8
+
9
+ content_tag(:body, capture(&block), Hash[attributes].merge(options)).html_safe
10
+ end
11
+
12
+ private
13
+ def __bullseye_action
14
+ @__bullseye_action || action_name
15
+ end
16
+
17
+ def __bullseye_controller
18
+ @__bullseye_controller || controller_path.gsub('/', Bullseye::FindParts::SEPARATOR)
6
19
  end
7
20
  end
8
21
  end
@@ -1,14 +1,17 @@
1
1
  require 'sass'
2
+ require 'bullseye/find_parts'
2
3
 
3
4
  module Sass::Script::Functions
4
5
  def bullseye(target)
5
6
  assert_type target, :String
6
7
 
7
- parts = target.value.split('/')
8
- action = parts.pop
9
- controller = parts.join('/')
8
+ part_finder = Bullseye::FindParts::PartFinder.new(target.value)
10
9
 
11
- Sass::Script::String.new(Bullseye.config.css_selector.gsub(':action', action).gsub(':controller', controller))
10
+ selectors = part_finder.actions.collect do |action|
11
+ Bullseye.config.css_selector.gsub(':action', action).gsub(':controller', part_finder.controller)
12
+ end
13
+
14
+ Sass::Script::String.new(selectors.join(','))
12
15
  end
13
16
  end
14
17
 
@@ -1,10 +1,11 @@
1
1
  require 'tilt'
2
- require 'bullseye/tilt/find_parts'
2
+ require 'bullseye/find_parts'
3
+ require 'json'
3
4
 
4
5
  module Bullseye
5
6
  module Tilt
6
7
  class BullseyeTemplate < ::Tilt::Template
7
- include Bullseye::Tilt::FindParts
8
+ include Bullseye::FindParts
8
9
 
9
10
  def self.default_mime_type
10
11
  'application/javascript'
@@ -14,10 +15,10 @@ module Bullseye
14
15
  end
15
16
 
16
17
  def evaluate(scope, locals, &block)
17
- @scope = scope
18
+ @source = scope.logical_path.gsub(%r{^[^/]*/}, '')
18
19
 
19
20
  <<-JS
20
- Bullseye.target('#{controller}', '#{action}', function() {
21
+ Bullseye.target('#{controller}', #{actions.to_json}, function() {
21
22
  #{data}
22
23
  });
23
24
  JS
@@ -1,3 +1,3 @@
1
1
  module Bullseye
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -0,0 +1,9 @@
1
+ Bullseye.configure do |c|
2
+ c.js_controller_search = %{$('body').data('controller')}
3
+ c.js_action_search = %{$('body').data('action')}
4
+
5
+ c.css_selector = %{body[data-action=':action'][data-controller=':controller']}
6
+ c.html_tag = { 'data-action' => ':action', 'data-controller' => ':controller' }
7
+
8
+ c.fuzzy_search = false
9
+ 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.4
4
+ version: 0.0.7
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-29 00:00:00.000000000 Z
12
+ date: 2012-10-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: tilt
@@ -76,10 +76,11 @@ files:
76
76
  - bullseye.gemspec
77
77
  - lib/bullseye.rb
78
78
  - lib/bullseye/engine.rb
79
+ - lib/bullseye/find_parts.rb
80
+ - lib/bullseye/helpers/bullseye_controller_helper.rb
79
81
  - lib/bullseye/helpers/bullseye_helper.rb
80
82
  - lib/bullseye/sass/bullseye_functions.rb
81
83
  - lib/bullseye/tilt/bullseye_template.rb
82
- - lib/bullseye/tilt/find_parts.rb
83
84
  - lib/bullseye/version.rb
84
85
  - script/gemfile
85
86
  - script/hooks/commit-msg
@@ -87,6 +88,7 @@ files:
87
88
  - script/hooks/pre-commit
88
89
  - script/initialize-environment
89
90
  - script/install-git-hooks
91
+ - skel/config/initializers/bullseye.rb
90
92
  homepage: ''
91
93
  licenses: []
92
94
  post_install_message:
@@ -99,12 +101,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
99
101
  - - ! '>='
100
102
  - !ruby/object:Gem::Version
101
103
  version: '0'
104
+ segments:
105
+ - 0
106
+ hash: -2184598113518927459
102
107
  required_rubygems_version: !ruby/object:Gem::Requirement
103
108
  none: false
104
109
  requirements:
105
110
  - - ! '>='
106
111
  - !ruby/object:Gem::Version
107
112
  version: '0'
113
+ segments:
114
+ - 0
115
+ hash: -2184598113518927459
108
116
  requirements: []
109
117
  rubyforge_project:
110
118
  rubygems_version: 1.8.23
@@ -112,4 +120,3 @@ signing_key:
112
120
  specification_version: 3
113
121
  summary: Implement DOM-ready execution in Rails using the Asset Pipeline.
114
122
  test_files: []
115
- has_rdoc:
@@ -1,18 +0,0 @@
1
- module Bullseye
2
- module Tilt
3
- module FindParts
4
- def action
5
- parts.last
6
- end
7
-
8
- def controller
9
- parts[0..-2].join('/')
10
- end
11
-
12
- def parts
13
- @scope.logical_path.split('/')[1..-1]
14
- end
15
- end
16
- end
17
- end
18
-