remote_css 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/CHANGELOG.md +9 -0
- data/lib/remote_css/client.rb +32 -7
- data/lib/remote_css/version.rb +1 -1
- data/lib/remote_css.rb +1 -1
- data/remote_css.gemspec +1 -0
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 78aef9720435bb2986191a1067213c3c89cd85c3
|
4
|
+
data.tar.gz: 13cdb7c78dd5c7a1f5e9e354b06c2305742b7e22
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c540cec4b3381b87801144638bf20d7bd0b3e442d3e2b431640e2614b3c547d4d66e108d19c1f734fe8507ddd40a6f583ac852810446306ae2c6e6ea8cb01e93
|
7
|
+
data.tar.gz: 56babd5e5025062d21eaaf9ab341161c9fb66c1f9ec9e253fcaaacd180bc2cbdbcd4254f7666bbdd5b97a21310a30a3cfa418491c0b9e19f2e393a0614034988
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ruby-2.4.
|
1
|
+
ruby-2.4.1
|
data/CHANGELOG.md
ADDED
data/lib/remote_css/client.rb
CHANGED
@@ -4,21 +4,46 @@ module RemoteCss
|
|
4
4
|
|
5
5
|
attr_accessor :url
|
6
6
|
|
7
|
-
def initialize(options)
|
7
|
+
def initialize(options={})
|
8
8
|
validate_options!(options)
|
9
|
-
@
|
9
|
+
@options = options
|
10
|
+
@options[:minify] = true unless @options.has_key?(:minify)
|
11
|
+
@options[:verbose] = false unless @options.has_key?(:verbose)
|
10
12
|
end
|
11
13
|
|
12
14
|
def css
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
[
|
15
|
+
verbose("Reading HTML")
|
16
|
+
doc = Nokogiri::HTML(@options[:body] || open(@options[:url]))
|
17
|
+
verbose("Reading inline styles")
|
18
|
+
styles = []
|
19
|
+
inline_styles = doc.css("style").map{|s| styles << {:source => :inline, :style => s.text.strip} }
|
20
|
+
threads = []
|
21
|
+
remote_styles = doc.css("link[rel='stylesheet'][href]").each do |c|
|
22
|
+
verbose("Loading #{c.attr("href")}")
|
23
|
+
threads << Thread.new do
|
24
|
+
styles << {:source => URI.join(@options[:url], c.attr("href")), :style => open(URI.join(@options[:url], c.attr("href"))).read.strip}
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
threads.each { |thr| thr.join }
|
29
|
+
|
30
|
+
style = styles.map{|s| "/* #{s[:source]} */\n\n#{s[:style]}" }.join("\n\n")
|
31
|
+
|
32
|
+
if @options[:minify]
|
33
|
+
CSSminify.compress(style)
|
34
|
+
else
|
35
|
+
style
|
36
|
+
end
|
37
|
+
|
17
38
|
end
|
18
39
|
|
19
40
|
private
|
20
41
|
def validate_options!(options)
|
21
|
-
raise ":url is required" unless options.has_key?(:url)
|
42
|
+
raise ":url or :body is required" unless options.has_key?(:url) || options.has_key?(:body)
|
43
|
+
end
|
44
|
+
|
45
|
+
def verbose(text)
|
46
|
+
puts text if @options[:verbose]
|
22
47
|
end
|
23
48
|
end
|
24
49
|
end
|
data/lib/remote_css/version.rb
CHANGED
data/lib/remote_css.rb
CHANGED
data/remote_css.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: remote_css
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stewart McKee
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-07-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: cssminify
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
description: Obtains and collates css from another url
|
70
84
|
email:
|
71
85
|
- stewart@theizone.co.uk
|
@@ -78,6 +92,7 @@ files:
|
|
78
92
|
- ".ruby-gemset"
|
79
93
|
- ".ruby-version"
|
80
94
|
- ".travis.yml"
|
95
|
+
- CHANGELOG.md
|
81
96
|
- CODE_OF_CONDUCT.md
|
82
97
|
- Gemfile
|
83
98
|
- LICENSE.txt
|
@@ -109,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
124
|
version: '0'
|
110
125
|
requirements: []
|
111
126
|
rubyforge_project:
|
112
|
-
rubygems_version: 2.6.
|
127
|
+
rubygems_version: 2.6.12
|
113
128
|
signing_key:
|
114
129
|
specification_version: 4
|
115
130
|
summary: Obtains and collates css from another url
|