stylesheet 0.1.5 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d61c5fd85f824f45f5418d740d9bdb79f7025a18d6cf271fe85bda02598e1efa
4
- data.tar.gz: 1743549221b9794d3abfd0cc34c3247136ada918797a9c06567d06e3ca2171b0
3
+ metadata.gz: d8731f136d13c2aafa5686bc348ed721890e8d8186ccf7b3d07b04b5e4b1d286
4
+ data.tar.gz: 5e1a9e9c982d43c12c2e7bed8c43703b7fae491282d1c17e24f25567bbbec08a
5
5
  SHA512:
6
- metadata.gz: e6e3aac46073dfe973a59da7480e80effb4e323f63d3e93ed5a0b3c0e53cf539f8660294a681f38df40935df963e6085993dd0fb2347bf9a9e5250b7c25ed36c
7
- data.tar.gz: 379b785b6f417d1c8486cf28575703c525947897a9af735c9a134bda5fc41476d46554657851b37a4945c1a3aaf6bc6462b088cb9059343c5cedfb3b600c4191
6
+ metadata.gz: 73c42acfa16d26fe5c48dffaaf738cf21452dcdc8e1c2be9ae050663a70be53eaab99a87cb9cce8f7096b04bd52b828e0704f15b70ec74cb0edf93323bc4bc42
7
+ data.tar.gz: 696f793a09c89575152c2a31730909e76d0328bb095c540c7c405347b6bc53f3e414619e86e956bee3e51d3a10f7ce47c4bfbcc34be627f2d6f3fb8b8354e8f5
@@ -49,7 +49,7 @@ module Stylesheet
49
49
  end
50
50
 
51
51
  def content=(content)
52
- @content = content if content != ""
52
+ @content = content if content
53
53
  end
54
54
 
55
55
  def content
@@ -47,7 +47,7 @@ module Stylesheet
47
47
  end
48
48
 
49
49
  def valid?
50
- valid_protocol? && valid_host?
50
+ !!(valid_protocol? && valid_host?)
51
51
  end
52
52
 
53
53
  def expand_paths_from_parent
@@ -74,19 +74,19 @@ module Stylesheet
74
74
  def valid_protocol?
75
75
  protocol && protocol != ":"
76
76
  end
77
-
77
+
78
78
  def valid_host?
79
79
  host && host != ""
80
80
  end
81
-
81
+
82
82
  def valid_port?
83
83
  port && port != ""
84
84
  end
85
-
85
+
86
86
  def standard_port?
87
87
  port_80? || port_443?
88
88
  end
89
-
89
+
90
90
  def port_80?
91
91
  uri && uri.port == 80 && uri.scheme == "http"
92
92
  end
@@ -100,14 +100,13 @@ module Stylesheet
100
100
  URI.parse(url.strip)
101
101
  rescue URI::InvalidURIError
102
102
  URI.parse(URI.escape(url.strip))
103
- end
103
+ end
104
104
 
105
105
  # re-raise external library errors in our namespace
106
106
  rescue URI::InvalidURIError => error
107
107
  raise Stylesheet::InvalidLocationError.new(
108
108
  "#{error.class}: #{error.message}")
109
109
  end
110
-
110
+
111
111
  end
112
112
  end
113
-
@@ -1,3 +1,3 @@
1
1
  module Stylesheet
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
@@ -23,17 +23,17 @@ describe CssCharsetRule do
23
23
  describe ".matches_rule?" do
24
24
  it "should match text starting with @charset" do
25
25
  matches = CssCharsetRule.matches_rule?(css_text)
26
- expect(matches).to be_true
26
+ expect(matches).to eq true
27
27
  end
28
28
 
29
29
  it "should not match text without at-rule" do
30
30
  matches = CssCharsetRule.matches_rule?("a:link { color: #357ad1; }")
31
- expect(matches).to be_false
31
+ expect(matches).to eq false
32
32
  end
33
33
 
34
34
  it "should not match text without charset" do
35
35
  matches = CssCharsetRule.matches_rule?("@import url(\"import1.css\");")
36
- expect(matches).to be_false
36
+ expect(matches).to eq false
37
37
  end
38
38
  end
39
- end
39
+ end
@@ -31,17 +31,17 @@ describe CssFontFaceRule do
31
31
  describe ".matches_rule?" do
32
32
  it "should match text starting with @font-face" do
