abscss 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Tony Doan
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,13 @@
1
+ = abscss
2
+
3
+ Breadth first search an HTML page and spit out all the branches of the tree as CSS selectors. Simple filtering is currently hardcoded to ignore HTML tags that we don't style.
4
+
5
+ == Notes
6
+
7
+ Inspired by Russ Russ Weakley's explanation of how he gets started adding style to semantically marked up HTML document.
8
+
9
+ If you find this at all useful please submit feature requests. Right now it's pretty simplistic. One idea was to add spidering so you could build selectors up over an entire site.
10
+
11
+ == Copyright
12
+
13
+ Copyright (c) 2010 Tony Doan. See LICENSE for details.
@@ -0,0 +1,54 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "abscss"
8
+ gem.summary = %Q{Reduce an HTML page into CSS selectors}
9
+ gem.description = %Q{Breadth first search an HTML page and spit out all the branches of the tree as CSS selectors. Simple filtering is currently hardcoded to ignore HTML tags that we don't style.}
10
+ gem.email = "tdoan@tdoan.com"
11
+ gem.homepage = "http://github.com/tdoan/abscss"
12
+ gem.authors = ["Tony Doan"]
13
+ gem.add_runtime_dependency "nokogiri"
14
+ gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
15
+ gem.files = %w{LICENSE ReADME.rdoc Rakefile VERSION lib/abscss.rb lib/cli.rb bin/abscss}
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
+ end
21
+
22
+ require 'rake/testtask'
23
+ Rake::TestTask.new(:test) do |test|
24
+ test.libs << 'lib' << 'test'
25
+ test.pattern = 'test/**/test_*.rb'
26
+ test.verbose = true
27
+ end
28
+
29
+ begin
30
+ require 'rcov/rcovtask'
31
+ Rcov::RcovTask.new do |test|
32
+ test.libs << 'test'
33
+ test.pattern = 'test/**/test_*.rb'
34
+ test.verbose = true
35
+ end
36
+ rescue LoadError
37
+ task :rcov do
38
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
39
+ end
40
+ end
41
+
42
+ task :test => :check_dependencies
43
+
44
+ task :default => :test
45
+
46
+ require 'rake/rdoctask'
47
+ Rake::RDocTask.new do |rdoc|
48
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
49
+
50
+ rdoc.rdoc_dir = 'rdoc'
51
+ rdoc.title = "abscss #{version}"
52
+ rdoc.rdoc_files.include('README*')
53
+ rdoc.rdoc_files.include('lib/**/*.rb')
54
+ end
@@ -0,0 +1,13 @@
1
+ = abscss
2
+
3
+ Breadth first search an HTML page and spit out all the branches of the tree as CSS selectors. Simple filtering is currently hardcoded to ignore HTML tags that we don't style.
4
+
5
+ == Notes
6
+
7
+ Inspired by Russ Russ Weakley's explanation of how he gets started adding style to semantically marked up HTML document.
8
+
9
+ If you find this at all useful please submit feature requests. Right now it's pretty simplistic. One idea was to add spidering so you could build selectors up over an entire site.
10
+
11
+ == Copyright
12
+
13
+ Copyright (c) 2010 Tony Doan. See LICENSE for details.
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Created on 2010-7-11.
4
+ # Copyright (c) 2010. All rights reserved.
5
+
6
+ require 'rubygems'
7
+ require File.expand_path(File.dirname(__FILE__) + "/../lib/abscss")
8
+ require File.expand_path(File.dirname(__FILE__) + "/../lib/cli")
9
+
10
+ Abscss::CLI.execute(STDOUT, ARGV)
@@ -0,0 +1,27 @@
1
+ require 'rubygems'
2
+ require 'open-uri'
3
+ require 'nokogiri'
4
+
5
+ module Abscss
6
+ class Traverser
7
+ def initialize
8
+ @selectors = {}
9
+ end
10
+
11
+ def traverse(node,parent="")
12
+ has_id = node.attributes['id']
13
+ name_to_use = has_id ? "##{node.attributes['id'].value}" : node.name
14
+ parent = "" if has_id
15
+ @selectors[[parent,name_to_use].join(" ").strip] = 1 unless (node.text? or node.name == "meta" or node.name == "link" or node.name == "style" or node.name == "#cdata-section" or node.name == "head")
16
+ if node.children.size > 0
17
+ node.children.each do |child|
18
+ traverse(child,[parent, name_to_use].join(" "))
19
+ end
20
+ end
21
+ end
22
+
23
+ def output
24
+ @selectors.keys.join("\n")
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,24 @@
1
+ require 'optparse'
2
+ require 'ostruct'
3
+
4
+ module Abscss
5
+ class CLI
6
+ def self.execute(stdout, arguments=[])
7
+
8
+ if ARGV.size < 1
9
+ $stderr.puts "Usage: abscss files_or_urls"
10
+ exit(-1)
11
+ end
12
+
13
+ t = Abscss::Traverser.new
14
+ ARGV.each do |arg|
15
+ raw = open(arg).read
16
+ doc = Nokogiri::HTML(raw)
17
+ doc.root.children.each do |child|
18
+ t.traverse(child)
19
+ end
20
+ end
21
+ puts t.output
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'abscss'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestAbscss < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: abscss
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 0
9
+ version: 0.0.0
10
+ platform: ruby
11
+ authors:
12
+ - Tony Doan
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-07-11 00:00:00 -07:00
18
+ default_executable: abscss
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: nokogiri
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ type: :runtime
32
+ version_requirements: *id001
33
+ - !ruby/object:Gem::Dependency
34
+ name: thoughtbot-shoulda
35
+ prerelease: false
36
+ requirement: &id002 !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ version: "0"
44
+ type: :development
45
+ version_requirements: *id002
46
+ description: Breadth first search an HTML page and spit out all the branches of the tree as CSS selectors. Simple filtering is currently hardcoded to ignore HTML tags that we don't style.
47
+ email: tdoan@tdoan.com
48
+ executables:
49
+ - abscss
50
+ extensions: []
51
+
52
+ extra_rdoc_files:
53
+ - LICENSE
54
+ - README.rdoc
55
+ files:
56
+ - LICENSE
57
+ - Rakefile
58
+ - ReADME.rdoc
59
+ - VERSION
60
+ - bin/abscss
61
+ - lib/abscss.rb
62
+ - lib/cli.rb
63
+ - README.rdoc
64
+ - test/helper.rb
65
+ - test/test_abscss.rb
66
+ has_rdoc: true
67
+ homepage: http://github.com/tdoan/abscss
68
+ licenses: []
69
+
70
+ post_install_message:
71
+ rdoc_options:
72
+ - --charset=UTF-8
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ segments:
81
+ - 0
82
+ version: "0"
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ segments:
89
+ - 0
90
+ version: "0"
91
+ requirements: []
92
+
93
+ rubyforge_project:
94
+ rubygems_version: 1.3.7
95
+ signing_key:
96
+ specification_version: 3
97
+ summary: Reduce an HTML page into CSS selectors
98
+ test_files:
99
+ - test/helper.rb
100
+ - test/test_abscss.rb