rearrange stuff and make some other things super-cool
This commit is contained in:
parent
cf004ac1d8
commit
051766915f
19
README.md
19
README.md
@ -83,13 +83,30 @@ Create an initializer, like `config/initializers/bullseye.rb` and add the follow
|
|||||||
Bullseye.configure do |config|
|
Bullseye.configure do |config|
|
||||||
config.fuzzy_search = %{$('body').get(0).classNames.split(/\\s+/)}
|
config.fuzzy_search = %{$('body').get(0).classNames.split(/\\s+/)}
|
||||||
config.css_selector = 'body.:action.:controller'
|
config.css_selector = 'body.:action.:controller'
|
||||||
|
config.html_tag = { 'class' => ':action :controller' }
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
Then you can make your `controller/action.bullseye` files and everything should just work.
|
Then you can make your `controller/action.bullseye` files and everything should just work.
|
||||||
|
|
||||||
|
## Force the name of the controller/action
|
||||||
|
|
||||||
|
For things like error handling in `rescue_from`, you can force the `action` and `controller` that
|
||||||
|
Bullseye will use:
|
||||||
|
|
||||||
|
``` ruby
|
||||||
|
rescue_from StandardError do |e|
|
||||||
|
bullseye_target 'application/errors/http_500'
|
||||||
|
|
||||||
|
render 'http_500'
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
|
This will resolve to the controller `application/errors` and the action `http_500` in the Bullseye
|
||||||
|
HTML `body` tag for that page.
|
||||||
|
|
||||||
## Hacking
|
## Hacking
|
||||||
|
|
||||||
_You'll need to install [Penchant](http://github.com/johnbintz/penchant) to mess with the Gemfile
|
_You'll need to install [Penchant](http://github.com/johnbintz/penchant) to mess with the Gemfile
|
||||||
during development._
|
during development.
|
||||||
|
|
||||||
|
@ -5,13 +5,14 @@ require 'bullseye/sass/bullseye_functions'
|
|||||||
|
|
||||||
module Bullseye
|
module Bullseye
|
||||||
class Configuration
|
class Configuration
|
||||||
attr_accessor :js_controller_search, :js_action_search, :css_selector, :fuzzy_search
|
attr_accessor :js_controller_search, :js_action_search, :css_selector, :html_tag, :fuzzy_search
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@js_controller_search = %{$('body').data('controller')}
|
@js_controller_search = %{$('body').data('controller')}
|
||||||
@js_action_search = %{$('body').data('action')}
|
@js_action_search = %{$('body').data('action')}
|
||||||
|
|
||||||
@css_selector = %{body[data-action=':action'][data-controller=':controller']}
|
@css_selector = %{body[data-action=':action'][data-controller=':controller']}
|
||||||
|
@html_tag = { 'data-action' => ':action', 'data-controller' => ':controller' }
|
||||||
|
|
||||||
@fuzzy_search = false
|
@fuzzy_search = false
|
||||||
end
|
end
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
require 'bullseye/helpers/bullseye_helper'
|
require 'bullseye/helpers/bullseye_helper'
|
||||||
|
require 'bullseye/helpers/bullseye_controller_helper'
|
||||||
|
|
||||||
module Bullseye
|
module Bullseye
|
||||||
class Engine < ::Rails::Engine
|
class Engine < ::Rails::Engine
|
||||||
initializer 'bullseye.view_helpers' do
|
initializer 'bullseye.view_helpers' do
|
||||||
ActionView::Base.send(:include, Bullseye::Helpers::BullseyeHelper)
|
ActionView::Base.send(:include, Bullseye::Helpers::BullseyeHelper)
|
||||||
|
ActionController::Base.send(:include, Bullseye::Helpers::BullseyeControllerHelper)
|
||||||
end
|
end
|
||||||
|
|
||||||
initializer 'bullseye.sprockets', :after => 'sprockets.environment' do |app|
|
initializer 'bullseye.sprockets', :after => 'sprockets.environment' do |app|
|
||||||
|
24
lib/bullseye/find_parts.rb
Normal file
24
lib/bullseye/find_parts.rb
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
module Bullseye
|
||||||
|
module FindParts
|
||||||
|
def actions
|
||||||
|
parts.last.split('-')
|
||||||
|
end
|
||||||
|
|
||||||
|
def controller
|
||||||
|
parts[0..-2].join('-')
|
||||||
|
end
|
||||||
|
|
||||||
|
def parts
|
||||||
|
@source.split('/')
|
||||||
|
end
|
||||||
|
|
||||||
|
class PartFinder
|
||||||
|
include Bullseye::FindParts
|
||||||
|
|
||||||
|
def initialize(source)
|
||||||
|
@source = source
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
14
lib/bullseye/helpers/bullseye_controller_helper.rb
Normal file
14
lib/bullseye/helpers/bullseye_controller_helper.rb
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
require 'bullseye/find_parts'
|
||||||
|
|
||||||
|
module Bullseye
|
||||||
|
module Helpers
|
||||||
|
module BullseyeControllerHelper
|
||||||
|
def bullseye_target(target)
|
||||||
|
part_finder = Bullseye::FindParts::PartFinder.new(target)
|
||||||
|
|
||||||
|
@__bullseye_action = part_finder.actions.first
|
||||||
|
@__bullseye_controller = part_finder.controller
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -2,7 +2,20 @@ module Bullseye
|
|||||||
module Helpers
|
module Helpers
|
||||||
module BullseyeHelper
|
module BullseyeHelper
|
||||||
def bullseye_body(options = {}, &block)
|
def bullseye_body(options = {}, &block)
|
||||||
content_tag(:body, capture(&block), { 'data-action' => action_name, 'data-controller' => controller_path }.merge(options)).html_safe
|
attributes = Bullseye.config.html_tag.collect do |key, value|
|
||||||
|
[ key, value.gsub(':action', __bullseye_action).gsub(':controller', __bullseye_controller) ]
|
||||||
|
end
|
||||||
|
|
||||||
|
content_tag(:body, capture(&block), Hash[attributes].merge(options)).html_safe
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def __bullseye_action
|
||||||
|
@__bullseye_action || action_name
|
||||||
|
end
|
||||||
|
|
||||||
|
def __bullseye_controller
|
||||||
|
@__bullseye_controller || controller_path
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,14 +1,17 @@
|
|||||||
require 'sass'
|
require 'sass'
|
||||||
|
require 'bullseye/find_parts'
|
||||||
|
|
||||||
module Sass::Script::Functions
|
module Sass::Script::Functions
|
||||||
def bullseye(target)
|
def bullseye(target)
|
||||||
assert_type target, :String
|
assert_type target, :String
|
||||||
|
|
||||||
parts = target.value.split('/')
|
part_finder = Bullseye::FindParts::PartFinder.new(target.value)
|
||||||
action = parts.pop
|
|
||||||
controller = parts.join('/')
|
|
||||||
|
|
||||||
Sass::Script::String.new(Bullseye.config.css_selector.gsub(':action', action).gsub(':controller', controller))
|
selectors = part_finder.actions.collect do |action|
|
||||||
|
Bullseye.config.css_selector.gsub(':action', action).gsub(':controller', part_finder.controller)
|
||||||
|
end
|
||||||
|
|
||||||
|
Sass::Script::String.new(selectors.join(','))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
require 'tilt'
|
require 'tilt'
|
||||||
require 'bullseye/tilt/find_parts'
|
require 'bullseye/find_parts'
|
||||||
require 'json'
|
require 'json'
|
||||||
|
|
||||||
module Bullseye
|
module Bullseye
|
||||||
module Tilt
|
module Tilt
|
||||||
class BullseyeTemplate < ::Tilt::Template
|
class BullseyeTemplate < ::Tilt::Template
|
||||||
include Bullseye::Tilt::FindParts
|
include Bullseye::FindParts
|
||||||
|
|
||||||
def self.default_mime_type
|
def self.default_mime_type
|
||||||
'application/javascript'
|
'application/javascript'
|
||||||
@ -15,7 +15,7 @@ module Bullseye
|
|||||||
end
|
end
|
||||||
|
|
||||||
def evaluate(scope, locals, &block)
|
def evaluate(scope, locals, &block)
|
||||||
@scope = scope
|
@source = scope.logical_path[1..-1]
|
||||||
|
|
||||||
<<-JS
|
<<-JS
|
||||||
Bullseye.target('#{controller}', #{actions.to_json}, function() {
|
Bullseye.target('#{controller}', #{actions.to_json}, function() {
|
||||||
|
@ -1,18 +0,0 @@
|
|||||||
module Bullseye
|
|
||||||
module Tilt
|
|
||||||
module FindParts
|
|
||||||
def actions
|
|
||||||
parts.last.split('-')
|
|
||||||
end
|
|
||||||
|
|
||||||
def controller
|
|
||||||
parts[0..-2].join('/')
|
|
||||||
end
|
|
||||||
|
|
||||||
def parts
|
|
||||||
@scope.logical_path.split('/')[1..-1]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
|||||||
module Bullseye
|
module Bullseye
|
||||||
VERSION = "0.0.5"
|
VERSION = "0.0.6"
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user