rack-pagespeed 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.1
1
+ 1.0.2
@@ -1,3 +1,5 @@
1
+ require 'uri'
2
+
1
3
  module Rack::PageSpeed::Filters
2
4
  class Base
3
5
  attr_reader :document, :options
@@ -44,7 +46,7 @@ module Rack::PageSpeed::Filters
44
46
 
45
47
  private
46
48
  def file_for node
47
- path = ::File.join options[:public], case node.name
49
+ path = case node.name
48
50
  when 'script'
49
51
  node['src']
50
52
  when 'img'
@@ -52,6 +54,8 @@ module Rack::PageSpeed::Filters
52
54
  when 'link'
53
55
  node['href']
54
56
  end
57
+ return false unless path
58
+ path = ::File.join(options[:public], URI.parse(path).path)
55
59
  ::File.open path if ::File.exists? path
56
60
  end
57
61
  end
@@ -9,7 +9,7 @@ class Rack::PageSpeed::Filters::CombineCSS < Rack::PageSpeed::Filter
9
9
  priority 9
10
10
 
11
11
  def execute! document
12
- nodes = document.css('link[rel="stylesheet"][href$=".css"]:not([href^="http"])')
12
+ nodes = document.css('link[rel="stylesheet"][href]')
13
13
  return false unless nodes.count > 0
14
14
  groups = group_siblings topmost_of_sequence(nodes)
15
15
  groups.each do |group|
@@ -32,7 +32,7 @@ class Rack::PageSpeed::Filters::CombineCSS < Rack::PageSpeed::Filter
32
32
  end
33
33
 
34
34
  def local_css? node
35
- node.name == 'link' && !(node['href'] =~ /^http/ or !(node['href'] =~ /.css$/))
35
+ node.name == 'link' and file_for(node)
36
36
  end
37
37
 
38
38
  def topmost_of_sequence nodes
@@ -10,7 +10,7 @@ class Rack::PageSpeed::Filters::CombineJavaScripts < Rack::PageSpeed::Filter
10
10
  priority 2
11
11
 
12
12
  def execute! document
13
- nodes = document.css('script[src$=".js"]:not([src^="http"])')
13
+ nodes = document.css('script[src]')
14
14
  return false unless nodes.count > 0
15
15
  groups = group_siblings topmost_of_sequence(nodes)
16
16
  groups.each do |group|
@@ -36,7 +36,7 @@ class Rack::PageSpeed::Filters::CombineJavaScripts < Rack::PageSpeed::Filter
36
36
  end
37
37
 
38
38
  def local_script? node
39
- node.name == 'script' && !(node['src'] =~ /^http/ or !(node['src'] =~ /.js$/))
39
+ node.name == 'script' and file_for(node)
40
40
  end
41
41
 
42
42
  def topmost_of_sequence nodes
@@ -44,7 +44,7 @@ class Rack::PageSpeed::Filters::CombineJavaScripts < Rack::PageSpeed::Filter
44
44
  nodes.each do |node|
45
45
  _previous, _next = node.previous_sibling, node.next_sibling
46
46
  if _previous && local_script?(_previous) &&
47
- (!_next || !local_script?(_next))
47
+ (!_next || !file_for(_next))
48
48
  result << node
49
49
  end
50
50
  end
@@ -2,11 +2,11 @@ class Rack::PageSpeed::Filters::InlineCSS < Rack::PageSpeed::Filter
2
2
  priority 10
3
3
 
4
4
  def execute! document
5
- nodes = document.css('link[rel="stylesheet"][href$=".css"]:not([href^="http"])')
5
+ nodes = document.css('link[rel="stylesheet"][href]')
6
6
  return false unless nodes.count > 0
7
7
  nodes.each do |node|
8
8
  file = file_for node
9
- next if file.stat.size > (@options[:max_size] or 2048)
9
+ next if !file or file.stat.size > (@options[:max_size] or 2048)
10
10
  inline = Nokogiri::XML::Node.new 'style', document
11
11
  inline.content = file.read
12
12
  node.before inline
@@ -3,11 +3,11 @@ class Rack::PageSpeed::Filters::InlineJavaScripts < Rack::PageSpeed::Filter
3
3
  priority 10
4
4
 
5
5
  def execute! document
6
- nodes = document.css('script[src$=".js"]:not([src^="http"])')
6
+ nodes = document.css('script[src]')
7
7
  return false unless nodes.count > 0
8
8
  nodes.each do |node|
9
9
  file = file_for node
10
- next if file.stat.size > (@options[:max_size] or 2048)
10
+ next if !file or file.stat.size > (@options[:max_size] or 2048)
11
11
  inline = Nokogiri::XML::Node.new 'script', document
12
12
  inline.content = file.read
13
13
  node.before inline
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rack-pagespeed}
8
- s.version = "1.0.1"
8
+ s.version = "1.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Julio Cesar Ody"]
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 0
8
- - 1
9
- version: 1.0.1
8
+ - 2
9
+ version: 1.0.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Julio Cesar Ody