lint_search 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fcbcdbde064e95acad037b44eaec0eef298d2be4
4
+ data.tar.gz: 6461ff7b45244a76821bc2b12e7a2e11892b2d95
5
+ SHA512:
6
+ metadata.gz: c88fe9748c5b59a3d7c88d6d3407a7fbcd6ccd2641188f33c396dbed8900501817d25978ad46585059f92205dab495ae9ffd113002aa34395e0dd613fa581b7f
7
+ data.tar.gz: e84030d65a984c9ca01e274664a9db08935706796e11330275e47ba53b7a6f11935d08b1d52f26a89c77ab324a439779dc5a6a94273142a658d0f824a294a8d9
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.2
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in lint_search.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,73 @@
1
+ # LintSearch
2
+
3
+ LintSearch is a ruby console application for searching for a keyword and linting the HTML of the first result.
4
+
5
+
6
+ ## Installation
7
+
8
+ `gem install lint_search`
9
+
10
+ ## Usage
11
+
12
+ For full information:
13
+
14
+ `lint_search help`
15
+
16
+ If no alternatives are provided, LintSearch will perform the search using Google and the linting using the W3C validator.
17
+
18
+ To search for a keyword using only default settings run:
19
+
20
+ `lint_search search [KEYWORD]`
21
+
22
+ For example, `lint_search search banana` will output:
23
+
24
+ ```
25
+ Searching for banana...
26
+ Complete!
27
+ Lint results of https://en.wikipedia.org/wiki/Banana via https://validator.w3.org
28
+ (0)
29
+ Info: The Content-Type was text/html. Using the HTML parser.
30
+ ---
31
+
32
+ (1)
33
+ Info: Using the schema for HTML with SVG 1.1, MathML 3.0, RDFa 1.1, and ITS 2.0 support.
34
+ ---
35
+
36
+ (2)
37
+ Warning: A table row was 2 columns wide, which is less than the column count established by the first row (3).From line 1128, column 22; to line 1129, column 5="2"></td>↩</tr>↩<tr>↩
38
+ ---
39
+
40
+ (3)
41
+ Warning: A table row was 2 columns wide, which is less than the column count established by the first row (3).From line 1187, column 22; to line 1188, column 5="2"></td>↩</tr>↩<tr>↩
42
+ ---
43
+
44
+ (4)
45
+ Warning: Potentially bad value zh-min-nan for attribute lang on element a: The grandfathered language tag zh-min-nan is deprecated. Use nan instead.From line 1680, column 1670; to line 1680, column 1797-min-nan"><a href="//zh-min-nan.wikipedia.org/wiki/Kin-chio" title="Kin-chio – Chinese (Min Nan)" lang="zh-min-nan" hreflang="zh-min-nan">Bân-lâSyntax of language tag:An RFC 5646 language tag consists of hyphen-separated ASCII-alphanumeric subtags. There is a primary tag identifying a natural language by its shortest ISO 639 language code (e.g. en for English) and zero or more additional subtags adding precision. The most common additional subtag type is a region subtag which most commonly is a two-letter ISO 3166 country code (e.g. GB for the United Kingdom). IANA maintains a registry of permissible subtags.
46
+ ---
47
+
48
+ (5)
49
+ Warning: Potentially bad value zh-min-nan for attribute hreflang on element a: The grandfathered language tag zh-min-nan is deprecated. Use nan instead.From line 1680, column 1670; to line 1680, column 1797-min-nan"><a href="//zh-min-nan.wikipedia.org/wiki/Kin-chio" title="Kin-chio – Chinese (Min Nan)" lang="zh-min-nan" hreflang="zh-min-nan">Bân-lâSyntax of language tag:An RFC 5646 language tag consists of hyphen-separated ASCII-alphanumeric subtags. There is a primary tag identifying a natural language by its shortest ISO 639 language code (e.g. en for English) and zero or more additional subtags adding precision. The most common additional subtag type is a region subtag which most commonly is a two-letter ISO 3166 country code (e.g. GB for the United Kingdom). IANA maintains a registry of permissible subtags.
50
+ ---
51
+
52
+ (6)
53
+ Warning: Potentially bad value zh-yue for attribute lang on element a: The language tag zh-yue is deprecated. Use yue instead.From line 1680, column 21690; to line 1680, column 21801i-zh-yue"><a href="//zh-yue.wikipedia.org/wiki/%E9%A6%99%E8%95%89" title="香蕉 – Cantonese" lang="zh-yue" hreflang="zh-yue">粵語</a>Syntax of language tag:An RFC 5646 language tag consists of hyphen-separated ASCII-alphanumeric subtags. There is a primary tag identifying a natural language by its shortest ISO 639 language code (e.g. en for English) and zero or more additional subtags adding precision. The most common additional subtag type is a region subtag which most commonly is a two-letter ISO 3166 country code (e.g. GB for the United Kingdom). IANA maintains a registry of permissible subtags.
54
+ ---
55
+
56
+ (7)
57
+ Warning: Potentially bad value zh-yue for attribute hreflang on element a: The language tag zh-yue is deprecated. Use yue instead.From line 1680, column 21690; to line 1680, column 21801i-zh-yue"><a href="//zh-yue.wikipedia.org/wiki/%E9%A6%99%E8%95%89" title="香蕉 – Cantonese" lang="zh-yue" hreflang="zh-yue">粵語</a>Syntax of language tag:An RFC 5646 language tag consists of hyphen-separated ASCII-alphanumeric subtags. There is a primary tag identifying a natural language by its shortest ISO 639 language code (e.g. en for English) and zero or more additional subtags adding precision. The most common additional subtag type is a region subtag which most commonly is a two-letter ISO 3166 country code (e.g. GB for the United Kingdom). IANA maintains a registry of permissible subtags.
58
+ ---
59
+ ```
60
+
61
+
62
+
63
+
64
+ ## Development
65
+
66
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
67
+
68
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
69
+
70
+ ## Contributing
71
+
72
+ Bug reports and pull requests are welcome on GitHub at https://github.com/OkayDave/lint_search.
73
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "lint_search"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/lint_search ADDED
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'thor'
5
+ require 'lint_search'
6
+
7
+ module LintSearch
8
+ class CLI < Thor
9
+ include Thor::Actions
10
+ default_task :help
11
+
12
+
13
+ desc "search", "Search for a keyword and lint the first result"
14
+ method_option :query_url, aliases: "-q", desc: "Search query url", default: "http://www.google.co.uk/"
15
+ method_option :query_css_selector, aliases: "-c", desc: "Search result CSS selector", default: "h3.r a"
16
+ method_option :linter_url, aliases: "-l", desc: "Linter url", default: "https://validator.w3.org"
17
+ method_option :linter_css_selector, aliases: "-r", desc: "Linter CSS Selector", default: "li.info"
18
+ def search(keyword)
19
+ puts "Searching for #{keyword}..."
20
+ search_result = LintSearch::Search.new({
21
+ keyword: keyword,
22
+ query_url: options[:query_url],
23
+ css_selector: options[:query_css_selector]
24
+ }).search
25
+
26
+ puts "Linting #{search_result.url}..."
27
+ lint_result = LintSearch::Lint.new({
28
+ search_result: search_result,
29
+ linter_url: options[:linter_url],
30
+ css_selector: options[:linter_css_selector]
31
+ }).lint
32
+
33
+ puts "Complete!"
34
+ puts "Lint results of #{search_result.url} via #{options[:linter_url]}"
35
+ lint_result.each_with_index do |result, index|
36
+ puts "(#{index})"
37
+ puts result
38
+ puts "---"
39
+ puts ""
40
+ end
41
+
42
+
43
+ end
44
+
45
+ end
46
+
47
+ end
48
+
49
+
50
+ LintSearch::CLI.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,40 @@
1
+ require 'rubygems'
2
+ require 'mechanize'
3
+
4
+ module LintSearch
5
+ class Lint
6
+
7
+ attr_reader :search_result, :linter_url, :css_selector
8
+
9
+ def initialize(options)
10
+ @search_result = options[:search_result]
11
+ @linter_url = options[:linter_url]
12
+ @css_selector = options[:css_selector]
13
+
14
+ raise Exception.new("Lint: search_result is required") if @search_result.nil?
15
+ raise Exception.new("Lint: search_result must be a LintSearch::SearchResult") unless @search_result.is_a?(LintSearch::SearchResult)
16
+ raise Exception.new("Lint: linter_url is required") if @linter_url.nil?
17
+ raise Exception.new("Lint: css_selector is required") if @css_selector.nil?
18
+ end
19
+
20
+ def lint
21
+ robot = Mechanize.new
22
+ robot.user_agent_alias = 'Linux Firefox'
23
+
24
+ robot.get(@linter_url) do |page|
25
+ form = page.forms.first
26
+ form.texts.first.value = @search_result.url
27
+ results_page = form.submit
28
+
29
+ lint_results = []
30
+ results_page.search(@css_selector).each do |item|
31
+ lint_results << item.text
32
+ end
33
+
34
+ return lint_results
35
+ end
36
+ end
37
+ end
38
+
39
+
40
+ end
@@ -0,0 +1,45 @@
1
+ require 'rubygems'
2
+ require 'mechanize'
3
+
4
+ module LintSearch
5
+ class Search
6
+ attr_reader :query_url, :css_selector, :keyword
7
+
8
+ def initialize(options={})
9
+ @query_url = options[:query_url]
10
+ @css_selector = options[:css_selector]
11
+ @keyword = options[:keyword]
12
+
13
+ raise Exception.new("Keyword required") if @keyword.nil?
14
+ raise Exception.new("CSS Selector required") if @css_selector.nil?
15
+ raise Exception.new("Query url required") if @query_url.nil?
16
+ end
17
+
18
+ def search
19
+ robot = Mechanize.new
20
+ robot.user_agent_alias = 'Linux Firefox'
21
+
22
+ robot.get(@query_url) do |page|
23
+
24
+ # Fill out the search form
25
+ form = page.forms.first
26
+ form.texts.first.value = @keyword
27
+
28
+ # Nice opportunity to use the "I'm feeling lucky!" button for google,
29
+ # though as this app aims to be search agnostic it's not a good fit
30
+ # for other providers
31
+ search_result = form.click_button(form.buttons.first)
32
+ first_result = robot.click(search_result.search(@css_selector).first)
33
+
34
+
35
+ # create a SearchResult object
36
+ return LintSearch::SearchResult.new(url: first_result.uri.to_s, title: first_result.title)
37
+ end
38
+ end
39
+
40
+ def query
41
+ "#{@query_url}#{@keyword}"
42
+ end
43
+
44
+ end
45
+ end
@@ -0,0 +1,15 @@
1
+ module LintSearch
2
+ class SearchResult
3
+ attr_reader :url, :title
4
+ attr_writer :url, :title
5
+
6
+ def initialize(url: nil, title: nil)
7
+ @url = url
8
+ @title = title
9
+
10
+ raise Exception.new("SearchResult: URL is required") if @url.nil?
11
+ raise Exception.new("SearchResult: title is required") if @title.nil?
12
+ end
13
+ end
14
+
15
+ end
@@ -0,0 +1,3 @@
1
+ module LintSearch
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,7 @@
1
+ require 'lint_search/version'
2
+ require 'lint_search/search'
3
+ require 'lint_search/search_result'
4
+ require 'lint_search/lint'
5
+
6
+ module LintSearch
7
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'lint_search/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "lint_search"
8
+ spec.version = LintSearch::VERSION
9
+ spec.authors = ["Dave Russell"]
10
+ spec.email = ["dave.kerr@gmail.com"]
11
+
12
+ spec.summary = %q{LintSearch is a an application which searchs for a keyword and then liunts the first results}
13
+ spec.homepage = "http://github.com/OkayDave/lint_search"
14
+
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.10"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec"
24
+
25
+
26
+ spec.add_runtime_dependency "thor", "~> 0.19"
27
+ spec.add_runtime_dependency "mechanize", "~> 2.7"
28
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lint_search
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dave Russell
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-08-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: thor
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.19'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.19'
69
+ - !ruby/object:Gem::Dependency
70
+ name: mechanize
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.7'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.7'
83
+ description:
84
+ email:
85
+ - dave.kerr@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - README.md
95
+ - Rakefile
96
+ - bin/console
97
+ - bin/lint_search
98
+ - bin/setup
99
+ - lib/lint_search.rb
100
+ - lib/lint_search/lint.rb
101
+ - lib/lint_search/search.rb
102
+ - lib/lint_search/search_result.rb
103
+ - lib/lint_search/version.rb
104
+ - lint_search.gemspec
105
+ homepage: http://github.com/OkayDave/lint_search
106
+ licenses: []
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.2.2
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: LintSearch is a an application which searchs for a keyword and then liunts
128
+ the first results
129
+ test_files: []
130
+ has_rdoc: