blinkr 0.2.9 → 0.3.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.
- checksums.yaml +4 -4
- data/Gemfile +3 -0
- data/bin/blinkr +1 -0
- data/blinkr.gemspec +16 -8
- data/lib/blinkr.rb +2 -1
- data/lib/blinkr/cache.rb +5 -1
- data/lib/blinkr/config.rb +2 -1
- data/lib/blinkr/engine.rb +49 -36
- data/lib/blinkr/error.rb +30 -0
- data/lib/blinkr/extensions/a_title.rb +7 -1
- data/lib/blinkr/extensions/empty_a_href.rb +7 -1
- data/lib/blinkr/extensions/img_alt.rb +7 -1
- data/lib/blinkr/extensions/inline_css.rb +13 -2
- data/lib/blinkr/extensions/javascript.rb +5 -1
- data/lib/blinkr/extensions/links.rb +66 -22
- data/lib/blinkr/extensions/meta.rb +37 -8
- data/lib/blinkr/extensions/resources.rb +5 -1
- data/lib/blinkr/hacks.rb +20 -0
- data/lib/blinkr/http_utils.rb +10 -5
- data/lib/blinkr/manticore_wrapper.rb +59 -0
- data/lib/blinkr/phantomjs_wrapper.rb +22 -9
- data/lib/blinkr/report.html.slim +186 -210
- data/lib/blinkr/report.rb +22 -19
- data/lib/blinkr/sitemap.rb +5 -4
- data/lib/blinkr/typhoeus_wrapper.rb +19 -16
- data/lib/blinkr/version.rb +1 -1
- metadata +8 -6
- data/.gitignore +0 -18
- data/.ruby-gemset +0 -1
- data/.ruby-version +0 -1
    
        data/lib/blinkr/report.rb
    CHANGED
    
    | @@ -1,5 +1,6 @@ | |
| 1 1 | 
             
            require 'slim'
         | 
| 2 2 | 
             
            require 'ostruct'
         | 
| 3 | 
            +
            require 'blinkr/error'
         | 
| 3 4 |  | 
| 4 5 | 
             
            module Blinkr
         | 
| 5 6 | 
             
              class Report
         | 
| @@ -17,31 +18,33 @@ module Blinkr | |
| 17 18 | 
             
                end
         | 
| 18 19 |  | 
| 19 20 | 
             
                def render
         | 
| 20 | 
            -
                  @context. | 
| 21 | 
            -
                  @context. | 
| 22 | 
            -
                  @context. | 
| 23 | 
            -
                  @context. | 
| 24 | 
            -
             | 
| 21 | 
            +
                  @context.pages.delete_if { |_, page| page.errors.empty? }
         | 
| 22 | 
            +
                  @context.total = 0
         | 
| 23 | 
            +
                  @context.severity = {}
         | 
| 24 | 
            +
                  @context.category = {}
         | 
| 25 | 
            +
                  @context.type = {}
         | 
| 26 | 
            +
                  @context.pages.each do |_, page|
         | 
| 27 | 
            +
                    page.max_severity = ::Blinkr::SEVERITY.first # :success
         | 
| 25 28 | 
             
                    page.errors.each do |error|
         | 
| 26 | 
            -
                      raise "#{error.severity} not a valid severity. Must be one of #{SEVERITY.join(',')}" unless SEVERITY.include? error.severity
         | 
| 29 | 
            +
                      raise "#{error.severity} not a valid severity. Must be one of #{::Blinkr::SEVERITY.join(',')}" unless ::Blinkr::SEVERITY.include? error.severity
         | 
| 27 30 | 
             
                      raise "#{error.category} must be specified." if error.category.nil?
         | 
| 28 | 
            -
                      @context. | 
| 29 | 
            -
                      @context. | 
| 30 | 
            -
                       | 
| 31 | 
            -
                       | 
| 32 | 
            -
                      @context. | 
| 33 | 
            -
                      @context. | 
| 34 | 
            -
                      @context. | 
| 31 | 
            +
                      @context.total += 1
         | 
| 32 | 
            +
                      @context.severity[error.severity] ||= OpenStruct.new({:count => 0})
         | 
| 33 | 
            +
                      @context.severity[error.severity].count += 1
         | 
| 34 | 
            +
                      page.max_severity = error.severity if ::Blinkr::SEVERITY.index(error.severity) > ::Blinkr::SEVERITY.index(page.max_severity)
         | 
| 35 | 
            +
                      @context.category[error.category] ||= OpenStruct.new({:count => 0})
         | 
| 36 | 
            +
                      @context.category[error.category].count += 1
         | 
| 37 | 
            +
                      @context.type[error.type] ||= OpenStruct.new({:count => 0})
         | 
| 38 | 
            +
                      @context.type[error.type].count += 1
         | 
| 35 39 | 
             
                    end
         | 
| 36 40 | 
             
                  end
         | 
| 37 | 
            -
                   | 
| 38 | 
            -
             | 
| 41 | 
            +
                  File.open(@config.report, 'w') do |file|
         | 
| 42 | 
            +
                    file.write(Slim::Template.new(TMPL).render(OpenStruct.new({:blinkr => @context, :engine => @engine,
         | 
| 43 | 
            +
                                                                               :errors => @context.to_json})))
         | 
| 44 | 
            +
                  end
         | 
| 45 | 
            +
                  
         | 
| 39 46 | 
             
                  puts "Wrote report to #{@config.report}" if @config.verbose
         | 
| 40 47 | 
             
                end
         | 
| 41 48 |  | 
| 42 | 
            -
                private 
         | 
| 43 | 
            -
                
         | 
| 44 | 
            -
                SEVERITY = ['success', 'info', 'warning', 'danger']
         | 
| 45 | 
            -
             | 
| 46 49 | 
             
              end
         | 
| 47 50 | 
             
            end
         | 
    
        data/lib/blinkr/sitemap.rb
    CHANGED
    
    | @@ -1,16 +1,17 @@ | |
| 1 | 
            +
            require 'open-uri'
         | 
| 1 2 | 
             
            module Blinkr
         | 
| 2 3 | 
             
              module Sitemap
         | 
| 3 4 |  | 
| 4 5 | 
             
                def sitemap_locations
         | 
| 5 | 
            -
                   | 
| 6 | 
            +
                  open_sitemap.css('loc').collect { |loc| loc.content }
         | 
| 6 7 | 
             
                end
         | 
| 7 8 |  | 
| 8 9 | 
             
                private
         | 
| 9 | 
            -
             | 
| 10 | 
            -
                def  | 
| 10 | 
            +
             | 
| 11 | 
            +
                def open_sitemap
         | 
| 11 12 | 
             
                  puts "Loading sitemap from #{@config.sitemap}"
         | 
| 12 13 | 
             
                  if @config.sitemap =~ URI::regexp
         | 
| 13 | 
            -
                    Nokogiri::XML( | 
| 14 | 
            +
                    Nokogiri::XML(open(@config.sitemap).read)
         | 
| 14 15 | 
             
                  else
         | 
| 15 16 | 
             
                    Nokogiri::XML(File.open(@config.sitemap))
         | 
| 16 17 | 
             
                  end
         | 
| @@ -1,6 +1,3 @@ | |
| 1 | 
            -
            require 'typhoeus/request'
         | 
| 2 | 
            -
            require 'typhoeus/response'
         | 
| 3 | 
            -
            require 'typhoeus/hydra'
         | 
| 4 1 | 
             
            require 'typhoeus'
         | 
| 5 2 | 
             
            require 'blinkr/cache'
         | 
| 6 3 | 
             
            require 'blinkr/http_utils'
         | 
| @@ -11,24 +8,30 @@ module Blinkr | |
| 11 8 |  | 
| 12 9 | 
             
                attr_reader :count, :hydra
         | 
| 13 10 |  | 
| 14 | 
            -
                def initialize | 
| 11 | 
            +
                def initialize(config, context)
         | 
| 15 12 | 
             
                  @config = config.validate
         | 
| 16 | 
            -
                   | 
| 13 | 
            +
                  # Configure Typhoeus a bit
         | 
| 14 | 
            +
                  Typhoeus::Config.verbose = true if config.vverbose
         | 
| 15 | 
            +
                  Typhoeus::Config.cache = Blinkr::Cache.new
         | 
| 16 | 
            +
                  @hydra = Typhoeus::Hydra.new(:maxconnects => (@config.maxconnects || 30),
         | 
| 17 | 
            +
                                               :max_total_connections => (@config.maxconnects || 30),
         | 
| 18 | 
            +
                                               :max_concurrency => (@config.maxconnects || 30))
         | 
| 17 19 | 
             
                  @count = 0
         | 
| 18 20 | 
             
                  @context = context
         | 
| 19 21 | 
             
                end
         | 
| 20 22 |  | 
| 21 | 
            -
                def process_all | 
| 23 | 
            +
                def process_all(urls, limit, opts = {}, &block)
         | 
| 22 24 | 
             
                  urls.each do |url|
         | 
| 23 | 
            -
                    process url, limit, &block
         | 
| 25 | 
            +
                    process url, limit, opts, &block
         | 
| 24 26 | 
             
                  end
         | 
| 27 | 
            +
                  @hydra.run
         | 
| 25 28 | 
             
                end
         | 
| 26 29 |  | 
| 27 | 
            -
                def process | 
| 28 | 
            -
                  _process url, limit, limit, &block
         | 
| 30 | 
            +
                def process(url, limit, opts = {}, &block)
         | 
| 31 | 
            +
                  _process url, limit, limit, opts, &block
         | 
| 29 32 | 
             
                end
         | 
| 30 33 |  | 
| 31 | 
            -
                def debug | 
| 34 | 
            +
                def debug(url)
         | 
| 32 35 | 
             
                  process(url, @config.max_retrys) do |resp|
         | 
| 33 36 | 
             
                    puts "\n++++++++++"
         | 
| 34 37 | 
             
                    puts "+ Blinkr +"
         | 
| @@ -65,21 +68,21 @@ module Blinkr | |
| 65 68 |  | 
| 66 69 | 
             
                private
         | 
| 67 70 |  | 
| 68 | 
            -
                def _process | 
| 71 | 
            +
                def _process(url, limit, max, opts = {}, &block)
         | 
| 69 72 | 
             
                  unless @config.skipped? url
         | 
| 70 73 | 
             
                    req = Typhoeus::Request.new(
         | 
| 71 | 
            -
             | 
| 72 | 
            -
             | 
| 73 | 
            -
                      verbose: @config.vverbose
         | 
| 74 | 
            +
                        url,
         | 
| 75 | 
            +
                        opts.merge(:followlocation => true)
         | 
| 74 76 | 
             
                    )
         | 
| 75 77 | 
             
                    req.on_complete do |resp|
         | 
| 76 78 | 
             
                      if retry? resp
         | 
| 77 | 
            -
                        if limit > 1 | 
| 79 | 
            +
                        if limit > 1
         | 
| 78 80 | 
             
                          puts "Loading #{url} via typhoeus (attempt #{max - limit + 2} of #{max})" if @config.verbose
         | 
| 79 81 | 
             
                          _process(url, limit - 1, max, &Proc.new)
         | 
| 80 82 | 
             
                        else
         | 
| 81 83 | 
             
                          puts "Loading #{url} via typhoeus failed" if @config.verbose
         | 
| 82 | 
            -
                          response = Typhoeus::Response.new(code | 
| 84 | 
            +
                          response = Typhoeus::Response.new(:code => 0, :status_message => "Server timed out after #{max} retries",
         | 
| 85 | 
            +
                                                            :mock => true)
         | 
| 83 86 | 
             
                          response.request = Typhoeus::Request.new(url)
         | 
| 84 87 | 
             
                          Typhoeus.stub(url).and_return(response)
         | 
| 85 88 | 
             
                          block.call response, nil, nil
         | 
    
        data/lib/blinkr/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,15 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: blinkr
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.3.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Pete Muir
         | 
| 8 | 
            +
            - Jason Porter
         | 
| 8 9 | 
             
            autorequire: 
         | 
| 9 10 | 
             
            bindir: bin
         | 
| 10 11 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2015- | 
| 12 | 
            +
            date: 2015-07-06 00:00:00.000000000 Z
         | 
| 12 13 | 
             
            dependencies:
         | 
| 13 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 15 | 
             
              name: bundler
         | 
| @@ -99,14 +100,12 @@ description: A broken page and link checker for websites. Optionally uses phanto | |
| 99 100 | 
             
              page load errors.
         | 
| 100 101 | 
             
            email:
         | 
| 101 102 | 
             
            - pmuir@bleepbleep.org.uk
         | 
| 103 | 
            +
            - lightguard.jp@gmail.com
         | 
| 102 104 | 
             
            executables:
         | 
| 103 105 | 
             
            - blinkr
         | 
| 104 106 | 
             
            extensions: []
         | 
| 105 107 | 
             
            extra_rdoc_files: []
         | 
| 106 108 | 
             
            files:
         | 
| 107 | 
            -
            - ".gitignore"
         | 
| 108 | 
            -
            - ".ruby-gemset"
         | 
| 109 | 
            -
            - ".ruby-version"
         | 
| 110 109 | 
             
            - Gemfile
         | 
| 111 110 | 
             
            - LICENSE.txt
         | 
| 112 111 | 
             
            - README.md
         | 
| @@ -117,6 +116,7 @@ files: | |
| 117 116 | 
             
            - lib/blinkr/cache.rb
         | 
| 118 117 | 
             
            - lib/blinkr/config.rb
         | 
| 119 118 | 
             
            - lib/blinkr/engine.rb
         | 
| 119 | 
            +
            - lib/blinkr/error.rb
         | 
| 120 120 | 
             
            - lib/blinkr/extensions/a_title.rb
         | 
| 121 121 | 
             
            - lib/blinkr/extensions/empty_a_href.rb
         | 
| 122 122 | 
             
            - lib/blinkr/extensions/img_alt.rb
         | 
| @@ -127,7 +127,9 @@ files: | |
| 127 127 | 
             
            - lib/blinkr/extensions/meta.rb
         | 
| 128 128 | 
             
            - lib/blinkr/extensions/pipeline.rb
         | 
| 129 129 | 
             
            - lib/blinkr/extensions/resources.rb
         | 
| 130 | 
            +
            - lib/blinkr/hacks.rb
         | 
| 130 131 | 
             
            - lib/blinkr/http_utils.rb
         | 
| 132 | 
            +
            - lib/blinkr/manticore_wrapper.rb
         | 
| 131 133 | 
             
            - lib/blinkr/phantomjs_wrapper.rb
         | 
| 132 134 | 
             
            - lib/blinkr/report.html.slim
         | 
| 133 135 | 
             
            - lib/blinkr/report.rb
         | 
| @@ -147,7 +149,7 @@ required_ruby_version: !ruby/object:Gem::Requirement | |
| 147 149 | 
             
              requirements:
         | 
| 148 150 | 
             
              - - "~>"
         | 
| 149 151 | 
             
                - !ruby/object:Gem::Version
         | 
| 150 | 
            -
                  version: ' | 
| 152 | 
            +
                  version: '1.9'
         | 
| 151 153 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 152 154 | 
             
              requirements:
         | 
| 153 155 | 
             
              - - ">="
         | 
    
        data/.gitignore
    DELETED
    
    
    
        data/.ruby-gemset
    DELETED
    
    | @@ -1 +0,0 @@ | |
| 1 | 
            -
            blink
         | 
    
        data/.ruby-version
    DELETED
    
    | @@ -1 +0,0 @@ | |
| 1 | 
            -
            ruby-2.1.2
         |