applied_css 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile.lock +38 -34
- data/lib/applied_css/version.rb +1 -1
- data/lib/applied_css.rb +13 -6
- data/spec/applied_css/applied_css_spec.rb +8 -8
- metadata +61 -20
- data/.rvmrc +0 -1
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
applied_csv
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-1.9.3-p429
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
applied_css (0.0.
|
4
|
+
applied_css (0.0.3)
|
5
5
|
addressable
|
6
6
|
awesome_print
|
7
7
|
bundler
|
@@ -14,63 +14,67 @@ PATH
|
|
14
14
|
GEM
|
15
15
|
remote: http://rubygems.org/
|
16
16
|
specs:
|
17
|
-
addressable (2.3.
|
17
|
+
addressable (2.3.5)
|
18
18
|
awesome_print (1.1.0)
|
19
|
-
cobweb (1.0.
|
19
|
+
cobweb (1.0.11)
|
20
20
|
addressable
|
21
21
|
awesome_print
|
22
22
|
haml
|
23
23
|
json
|
24
|
-
namespaced_redis
|
24
|
+
namespaced_redis
|
25
25
|
nokogiri
|
26
26
|
redis
|
27
27
|
resque
|
28
28
|
rspec
|
29
29
|
sinatra
|
30
|
+
slop
|
30
31
|
thin
|
31
|
-
css_parser (1.
|
32
|
+
css_parser (1.3.4)
|
32
33
|
addressable
|
33
|
-
rdoc
|
34
34
|
daemons (1.1.9)
|
35
|
-
diff-lcs (1.
|
36
|
-
eventmachine (1.0.
|
35
|
+
diff-lcs (1.2.4)
|
36
|
+
eventmachine (1.0.3)
|
37
37
|
fakeweb (1.3.0)
|
38
|
-
haml (
|
39
|
-
|
40
|
-
|
38
|
+
haml (4.0.3)
|
39
|
+
tilt
|
40
|
+
json (1.8.0)
|
41
|
+
mini_portile (0.5.1)
|
42
|
+
mono_logger (1.1.0)
|
43
|
+
multi_json (1.7.7)
|
41
44
|
namespaced_redis (1.0.4)
|
42
45
|
redis
|
43
|
-
nokogiri (1.
|
44
|
-
|
45
|
-
rack
|
46
|
+
nokogiri (1.6.0)
|
47
|
+
mini_portile (~> 0.5.0)
|
48
|
+
rack (1.5.2)
|
49
|
+
rack-protection (1.5.0)
|
46
50
|
rack
|
47
|
-
|
48
|
-
|
49
|
-
redis (3.0.2)
|
50
|
-
redis-namespace (1.2.1)
|
51
|
+
redis (3.0.4)
|
52
|
+
redis-namespace (1.3.0)
|
51
53
|
redis (~> 3.0.0)
|
52
|
-
resque (1.
|
54
|
+
resque (1.24.1)
|
55
|
+
mono_logger (~> 1.0)
|
53
56
|
multi_json (~> 1.0)
|
54
|
-
redis-namespace (~> 1.
|
57
|
+
redis-namespace (~> 1.2)
|
55
58
|
sinatra (>= 0.9.2)
|
56
59
|
vegas (~> 0.1.2)
|
57
|
-
rspec (2.
|
58
|
-
rspec-core (~> 2.
|
59
|
-
rspec-expectations (~> 2.
|
60
|
-
rspec-mocks (~> 2.
|
61
|
-
rspec-core (2.
|
62
|
-
rspec-expectations (2.
|
63
|
-
diff-lcs (
|
64
|
-
rspec-mocks (2.
|
65
|
-
sinatra (1.
|
66
|
-
rack (~> 1.
|
67
|
-
rack-protection (~> 1.
|
68
|
-
tilt (~> 1.3, >= 1.3.
|
69
|
-
|
60
|
+
rspec (2.14.1)
|
61
|
+
rspec-core (~> 2.14.0)
|
62
|
+
rspec-expectations (~> 2.14.0)
|
63
|
+
rspec-mocks (~> 2.14.0)
|
64
|
+
rspec-core (2.14.3)
|
65
|
+
rspec-expectations (2.14.0)
|
66
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
67
|
+
rspec-mocks (2.14.1)
|
68
|
+
sinatra (1.4.3)
|
69
|
+
rack (~> 1.4)
|
70
|
+
rack-protection (~> 1.4)
|
71
|
+
tilt (~> 1.3, >= 1.3.4)
|
72
|
+
slop (3.4.5)
|
73
|
+
thin (1.5.1)
|
70
74
|
daemons (>= 1.0.9)
|
71
75
|
eventmachine (>= 0.12.6)
|
72
76
|
rack (>= 1.0.0)
|
73
|
-
tilt (1.
|
77
|
+
tilt (1.4.1)
|
74
78
|
vegas (0.1.11)
|
75
79
|
rack (>= 1.0.0)
|
76
80
|
|
data/lib/applied_css/version.rb
CHANGED
data/lib/applied_css.rb
CHANGED
@@ -12,6 +12,8 @@ class AppliedCSS
|
|
12
12
|
@options = {:ancestors => false}.merge(options)
|
13
13
|
@options[:cache] = 120 unless @options.has_key? :cache
|
14
14
|
@options[:cache_type] = :full unless @options.has_key? :cache_type
|
15
|
+
|
16
|
+
@options[:debug] = false unless @options.has_key? :debug
|
15
17
|
|
16
18
|
@base_uri = Addressable::URI.parse(@options[:url])
|
17
19
|
raise "url must be specified" unless @base_uri
|
@@ -23,11 +25,14 @@ class AppliedCSS
|
|
23
25
|
@doc = Nokogiri::HTML.parse(html) unless html.nil?
|
24
26
|
end
|
25
27
|
|
28
|
+
puts "Genrating Parser." if @options[:debug]
|
26
29
|
@parser = CssParser::Parser.new
|
27
30
|
styles.each do |uri, style|
|
31
|
+
puts "adding #{style}" if @options[:debug]
|
28
32
|
@parser.add_block! style
|
29
33
|
end
|
30
34
|
@doc.css("style").each do |style_node|
|
35
|
+
puts "adding #{style_node.text()}" if @options[:debug]
|
31
36
|
@parser.add_block! style_node.text()
|
32
37
|
end
|
33
38
|
end
|
@@ -56,9 +61,11 @@ class AppliedCSS
|
|
56
61
|
private
|
57
62
|
def populate_style_hash
|
58
63
|
@style_hash = {}
|
59
|
-
@doc.
|
60
|
-
|
61
|
-
|
64
|
+
@doc.search("link").each do |link|
|
65
|
+
if link["rel"].downcase == "stylesheet"
|
66
|
+
uri = @base_uri.join(link["href"]).to_s
|
67
|
+
get_style(uri)
|
68
|
+
end
|
62
69
|
end
|
63
70
|
end
|
64
71
|
|
@@ -84,7 +91,7 @@ class AppliedCSS
|
|
84
91
|
declarations = {}
|
85
92
|
node_identifications(node).each do |node_path|
|
86
93
|
@parser.find_by_selector(node_path).each do |detected_decs|
|
87
|
-
detected_decs.split(";").map{|detected_dec| declarations[detected_dec.split(":")[0].strip.
|
94
|
+
detected_decs.split(";").map{|detected_dec| declarations[detected_dec.split(":")[0].strip.to_s] = detected_dec.split(":")[1].strip}
|
88
95
|
end
|
89
96
|
end
|
90
97
|
declarations
|
@@ -114,7 +121,7 @@ class AppliedCSS
|
|
114
121
|
nodes += node.ancestors[0..-2].reverse
|
115
122
|
end
|
116
123
|
nodes << node
|
117
|
-
nodes
|
124
|
+
nodes.reject{|node| node.nil?}
|
118
125
|
end
|
119
126
|
|
120
127
|
def get(url)
|
@@ -136,7 +143,7 @@ class AppliedCSS
|
|
136
143
|
http.request(request)
|
137
144
|
}
|
138
145
|
if response.code.to_i.between? 300, 399
|
139
|
-
puts "redirecting to #{response["location"]}"
|
146
|
+
puts "redirecting to #{response["location"]}" if @options[:debug]
|
140
147
|
uri = uri.merge(response["location"])
|
141
148
|
elsif response.code.to_i == 404
|
142
149
|
raise "The style #{url} doesen't exist (404)"
|
@@ -80,11 +80,11 @@ describe AppliedCSS do
|
|
80
80
|
|
81
81
|
describe "load ordering" do
|
82
82
|
it "should overwrite earlier declarations" do
|
83
|
-
@applied_css.css("#container")[
|
83
|
+
@applied_css.css("#container")["height"].should == "600px"
|
84
84
|
end
|
85
85
|
|
86
86
|
it "should not take settings from ancestors" do
|
87
|
-
@applied_css.css("#container")[
|
87
|
+
@applied_css.css("#container")["font-size"].should be_nil
|
88
88
|
end
|
89
89
|
|
90
90
|
describe "with ancestors" do
|
@@ -92,28 +92,28 @@ describe AppliedCSS do
|
|
92
92
|
@applied_css = AppliedCSS.new(:url => @sample_html, :ancestors => true)
|
93
93
|
end
|
94
94
|
it "should take settings from ancestors" do
|
95
|
-
@applied_css.css("#container")[
|
95
|
+
@applied_css.css("#container")["font-size"].should == "20px"
|
96
96
|
end
|
97
97
|
end
|
98
98
|
end
|
99
99
|
|
100
100
|
describe "using ids" do
|
101
101
|
it "should find declarations using ids" do
|
102
|
-
@applied_css.css("#container")[
|
102
|
+
@applied_css.css("#container")["width"].should == "900px"
|
103
103
|
end
|
104
104
|
end
|
105
105
|
|
106
106
|
describe "using classes" do
|
107
107
|
it "should find declarations using classes" do
|
108
|
-
@applied_css.css("#container > span").keys.should include
|
109
|
-
@applied_css.css("#container > span")[
|
108
|
+
@applied_css.css("#container > span").keys.should include "color"
|
109
|
+
@applied_css.css("#container > span")["color"].should == "#ff0000"
|
110
110
|
end
|
111
111
|
end
|
112
112
|
|
113
113
|
describe "for imported stylesheets using @import" do
|
114
114
|
it "should find declarations delared on imported stylesheets" do
|
115
|
-
@applied_css.css("#from-imported").keys.should include
|
116
|
-
@applied_css.css("#from-imported")[
|
115
|
+
@applied_css.css("#from-imported").keys.should include "color"
|
116
|
+
@applied_css.css("#from-imported")["color"].should == "green"
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: applied_css
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-07-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,15 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: bundler
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ! '>='
|
@@ -32,10 +37,15 @@ dependencies:
|
|
32
37
|
version: '0'
|
33
38
|
type: :runtime
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
36
46
|
- !ruby/object:Gem::Dependency
|
37
47
|
name: nokogiri
|
38
|
-
requirement:
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
39
49
|
none: false
|
40
50
|
requirements:
|
41
51
|
- - ! '>='
|
@@ -43,10 +53,15 @@ dependencies:
|
|
43
53
|
version: '0'
|
44
54
|
type: :runtime
|
45
55
|
prerelease: false
|
46
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
47
62
|
- !ruby/object:Gem::Dependency
|
48
63
|
name: css_parser
|
49
|
-
requirement:
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
50
65
|
none: false
|
51
66
|
requirements:
|
52
67
|
- - ! '>='
|
@@ -54,10 +69,15 @@ dependencies:
|
|
54
69
|
version: '0'
|
55
70
|
type: :runtime
|
56
71
|
prerelease: false
|
57
|
-
version_requirements:
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
58
78
|
- !ruby/object:Gem::Dependency
|
59
79
|
name: fakeweb
|
60
|
-
requirement:
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
61
81
|
none: false
|
62
82
|
requirements:
|
63
83
|
- - ! '>='
|
@@ -65,10 +85,15 @@ dependencies:
|
|
65
85
|
version: '0'
|
66
86
|
type: :runtime
|
67
87
|
prerelease: false
|
68
|
-
version_requirements:
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
69
94
|
- !ruby/object:Gem::Dependency
|
70
95
|
name: awesome_print
|
71
|
-
requirement:
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
72
97
|
none: false
|
73
98
|
requirements:
|
74
99
|
- - ! '>='
|
@@ -76,10 +101,15 @@ dependencies:
|
|
76
101
|
version: '0'
|
77
102
|
type: :runtime
|
78
103
|
prerelease: false
|
79
|
-
version_requirements:
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
80
110
|
- !ruby/object:Gem::Dependency
|
81
111
|
name: addressable
|
82
|
-
requirement:
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
83
113
|
none: false
|
84
114
|
requirements:
|
85
115
|
- - ! '>='
|
@@ -87,10 +117,15 @@ dependencies:
|
|
87
117
|
version: '0'
|
88
118
|
type: :runtime
|
89
119
|
prerelease: false
|
90
|
-
version_requirements:
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
91
126
|
- !ruby/object:Gem::Dependency
|
92
127
|
name: cobweb
|
93
|
-
requirement:
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
94
129
|
none: false
|
95
130
|
requirements:
|
96
131
|
- - ! '>='
|
@@ -98,7 +133,12 @@ dependencies:
|
|
98
133
|
version: '0'
|
99
134
|
type: :runtime
|
100
135
|
prerelease: false
|
101
|
-
version_requirements:
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
102
142
|
description: Gem for interrogating CSS and Script elements of a html document
|
103
143
|
email:
|
104
144
|
- stewart@theizone.co.uk
|
@@ -108,7 +148,8 @@ extra_rdoc_files: []
|
|
108
148
|
files:
|
109
149
|
- .gitignore
|
110
150
|
- .rspec
|
111
|
-
- .
|
151
|
+
- .ruby-gemset
|
152
|
+
- .ruby-version
|
112
153
|
- Gemfile
|
113
154
|
- Gemfile.lock
|
114
155
|
- LICENSE.txt
|
@@ -148,7 +189,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
148
189
|
version: '0'
|
149
190
|
requirements: []
|
150
191
|
rubyforge_project: applied_css
|
151
|
-
rubygems_version: 1.8.
|
192
|
+
rubygems_version: 1.8.25
|
152
193
|
signing_key:
|
153
194
|
specification_version: 3
|
154
195
|
summary: CSS and Script extraction tool for html documents
|
data/.rvmrc
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
rvm use 1.9.2@applied_css
|