nunchaku 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 85e68ba556c156c4f52a40427ea5e7003946ed4b
4
+ data.tar.gz: dd044567c165768235b66ff5617f86966ad338e5
5
+ SHA512:
6
+ metadata.gz: e7a7029ce24f2dbf674adcc793adbe4e68fce786720f3e9cbb3f65d4266fae81b09145c4edf986e0af224f47661a7d3570b1a78a8067b5c65d48f14f47cad49d
7
+ data.tar.gz: 522ed0a7b1cddad886c57b342e4018305d7ff113a5a8b33444ee6053f27aedbf5ecfa07244a4a2183961a8fb1062c2c73c6dc185c4e20f76d09ef6459a8ed869
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in nunchaku.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Jaime Iniesta
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,88 @@
1
+ # Nunchaku
2
+
3
+ Nunchaku is a Ruby client for the [Nu HTML Checker](https://github.com/validator/validator). It lets you easily check HTML markup of web pages, by querying a remote instance of the checker.
4
+
5
+ ![Nunchaku image](https://dl.dropboxusercontent.com/u/2268180/nunchaku/Nunchaku.png "Nunchaku image taken from http://commons.wikimedia.org/wiki/File:Nunchaku.png")
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'nunchaku'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install nunchaku
22
+
23
+ ## Usage
24
+
25
+ To check HTML on a web page, just pass it the URL to check, like this:
26
+
27
+ ```ruby
28
+ checker = Nunchaku.check('http://example.com')
29
+ ```
30
+
31
+ Then, you can check the JSON response like this:
32
+
33
+ ```ruby
34
+ checker.raw # {
35
+ # "url": "http://validationhell.com",
36
+ # "messages": [{
37
+ # "type": "error",
38
+ # "lastLine": 73,
39
+ # "lastColumn": 67,
40
+ # "firstColumn": 64,
41
+ # "message": "Stray end tag “a”.",
42
+ # "extract": "idates</a></a></li>\n",
43
+ # "hiliteStart": 10,
44
+ # "hiliteLength": 4
45
+ # }, (...)
46
+
47
+ ```
48
+
49
+ Every message returned will also be accessible in a more friendly way like this:
50
+
51
+ ```ruby
52
+ msg = checker.messages.first
53
+
54
+ msg.type # "error"
55
+ msg.last_line # 73
56
+ msg.first_column # 64
57
+ msg.last_column # 67
58
+ msg.message # "Stray end tag “a”."
59
+ msg.extract # "idates</a></a></li>\n"
60
+ msg.hilite_start # 10
61
+ msg.hilite_length # 4
62
+ ```
63
+
64
+ The `messages` array contains all messages returned by the checker, but you'll typically be more interested in `errors` (that contains all messages of type "error") and `warnings` (that contains all messages of subtype "warning").
65
+
66
+ ## Using an alternate server
67
+
68
+ By default, Nunchaku will query the Nu HTML Checker at https://html5.validator.nu, but you're encouraged to install your own instance and use it instead. You can follow the [Nu installation instructions](https://github.com/validator/validator) and then specify the alternate server like this:
69
+
70
+ ```ruby
71
+ checker = Nunchaku.check('http://example.com', checker_uri: 'http://mychecker.example.com')
72
+ ```
73
+
74
+ ## Development
75
+
76
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
77
+
78
+ To install this gem onto your local machine, run `bundle exec rake install`.
79
+
80
+ To run the specs, run `bundle exec rake`.
81
+
82
+ ## Contributing
83
+
84
+ 1. Fork it ( https://github.com/sitevalidator/nunchaku/fork )
85
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
86
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
87
+ 4. Push to the branch (`git push origin my-new-feature`)
88
+ 5. Create a new Pull Request
@@ -0,0 +1,7 @@
1
+ require 'bundler'
2
+ require 'rspec/core/rake_task'
3
+
4
+ Bundler::GemHelper.install_tasks
5
+ RSpec::Core::RakeTask.new :spec
6
+
7
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "nunchaku"
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
@@ -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,9 @@
1
+ require "nunchaku/version"
2
+ require "nunchaku/checker"
3
+ require "nunchaku/message"
4
+
5
+ module Nunchaku
6
+ def self.check(url, options = {})
7
+ Nunchaku::Checker.new(url, options)
8
+ end
9
+ end
@@ -0,0 +1,37 @@
1
+ require 'httparty'
2
+ require 'json'
3
+
4
+ module Nunchaku
5
+ class Checker
6
+ attr_reader :url, :checker_uri
7
+
8
+ def initialize(url, options = {})
9
+ options = defaults.merge(options)
10
+
11
+ @url = url
12
+ @checker_uri = options[:checker_uri]
13
+ end
14
+
15
+ def raw
16
+ @raw ||= JSON.parse HTTParty.get("#{checker_uri}?out=json&doc=#{@url}").body
17
+ end
18
+
19
+ def messages
20
+ @messages ||= raw['messages'].map { |message| Nunchaku::Message.new(message) }
21
+ end
22
+
23
+ def errors
24
+ messages.select { |message| message.type == 'error' }
25
+ end
26
+
27
+ def warnings
28
+ messages.select { |message| message.subtype == 'warning' }
29
+ end
30
+
31
+ private
32
+
33
+ def defaults
34
+ { checker_uri: 'https://html5.validator.nu/' }
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,20 @@
1
+ module Nunchaku
2
+ class Message
3
+ attr_reader :type, :subtype, :first_line, :last_line,
4
+ :first_column, :last_column, :message,
5
+ :extract, :hilite_start, :hilite_length
6
+
7
+ def initialize(data)
8
+ @type = data['type']
9
+ @subtype = data['subType']
10
+ @first_line = data['firstLine']
11
+ @last_line = data['lastLine']
12
+ @first_column = data['firstColumn']
13
+ @last_column = data['lastColumn']
14
+ @message = data['message']
15
+ @extract = data['extract']
16
+ @hilite_start = data['hiliteStart']
17
+ @hilite_length = data['hiliteLength']
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+ module Nunchaku
2
+ VERSION = "0.1.0"
3
+ 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 'nunchaku/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "nunchaku"
8
+ spec.version = Nunchaku::VERSION
9
+ spec.authors = ["Jaime Iniesta"]
10
+ spec.email = ["jaimeiniesta@gmail.com"]
11
+
12
+ spec.summary = %q{Ruby client for the Nu HTML Checker}
13
+ spec.description = %q{Ruby client to check HTML markup using the Nu HTML Checker at https://html5.validator.nu/}
14
+ spec.homepage = "https://github.com/sitevalidator/nunchaku"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_runtime_dependency "httparty", "~> 0.13"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.8"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.2"
27
+ spec.add_development_dependency "webmock", "~> 1.20"
28
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nunchaku
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jaime Iniesta
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-03-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.13'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.8'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.8'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.2'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.20'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.20'
83
+ description: Ruby client to check HTML markup using the Nu HTML Checker at https://html5.validator.nu/
84
+ email:
85
+ - jaimeiniesta@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - CODE_OF_CONDUCT.md
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - bin/console
97
+ - bin/setup
98
+ - lib/nunchaku.rb
99
+ - lib/nunchaku/checker.rb
100
+ - lib/nunchaku/message.rb
101
+ - lib/nunchaku/version.rb
102
+ - nunchaku.gemspec
103
+ homepage: https://github.com/sitevalidator/nunchaku
104
+ licenses:
105
+ - MIT
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 2.4.5
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: Ruby client for the Nu HTML Checker
127
+ test_files: []