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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c7d4783e68649ff499540f26ced8049280505bf6
4
- data.tar.gz: fa2c849405776d53b07e622a0b6c46cb4e63ee9d
3
+ metadata.gz: 78aef9720435bb2986191a1067213c3c89cd85c3
4
+ data.tar.gz: 13cdb7c78dd5c7a1f5e9e354b06c2305742b7e22
5
5
  SHA512:
6
- metadata.gz: 4363a7c0d8f148861f7f15a7f0a57dc57a79619727befac189623c3624dae0148e398d50285a7e61a930d70fa4f10921ff6ba0d1fb6a573138f1713b70bf7cc3
7
- data.tar.gz: 3d8f2df2314297e6c1d5749a7cd5498cef7371bd598cd84a8f0b5d6921487e3e78240ce162f33929f22e5f6e34a08906566841b4fb35c80d70fbe3ad3f2397df
6
+ metadata.gz: c540cec4b3381b87801144638bf20d7bd0b3e442d3e2b431640e2614b3c547d4d66e108d19c1f734fe8507ddd40a6f583ac852810446306ae2c6e6ea8cb01e93
7
+ data.tar.gz: 56babd5e5025062d21eaaf9ab341161c9fb66c1f9ec9e253fcaaacd180bc2cbdbcd4254f7666bbdd5b97a21310a30a3cfa418491c0b9e19f2e393a0614034988
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- ruby-2.4.0
1
+ ruby-2.4.1
data/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ ## [0.2.2] - 2017-07-31
2
+ ### Added
3
+ - minfiication of css
4
+ - ability to specify body of html to parse
5
+ - multithreaded loading of external urls
6
+
7
+ ## 0.1.0 - ?
8
+ ### Added
9
+ - Start of all things
@@ -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
- @url = options[:url]
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
- doc = Nokogiri::HTML(open(@url))
14
- inline_styles = doc.css("style").map{|s| s.text }
15
- remote_styles = doc.css("link[rel='stylesheet'][href]").map{|c| open(URI.join(@url, c.attr("href"))).read }
16
- [inline_styles, remote_styles].join("\n")
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
@@ -1,3 +1,3 @@
1
1
  module RemoteCss
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/remote_css.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require "remote_css/version"
2
2
  require "remote_css/client"
3
3
  require 'nokogiri'
4
-
4
+ require 'cssminify'
5
5
  module RemoteCss
6
6
 
7
7
  end
data/remote_css.gemspec CHANGED
@@ -25,4 +25,5 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency "rake", "~> 10.0"
26
26
  spec.add_development_dependency "rspec", "~> 3.0"
27
27
  spec.add_dependency "nokogiri"
28
+ spec.add_dependency "cssminify"
28
29
  end
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.1.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-04-28 00:00:00.000000000 Z
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.8
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