page_weight 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +28 -0
- data/README +3 -0
- data/Rakefile +51 -0
- data/lib/page_weight.rb +10 -0
- data/lib/page_weight/html_document.rb +8 -0
- data/lib/page_weight/http.rb +7 -0
- data/lib/page_weight/page_weight.rb +64 -0
- data/lib/page_weight/parser.rb +65 -0
- data/lib/page_weight/reporter.rb +54 -0
- data/lib/page_weight/url.rb +21 -0
- metadata +90 -0
data/LICENSE
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
Copyright (c) 2011, Adebola Oke
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
6
|
+
|
7
|
+
1. Redistributions of source code must retain the above copyright notice,
|
8
|
+
this list of conditions and the following disclaimer.
|
9
|
+
|
10
|
+
2. Redistributions in binary form must reproduce the above copyright
|
11
|
+
notice, this list of conditions and the following disclaimer in the
|
12
|
+
documentation and/or other materials provided with the distribution.
|
13
|
+
|
14
|
+
3. Neither the name Adebola Oke nor the names of contributors to
|
15
|
+
this software may be used to endorse or promote products derived from this
|
16
|
+
software without specific prior written permission.
|
17
|
+
|
18
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
|
19
|
+
IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
20
|
+
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
21
|
+
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
|
22
|
+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
23
|
+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
24
|
+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
25
|
+
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
26
|
+
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
27
|
+
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
28
|
+
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'rake/clean'
|
4
|
+
require 'rubygems/package_task'
|
5
|
+
require 'rdoc/task'
|
6
|
+
require 'rake/testtask'
|
7
|
+
require 'rspec/core/rake_task'
|
8
|
+
require 'cucumber'
|
9
|
+
require 'cucumber/rake/task'
|
10
|
+
|
11
|
+
spec = Gem::Specification.new do |s|
|
12
|
+
s.name = 'page_weight'
|
13
|
+
s.version = '0.0.1'
|
14
|
+
s.has_rdoc = true
|
15
|
+
s.extra_rdoc_files = ['README', 'LICENSE']
|
16
|
+
s.summary = 'Get HTTP PageWeight in Ruby'
|
17
|
+
s.description = s.summary
|
18
|
+
s.author = 'Adebola Oke'
|
19
|
+
s.email = 'adesmail.100@gmail.com'
|
20
|
+
s.files = %w(LICENSE README Rakefile) + Dir.glob("{bin,lib}/**/*")
|
21
|
+
s.require_path = "lib"
|
22
|
+
s.bindir = "bin"
|
23
|
+
s.add_dependency('nokogiri')
|
24
|
+
end
|
25
|
+
|
26
|
+
Gem::PackageTask.new(spec) do |p|
|
27
|
+
p.gem_spec = spec
|
28
|
+
p.need_tar = true
|
29
|
+
p.need_zip = true
|
30
|
+
end
|
31
|
+
|
32
|
+
Rake::RDocTask.new do |rdoc|
|
33
|
+
files =['README', 'LICENSE', 'lib/**/*.rb']
|
34
|
+
rdoc.rdoc_files.add(files)
|
35
|
+
rdoc.main = "README" # page to start on
|
36
|
+
rdoc.title = "page_weight Docs"
|
37
|
+
rdoc.rdoc_dir = 'doc/rdoc' # rdoc output folder
|
38
|
+
rdoc.options << '--line-numbers'
|
39
|
+
end
|
40
|
+
|
41
|
+
RSpec::Core::RakeTask.new do |t|
|
42
|
+
t.ruby_opts = "-I lib"
|
43
|
+
end
|
44
|
+
|
45
|
+
Cucumber::Rake::Task.new do |t|
|
46
|
+
t.cucumber_opts = "--format pretty -q"
|
47
|
+
end
|
48
|
+
|
49
|
+
task :push => :gem do |t|
|
50
|
+
sh "gem push pkg/#{spec.name}-#{spec.version}.gem"
|
51
|
+
end
|
data/lib/page_weight.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
module PageWeight
|
2
|
+
class PageWeight
|
3
|
+
attr_accessor :base_url
|
4
|
+
def self.report_for(input)
|
5
|
+
@base_url = URL.builder(input)
|
6
|
+
Reporter.full_report_for(@base_url)
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.of_html_for(input)
|
10
|
+
@base_url = URL.builder(input)
|
11
|
+
Reporter.body_content_length_for(@base_url)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.of_images_for(input)
|
15
|
+
@base_url = URL.builder(input)
|
16
|
+
Reporter.images_content_length_for(@base_url)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.number_of_images_for(input)
|
20
|
+
@base_url = URL.builder(input)
|
21
|
+
Reporter.image_count_for(@base_url)
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.number_of_flash_objects_for(input)
|
25
|
+
@base_url = URL.builder(input)
|
26
|
+
Reporter.flash_count_for(@base_url)
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.of_flash_for(input)
|
30
|
+
@base_url = URL.builder(input)
|
31
|
+
Reporter.flash_content_length_for(@base_url)
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.of_css_for(input)
|
35
|
+
@base_url = URL.builder(input)
|
36
|
+
Reporter.css_content_length_for(@base_url)
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.css_files_count_for(input)
|
40
|
+
@base_url = URL.builder(input)
|
41
|
+
Reporter.css_count_for(@base_url)
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.of_javascript_for(input)
|
45
|
+
@base_url = URL.builder(input)
|
46
|
+
Reporter.javascript_content_length_for(@base_url)
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.javascript_files_count_for(input)
|
50
|
+
@base_url = URL.builder(input)
|
51
|
+
Reporter.javascript_count_for(@base_url)
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.url
|
55
|
+
@base_url
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def self.url=(input)
|
61
|
+
@base_url = input
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module PageWeight
|
2
|
+
class Parser
|
3
|
+
def self.html_body_content_for(input)
|
4
|
+
HTTP.response_for(input).body
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.images_body_content_for(input)
|
8
|
+
images_body = []
|
9
|
+
images = images_in(input)
|
10
|
+
images_body = body_content_for(images)
|
11
|
+
images_body.inject(:+)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.images_in(input)
|
15
|
+
files_for_url_with_xpath(input, "//img/@src")
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.flash_objects_in(input)
|
19
|
+
files_for_url_with_xpath(input, "//embed[contains(@type, 'flash')]/@src")
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.css_files_in(input)
|
23
|
+
files_for_url_with_xpath(input, "//link[@type='text/css']/@href")
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.javascript_files_in(input)
|
27
|
+
files_for_url_with_xpath(input, "//script[@type='text/javascript']/@src")
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.flash_objects_body_content_for(input)
|
31
|
+
flash_body = []
|
32
|
+
flash_files = flash_objects_in(input)
|
33
|
+
flash_body = body_content_for(flash_files)
|
34
|
+
flash_body.inject(:+)
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.css_files_body_content_for(input)
|
38
|
+
css_body = []
|
39
|
+
css_files = css_files_in(input)
|
40
|
+
css_body = body_content_for(css_files)
|
41
|
+
css_body.inject(:+)
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.javascript_content_length_for(input)
|
45
|
+
javascript_body = []
|
46
|
+
javascript_files = javascript_files_in(input)
|
47
|
+
javascript_body = body_content_for(javascript_files)
|
48
|
+
javascript_body.inject(:+)
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.body_content_for(file_type)
|
52
|
+
file_type.collect do |path|
|
53
|
+
path.to_s.downcase.start_with?("http://", "https://") ? file_path = path : file_path = "#{PageWeight.url}#{path}"
|
54
|
+
HTTP.response_for(URL.builder(file_path)).body
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def self.files_for_url_with_xpath(input, xpath)
|
61
|
+
doc = HTMLDocument.creator_for(input)
|
62
|
+
doc.xpath(xpath)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module PageWeight
|
2
|
+
class Reporter
|
3
|
+
def self.body_content_length_for(input)
|
4
|
+
full_report_for(input)[:html]
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.images_content_length_for(input)
|
8
|
+
full_report_for(input)[:images]
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.image_count_for(input)
|
12
|
+
full_report_for(input)[:number_of_images_files]
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.flash_content_length_for(input)
|
16
|
+
full_report_for(input)[:flash]
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.flash_count_for(input)
|
20
|
+
full_report_for(input)[:number_of_flash_files]
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.css_content_length_for(input)
|
24
|
+
full_report_for(input)[:css]
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.css_count_for(input)
|
28
|
+
full_report_for(input)[:number_of_css_files]
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.javascript_content_length_for(input)
|
32
|
+
full_report_for(input)[:javascript]
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.javascript_count_for(input)
|
36
|
+
full_report_for(input)[:number_of_javascript_files]
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.full_report_for(input)
|
40
|
+
result = {}
|
41
|
+
result[:html] = Parser.html_body_content_for(input).size
|
42
|
+
result[:css] = Parser.css_files_body_content_for(input).size
|
43
|
+
result[:number_of_css_files] = Parser.css_files_in(input).size
|
44
|
+
result[:javascript] = Parser.javascript_content_length_for(input).size
|
45
|
+
result[:number_of_javascript_files] = Parser.javascript_files_in(input).size
|
46
|
+
result[:images] = Parser.images_body_content_for(input).size
|
47
|
+
result[:number_of_images_files] = Parser.images_in(input).size
|
48
|
+
result[:flash] = Parser.flash_objects_body_content_for(input).size
|
49
|
+
result[:number_of_flash_files] = Parser.flash_objects_in(input).size
|
50
|
+
result[:total_weight] = result.values.compact.inject(:+)
|
51
|
+
result
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module PageWeight
|
2
|
+
class URL
|
3
|
+
def self.builder(input)
|
4
|
+
url_input = parse(input)
|
5
|
+
url = ""
|
6
|
+
url << url_input.scheme if !url_input.scheme.nil?
|
7
|
+
url << "://"
|
8
|
+
url << url_input.userinfo if !url_input.userinfo.nil?
|
9
|
+
url << url_input.host if !url_input.host.nil?
|
10
|
+
url << ":" << url_input.port.to_s if !url_input.port.nil?
|
11
|
+
url << url_input.path if !url_input.path.nil?
|
12
|
+
url << "?#{url_input.query}" if !url_input.query.nil?
|
13
|
+
url << "/" if !url.strip.end_with?("/") && url_input.path.size <= 1
|
14
|
+
parse(url)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.parse(input)
|
18
|
+
URI.parse(input)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: page_weight
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Adebola Oke
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-08-30 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: nokogiri
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
description: Get HTTP PageWeight in Ruby
|
36
|
+
email: adesmail.100@gmail.com
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- README
|
43
|
+
- LICENSE
|
44
|
+
files:
|
45
|
+
- LICENSE
|
46
|
+
- README
|
47
|
+
- Rakefile
|
48
|
+
- lib/page_weight/html_document.rb
|
49
|
+
- lib/page_weight/http.rb
|
50
|
+
- lib/page_weight/page_weight.rb
|
51
|
+
- lib/page_weight/parser.rb
|
52
|
+
- lib/page_weight/reporter.rb
|
53
|
+
- lib/page_weight/url.rb
|
54
|
+
- lib/page_weight.rb
|
55
|
+
has_rdoc: true
|
56
|
+
homepage:
|
57
|
+
licenses: []
|
58
|
+
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
hash: 3
|
70
|
+
segments:
|
71
|
+
- 0
|
72
|
+
version: "0"
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
hash: 3
|
79
|
+
segments:
|
80
|
+
- 0
|
81
|
+
version: "0"
|
82
|
+
requirements: []
|
83
|
+
|
84
|
+
rubyforge_project:
|
85
|
+
rubygems_version: 1.5.2
|
86
|
+
signing_key:
|
87
|
+
specification_version: 3
|
88
|
+
summary: Get HTTP PageWeight in Ruby
|
89
|
+
test_files: []
|
90
|
+
|