sqt 1.1.0 → 1.2.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.
Files changed (3) hide show
  1. data/bin/sqt +6 -1
  2. data/lib/sqt.rb +35 -5
  3. metadata +2 -2
data/bin/sqt CHANGED
@@ -34,6 +34,10 @@ OptionParser.new do |opts|
34
34
  options[:url] = u || ""
35
35
  end
36
36
 
37
+ opts.on("-d", "--depth DEPTH", "Curl depth") do |d|
38
+ options[:depth] = d.to_i if not d.nil?
39
+ end
40
+
37
41
  opts.on("-w", "--write [FILENAME]", "Écrit les résultats dans un fichier.") do |w|
38
42
  options[:fileName] = w || "Sarbotte Quality.txt"
39
43
  end
@@ -52,11 +56,12 @@ elsif options[:file]
52
56
  filesProperties.push SQT.sarbotteFile(options[:file])
53
57
  # Si une url est donnée en option
54
58
  elsif options[:url]
55
- filesProperties.push SQT.sarbotteCurl(options[:url])
59
+ filesProperties.push SQT.sarbotteCurl(options[:url], options[:depth])
56
60
  end
57
61
 
58
62
  # Si on a pu calculer le sqi d'un ou plusieurs fichiers
59
63
  unless filesProperties.empty?
64
+ filesProperties.flatten!
60
65
  filesProperties.sort_by! { |a| a[:sqi] }
61
66
  SQT.sarbottePrint(filesProperties, options)
62
67
  SQT.sarbotteWrite(filesProperties, options) if options[:fileName]
data/lib/sqt.rb CHANGED
@@ -35,6 +35,31 @@ module SQT
35
35
  (1 - jsAndCss.to_f/total.to_f) * 100
36
36
  end
37
37
 
38
+ # Curl with depth
39
+ def self.sarbotteCurlWithDepth(url, depth, result)
40
+ http = Curl.get(url)
41
+ file = http.body_str
42
+ xmlFile = Nokogiri::HTML(file)
43
+ if depth > 0
44
+ xmlFile.search('//a').each do |foundLink|
45
+ if foundLink['href'] =~ /^\//
46
+ toVisit = url + foundLink['href']
47
+ else
48
+ toVisit = foundLink['href']
49
+ end
50
+ if !(toVisit =~ /^http:\/\//).nil? && !result.any? {|sqr| sqr[:uri] == toVisit || sqr[:uri] == toVisit + '/' || sqr[:uri] + '/' == toVisit }
51
+ d = sarbotteCurlWithDepth(toVisit, depth - 1, result)
52
+ result = d if !d.nil?
53
+ end
54
+ end
55
+ end
56
+ if !(result.any? {|sqr| sqr[:uri] == url || sqr[:uri] == url + '/' || sqr[:uri] + '/' == url })
57
+ puts url
58
+ result.push Sqt.buildResult(url, file)
59
+ end
60
+ end
61
+
62
+
38
63
  end
39
64
 
40
65
  def self.sarbottePath(path, extension)
@@ -50,16 +75,21 @@ module SQT
50
75
  Sqt.buildResult("", string)
51
76
  end
52
77
 
53
- def self.sarbotteCurl(url)
78
+ def self.sarbotteCurl(url, depth)
54
79
  require 'curb'
55
- http = Curl.get(url)
56
- file = http.body_str
57
- Sqt.buildResult(url, file)
80
+ result = []
81
+ if depth.nil?
82
+ http = Curl.get(url)
83
+ file = http.body_str
84
+ result = Sqt.buildResult(url, file)
85
+ else
86
+ result = Sqt.sarbotteCurlWithDepth(url, depth, [])
87
+ end
88
+ return result
58
89
  end
59
90
 
60
91
  # Affiche en console les résultats
61
92
  def self.sarbottePrint(filesProperties, options)
62
- system("cls")
63
93
  puts "\nSarbotte Quality Tool\n".colorize( :cyan )
64
94
  if options[:path] then
65
95
  puts "Chemin : " + options[:path] + "\n\n"
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.1.0
4
+ version: 1.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -84,7 +84,7 @@ extra_rdoc_files: []
84
84
  files:
85
85
  - lib/sqt.rb
86
86
  - bin/sqt
87
- homepage: https://github.com/SarbotteDesigns/sqt
87
+ homepage: http://www.sarbotte-designs.com/sqt
88
88
  licenses: []
89
89
  post_install_message:
90
90
  rdoc_options: []