33
33
  matches = CssFontFaceRule.matches_rule?(css_text)
34
- expect(matches).to be_true
34
+ expect(matches).to eq true
35
35
  end
36
36
 
37
37
  it "should not match text without at-rule" do
38
38
  matches = CssFontFaceRule.matches_rule?("a:link { color: #357ad1; }")
39
- expect(matches).to be_false
39
+ expect(matches).to eq false
40
40
  end
41
41
 
42
42
  it "should not match text without font-face" do
43
43
  matches = CssFontFaceRule.matches_rule?("@import url(\"import1.css\");")
44
- expect(matches).to be_false
44
+ expect(matches).to eq false
45
45
  end
46
46
  end
47
- end
47
+ end
@@ -162,17 +162,17 @@ describe CssImportRule do
162
162
  describe ".matches_rule?" do
163
163
  it "should match text starting with @import" do
164
164
  matches = CssImportRule.matches_rule?(css_text)
165
- expect(matches).to be_true
165
+ expect(matches).to eq true
166
166
  end
167
167
 
168
168
  it "should not match text without at-rule" do
169
169
  matches = CssImportRule.matches_rule?("a:link { color: #357ad1; }")
170
- expect(matches).to be_false
170
+ expect(matches).to eq false
171
171
  end
172
172
 
173
173
  it "should not match text without import" do
174
174
  matches = CssImportRule.matches_rule?("@charset \"UTF-8\";")
175
- expect(matches).to be_false
175
+ expect(matches).to eq false
176
176
  end
177
177
  end
178
- end
178
+ end
@@ -41,17 +41,17 @@ describe CssMediaRule do
41
41
  describe ".matches_rule?" do
42
42
  it "should match text starting with @media" do
43
43
  matches = CssMediaRule.matches_rule?(css_text)
44
- expect(matches).to be_true
44
+ expect(matches).to eq true
45
45
  end
46
46
 
47
47
  it "should not match text without at-rule" do
48
48
  matches = CssMediaRule.matches_rule?("a:link { color: #357ad1; }")
49
- expect(matches).to be_false
49
+ expect(matches).to eq false
50
50
  end
51
51
 
52
52
  it "should not match text without media" do
53
53
  matches = CssMediaRule.matches_rule?("@charset \"UTF-8\";")
54
- expect(matches).to be_false
54
+ expect(matches).to eq false
55
55
  end
56
56
  end
57
- end
57
+ end
@@ -42,12 +42,12 @@ describe CssStyleRule do
42
42
  describe ".matches_rule?" do
43
43
  it "should match text that doesn't begin with an at-rule" do
44
44
  matches = CssStyleRule.matches_rule?(css_text)
45
- expect(matches).to be_true
45
+ expect(matches).to eq true
46
46
  end
47
47
 
48
48
  it "should not match rules starting with at-rule" do
49
49
  matches = CssStyleRule.matches_rule?("@import url(\"import1.css\");")
50
- expect(matches).to be_false
50
+ expect(matches).to eq false
51
51
  end
52
52
  end
53
- end
53
+ end
@@ -8,10 +8,10 @@ describe CssStyleSheet do
8
8
  describe "#disabled" do
9
9
  it "shows if style sheet is disabled" do
10
10
  sheet = CssStyleSheet.new("http://example.com/css/stylesheets/screen.css")
11
- expect(sheet.disabled?).to be_false
11
+ expect(sheet.disabled?).to eq false
12
12
 
13
13
  sheet.disabled = true
14
- expect(sheet.disabled?).to be_true
14
+ expect(sheet.disabled?).to eq true
15
15
  end
16
16
  end
17
17
 
@@ -127,7 +127,18 @@ describe CssStyleSheet do
127
127
  expect(sheet.type).to eq "text/css"
128
128
  end
129
129
  end
130
-
130
+
131
+ describe "#content" do
132
+ it "doesn't fetch for empty inline styles" do
133
+ sheet = CssStyleSheet.new(content: "")
134
+
135
+ expect {
136
+ sheet.css_rules.map {|r| r.content }
137
+ }.not_to raise_error
138
+ end
139
+
140
+ end
141
+
131
142
  describe "#css_rules" do
132
143
  it "returns a list of css rules found in the style sheet" do
133
144
  sheet = CssStyleSheet.new("http://example.com/css/stylesheets/screen.css")
@@ -207,4 +218,4 @@ describe CssStyleSheet do
207
218
 
208
219
  end
209
220
  end
210
- end
221
+ end
@@ -8,18 +8,14 @@ describe Location do
8
8
  location = Location.new(url)
9
9
  expect(location.host).to eq "initvisual.com"
10
10
  end
11
-
11
+
12
12
  it "should accept relative urls" do
13
13
  location = Location.new("/some/path.html")
14
14
  expect(location.to_s).to eq "/some/path.html"
15
15
  end
16
-
17
- it "should throw error for invalid host" do
18
- expect { Location.new("http://") }.to raise_error(InvalidLocationError)
19
- end
20
16
  end
21
-
22
-
17
+
18
+
23
19
  describe "#new with parent" do
24
20
  it "should not expand a full url" do
25
21
  parent = Location.new("http://example.com/css/url.html")
@@ -31,7 +27,7 @@ describe Location do
31
27
  it "should expand a relative path into a full path given the parent" do
32
28
  parent = Location.new("http://example.com/css/relative.html")
33
29
  location = Location.new("stylesheets/screen.css", parent)
34
-
30
+
35
31
  expect(location.to_s).to eq "http://example.com/css/stylesheets/screen.css"
36
32
  end
37
33
 
@@ -40,9 +36,9 @@ describe Location do
40
36
  location = Location.new("/css/stylesheets/screen.css", parent)
41
37
 
42
38
  expect(location.to_s).to eq "http://example.com/css/stylesheets/screen.css"
43
- end
39
+ end
44
40
  end
45
-
41
+
46
42
 
47
43
  describe "#host" do
48
44
  it "should parse out the url host" do
@@ -50,27 +46,27 @@ describe Location do
50
46
  expect(location.host).to eq "initvisual.com"
51
47
  end
52
48
  end
53
-
54
- describe "#host=" do
55
- it "should assign host to url" do
49
+
50
+ describe "#host=" do
51
+ it "should assign host to url" do
56
52
  location = Location.new(url)
57
-
53
+
58
54
  location.host = "derekdevries.com"
59
55
  expect(location.host).to eq "derekdevries.com"
60
56
  end
61
57
  end
62
-
58
+
63
59
  describe "#hostname" do
64
60
  it "should parse out the url hostname" do
65
61
  location = Location.new(url)
66
62
  expect(location.hostname).to eq "initvisual.com"
67
63
  end
68
64
  end
69
-
65
+
70
66
  describe "#hostname=" do
71
67
  it "should assign hostname to url" do
72
68
  location = Location.new(url)
73
-
69
+
74
70
  location.hostname = "derekdevries.com"
75
71
  expect(location.hostname).to eq "derekdevries.com"
76
72
  end
@@ -86,14 +82,14 @@ describe Location do
86
82
  describe "#pathname=" do
87
83
  it "should assign path to url" do
88
84
  location = Location.new(url)
89
-
85
+
90
86
  location.pathname = "/work"
91
87
  expect(location.pathname).to eq "/work"
92
88
  end
93
89
 
94
90
  it "add initial forward-slash if not given" do
95
91
  location = Location.new(url)
96
-
92
+
97
93
  location.pathname = "work"
98
94
  expect(location.pathname).to eq "/work"
99
95
  end
@@ -243,18 +239,23 @@ describe Location do
243
239
  describe "#valid?" do
244
240
  it "should be true with a valid host and protocol" do
245
241
  location = Location.new("http://initvisual.com")
246
- expect(location.valid?).to be_true
242
+ expect(location.valid?).to eq true
247
243
  end
248
244
 
249
- it "should be false for an invalid host" do
245
+ it "should be false for an invalid host" do
250
246
  location = Location.new("/asdf")
251
- expect(location.valid?).to be_false
247
+ expect(location.valid?).to eq false
248
+ end
249
+
250
+ it "should be false for a missing host" do
251
+ location = Location.new("http://")
252
+ expect(location.valid?).to eq false
252
253
  end
253
254
 
254
- it "should be false for an invalid protocol" do
255
+ it "should be false for an invalid protocol" do
255
256
  location = Location.new("foo.com/asdf")
256
- expect(location.valid?).to be_false
257
+ expect(location.valid?).to eq false
257
258
  end
258
259
  end
259
260
 
260
- end
261
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stylesheet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Derek DeVries
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-23 00:00:00.000000000 Z
11
+ date: 2020-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: curb