jill 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e41b93b0c457ab82f85eff9c1cdc4c75a2b30f15
4
+ data.tar.gz: 24ff8e783950271c862c234866361c423f8b7634
5
+ SHA512:
6
+ metadata.gz: bd33c61de6261033108b49fd76cbe1f7bae5a90fe73bad7b7898328061711355b39a02812a3dfb2f390efc256eec326ea2c7581d96ee968897d4e4144cfdfaed
7
+ data.tar.gz: 991826e6c6d49ac7a1576caabce4358c96f32139eae52f652d2b9d0aa17e2e1a470b0d0f3bb7ae69c454b67ca8e35cbf2357032f26d649450dc988245cc7682c
@@ -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,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
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 mediumize.gemspec
4
+ gemspec
@@ -0,0 +1,7 @@
1
+
2
+ guard :minitest do
3
+ # with Minitest::Spec
4
+ watch(%r{^spec/(.*)_spec\.rb$})
5
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
6
+ watch(%r{^spec/spec_helper\.rb$}) { 'spec' }
7
+ end
@@ -0,0 +1,33 @@
1
+ # Jill
2
+
3
+ Like [Joe](https://github.com/karan/joe) and [Harvey](https://github.com/architv/harvey), but for `README.md`s.
4
+
5
+
6
+ ## Quickstart
7
+
8
+ ```
9
+ $ gem install jill
10
+
11
+ # embed stars for each github link
12
+ $ jill -s --star-in README.md --star-out README_STARRED.md
13
+
14
+ # verify links
15
+ $ jill -l --links-file README.md --links-base-url http://example.com
16
+
17
+ # dedup links
18
+ $ jill -d --dedup-file README.md --dedup-base-url http://example.com
19
+ ```
20
+
21
+ Done.
22
+
23
+ # Contributing
24
+
25
+ Fork, implement, add tests, pull request, get my everlasting thanks and a respectable place here :).
26
+
27
+ ### Thanks:
28
+
29
+ To all [contributors](https://github.com/jondot/tiny-cli-ruby-gem/graphs/contributors)
30
+
31
+ # Copyright
32
+
33
+ Copyright (c) 2016 [Dotan Nahum](http://gplus.to/dotan) [@jondot](http://twitter.com/jondot). See [LICENSE](LICENSE.txt) for further details.
@@ -0,0 +1,65 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "spec"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['spec/**/*_spec.rb']
8
+ end
9
+
10
+ task :default => :test
11
+
12
+ require 'fileutils'
13
+ include FileUtils
14
+
15
+ # rake provision[Farble,farble]
16
+ desc "make a new cli"
17
+ task :provision, [:classname, :gemname] do |t, args|
18
+ gemname = args[:gemname]
19
+ classname = args[:classname]
20
+ puts "--> Generating #{gemname}..."
21
+
22
+ replacements = {
23
+ "tinycli" => gemname,
24
+ "Tinycli" => classname
25
+ }
26
+ files = %w{ bin/tinycli
27
+ lib/tinycli/version.rb
28
+ lib/tinycli.rb
29
+ spec/tinycli_spec.rb
30
+ spec/spec_helper.rb
31
+ tinycli.gemspec }
32
+
33
+ files.each do |file|
34
+ sed file, replacements
35
+ end
36
+
37
+
38
+ mkdir "lib/#{gemname}"
39
+ files.each do |file|
40
+ target = file.gsub("tinycli", replacements["tinycli"])
41
+ mv file, target if file != target
42
+ end
43
+ rmdir "lib/tinycli"
44
+
45
+ `rm -rf .git`
46
+ `git init .`
47
+ `git add .`
48
+ `git commit -am 'initial commit'`
49
+ puts "\n\n--> Running a test of #{gemname} --help\n\n"
50
+ puts `ruby -Ilib bin/#{gemname} --help`
51
+
52
+ puts "\n\n--> Done provisioning CLI gem: #{gemname}.\n--> You can now create Github repo when you like."
53
+
54
+ end
55
+
56
+ def sed(file, replacements)
57
+ content = File.read(file)
58
+ replacements.each do |old,new|
59
+ content.gsub!(old, new)
60
+ end
61
+ File.open(file, "w") do |f|
62
+ f.write(content)
63
+ end
64
+ end
65
+
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "jill"
4
+ require "slop"
5
+
6
+ def bail(err, opts)
7
+ puts err
8
+ puts
9
+ puts opts
10
+ exit(1)
11
+ end
12
+
13
+ begin
14
+ o = Slop::Options.new
15
+ jill = Jill::Runner.new
16
+ jill.setup(o)
17
+ o.on '--version', 'print the version' do
18
+ puts Jill::VERSION
19
+ exit
20
+ end
21
+ o.on '--help' do
22
+ puts o
23
+ exit
24
+ end
25
+ opts = Slop::Parser.new(o).parse(ARGV)
26
+
27
+ exit(1) unless jill.run(opts)
28
+ rescue
29
+ raise if ENV["DEBUG"]
30
+ bail "Error: #{$!}", o
31
+ end
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'jill/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "jill"
8
+ spec.version = Jill::VERSION
9
+ spec.authors = ["Dotan Nahum"]
10
+ spec.email = ["jondotan@gmail.com"]
11
+
12
+ spec.summary = %q{Jill is your README.md assistant}
13
+ spec.description = %q{Jill is your README.md assistant}
14
+ spec.homepage = "https://github.com/jondot/jill"
15
+
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "bin"
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency 'slop', '~> 4.2.1'
23
+ spec.add_dependency 'colorize', '~> 0.7.7'
24
+ spec.add_dependency 'kramdown', '~> 1.9.0'
25
+ spec.add_dependency 'nokogiri', '~> 1.6.7'
26
+ spec.add_dependency 'parallel', '~> 1.6.1'
27
+ spec.add_dependency 'httparty', '~> 0.13.7'
28
+
29
+ spec.add_development_dependency "bundler", "~> 1.10"
30
+ spec.add_development_dependency "rake", "~> 10.0"
31
+ spec.add_development_dependency "minitest"
32
+ end
@@ -0,0 +1,27 @@
1
+ require "jill/version"
2
+ require "jill/commands/base"
3
+
4
+ require "jill/commands/dedup"
5
+ require "jill/commands/star"
6
+ require "jill/commands/links"
7
+
8
+ module Jill
9
+ class Runner
10
+ def initialize
11
+ @commands = [
12
+ Commands::Star.new,
13
+ Commands::Dedup.new,
14
+ Commands::Links.new
15
+ ]
16
+ end
17
+
18
+ def setup(o)
19
+ @commands.each{|c| c.setup(o) }
20
+ end
21
+
22
+ def run(opts)
23
+ @commands.map{|c| c.run(opts) }.inject(true){|a,s| a && s}
24
+ end
25
+ end
26
+ end
27
+
@@ -0,0 +1,28 @@
1
+ module Jill
2
+ module Commands
3
+ class Base
4
+ def setup(o)
5
+ o.bool "-#{flagname[0]}", "-#{flagname}", help
6
+ end
7
+
8
+ def run(opts)
9
+ return unless opts[flagname.to_sym]
10
+ run_if_switched(opts)
11
+
12
+ end
13
+
14
+ def run_if_switched(opts)
15
+ end
16
+
17
+ def help
18
+ ""
19
+ end
20
+
21
+ def flagname
22
+ @flagname ||= self.class.name.split("::").last.downcase
23
+ @flagname
24
+ end
25
+ end
26
+ end
27
+ end
28
+
@@ -0,0 +1,55 @@
1
+ require 'parallel'
2
+ require 'nokogiri'
3
+ require 'open-uri'
4
+ require 'kramdown'
5
+
6
+ module Jill
7
+ module Commands
8
+ class Dedup < Base
9
+ def setup(o)
10
+ super
11
+ o.string "--dedup-base-url", "Dedup base url", default: "/"
12
+ o.string "--dedup-file", "Dedup input file" , default: "README.md"
13
+ end
14
+
15
+ def help
16
+ "Dedups links out of a markdown file"
17
+ end
18
+
19
+ def run_if_switched(opts)
20
+ file = opts[:dedup_file]
21
+ base_url = opts[:dedup_base_url]
22
+
23
+ doc = Nokogiri::HTML(Kramdown::Document.new(open(file).read).to_html)
24
+ links = doc.css('a').to_a
25
+ puts "Deduping #{links.count} links..."
26
+
27
+ map = {}
28
+ dups = []
29
+
30
+ links.each do |link|
31
+ uri = URI.join(base_url, link.attr('href'))
32
+ if map[uri]
33
+ dups << link
34
+ end
35
+ map[uri] = link
36
+ end
37
+
38
+ unless dups.empty?
39
+ puts "\nDuplicate links:"
40
+ dups.each do |link|
41
+ puts "- #{link}"
42
+ puts `grep -nr '#{link.attr('href')}' #{file}`
43
+ end
44
+ puts "\nDone with errors."
45
+ return false
46
+ end
47
+
48
+ puts "\nDone."
49
+
50
+ return true
51
+ end
52
+ end
53
+ end
54
+ end
55
+
@@ -0,0 +1,58 @@
1
+ require 'parallel'
2
+ require 'nokogiri'
3
+ require 'open-uri'
4
+ require 'httparty'
5
+ require 'kramdown'
6
+
7
+ module Jill
8
+ module Commands
9
+ class Links < Base
10
+ def setup(o)
11
+ super
12
+ o.string "--links-base-url", "Links base url", default: "/"
13
+ o.string "--links-file", "Links input file", default: "README.md"
14
+ end
15
+
16
+ def help
17
+ "Validate live links out of a markdown file"
18
+ end
19
+
20
+ def run_if_switched(opts)
21
+ file = opts[:links_file]
22
+ base_url = opts[:links_base_url]
23
+
24
+ doc = Nokogiri::HTML(Kramdown::Document.new(open(file).read).to_html)
25
+ links = doc.css('a').to_a
26
+ puts "Validating #{links.count} links..."
27
+
28
+ invalids = []
29
+ Parallel.each(links, :in_threads => 4) do |link|
30
+ begin
31
+ uri = URI.join(base_url, link.attr('href'))
32
+ check_link(uri)
33
+ putc('.')
34
+ rescue
35
+ putc('F')
36
+ invalids << "#{link} (reason: #{$!})"
37
+ end
38
+ end
39
+
40
+ unless invalids.empty?
41
+ puts "\n\nFailed links:"
42
+ invalids.each do |link|
43
+ puts "- #{link}"
44
+ end
45
+ puts "Done with errors."
46
+ exit(1)
47
+ end
48
+
49
+ puts "\nDone."
50
+ end
51
+ def check_link(uri)
52
+ code = HTTParty.head(uri, :follow_redirects => false).code
53
+ return code >= 200 && code < 400
54
+ end
55
+ end
56
+ end
57
+ end
58
+
@@ -0,0 +1,61 @@
1
+ require 'uri'
2
+ require 'json'
3
+ require 'open-uri'
4
+ require 'nokogiri'
5
+
6
+ module Jill
7
+ module Commands
8
+ class Star < Base
9
+ STAR = '★'
10
+
11
+ def setup(o)
12
+ super
13
+ o.string "--star-in", "Star input file", default: "README.md"
14
+ o.string "--star-out", "Star output file", default: "README.md"
15
+ end
16
+
17
+ def help
18
+ "Embed stars in markdown file"
19
+ end
20
+
21
+ def run_if_switched(opts)
22
+ file = opts[:star_in]
23
+ file_out = opts[:star_out]
24
+ out = ""
25
+ puts "Starring #{file}..."
26
+
27
+ # do this serially as to not piss off github
28
+ File.read(file).each_line do |line|
29
+ # is a bullet,
30
+ # starts with github.com,
31
+ # has only 2 segments in path,
32
+ # remove trailing slashes.
33
+ if line =~ /^- \[(.*?)\]\(https?:\/\/github\.com\/([^\/]+?)\/([^\/]+?)\/?\)(\s+.*)$/
34
+ begin
35
+ ghslug = "#{$2}/#{$3}"
36
+ rest = $4
37
+ # remove existing stars if existing
38
+ name = $1.gsub(/\s?#{STAR}\d+/, '')
39
+
40
+ doc = Nokogiri::HTML(open("https://github.com/#{ghslug}").read)
41
+ stars = doc.css('.js-social-count').text.strip.gsub(',','')
42
+
43
+ out << "- [#{name} #{STAR}#{stars}](https://github.com/#{ghslug})#{rest}\n"
44
+ rescue
45
+ out << line
46
+ out << "<!-- error fetching stars for #{ghslug}: #{$!} -->\n"
47
+ end
48
+ putc "."
49
+
50
+ else
51
+ out << line
52
+ end
53
+ end
54
+ File.open(file_out, "w"){|f| f.write(out)}
55
+ puts "\nDone."
56
+
57
+ return true
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,3 @@
1
+ module Jill
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,184 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jill
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Dotan Nahum
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: slop
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 4.2.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 4.2.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: colorize
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.7.7
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.7.7
41
+ - !ruby/object:Gem::Dependency
42
+ name: kramdown
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.9.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.9.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: nokogiri
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.6.7
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.6.7
69
+ - !ruby/object:Gem::Dependency
70
+ name: parallel
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 1.6.1
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 1.6.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: httparty
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.13.7
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.13.7
97
+ - !ruby/object:Gem::Dependency
98
+ name: bundler
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.10'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.10'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rake
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '10.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '10.0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: minitest
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: Jill is your README.md assistant
140
+ email:
141
+ - jondotan@gmail.com
142
+ executables:
143
+ - jill
144
+ extensions: []
145
+ extra_rdoc_files: []
146
+ files:
147
+ - ".gitignore"
148
+ - ".travis.yml"
149
+ - Gemfile
150
+ - Guardfile
151
+ - README.md
152
+ - Rakefile
153
+ - bin/jill
154
+ - jill.gemspec
155
+ - lib/jill.rb
156
+ - lib/jill/commands/base.rb
157
+ - lib/jill/commands/dedup.rb
158
+ - lib/jill/commands/links.rb
159
+ - lib/jill/commands/star.rb
160
+ - lib/jill/version.rb
161
+ homepage: https://github.com/jondot/jill
162
+ licenses: []
163
+ metadata: {}
164
+ post_install_message:
165
+ rdoc_options: []
166
+ require_paths:
167
+ - lib
168
+ required_ruby_version: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ version: '0'
173
+ required_rubygems_version: !ruby/object:Gem::Requirement
174
+ requirements:
175
+ - - ">="
176
+ - !ruby/object:Gem::Version
177
+ version: '0'
178
+ requirements: []
179
+ rubyforge_project:
180
+ rubygems_version: 2.4.5.1
181
+ signing_key:
182
+ specification_version: 4
183
+ summary: Jill is your README.md assistant
184
+ test_files: []