komplement 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: 2400a082d25fa86f6d7bf5541813fbc2c76227c4
4
+ data.tar.gz: b5d8f7aebb735cc924e81917416ba6ba5b3caaaf
5
+ SHA512:
6
+ metadata.gz: 0b20765a4e4a02dc65b6822a13290106a049401d2b795b40d70ce9c329f1f8ccf005c69fca1eb94791005efb2526f927350065ec92594819d919ccd65d568a20
7
+ data.tar.gz: ba0808df7142c46dd674a468f0e5162499ba09356a1665e474e2f5b33d4d6628efe671cb2366cd465b91c829036e3beef37fa5787f2a6ef37ff7c35483faf5a5
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ README.md
3
+ ChangeLog.md
4
+
5
+ LICENSE.txt
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ /.bundle
2
+ /Gemfile.lock
3
+ /html/
4
+ /pkg/
5
+ /vendor/cache/*.gem
data/.rdoc_options ADDED
@@ -0,0 +1,16 @@
1
+ --- !ruby/object:RDoc::Options
2
+ encoding: UTF-8
3
+ static_path: []
4
+ rdoc_include:
5
+ - .
6
+ charset: UTF-8
7
+ exclude:
8
+ hyperlink_all: false
9
+ line_numbers: false
10
+ main_page: README.md
11
+ markup: markdown
12
+ show_hash: false
13
+ tab_width: 8
14
+ title: komplement Documentation
15
+ visibility: :protected
16
+ webcvs:
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour --format documentation
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ before_install:
2
+ - gem install bundler
3
+ language: ruby
4
+ rvm:
5
+ - 2.2.3
6
+ script: bundle exec rspec spec
data/ChangeLog.md ADDED
@@ -0,0 +1,4 @@
1
+ ### 0.1.0 / 2016-05-11
2
+
3
+ * Initial release:
4
+
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2016 Simon Symeonidis
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,58 @@
1
+ # komplement
2
+
3
+ It's a dumb sanity check tool for your html. The idea is that if you create your
4
+ custom elements (for example, look at knockout.js components), and you want to
5
+ make sure that nothing goes awry while maintaining your source, you can run this
6
+ easilly configurable tool to do it for you.
7
+
8
+ * [Homepage](https://github.com/psyomn/komplement#readme)
9
+ * [Issues](https://github.com/psyomn/komplement/issues)
10
+ * [Documentation](http://rubydoc.info/gems/komplement/frames)
11
+ * [Email](mailto:lethaljellybean at gmail.com)
12
+
13
+ [![Build Status](https://secure.travis-ci.org/psyomn/komplement.svg?branch=master)](https://travis-ci.org/psyomn/komplement)
14
+
15
+ ## Features
16
+ ## Examples
17
+
18
+ If you want to do things by hand:
19
+
20
+ ```ruby
21
+ require 'komplement'
22
+
23
+ Komplement
24
+ .new
25
+ .with_ignored(%w[a br div])
26
+ .with_ignored(%w[custom-element potato])
27
+ .in_filetypes(%w[rb erb.html html])
28
+ .in_dirs(%w[./app ./some-other-place])
29
+ .run
30
+ ```
31
+
32
+ A constant to get rid of most manual workings is provided for you if you want to
33
+ use it:
34
+
35
+ ```ruby
36
+ require 'komplement'
37
+
38
+ Komplement
39
+ .new
40
+ .with_ignored(Komplement::HTML_ELEMENTS)
41
+ .with_ignored(%w[custom-element potato])
42
+ .in_filetypes(%w[rb erb.html html])
43
+ .in_dirs(%w[./app ./some-other-place])
44
+ .run
45
+ ```
46
+ ## Install
47
+
48
+ $ gem install komplement
49
+
50
+ ## Synopsis
51
+
52
+ $ komplement
53
+
54
+ ## Copyright
55
+
56
+ Copyright (c) 2016 Simon (psyomn) Symeonidis
57
+
58
+ See LICENSE.txt for details.
data/Rakefile ADDED
@@ -0,0 +1,25 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+
5
+ begin
6
+ require 'bundler/setup'
7
+ rescue LoadError => e
8
+ abort e.message
9
+ end
10
+
11
+ require 'rake'
12
+
13
+
14
+ require 'rubygems/tasks'
15
+ Gem::Tasks.new
16
+
17
+ require 'rdoc/task'
18
+ RDoc::Task.new
19
+ task :doc => :rdoc
20
+
21
+ require 'rspec/core/rake_task'
22
+ RSpec::Core::RakeTask.new
23
+
24
+ task :test => :spec
25
+ task :default => :spec
data/bin/komplement ADDED
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ root = File.expand_path(File.join(File.dirname(__FILE__),'..'))
4
+ if File.directory?(File.join(root,'.git'))
5
+ Dir.chdir(root) do
6
+ begin
7
+ require 'bundler/setup'
8
+ rescue LoadError => e
9
+ warn e.message
10
+ warn "Run `gem install bundler` to install Bundler"
11
+ exit -1
12
+ end
13
+ end
14
+ end
15
+
16
+ require 'komplement'
17
+ include Komplement
18
+
19
+ puts "Looking into #{ARGV[0]}"
20
+
21
+ Komplement::Base
22
+ .new
23
+ .with_ignored(Komplement::HTML_ELEMENTS)
24
+ .in_filetypes(['html'])
25
+ .in_dirs([ARGV[0]])
26
+ .run
@@ -0,0 +1,44 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'komplement/version'
6
+
7
+ Gem::Specification.new do |gem|
8
+ gem.name = "komplement"
9
+ gem.version = Komplement::VERSION
10
+ gem.summary = %q{Simple sanity checking tool for your html}
11
+ gem.description = <<DESC
12
+ Simple sanity checking tool for your html, that will
13
+ scan files, and detect html elements you might be unaware of}
14
+ DESC
15
+ gem.license = "MIT"
16
+ gem.authors = ["Simon Symeonidis"]
17
+ gem.email = "lethaljellybean@gmail.com"
18
+ gem.homepage = "https://github.com/psyomn/komplement#readme"
19
+
20
+ gem.files = `git ls-files`.split($/)
21
+
22
+ `git submodule --quiet foreach --recursive pwd`.split($/).each do |submodule|
23
+ submodule.sub!("#{Dir.pwd}/",'')
24
+
25
+ Dir.chdir(submodule) do
26
+ `git ls-files`.split($/).map do |subpath|
27
+ gem.files << File.join(submodule,subpath)
28
+ end
29
+ end
30
+ end
31
+
32
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
33
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
34
+ gem.require_paths = ['lib']
35
+
36
+ gem.add_development_dependency 'bundler', '~> 1.10'
37
+ gem.add_development_dependency 'rake', '~> 10.0'
38
+ gem.add_development_dependency 'rdoc', '~> 4.0'
39
+ gem.add_development_dependency 'rspec', '~> 3.0'
40
+ gem.add_development_dependency 'rubygems-tasks', '~> 0.2'
41
+
42
+ gem.add_runtime_dependency 'nokogiri', '~> 1.6'
43
+ gem.add_runtime_dependency 'colorize', '~> 0.7.7'
44
+ end
@@ -0,0 +1,101 @@
1
+ require 'komplement'
2
+
3
+ module Komplement
4
+ class Base
5
+ def initialize
6
+ @ignored_elements = @filetypes = @dirs = []
7
+ end
8
+
9
+ # which html elements to ignore
10
+ def with_ignored(ignored_a)
11
+ @ignored_elements += ignored_a
12
+ self
13
+ end
14
+
15
+ # filetypes to look into for html elements
16
+ def in_filetypes(filetypes_a)
17
+ @filetypes = filetypes_a.map { |e| "*.#{e}" }
18
+ self
19
+ end
20
+
21
+ # all the paths we should look into
22
+ def in_dirs(dirs_a)
23
+ @dirs += dirs_a
24
+ self
25
+ end
26
+
27
+ # returns 0 on no offenses, else 2
28
+ def run
29
+ unknown = find_offenses
30
+ exit process_output(unknown)
31
+ end
32
+
33
+ def find_offenses
34
+ [@ignored_elements, @filetypes, @dirs].map { |e| e.uniq! }
35
+
36
+ paths = make_paths
37
+ @files_of_interest = make_files(paths)
38
+
39
+ unknown = Hash.new { |h, k| h[k] = [] }
40
+
41
+ @files_of_interest.each do |file|
42
+ contents = File.read(file)
43
+ Nokogiri::HTML(contents).traverse do |node|
44
+ unless @ignored_elements.include? nm = node.name
45
+ unknown[file].push nm
46
+ end
47
+ end
48
+ end
49
+ unknown
50
+ end
51
+
52
+ attr_accessor :ignored_elements
53
+ attr_accessor :filetypes
54
+ attr_accessor :dirs
55
+
56
+ attr_reader :files_of_interest
57
+
58
+ private
59
+
60
+ def make_paths
61
+ @dirs.uniq!
62
+ paths = []
63
+ @dirs.each do |dir|
64
+ @filetypes.each do |filetype|
65
+ paths.push File.join(dir, '**', filetype)
66
+ end
67
+ end
68
+ paths
69
+ end
70
+
71
+ def make_files(paths_a)
72
+ files = []
73
+ paths_a.each do |path|
74
+ files += Dir.glob(path)
75
+ end
76
+ files
77
+ end
78
+
79
+ # @param unknown_h are the unknown elements that may have been detected
80
+ def process_output(unknown_h)
81
+ if unknown_h.empty?
82
+ $stderr.puts 'No problematic html found'.green.bold
83
+ return EXIT_SUCCESS
84
+ end
85
+
86
+ $stderr.puts 'ERROR: Detected possible unknown components:'.red.bold
87
+
88
+ unknown_h.each do |file_name, elements|
89
+ $stderr.puts file_name.green.bold
90
+ elements.each do |offending_element_name|
91
+ $stderr.puts " #{offending_element_name}"
92
+ end
93
+ end
94
+
95
+ EXIT_FAIL
96
+ end
97
+
98
+ EXIT_SUCCESS = 0
99
+ EXIT_FAIL = 2
100
+ end
101
+ end
@@ -0,0 +1,4 @@
1
+ module Komplement
2
+ # komplement version
3
+ VERSION = "0.1.0"
4
+ end
data/lib/komplement.rb ADDED
@@ -0,0 +1,17 @@
1
+ require 'nokogiri'
2
+ require 'colorize'
3
+
4
+ require 'komplement/version'
5
+ require 'komplement/base'
6
+
7
+ module Komplement
8
+ HTML_ELEMENTS = %w[
9
+ a abbr article aside audio b body br button canvas caption col colgroup
10
+ comment datalist dd details div dl document dt em fieldset footer form g h1 h2
11
+ h3 h4 h5 head header hgroup hr HTML html i iframe img input label legend li link
12
+ math meta meter mfrac mi mn mo mrow msup nav noscript object ol optgroup option
13
+ p parameter pre progress rect rt ruby script section select small source span
14
+ strong style summary svg table tbody td template text textarea tfoot th thead
15
+ title tr ul video xml #cdata-section
16
+ ]
17
+ end
@@ -0,0 +1,9 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head></head>
4
+
5
+ <body>
6
+ <h1> This is fine </h2>
7
+ <potato> this is a potato </potato>
8
+ </body>
9
+ </html>
@@ -0,0 +1,7 @@
1
+ <html>
2
+ <head></heAD>
3
+
4
+ <body>
5
+ <h1> Hello world </h1>
6
+ </body>
7
+ </html>
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+ require 'komplement'
3
+
4
+ describe Komplement do
5
+ it "should have a VERSION constant" do
6
+ expect(subject.const_get('VERSION')).to_not be_empty
7
+ end
8
+
9
+ describe Base do
10
+ it "should detect common html elements" do
11
+ ret = Komplement::Base
12
+ .new
13
+ .with_ignored(Komplement::HTML_ELEMENTS)
14
+ .in_filetypes(['html'])
15
+ .in_dirs(['./spec/files/'])
16
+ .find_offenses
17
+
18
+ expect(ret).to_not be_empty
19
+ expect(ret['./spec/files/bad_html.html']).to eq(['potato'])
20
+ end
21
+
22
+ it "should detect everything if no exclusion list is given" do
23
+ ret = Komplement::Base
24
+ .new
25
+ .with_ignored([])
26
+ .in_filetypes(['html'])
27
+ .in_dirs(['./spec/files/'])
28
+ .find_offenses
29
+
30
+ expect(ret).to_not be_empty
31
+
32
+ expect(ret['./spec/files/bad_html.html']).to eq([
33
+ "html", "text", "head", "text", "text", "text", "text",
34
+ "potato", "text", "h1", "body", "text", "html", "document"])
35
+ end
36
+
37
+ it "should ignore custom elements if specified so" do
38
+ ret = Komplement::Base
39
+ .new
40
+ .with_ignored(Komplement::HTML_ELEMENTS)
41
+ .with_ignored(['potato'])
42
+ .in_filetypes(['html'])
43
+ .in_dirs(['./spec/files/'])
44
+ .find_offenses
45
+
46
+ expect(ret).to be_empty
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,4 @@
1
+ require 'rspec'
2
+ require 'komplement/version'
3
+
4
+ include Komplement
metadata ADDED
@@ -0,0 +1,167 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: komplement
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Simon Symeonidis
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-05-12 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: rdoc
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '4.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '4.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.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubygems-tasks
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.2'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.2'
83
+ - !ruby/object:Gem::Dependency
84
+ name: nokogiri
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.6'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.6'
97
+ - !ruby/object:Gem::Dependency
98
+ name: colorize
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.7.7
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.7.7
111
+ description: |2
112
+ Simple sanity checking tool for your html, that will
113
+ scan files, and detect html elements you might be unaware of}
114
+ email: lethaljellybean@gmail.com
115
+ executables:
116
+ - komplement
117
+ extensions: []
118
+ extra_rdoc_files: []
119
+ files:
120
+ - ".document"
121
+ - ".gitignore"
122
+ - ".rdoc_options"
123
+ - ".rspec"
124
+ - ".travis.yml"
125
+ - ChangeLog.md
126
+ - Gemfile
127
+ - LICENSE.txt
128
+ - README.md
129
+ - Rakefile
130
+ - bin/komplement
131
+ - komplement.gemspec
132
+ - lib/komplement.rb
133
+ - lib/komplement/base.rb
134
+ - lib/komplement/version.rb
135
+ - spec/files/bad_html.html
136
+ - spec/files/normal_html.html
137
+ - spec/komplement_spec.rb
138
+ - spec/spec_helper.rb
139
+ homepage: https://github.com/psyomn/komplement#readme
140
+ licenses:
141
+ - MIT
142
+ metadata: {}
143
+ post_install_message:
144
+ rdoc_options: []
145
+ require_paths:
146
+ - lib
147
+ required_ruby_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ required_rubygems_version: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ requirements: []
158
+ rubyforge_project:
159
+ rubygems_version: 2.4.8
160
+ signing_key:
161
+ specification_version: 4
162
+ summary: Simple sanity checking tool for your html
163
+ test_files:
164
+ - spec/files/bad_html.html
165
+ - spec/files/normal_html.html
166
+ - spec/komplement_spec.rb
167
+ - spec/spec_helper.rb