deadlink 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -0
- data/exe/deadlink +1 -0
- data/lib/deadlink/decorator.rb +13 -2
- data/lib/deadlink/path.rb +8 -13
- data/lib/deadlink/scanner.rb +21 -8
- data/lib/deadlink/version.rb +1 -1
- data/lib/deadlink.rb +11 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb5e6436cde33615811d3788e82efa4aae463b0b
|
4
|
+
data.tar.gz: c4b3acda36bf178319b056384504370b5fa22802
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bafda7f50283eb4ecc701de7bcf60436697dc5611da533e7dcff1044fdd04804089ccb3a7b324898f5e32770c6ecaf1cd02594494b884670601ba3ddfd3c6151
|
7
|
+
data.tar.gz: a7e9dc7d73724d5af0eb690a1ec90a94b3cfadf017b4254d4f2e3fea6f26e77ae511323d0a178e46045a9f7bd36fb8170557a544fd5d4338a30fab0f62ad6a1d
|
data/.travis.yml
CHANGED
data/exe/deadlink
CHANGED
data/lib/deadlink/decorator.rb
CHANGED
@@ -2,10 +2,21 @@ module Deadlink
|
|
2
2
|
class Decorator
|
3
3
|
def self.print_info(path,opts)
|
4
4
|
if opts['p']
|
5
|
-
|
5
|
+
for_editor(path)
|
6
6
|
else
|
7
|
-
|
7
|
+
default(path)
|
8
8
|
end
|
9
9
|
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def self.for_editor(path)
|
14
|
+
puts '+' + path.index.to_s + " " + path.cur_file_path
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.default(path)
|
18
|
+
puts path.link + ' in ' + path.cur_file_path + ' line: ' + path.index.to_s
|
19
|
+
end
|
20
|
+
|
10
21
|
end
|
11
22
|
end
|
data/lib/deadlink/path.rb
CHANGED
@@ -4,10 +4,9 @@ module Deadlink
|
|
4
4
|
attr_reader :link, :cur_file_path, :index
|
5
5
|
|
6
6
|
def initialize(cur_file_path, link, index, repo_root)
|
7
|
-
@link = link
|
8
7
|
@cur_file_path = cur_file_path
|
8
|
+
@link = link
|
9
9
|
@index = index
|
10
|
-
|
11
10
|
@repo_root = repo_root
|
12
11
|
|
13
12
|
hash = split_link(link)
|
@@ -16,14 +15,10 @@ module Deadlink
|
|
16
15
|
end
|
17
16
|
|
18
17
|
def deadlink?
|
19
|
-
!exist? && ignore
|
18
|
+
!FileTest.exist?(abusolute_path) && ignore
|
20
19
|
end
|
21
20
|
|
22
21
|
private
|
23
|
-
|
24
|
-
def exist?
|
25
|
-
File.exist?(link_path) || Dir.exist?(link_path)
|
26
|
-
end
|
27
22
|
|
28
23
|
def ignore
|
29
24
|
!url?
|
@@ -33,20 +28,20 @@ module Deadlink
|
|
33
28
|
@link =~ /https?:\/\/[\S]+/
|
34
29
|
end
|
35
30
|
|
36
|
-
def
|
37
|
-
if
|
31
|
+
def abusolute_path
|
32
|
+
if specify_root?(@link_file_path)
|
38
33
|
return File.join(@repo_root, @link_file_path)
|
34
|
+
else
|
35
|
+
return File.expand_path(@link_file_path, File.dirname(@cur_file_path))
|
39
36
|
end
|
40
|
-
|
41
|
-
File.expand_path(@link_file_path, File.dirname(@cur_file_path))
|
42
37
|
end
|
43
38
|
|
44
39
|
def split_link(link)
|
45
|
-
# split <filenpath>#<
|
40
|
+
# split <filenpath>#<anchor>
|
46
41
|
hash = link.match(/(?<filepath>[^#]*)#*(?<anchor>.*)/)
|
47
42
|
end
|
48
43
|
|
49
|
-
def
|
44
|
+
def specify_root?(path)
|
50
45
|
path[0] == "/"
|
51
46
|
end
|
52
47
|
|
data/lib/deadlink/scanner.rb
CHANGED
@@ -1,17 +1,30 @@
|
|
1
1
|
module Deadlink
|
2
2
|
class Scanner
|
3
|
-
def initialize(
|
4
|
-
if
|
3
|
+
def initialize(target_path)
|
4
|
+
if target_path.nil?
|
5
5
|
@repo_root = repo_root(".")
|
6
|
-
@
|
6
|
+
@target_path = @repo_root
|
7
7
|
else
|
8
|
-
@
|
9
|
-
@repo_root = repo_root(@
|
8
|
+
@target_path = target_path
|
9
|
+
@repo_root = repo_root(@target_path)
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
+
def valid?
|
14
|
+
unless FileTest.exist?(@target_path)
|
15
|
+
puts @target_path + ": No such file or directory"
|
16
|
+
return false
|
17
|
+
end
|
18
|
+
return true
|
19
|
+
end
|
20
|
+
|
13
21
|
def md_files
|
14
|
-
|
22
|
+
if File.directory?(@target_path)
|
23
|
+
Dir.glob(File.join(@target_path, '/**/*.{md,markdown}'))
|
24
|
+
else
|
25
|
+
files = []
|
26
|
+
files.push(@target_path)
|
27
|
+
end
|
15
28
|
end
|
16
29
|
|
17
30
|
def paths(files)
|
@@ -30,8 +43,8 @@ module Deadlink
|
|
30
43
|
|
31
44
|
private
|
32
45
|
|
33
|
-
def repo_root(
|
34
|
-
dir =
|
46
|
+
def repo_root(target_path)
|
47
|
+
dir = target_path
|
35
48
|
until dir.empty? do
|
36
49
|
return dir if git_repo?(dir)
|
37
50
|
dir = prev_dir(dir)
|
data/lib/deadlink/version.rb
CHANGED
data/lib/deadlink.rb
CHANGED
@@ -9,11 +9,20 @@ module Deadlink
|
|
9
9
|
def self.scan()
|
10
10
|
|
11
11
|
opts = ARGV.getopts('','p')
|
12
|
-
|
12
|
+
target_path = ARGV[0]
|
13
13
|
|
14
|
+
scanner = Scanner.new(target_path)
|
15
|
+
|
16
|
+
unless scanner.valid?
|
17
|
+
exit 1
|
18
|
+
end
|
14
19
|
|
15
|
-
scanner = Scanner.new(target_dir)
|
16
20
|
files = scanner.md_files
|
21
|
+
|
22
|
+
if files.empty?
|
23
|
+
exit 0
|
24
|
+
end
|
25
|
+
|
17
26
|
paths = scanner.paths(files)
|
18
27
|
paths.print_deadlinks(opts)
|
19
28
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deadlink
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- yutakakinjyo
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -111,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
111
111
|
version: '0'
|
112
112
|
requirements: []
|
113
113
|
rubyforge_project:
|
114
|
-
rubygems_version: 2.
|
114
|
+
rubygems_version: 2.5.0
|
115
115
|
signing_key:
|
116
116
|
specification_version: 4
|
117
117
|
summary: check deadlink from markdown file in your git repository
|