Skip to content

Instantly share code, notes, and snippets.

@shikakun
Created April 16, 2014 08:46
Show Gist options
  • Save shikakun/10834795 to your computer and use it in GitHub Desktop.
Save shikakun/10834795 to your computer and use it in GitHub Desktop.
#! /usr/bin/env ruby
# -*- coding: utf-8 -*-
# css ファイルのなかのセレクタを一覧で出力する
# 参考: http://qiita.com/walf443/items/6524a3d042365f7f98dc
require 'sass/css'
def print_uniq_selectors(file)
css = ""
File.open(file) do |io|
css = io.read
end
css = Sass::CSS.new(css, {:filename => file})
css_tree = css.__send__(:build_tree)
selectors = []
css_tree.select {|n| n.is_a?(Sass::Tree::RuleNode) }.each do |rule|
selectors.push rule.parsed_rules.members
end
selectors.uniq!
selectors.each_with_index do |selector, i|
puts "#{i+1}: #{selector}"
end
end
print_uniq_selectors(ARGV[0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment