roadie 3.0.1 → 3.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -1
- data/Changelog.md +9 -1
- data/README.md +2 -1
- data/lib/roadie/errors.rb +0 -5
- data/lib/roadie/style_property.rb +0 -38
- data/lib/roadie/stylesheet.rb +17 -11
- data/lib/roadie/url_generator.rb +3 -1
- data/lib/roadie/version.rb +1 -1
- data/spec/lib/roadie/style_property_spec.rb +0 -33
- data/spec/lib/roadie/stylesheet_spec.rb +14 -0
- data/spec/lib/roadie/url_generator_spec.rb +8 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd4e9bce46c7a228c3bf830fa355cece328f7f20
|
4
|
+
data.tar.gz: 702ae383ac06b11cec36e355d396bc099862fd37
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b4d2d872d94aacd77c4625b37e8459b1bef7bc931f8487207d52c22529ec9a16160d53f5c3822abc39edd694f42f41a58bcb114e33eb351931dfa8c178f61c9
|
7
|
+
data.tar.gz: 55001582e4b9f3e673ca2418fae5e0a18cbac73bb9ed5b9bbda849f3df8c717e2f33069b90275a876eb91949058e40c16acdd35f7cbd5de753ba3c3377ef5df8
|
data/.travis.yml
CHANGED
data/Changelog.md
CHANGED
@@ -1,11 +1,19 @@
|
|
1
1
|
### dev
|
2
2
|
|
3
|
-
[full changelog](https://github.com/Mange/roadie/compare/v3.0.
|
3
|
+
[full changelog](https://github.com/Mange/roadie/compare/v3.0.2...master)
|
4
4
|
|
5
5
|
* Nothing yet.
|
6
6
|
|
7
7
|
### 3.0.1
|
8
8
|
|
9
|
+
[full changelog](https://github.com/Mange/roadie/compare/v3.0.1...v3.0.2)
|
10
|
+
|
11
|
+
* Bug fixes:
|
12
|
+
* Some `data:` URLs could cause exceptions. (#97)
|
13
|
+
* Correctly parse properties with semicolons in their values - [Aidan Feldman (afeld)](https://github.com/afeld) (#100)
|
14
|
+
|
15
|
+
### 3.0.1
|
16
|
+
|
9
17
|
[full changelog](https://github.com/Mange/roadie/compare/v3.0.0...v3.0.1)
|
10
18
|
|
11
19
|
* Enhancements:
|
data/README.md
CHANGED
data/lib/roadie/errors.rb
CHANGED
@@ -6,11 +6,6 @@ module Roadie
|
|
6
6
|
# it as a bug.
|
7
7
|
class Error < RuntimeError; end
|
8
8
|
|
9
|
-
# Raised when a declaration which cannot be parsed is encountered.
|
10
|
-
#
|
11
|
-
# A declaration is something like "font-size: 12pt;".
|
12
|
-
class UnparseableDeclaration < Error; end
|
13
|
-
|
14
9
|
# Raised when Roadie encounters an invalid URL which cannot be parsed by
|
15
10
|
# Ruby's +URI+ class.
|
16
11
|
#
|
@@ -14,17 +14,6 @@ module Roadie
|
|
14
14
|
# @todo Rename #property to #name
|
15
15
|
attr_reader :property
|
16
16
|
|
17
|
-
# Parse a property string.
|
18
|
-
#
|
19
|
-
# @example
|
20
|
-
# property = Roadie::StyleProperty.parse("color: green")
|
21
|
-
# property.property # => "color"
|
22
|
-
# property.value # => "green"
|
23
|
-
# property.important? # => false
|
24
|
-
def self.parse(declaration, specificity)
|
25
|
-
allocate.send :read_declaration!, declaration, specificity
|
26
|
-
end
|
27
|
-
|
28
17
|
def initialize(property, value, important, specificity)
|
29
18
|
@property = property
|
30
19
|
@value = value
|
@@ -54,34 +43,7 @@ module Roadie
|
|
54
43
|
"#{to_s} (#{specificity})"
|
55
44
|
end
|
56
45
|
|
57
|
-
protected
|
58
|
-
def read_declaration!(declaration, specificity)
|
59
|
-
if (matches = DECLARATION_MATCHER.match(declaration))
|
60
|
-
initialize matches[:property], matches[:value].strip, !!matches[:important], specificity
|
61
|
-
self
|
62
|
-
else
|
63
|
-
raise UnparseableDeclaration, "Cannot parse declaration #{declaration.inspect}"
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
46
|
private
|
68
|
-
DECLARATION_MATCHER = %r{
|
69
|
-
\A\s*
|
70
|
-
(?:
|
71
|
-
# !important declaration
|
72
|
-
(?<property>[^:]+):\s?
|
73
|
-
(?<value>.*?)
|
74
|
-
(?<important>\s!important)
|
75
|
-
;?
|
76
|
-
|
|
77
|
-
# normal declaration
|
78
|
-
(?<property>[^:]+):\s?
|
79
|
-
(?<value>[^;]+)
|
80
|
-
;?
|
81
|
-
)
|
82
|
-
\s*\Z
|
83
|
-
}x.freeze
|
84
|
-
|
85
47
|
def value_with_important
|
86
48
|
if important
|
87
49
|
"#{value} !important"
|
data/lib/roadie/stylesheet.rb
CHANGED
@@ -39,17 +39,27 @@ module Roadie
|
|
39
39
|
|
40
40
|
def parse_blocks(css)
|
41
41
|
blocks = []
|
42
|
-
setup_parser(css)
|
43
|
-
|
42
|
+
parser = setup_parser(css)
|
43
|
+
|
44
|
+
parser.each_rule_set do |rule_set, media_types|
|
45
|
+
rule_set.selectors.each do |selector_string|
|
46
|
+
blocks << create_style_block(selector_string, rule_set)
|
47
|
+
end
|
44
48
|
end
|
49
|
+
|
45
50
|
blocks
|
46
51
|
end
|
47
52
|
|
48
|
-
def create_style_block(selector_string,
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
+
def create_style_block(selector_string, rule_set)
|
54
|
+
specificity = CssParser.calculate_specificity(selector_string)
|
55
|
+
selector = Selector.new(selector_string, specificity)
|
56
|
+
properties = []
|
57
|
+
|
58
|
+
rule_set.each_declaration do |prop, val, important|
|
59
|
+
properties << StyleProperty.new(prop, val, important, specificity)
|
60
|
+
end
|
61
|
+
|
62
|
+
StyleBlock.new(selector, properties)
|
53
63
|
end
|
54
64
|
|
55
65
|
def setup_parser(css)
|
@@ -57,9 +67,5 @@ module Roadie
|
|
57
67
|
parser.add_block! css
|
58
68
|
parser
|
59
69
|
end
|
60
|
-
|
61
|
-
def parse_declarations(declarations, specificity)
|
62
|
-
declarations.split(';').map { |declaration| StyleProperty.parse(declaration, specificity) }
|
63
|
-
end
|
64
70
|
end
|
65
71
|
end
|
data/lib/roadie/url_generator.rb
CHANGED
@@ -107,7 +107,9 @@ module Roadie
|
|
107
107
|
def path_is_absolute?(path)
|
108
108
|
# Ruby's URI is pretty unforgiving, but roadie aims to be. Don't involve
|
109
109
|
# URI for URLs that's easy to determine to be absolute.
|
110
|
-
|
110
|
+
# URLs starting with a scheme (http:, data:) are absolute, as is URLs
|
111
|
+
# start start with double slashes (//css/app.css).
|
112
|
+
path =~ %r{^(\w+:|//)} || !parse_path(path).relative?
|
111
113
|
end
|
112
114
|
|
113
115
|
def parse_path(path)
|
data/lib/roadie/version.rb
CHANGED
@@ -45,38 +45,5 @@ module Roadie
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
48
|
-
|
49
|
-
describe "parsing" do
|
50
|
-
def parsing(declaration, specificity)
|
51
|
-
property = StyleProperty.parse(declaration, specificity)
|
52
|
-
[property.property, property.value, property.important?, property.specificity]
|
53
|
-
end
|
54
|
-
|
55
|
-
it "understands simple declarations" do
|
56
|
-
expect(parsing("color: green", 1)).to eq(["color", "green", false, 1])
|
57
|
-
expect(parsing(" color:green; ", 1)).to eq(["color", "green", false, 1])
|
58
|
-
expect(parsing("color: green ", 1)).to eq(["color", "green", false, 1])
|
59
|
-
expect(parsing("color: green ; ", 1)).to eq(["color", "green", false, 1])
|
60
|
-
end
|
61
|
-
|
62
|
-
it "understands more complex values" do
|
63
|
-
expect(parsing("padding:0 1px 5rem 9%;", 89)).to eq(["padding", "0 1px 5rem 9%", false, 89])
|
64
|
-
end
|
65
|
-
|
66
|
-
it "understands more complex names" do
|
67
|
-
expect(parsing("font-size: 50%", 10)).to eq(["font-size", "50%", false, 10])
|
68
|
-
end
|
69
|
-
|
70
|
-
it "correctly reads !important declarations" do
|
71
|
-
expect(parsing("color: green !important", 1)).to eq(["color", "green", true, 1])
|
72
|
-
expect(parsing("color: green !important;", 1)).to eq(["color", "green", true, 1])
|
73
|
-
end
|
74
|
-
|
75
|
-
it "raises an error on unparseable declarations" do
|
76
|
-
expect {
|
77
|
-
parsing("I want a red apple!", 1)
|
78
|
-
}.to raise_error(Roadie::UnparseableDeclaration, /red apple/)
|
79
|
-
end
|
80
|
-
end
|
81
48
|
end
|
82
49
|
end
|
@@ -37,5 +37,19 @@ module Roadie
|
|
37
37
|
stylesheet = Stylesheet.new("example.css", "body { color: green;}a{ color: red; font-size: small }")
|
38
38
|
expect(stylesheet.to_s).to eq("body{color:green}\na{color:red;font-size:small}")
|
39
39
|
end
|
40
|
+
|
41
|
+
it "understands data URIs" do
|
42
|
+
# http://css-tricks.com/data-uris/
|
43
|
+
stylesheet = Stylesheet.new("foo.css", <<-CSS)
|
44
|
+
h1 {
|
45
|
+
background-image: url(data:image/gif;base64,R0lGODl)
|
46
|
+
}
|
47
|
+
CSS
|
48
|
+
|
49
|
+
expect(stylesheet).to have(1).blocks
|
50
|
+
expect(stylesheet.blocks.map(&:to_s)).to eq([
|
51
|
+
"h1{background-image:url(data:image/gif;base64,R0lGODl)}"
|
52
|
+
])
|
53
|
+
end
|
40
54
|
end
|
41
55
|
end
|
@@ -82,7 +82,14 @@ module Roadie
|
|
82
82
|
end
|
83
83
|
|
84
84
|
it "does not touch data: URIs" do
|
85
|
-
|
85
|
+
# We've had failures with longer data URIs, but I have not been able to
|
86
|
+
# pinpoint where the problem is. I suspect a specific version of Ruby.
|
87
|
+
# This test might not actually catch the real issues since I couldn't
|
88
|
+
# get it red for the reported cases.
|
89
|
+
# It was solved by being more relaxed when determining if a URI is
|
90
|
+
# absolute or not.
|
91
|
+
data_uri = "data:image/png;dead/beef+/=="
|
92
|
+
expect(url(data_uri, host: "example.com")).to eq(data_uri)
|
86
93
|
end
|
87
94
|
|
88
95
|
it "does not touch absolute URLs without schemes" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: roadie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Magnus Bergmark
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|