From cf004ac1d86c97b0a730be8615cff6ae2e2dd390 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Thu, 30 Aug 2012 11:23:50 -0400 Subject: [PATCH] search multiple actions --- README.md | 8 ++++++++ app/assets/javascripts/bullseye.js.erb | 8 ++++++-- lib/bullseye/tilt/bullseye_template.rb | 3 ++- lib/bullseye/tilt/find_parts.rb | 4 ++-- lib/bullseye/version.rb | 2 +- 5 files changed, 19 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index eeea589..f11e24e 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,14 @@ alert("I am showing a site"); alert "I am also showing a site" ``` +Want to use the same JavaScript for two actions, say `new` and `edit`? Put both actions in the filename separated by a dash: + +``` coffeescript +# app/assets/javascripts/bullseye/sites/new-edit.bullseye.coffee + +alert "I appear on both the new and edit actions" +``` + Want to target that page in your Sass? Use a little string interpolation and a function that generates a selector: ``` sass diff --git a/app/assets/javascripts/bullseye.js.erb b/app/assets/javascripts/bullseye.js.erb index 00e8439..d060094 100644 --- a/app/assets/javascripts/bullseye.js.erb +++ b/app/assets/javascripts/bullseye.js.erb @@ -1,7 +1,11 @@ this.Bullseye = { - target: function(controller, action, callback) { + target: function(controller, actions, callback) { this.targets[controller] = (this.targets[controller] || {}); - this.targets[controller][action] = callback; + + var actions_i; + for (actions_i = 0; actions_i < actions.length; ++actions_i) { + this.targets[controller][actions[actions_i]] = callback; + } }, targets: {}, diff --git a/lib/bullseye/tilt/bullseye_template.rb b/lib/bullseye/tilt/bullseye_template.rb index c598dfd..53a31bb 100644 --- a/lib/bullseye/tilt/bullseye_template.rb +++ b/lib/bullseye/tilt/bullseye_template.rb @@ -1,5 +1,6 @@ require 'tilt' require 'bullseye/tilt/find_parts' +require 'json' module Bullseye module Tilt @@ -17,7 +18,7 @@ module Bullseye @scope = scope <<-JS -Bullseye.target('#{controller}', '#{action}', function() { +Bullseye.target('#{controller}', #{actions.to_json}, function() { #{data} }); JS diff --git a/lib/bullseye/tilt/find_parts.rb b/lib/bullseye/tilt/find_parts.rb index 8630b3d..065c763 100644 --- a/lib/bullseye/tilt/find_parts.rb +++ b/lib/bullseye/tilt/find_parts.rb @@ -1,8 +1,8 @@ module Bullseye module Tilt module FindParts - def action - parts.last + def actions + parts.last.split('-') end def controller diff --git a/lib/bullseye/version.rb b/lib/bullseye/version.rb index d7d8330..1a46414 100644 --- a/lib/bullseye/version.rb +++ b/lib/bullseye/version.rb @@ -1,3 +1,3 @@ module Bullseye - VERSION = "0.0.4" + VERSION = "0.0.5" end