Skip to content

Commit

Permalink
Included kss' change of more robust pseudo class generation
Browse files Browse the repository at this point in the history
kneath/kss@e2d245
  • Loading branch information
dewski committed Jan 26, 2012
1 parent 6033d13 commit cbfcf12
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
1 change: 0 additions & 1 deletion Gemfile
@@ -1,4 +1,3 @@
source 'http://rubygems.org' source 'http://rubygems.org'


# Specify your gem's dependencies in kss-server.gemspec
gemspec gemspec
12 changes: 6 additions & 6 deletions app/assets/javascripts/kss.coffee
@@ -1,24 +1,24 @@
# This class scans your stylesheets for pseudo classes, then inserts a new CSS # This class scans your stylesheets for pseudo classes, then inserts a new CSS
# rule with the same properties, but named 'psuedo-class-{{name}}'. # rule with the same properties, but named 'psuedo-class-{{name}}'.
# #
# Supported pseudo classes: hover, disabled. # Supported pseudo classes: hover, disabled, active, visited.
# #
# Example: # Example:
# #
# a:hover{ color:blue; } # a:hover{ color:blue; }
# => a.pseudo-class-hover{ color:blue; } # => a.pseudo-class-hover{ color:blue; }
class KssStateGenerator class KssStateGenerator
constructor: -> constructor: ->
hover = /:hover/ pseudos = /(\:hover|\:disabled|\:active|\:visited)/g
disabled = /:disabled/
active = /:active/


try try
for stylesheet in document.styleSheets for stylesheet in document.styleSheets
idxs = [] idxs = []
for rule, idx in stylesheet.cssRules 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)) if (rule.type == CSSRule.STYLE_RULE) && pseudos.test(rule.selectorText)
@insertRule(rule.cssText.replace(':', '.pseudo-class-')) 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. # Takes a given style and attaches it to the current page.
# #
Expand Down
10 changes: 5 additions & 5 deletions kss-rails.gemspec
@@ -1,16 +1,16 @@
# -*- encoding: utf-8 -*- # -*- encoding: utf-8 -*-
Gem::Specification.new do |gem| Gem::Specification.new do |gem|
gem.authors = ["Garrett Bjerkhoel"] gem.authors = ['Garrett Bjerkhoel']
gem.email = ["me@garrettbjerkhoel.com"] gem.email = ['me@garrettbjerkhoel.com']
gem.description = %q{Rails 3 engine to provide a living styleguide from Kyle Neath's KSS.} 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.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.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
gem.files = `git ls-files`.split("\n") gem.files = `git ls-files`.split("\n")
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
gem.name = "kss-rails" gem.name = 'kss-rails'
gem.require_paths = ["lib"] gem.require_paths = ['lib']
gem.version = '1.0.1' gem.version = '1.0.1'


gem.add_dependency 'kss' gem.add_dependency 'kss'
Expand Down

0 comments on commit cbfcf12

Please sign in to comment.