Permalink
Browse files

Included kss' change of more robust pseudo class generation

kneath/kss@e2d245
  • Loading branch information...
1 parent 6033d13 commit cbfcf1273981f69b9e0c25f0701df222405aafba @dewski committed Jan 26, 2012
Showing with 11 additions and 12 deletions.
  1. +0 −1 Gemfile
  2. +6 −6 app/assets/javascripts/kss.coffee
  3. +5 −5 kss-rails.gemspec
View
@@ -1,4 +1,3 @@
source 'http://rubygems.org'
-# Specify your gem's dependencies in kss-server.gemspec
gemspec
@@ -1,24 +1,24 @@
# This class scans your stylesheets for pseudo classes, then inserts a new CSS
# rule with the same properties, but named 'psuedo-class-{{name}}'.
#
-# Supported pseudo classes: hover, disabled.
+# Supported pseudo classes: hover, disabled, active, visited.
#
# Example:
#
# a:hover{ color:blue; }
# => a.pseudo-class-hover{ color:blue; }
class KssStateGenerator
constructor: ->
- hover = /:hover/
- disabled = /:disabled/
- active = /:active/
+ pseudos = /(\:hover|\:disabled|\:active|\:visited)/g
try
for stylesheet in document.styleSheets
idxs = []
for rule, idx in stylesheet.cssRules
- if rule.type is CSSRule.STYLE_RULE and (hover.test(rule.selectorText) or disabled.test(rule.selectorText) or active.test(rule.selectorText))
- @insertRule(rule.cssText.replace(':', '.pseudo-class-'))
+ if (rule.type == CSSRule.STYLE_RULE) && pseudos.test(rule.selectorText)
+ replaceRule = (matched, stuff) ->
+ return ".pseudo-class-" + matched.replace(':', '')
+ @insertRule(rule.cssText.replace(pseudos, replaceRule))
# Takes a given style and attaches it to the current page.
#
View
@@ -1,16 +1,16 @@
# -*- encoding: utf-8 -*-
Gem::Specification.new do |gem|
- gem.authors = ["Garrett Bjerkhoel"]
- gem.email = ["me@garrettbjerkhoel.com"]
+ gem.authors = ['Garrett Bjerkhoel']
+ gem.email = ['me@garrettbjerkhoel.com']
gem.description = %q{Rails 3 engine to provide a living styleguide from Kyle Neath's KSS.}
gem.summary = %q{Rails 3 engine to provide a living styleguide from Kyle Neath's KSS.}
- gem.homepage = "https://github.com/dewski/kss-rails"
+ gem.homepage = 'https://github.com/dewski/kss-rails'
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
gem.files = `git ls-files`.split("\n")
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
- gem.name = "kss-rails"
- gem.require_paths = ["lib"]
+ gem.name = 'kss-rails'
+ gem.require_paths = ['lib']
gem.version = '1.0.1'
gem.add_dependency 'kss'

0 comments on commit cbfcf12

Please sign in to comment.