sqt 1.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/sqt +64 -74
- data/lib/sqt.rb +103 -81
- metadata +42 -11
data/bin/sqt
CHANGED
@@ -1,74 +1,64 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
opts.
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
end
|
66
|
-
|
67
|
-
# Si on a pu calculer le sqi d'un ou plusieurs fichiers
|
68
|
-
unless filesProperties.empty?
|
69
|
-
filesProperties.sort_by! { |a| a[:sqi]}
|
70
|
-
printResults(filesProperties, options)
|
71
|
-
if options[:fileName]
|
72
|
-
writeResults(filesProperties, options)
|
73
|
-
end
|
74
|
-
end
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
# Sarbotte Quality Tool v1.0
|
5
|
+
# Copyright Sarbotte Designs
|
6
|
+
# Open Sarbotte License
|
7
|
+
|
8
|
+
require 'sqt'
|
9
|
+
|
10
|
+
options = {}
|
11
|
+
filesProperties = []
|
12
|
+
|
13
|
+
# Montre le messge d'aide si aucun argument n'est passé
|
14
|
+
ARGV.push "-h" if ARGV.empty?
|
15
|
+
|
16
|
+
# Définition des options du script
|
17
|
+
OptionParser.new do |opts|
|
18
|
+
opts.banner = "Sarbotte Quality Tool"
|
19
|
+
opts.separator "Utilisation : rb [options]"
|
20
|
+
|
21
|
+
opts.on("-f", "--file FILE", "Fichier à sarbottiser.") do |f|
|
22
|
+
options[:file] = f || ""
|
23
|
+
end
|
24
|
+
|
25
|
+
opts.on("-p", "--path [PATH]", "Répertoire à sarbottiser.") do |p|
|
26
|
+
options[:path] = p || "."
|
27
|
+
end
|
28
|
+
|
29
|
+
opts.on("-e", "--extension [EXTENSION]", "Extension recherchée.") do |e|
|
30
|
+
options[:extension] = e || ""
|
31
|
+
end
|
32
|
+
|
33
|
+
opts.on("-c", "--curl [URL]", "Curl.") do |u|
|
34
|
+
options[:url] = u || ""
|
35
|
+
end
|
36
|
+
|
37
|
+
opts.on("-w", "--write [FILENAME]", "Écrit les résultats dans un fichier.") do |w|
|
38
|
+
options[:fileName] = w || "Sarbotte Quality.txt"
|
39
|
+
end
|
40
|
+
|
41
|
+
opts.on("-h", "--help", "Affiche l'aide.") do
|
42
|
+
puts opts
|
43
|
+
exit
|
44
|
+
end
|
45
|
+
end.parse!
|
46
|
+
|
47
|
+
# Si le chemin d'un répertoire est donné en option
|
48
|
+
if options[:path]
|
49
|
+
filesProperties = SQT.sarbottePath(options[:path], options[:extension])
|
50
|
+
# Si le chemin vers un fichier est donné en option
|
51
|
+
elsif options[:file]
|
52
|
+
filesProperties.push SQT.sarbotteFile(options[:file])
|
53
|
+
# Si une url est donnée en option
|
54
|
+
elsif options[:url]
|
55
|
+
filesProperties.push SQT.sarbotteCurl(options[:url])
|
56
|
+
end
|
57
|
+
|
58
|
+
# Si on a pu calculer le sqi d'un ou plusieurs fichiers
|
59
|
+
unless filesProperties.empty?
|
60
|
+
filesProperties.sort_by! { |a| a[:sqi] }
|
61
|
+
SQT.sarbottePrint(filesProperties, options)
|
62
|
+
SQT.sarbotteWrite(filesProperties, options) if options[:fileName]
|
63
|
+
end
|
64
|
+
|
data/lib/sqt.rb
CHANGED
@@ -1,81 +1,103 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
# Sarbotte Quality Tool v1.0
|
4
|
-
# Sarbotte Designs
|
5
|
-
# Open Sarbotte License
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
require '
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
end
|
25
|
-
|
26
|
-
#
|
27
|
-
def
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
end
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
end
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
end
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
end
|
80
|
-
|
81
|
-
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
# Sarbotte Quality Tool v1.0
|
4
|
+
# Copyright Sarbotte Designs
|
5
|
+
# Open Sarbotte License
|
6
|
+
|
7
|
+
module SQT
|
8
|
+
|
9
|
+
require 'optparse'
|
10
|
+
require 'nokogiri'
|
11
|
+
|
12
|
+
require 'colorize'
|
13
|
+
|
14
|
+
class Sqt
|
15
|
+
|
16
|
+
# Construit l'objet qui sera affiché, en fonction de son uri et de son contenu
|
17
|
+
def self.buildResult(uri, file)
|
18
|
+
fileProperties = {}
|
19
|
+
fileProperties[:uri] = uri
|
20
|
+
fileProperties[:totalLength] = file.bytesize
|
21
|
+
fileProperties[:jsAndCssLength] = getJsAndCssLength file
|
22
|
+
fileProperties[:sqi] = sarbotteQuality(fileProperties[:jsAndCssLength], fileProperties[:totalLength])
|
23
|
+
fileProperties
|
24
|
+
end
|
25
|
+
|
26
|
+
# Récupère le nombre de caractères dans les balises script et style d'un fichier
|
27
|
+
def self.getJsAndCssLength(file)
|
28
|
+
xmlFile = Nokogiri::HTML(file)
|
29
|
+
jsLength = xmlFile.search('//script').reduce(0) { |total, script| total + script.text.bytesize }
|
30
|
+
xmlFile.search('//style').reduce(jsLength) { |total, style| total + style.text.bytesize }
|
31
|
+
end
|
32
|
+
|
33
|
+
# Définit le Sarbotte Quality Index d'un fichier
|
34
|
+
def self.sarbotteQuality(jsAndCss, total)
|
35
|
+
(1 - jsAndCss.to_f/total.to_f) * 100
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.sarbottePath(path, extension)
|
41
|
+
path.gsub!('\\', File::SEPARATOR)
|
42
|
+
Dir["#{path}/**/*\.#{extension}"].map{ |p| Sqt.buildResult(p, File.read(p))}
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.sarbotteFile(file)
|
46
|
+
Sqt.buildResult(file, File.read(file))
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.sarbotteString(string)
|
50
|
+
Sqt.buildResult("", string)
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.sarbotteCurl(url)
|
54
|
+
require 'curb'
|
55
|
+
http = Curl.get(url)
|
56
|
+
file = http.body_str
|
57
|
+
Sqt.buildResult(url, file)
|
58
|
+
end
|
59
|
+
|
60
|
+
# Affiche en console les résultats
|
61
|
+
def self.sarbottePrint(filesProperties, options)
|
62
|
+
system("cls")
|
63
|
+
puts "\nSarbotte Quality Tool\n".colorize( :cyan )
|
64
|
+
if options[:path] then
|
65
|
+
puts "Chemin : " + options[:path] + "\n\n"
|
66
|
+
end
|
67
|
+
if filesProperties.size > 1 then
|
68
|
+
average = filesProperties.reduce(0) { |total, fP| total + fP[:sqi] }.to_f / filesProperties.size
|
69
|
+
print "Moyenne : "
|
70
|
+
puts "#{'%.2f' % average}".colorize( average < 0.5 ? :red : average < 0.8 ? :yellow : :green )
|
71
|
+
puts ""
|
72
|
+
end
|
73
|
+
puts "Fichiers : "
|
74
|
+
filesProperties.each do |fP|
|
75
|
+
sqi = fP[:sqi]
|
76
|
+
print " #{fP[:uri].gsub(options[:path] && options[:path] != "." ? options[:path] : "", "")} : "
|
77
|
+
print "#{'%.2f' % fP[:sqi]}".colorize( sqi < 50 ? :red : sqi < 80 ? :yellow : :green )
|
78
|
+
puts " (#{fP[:jsAndCssLength]}/#{fP[:totalLength]})"
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# Écrit dans un fichier les résultats
|
83
|
+
def self.sarbotteWrite(filesProperties, options)
|
84
|
+
result = "Sarbotte Quality Tool\n\n"
|
85
|
+
if options[:path] then
|
86
|
+
result += "Chemin : " + options[:path] + "\n\n"
|
87
|
+
end
|
88
|
+
if filesProperties.size > 1 then
|
89
|
+
average = filesProperties.reduce(0) { |total, fP| total + fP[:sqi] }.to_f / filesProperties.size
|
90
|
+
result += "Moyenne : "
|
91
|
+
result += "#{'%.2f' % average}\n\n"
|
92
|
+
end
|
93
|
+
result += "Fichiers : \n"
|
94
|
+
filesProperties.each do |fP|
|
95
|
+
sqi = fP[:sqi]
|
96
|
+
result += " #{fP[:uri].gsub(options[:path] && options[:path] != "." ? options[:path] : "", "")} : "
|
97
|
+
result += "#{'%.2f' % fP[:sqi]}"
|
98
|
+
result += "(#{fP[:jsAndCssLength]}/#{fP[:totalLength]})\n"
|
99
|
+
end
|
100
|
+
File.open(options[:fileName], 'w') {|f| f.write(result) }
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sqt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-01-22 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,15 @@ dependencies:
|
|
21
21
|
version: 1.5.6
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.5.6
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: colorize
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ~>
|
@@ -32,18 +37,44 @@ dependencies:
|
|
32
37
|
version: 0.5.8
|
33
38
|
type: :runtime
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
36
|
-
- !ruby/object:Gem::Dependency
|
37
|
-
name: win32console
|
38
|
-
requirement: &21882216 !ruby/object:Gem::Requirement
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
41
|
none: false
|
40
42
|
requirements:
|
41
43
|
- - ~>
|
42
44
|
- !ruby/object:Gem::Version
|
43
|
-
version:
|
45
|
+
version: 0.5.8
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: curb
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
44
54
|
type: :runtime
|
45
55
|
prerelease: false
|
46
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rake
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
47
78
|
description: Client side quality validator
|
48
79
|
email: n.barbotte@gmail.com
|
49
80
|
executables:
|
@@ -73,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
73
104
|
version: '0'
|
74
105
|
requirements: []
|
75
106
|
rubyforge_project:
|
76
|
-
rubygems_version: 1.8.
|
107
|
+
rubygems_version: 1.8.23
|
77
108
|
signing_key:
|
78
109
|
specification_version: 3
|
79
110
|
summary: Sarbotte Quality Tool
|