From 1ab0f26aec6926a8c6628ebbfba2f894def7701f Mon Sep 17 00:00:00 2001 From: John Bintz Date: Tue, 2 Oct 2012 15:48:01 -0400 Subject: [PATCH] some stuff for better rails integration --- lib/bullseye.rb | 11 +---------- lib/bullseye/engine.rb | 18 ++++++++++++++++++ lib/bullseye/find_parts.rb | 6 ++++-- lib/bullseye/helpers/bullseye_helper.rb | 2 +- skel/config/initializers/bullseye.rb | 9 +++++++++ 5 files changed, 33 insertions(+), 13 deletions(-) create mode 100644 skel/config/initializers/bullseye.rb diff --git a/lib/bullseye.rb b/lib/bullseye.rb index 9b5f541..9d04395 100644 --- a/lib/bullseye.rb +++ b/lib/bullseye.rb @@ -6,16 +6,6 @@ require 'bullseye/sass/bullseye_functions' module Bullseye class Configuration attr_accessor :js_controller_search, :js_action_search, :css_selector, :html_tag, :fuzzy_search - - def initialize - @js_controller_search = %{$('body').data('controller')} - @js_action_search = %{$('body').data('action')} - - @css_selector = %{body[data-action=':action'][data-controller=':controller']} - @html_tag = { 'data-action' => ':action', 'data-controller' => ':controller' } - - @fuzzy_search = false - end end class << self @@ -28,3 +18,4 @@ module Bullseye end end end + diff --git a/lib/bullseye/engine.rb b/lib/bullseye/engine.rb index b1dad85..f57ea54 100644 --- a/lib/bullseye/engine.rb +++ b/lib/bullseye/engine.rb @@ -12,5 +12,23 @@ module Bullseye app.assets.register_engine '.bullseye', Bullseye::Tilt::BullseyeTemplate end end + + class InstallGenerator < ::Rails::Generators::Base + source_root File.expand_path('../../../skel', __FILE__) + + def create_initializer_file + copy_file "config/initializers/bullseye.rb", "config/initializers/bullseye.rb" + + puts + puts "Add to your main application.js file:" + puts + puts "//= require bullseye" + puts + puts "and replace your body tag layouts/application.html with a call to bullseye_body:" + puts + puts "= bullseye_body do" + puts + end + end end diff --git a/lib/bullseye/find_parts.rb b/lib/bullseye/find_parts.rb index e91e457..e6f0cca 100644 --- a/lib/bullseye/find_parts.rb +++ b/lib/bullseye/find_parts.rb @@ -1,11 +1,13 @@ module Bullseye module FindParts + SEPARATOR = '-' + def actions - parts.last.split('-') + parts.last.split(SEPARATOR) end def controller - parts[0..-2].join('-') + parts[0..-2].join(SEPARATOR) end def parts diff --git a/lib/bullseye/helpers/bullseye_helper.rb b/lib/bullseye/helpers/bullseye_helper.rb index 464921f..ec5f95c 100644 --- a/lib/bullseye/helpers/bullseye_helper.rb +++ b/lib/bullseye/helpers/bullseye_helper.rb @@ -15,7 +15,7 @@ module Bullseye end def __bullseye_controller - @__bullseye_controller || controller_path + @__bullseye_controller || controller_path.gsub('/', Bullseye::FindParts::SEPARATOR) end end end diff --git a/skel/config/initializers/bullseye.rb b/skel/config/initializers/bullseye.rb new file mode 100644 index 0000000..e427ff8 --- /dev/null +++ b/skel/config/initializers/bullseye.rb @@ -0,0 +1,9 @@ +Bullseye.configure do |c| + c.js_controller_search = %{$('body').data('controller')} + c.js_action_search = %{$('body').data('action')} + + c.css_selector = %{body[data-action=':action'][data-controller=':controller']} + c.html_tag = { 'data-action' => ':action', 'data-controller' => ':controller' } + + c.fuzzy_search = false +end