aanand-deadweight 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/deadweight.gemspec +1 -1
- data/lib/deadweight.rb +20 -17
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
data/deadweight.gemspec
CHANGED
data/lib/deadweight.rb
CHANGED
@@ -15,6 +15,7 @@ class Deadweight
|
|
15
15
|
@log_file = STDERR
|
16
16
|
end
|
17
17
|
|
18
|
+
# Find all unused CSS selectors and return them as an array.
|
18
19
|
def run
|
19
20
|
css = CssParser::Parser.new
|
20
21
|
|
@@ -66,12 +67,29 @@ class Deadweight
|
|
66
67
|
unused_selectors
|
67
68
|
end
|
68
69
|
|
69
|
-
|
70
|
-
|
70
|
+
# Returns the Mechanize instance, if +mechanize+ is set to +true+.
|
71
71
|
def agent
|
72
72
|
@agent ||= initialize_agent
|
73
73
|
end
|
74
74
|
|
75
|
+
# Fetch a path, using Mechanize if +mechanize+ is set to +true+.
|
76
|
+
def fetch(path)
|
77
|
+
log.info(path)
|
78
|
+
|
79
|
+
loc = root + path
|
80
|
+
|
81
|
+
if @mechanize
|
82
|
+
loc = "file://#{File.expand_path(loc)}" unless loc =~ %r{^\w+://}
|
83
|
+
page = agent.get(loc)
|
84
|
+
log.warn("#{path} redirected to #{page.uri}") unless page.uri.to_s == loc
|
85
|
+
page.body
|
86
|
+
else
|
87
|
+
open(loc).read
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
private
|
92
|
+
|
75
93
|
def log
|
76
94
|
@log ||= Logger.new(@log_file)
|
77
95
|
end
|
@@ -91,20 +109,5 @@ class Deadweight
|
|
91
109
|
raise
|
92
110
|
end
|
93
111
|
end
|
94
|
-
|
95
|
-
def fetch(path)
|
96
|
-
log.info(path)
|
97
|
-
|
98
|
-
loc = root + path
|
99
|
-
|
100
|
-
if @mechanize
|
101
|
-
loc = "file://#{File.expand_path(loc)}" unless loc =~ %r{^\w+://}
|
102
|
-
page = agent.get(loc)
|
103
|
-
log.warn("#{path} redirected to #{page.uri}") unless page.uri.to_s == loc
|
104
|
-
page.body
|
105
|
-
else
|
106
|
-
open(loc).read
|
107
|
-
end
|
108
|
-
end
|
109
112
|
end
|
110
113
|
|