deadlink 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 96e8b8e7addc2ee385e95fbd7f08b1aedee81abb
4
- data.tar.gz: 9341059baaaf395db53bd8d2f2676835cf721fe2
3
+ metadata.gz: f42e427eaed4d72f32f1792483e63ada02693bee
4
+ data.tar.gz: 9bce889bdc0bf45a1c9f801e5a38fa828d32d501
5
5
  SHA512:
6
- metadata.gz: 6abb1ca6bfb2b232946956bfcd9f3c02da7a183911ec790307610c2487ef1213aec16732289cc33feb352f7b9bcbaf0e50fa8b681897d80d03b96f0eea2ff4d4
7
- data.tar.gz: ddb87ccf752d575f4d5416f759e3728cdc2c38d7a7ac567b9920852c15f040d840f269ecb02a60b85f396e574c04300ac7ffc3c8dcaf278f76557d6b606b957c
6
+ metadata.gz: 4d390237db254c21ca8ad04326dc0984d08fa0f65fbd2d7c6b7007e375fef371d567b5b12f8ac59f242ca4ec75141462fbaae728339203523d54d784760d2ec0
7
+ data.tar.gz: bad4ecfdcb120bedd548d9774bbd422ceff9430fe66f6d87595bb8a4b718840aba1af271e93ed22294d33e0df1a43c599149c1f7b1b630e7c99fa19bca89d0ed
data/.travis.yml CHANGED
@@ -1,7 +1,8 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 2.2.2
4
+
4
5
  before_install: gem install bundler -v 1.10.6
5
6
 
6
7
  notifications:
7
- email: false
8
+ email: false
data/README.md CHANGED
@@ -1,6 +1,9 @@
1
1
  # Deadlink
2
2
 
