diff --git a/README.md b/README.md index 334f5b3..c42eb53 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,13 @@ # Bullseye! An *extremely quickly written* shoot-from-the-hip implementation of [so-called Garber-Irish DOM-ready execution](http://viget.com/inspire/extending-paul-irishs-comprehensive-dom-ready-execution) -for the Rails asset pipeline. Could work with other Sprockets stuff down the road, too. But for now, it's +for the Rails asset pipeline. Even provides functionalty for Sass to target those pages! Could work with other Sprockets stuff down the road, too. But for now, it's pretty married to Rails. Also, needs tests for the exactly four things that it does. Anyone wanna add exactly four Cucumber features? ## Why? I got sick of on-page JavaScript. Also I like using the Asset Pipeline for what it's actually intended for, -reducing the number of HTTP requests. +reducing the number of HTTP requests. Finally, targeting pages in Sass should be easy. ## How? @@ -51,4 +51,12 @@ alert("I am showing a site"); alert "I am also showing a site" ``` +Want to target that page in your Sass? Use a little string interpolation and a function that generates a selector: + +``` sass +#{bullseye('sites/show')} { + background-color: green; +} +``` + Piece of cake. diff --git a/bullseye.gemspec b/bullseye.gemspec index 57e7ad8..b2ec7a4 100644 --- a/bullseye.gemspec +++ b/bullseye.gemspec @@ -17,4 +17,5 @@ Gem::Specification.new do |gem| gem.add_dependency 'tilt' gem.add_dependency 'sprockets' + gem.add_dependency 'sass' end diff --git a/lib/bullseye.rb b/lib/bullseye.rb index 2c4bb69..8d43773 100644 --- a/lib/bullseye.rb +++ b/lib/bullseye.rb @@ -1,3 +1,4 @@ require "bullseye/version" require 'bullseye/engine' if defined?(Rails::Engine) require 'bullseye/tilt/bullseye_template' +require 'bullseye/sass/bullseye_functions' diff --git a/lib/bullseye/sass/bullseye_functions.rb b/lib/bullseye/sass/bullseye_functions.rb new file mode 100644 index 0000000..290a8be --- /dev/null +++ b/lib/bullseye/sass/bullseye_functions.rb @@ -0,0 +1,13 @@ +require 'sass' + +module Sass::Script::Functions + def bullseye(target) + assert_type target, :String + + parts = target.value.split('/') + action = parts.pop + controller = parts.join('/') + + Sass::Script::String.new("body[data-action='#{action}'][data-controller='#{controller}']") + end +end diff --git a/lib/bullseye/version.rb b/lib/bullseye/version.rb index 87a21db..33c6868 100644 --- a/lib/bullseye/version.rb +++ b/lib/bullseye/version.rb @@ -1,3 +1,3 @@ module Bullseye - VERSION = "0.0.1" + VERSION = "0.0.2" end