deadlink 0.6.1 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/deadlink.gemspec +1 -1
- data/lib/deadlink/md_file.rb +25 -9
- data/lib/deadlink/md_files.rb +5 -7
- data/lib/deadlink/path.rb +16 -8
- data/lib/deadlink/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b863c28a4eea2f7ba320860e8fc897de7a85fe67
|
4
|
+
data.tar.gz: 1855c3606b41771e512d347084294f4751f3e689
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de47980c6041ca67a30f39ff24222e8bece1380050653c624b8e70f810548f6033c671e0fd73c567cd6219bc4157dbd3a473199da3484a366c7818e020056617
|
7
|
+
data.tar.gz: e7615ca3e01b28556bcde16d983afe2dc2c21c7cf86cd7f68a14b55ed341d6da073a77ffdf669f7bf29c66ed2c3e8c5cb522b5b32f7877552c57c62b8cc9754f
|
data/.travis.yml
CHANGED
data/deadlink.gemspec
CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
-
spec.add_development_dependency "bundler", "~> 1.
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.11.0"
|
23
23
|
spec.add_development_dependency "rake", "~> 10.0"
|
24
24
|
spec.add_development_dependency "minitest"
|
25
25
|
spec.add_development_dependency "fakefs"
|
data/lib/deadlink/md_file.rb
CHANGED
@@ -7,33 +7,49 @@ module Deadlink
|
|
7
7
|
@path = file_path
|
8
8
|
@headers = []
|
9
9
|
@link_paths = []
|
10
|
-
|
10
|
+
attribute(repo_root)
|
11
11
|
end
|
12
12
|
|
13
13
|
private
|
14
14
|
|
15
|
-
def
|
15
|
+
def attribute(repo_root)
|
16
16
|
File.open(@path) do |f|
|
17
|
+
prev_line = nil
|
17
18
|
f.each_with_index do |line,index|
|
18
|
-
|
19
|
+
sharp_header(line) { |header| @headers.push header }
|
20
|
+
under_line_header(line, prev_line) { |header| @headers.push header }; prev_line = line
|
21
|
+
link(line, index, repo_root) { |path| @link_paths.push path }
|
19
22
|
end
|
20
23
|
end
|
21
24
|
end
|
22
25
|
|
23
|
-
def
|
24
|
-
if line =~
|
25
|
-
header = Regexp.last_match[:header].downcase.rstrip
|
26
|
-
|
26
|
+
def sharp_header(line)
|
27
|
+
if line =~ sharp_header_pattern # capture sharp header part
|
28
|
+
header = Regexp.last_match[:header].downcase.rstrip
|
29
|
+
yield header.gsub(" ", "-")
|
27
30
|
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def under_line_header(line, prev_line)
|
34
|
+
if line =~ under_header_pattern && !prev_line.nil?
|
35
|
+
yield prev_line.chomp
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def link(line, index, repo_root)
|
28
40
|
line.scan link_pattern do |link| # capthure links path part
|
29
|
-
|
41
|
+
yield Path.new(@path, link[0].rstrip, index + 1, repo_root)
|
30
42
|
end
|
31
43
|
end
|
32
44
|
|
33
|
-
def
|
45
|
+
def sharp_header_pattern
|
34
46
|
/^\#{1,6} +(?<header>.+)/
|
35
47
|
end
|
36
48
|
|
49
|
+
def under_header_pattern
|
50
|
+
/^[-]+$|^[=]+$/
|
51
|
+
end
|
52
|
+
|
37
53
|
def link_pattern
|
38
54
|
/\[[^\]]*\]\((?<link>[^)]+)\)/
|
39
55
|
end
|
data/lib/deadlink/md_files.rb
CHANGED
@@ -11,17 +11,15 @@ module Deadlink
|
|
11
11
|
@files = files
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
15
|
-
file
|
16
|
-
|
17
|
-
false
|
14
|
+
def find_by(path)
|
15
|
+
@files.each { |file| return file if abs(file.path) == abs(path) }
|
16
|
+
nil
|
18
17
|
end
|
19
18
|
|
20
19
|
private
|
21
20
|
|
22
|
-
def
|
23
|
-
|
24
|
-
nil
|
21
|
+
def abs(path)
|
22
|
+
File.expand_path(path, File.dirname(path))
|
25
23
|
end
|
26
24
|
|
27
25
|
end
|
data/lib/deadlink/path.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# coding: utf-8
|
1
2
|
module Deadlink
|
2
3
|
class Path
|
3
4
|
|
@@ -10,10 +11,11 @@ module Deadlink
|
|
10
11
|
@repo_root = repo_root
|
11
12
|
|
12
13
|
hash = split_link(link)
|
13
|
-
@link_file_path = hash[:filepath]
|
14
14
|
@anchor = hash[:anchor]
|
15
|
+
@link_file_path = hash[:filepath]
|
15
16
|
|
16
|
-
|
17
|
+
|
18
|
+
@abs_link_file_path = abs_link_file_path
|
17
19
|
end
|
18
20
|
|
19
21
|
def deadlink?(files)
|
@@ -24,17 +26,23 @@ module Deadlink
|
|
24
26
|
|
25
27
|
def anchor_invalid?(files)
|
26
28
|
return false if @anchor.empty?
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
29
|
+
|
30
|
+
# e.g [](#anchor)
|
31
|
+
path = only_anchor? ? @cur_file_path : @abs_link_file_path
|
32
|
+
file = files.find_by(path)
|
33
|
+
return !file.headers.include?(@anchor)
|
34
|
+
end
|
35
|
+
|
36
|
+
def only_anchor?
|
37
|
+
@link_file_path.empty? && !@anchor.empty?
|
31
38
|
end
|
32
39
|
|
33
40
|
def exist?
|
34
|
-
FileTest.exist?(@
|
41
|
+
FileTest.exist?(@abs_link_file_path)
|
35
42
|
end
|
36
43
|
|
37
|
-
def
|
44
|
+
def abs_link_file_path
|
45
|
+
|
38
46
|
if specify_root?(@link_file_path)
|
39
47
|
return File.join(@repo_root, @link_file_path)
|
40
48
|
else
|
data/lib/deadlink/version.rb
CHANGED
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.6.
|
4
|
+
version: 0.6.2
|
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
|
+
date: 2015-12-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.
|
19
|
+
version: 1.11.0
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1.
|
26
|
+
version: 1.11.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|