3
3
  [![Build Status](https://travis-ci.org/yutakakinjyo/deadlink.svg?branch=master)](https://travis-ci.org/yutakakinjyo/deadlink)
4
+ [![Code Climate](https://codeclimate.com/github/yutakakinjyo/deadlink/badges/gpa.svg)](https://codeclimate.com/github/yutakakinjyo/deadlink)
5
+ [![Dependency Status](https://gemnasium.com/yutakakinjyo/deadlink.svg)](https://gemnasium.com/yutakakinjyo/deadlink)
6
+ [![Gem Version](https://badge.fury.io/rb/deadlink.svg)](https://badge.fury.io/rb/deadlink)
4
7
 
5
8
  Check **deadlink** of markdown files in your git repository.
6
9
 
@@ -68,6 +71,25 @@ if you not specify `<dir>` path, deadlink scan top directory of current git repo
68
71
  $ deadlink
69
72
  ```
70
73
 
74
+ ### Option
75
+
76
+ `-p` option output for editor. In this repository case
77
+
78
+ `$ deadlink -p deadlink/`
79
+
80
+ ```
81
+ +46 ./README.md
82
+ +90 ./README.md
83
+ +2 ./test/files/dir1/nest_file1.md
84
+ +3 ./test/files/top.md
85
+ +5 ./test/files/top.md
86
+ +8 ./test/files/top.md
87
+ ```
88
+
89
+ Forexample you can jump deadlink line easily, like following command.
90
+
91
+ `$ vi $(deadlink -p deadlink/ | peco)`
92
+
71
93
  ## Development
72
94
 
73
95
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/exe/deadlink CHANGED
@@ -2,5 +2,4 @@
2
2
 
3
3
  require 'deadlink'
4
4
 
5
- target_dir = ARGV[0]
6
- Deadlink.scan(target_dir)
5
+ Deadlink.scan()
@@ -0,0 +1,11 @@
1
+ module Deadlink
2
+ class Decorator
3
+ def self.print_info(path,opts)
4
+ if opts['p']
5
+ puts '+' + path.index.to_s + " " + path.cur_file_path
6
+ else
7
+ puts path.link + ' in ' + path.cur_file_path + ' line: ' + path.index.to_s
8
+ end
9
+ end
10
+ end
11
+ end
data/lib/deadlink/path.rb CHANGED
@@ -1,14 +1,18 @@
1
1
  module Deadlink
2
2
  class Path
3
- def initialize(file_path, link, index, repo_root)
4
- @file_path = file_path
3
+
4
+ attr_reader :link, :cur_file_path, :index
5
+
6
+ def initialize(cur_file_path, link, index, repo_root)
5
7
  @link = link
8
+ @cur_file_path = cur_file_path
6
9
  @index = index
7
- @repo_root = repo_root
8
- end
9
10
 
10
- def deadlink
11
- puts @link + ' in ' + @file_path + ' line: ' + @index.to_s if deadlink?
11
+ @repo_root = repo_root
12
+
13
+ hash = split_link(link)
14
+ @link_file_path = hash[:filepath]
15
+ @anchor = hash[:anchor]
12
16
  end
13
17
 
14
18
  def deadlink?
@@ -28,17 +32,23 @@ module Deadlink
28
32
  def url?
29
33
  @link =~ /https?:\/\/[\S]+/
30
34
  end
31
-
35
+
32
36
  def link_path
33
- # split path ; <filename>#<title>
34
- cap = @link.match(/(?<filelink>[^#]*)#*(?<anchor>.*)/)
35
- if cap[:filelink][0] == "/"
36
- return File.join(@repo_root, cap[:filelink])
37
+ if absolute_path?(@link_file_path)
38
+ return File.join(@repo_root, @link_file_path)
37
39
  end
38
40
 
39
- File.expand_path(cap[:filelink], File.dirname(@file_path))
41
+ File.expand_path(@link_file_path, File.dirname(@cur_file_path))
40
42
  end
41
43
 
44
+ def split_link(link)
45
+ # split <filenpath>#<title>
46
+ hash = link.match(/(?<filepath>[^#]*)#*(?<anchor>.*)/)
47
+ end
48
+
49
+ def absolute_path?(path)
50
+ path[0] == "/"
51
+ end
42
52
 
43
53
  end
44
54
  end
@@ -1,5 +1,8 @@
1
1
  module Deadlink
2
2
  class Paths
3
+
4
+ attr_reader :deadlinks
5
+
3
6
  def initialize(paths)
4
7
  @paths = paths
5
8
  @deadlinks = paths.select { |path| path.deadlink? }
@@ -9,21 +12,13 @@ module Deadlink
9
12
  @deadlinks.any?
10
13
  end
11
14
 
12
- def deadlinks
13
- @deadlinks
14
- end
15
-
16
- def print_deadlinks
17
- @paths.each { |path| path.deadlink }
15
+ def print_deadlinks(opts)
16
+ @deadlinks.each { |path| Decorator.print_info(path,opts) }
18
17
  end
19
18
 
20
19
  def count
21
20
  @paths.count
22
21
  end
23
22
 
24
- def [](i)
25
- @paths[i]
26
- end
27
-
28
23
  end
29
24
  end
@@ -1,3 +1,3 @@
1
1
  module Deadlink
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
data/lib/deadlink.rb CHANGED
@@ -2,12 +2,19 @@ require "deadlink/version"
2
2
  require 'deadlink/scanner'
3
3
  require 'deadlink/path'
4
4
  require 'deadlink/paths'
5
+ require 'deadlink/decorator'
6
+ require 'optparse'
5
7
 
6
8
  module Deadlink
7
- def self.scan(target_dir)
9
+ def self.scan()
10
+
11
+ opts = ARGV.getopts('','p')
12
+ target_dir = ARGV[0]
13
+
14
+
8
15
  scanner = Scanner.new(target_dir)
9
16
  files = scanner.md_files
10
17
  paths = scanner.paths(files)
11
- paths.print_deadlinks
18
+ paths.print_deadlinks(opts)
12
19
  end
13
20
  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.2.0
4
+ version: 0.3.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-10 00:00:00.000000000 Z
11
+ date: 2015-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -86,6 +86,7 @@ files:
86
86
  - deadlink.gemspec
87
87
  - exe/deadlink
88
88
  - lib/deadlink.rb
89
+ - lib/deadlink/decorator.rb
89
90
  - lib/deadlink/path.rb
90
91
  - lib/deadlink/paths.rb
91
92
  - lib/deadlink/scanner.rb