html-pipeline-nico_link 0.4.0 → 0.5.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6ae571a46d4a1978dda095d9278c7e7063b2aaecfae7e0d4bb9bcfd592df94c9
4
- data.tar.gz: ea58a1fcb4bedee2d259a0923a5d605babc2a73c88bd003ead98de6331ca68b3
3
+ metadata.gz: e97d52ee866a3d14710eb88972d922aeb704bc07cf8176ae437fca9ed762e05c
4
+ data.tar.gz: 79313c428ece52f5febf205dd32d45edf89095ce5fa44463d922279b14c6e4be
5
5
  SHA512:
6
- metadata.gz: d348ab7ba43e58138d0796d8f3259e340ae3e2f09f25507329d187f3f76ee95dbecbb7eae35733c9023452059a4a503ae5b30a3da2299ac75d782b2b14f3c6c0
7
- data.tar.gz: ceda942499fc34d4a8a2bf8a0ef6a51d31234387997dae3057c7d9de28b98b5872358a14b64c7778096ab218459e4a91464d26f2f6bc730fdee323d6cf7d0217
6
+ metadata.gz: b76a18ab70ccd9ba093ba9deb3006db36615f7b2adefc2ee2246aa034cfeead09ecc802b7042a3e3831f7ddec400c4cd2d68c0fdfe72c5ffa66c72eb9fc6e7f8
7
+ data.tar.gz: c4a8ab35c272df73a7bd47afd5e69f9d88efdf628642793f206077a64a52fdc097ed08dc21982350bf445b1204980ae7199fdb4589991c34383ad6312a137a01
@@ -0,0 +1,23 @@
1
+ name: Ruby
2
+
3
+ on: [push]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ strategy:
9
+ matrix:
10
+ ruby: [ '2.4', '2.5', '2.6', '2.7' ]
11
+ name: Ruby ${{ matrix.ruby }}
12
+ steps:
13
+ - uses: actions/checkout@v2
14
+ - name: Set up Ruby ${{ matrix.ruby }}
15
+ uses: eregon/use-ruby-action@v1
16
+ with:
17
+ ruby-version: ${{ matrix.ruby }}
18
+ - name: Build and test with Rake
19
+ run: |
20
+ gem install bundler
21
+ bundle install --jobs 4 --retry 3
22
+ bundle exec rubocop
23
+ bundle exec rake
data/.gitignore CHANGED
File without changes
data/.rubocop.yml CHANGED
@@ -1,32 +1,89 @@
1
1
  AllCops:
2
2
  Exclude:
3
- - bin/**/*
4
3
  - tmp/**/*
5
4
  - vendor/**/*
5
+ TargetRubyVersion: 2.4
6
+ DisplayCopNames: true
6
7
 
7
- BlockLength:
8
+ # use japanese :)
9
+ Style/AsciiComments:
8
10
  Enabled: false
9
11
 
10
- SpecialGlobalVars:
12
+ # use method chain ( avoid use `end.compact` )
13
+ #
14
+ # hoge.map { |item|
15
+ # item.piyo
16
+ # }.compact
17
+ Style/BlockDelimiters:
11
18
  Enabled: false
12
19
 
13
- AsciiComments:
20
+ # no document
21
+ Style/Documentation:
14
22
  Enabled: false
15
23
 
16
- ClassLength:
17
- Max: 200
24
+ # use `!!hoge`
25
+ Style/DoubleNegation:
26
+ Enabled: false
18
27
 
19
- Documentation:
28
+ # empty case is useful
29
+ #
30
+ # case
31
+ # when user.admin?
32
+ # ...
33
+ # when user.active?
34
+ # ...
35
+ # else
36
+ # ...
37
+ # end
38
+ Style/EmptyCaseCondition:
20
39
  Enabled: false
21
40
 
22
- LineLength:
41
+ # my preference :)
42
+ Style/EmptyMethod:
43
+ EnforcedStyle: expanded
44
+
45
+ # use `-> {}` syntax
46
+ Style/Lambda:
47
+ Enabled: false
48
+
49
+ # see Style/BlockDelimiters
50
+ Style/MultilineBlockChain:
51
+ Enabled: false
52
+
53
+ # I feel `.zero?` difficult to understand...
54
+ Style/NumericPredicate:
55
+ Enabled: false
56
+
57
+ # %w[a b c] or %i[a b c] ?
58
+ Style/SymbolArray:
59
+ Enabled: false
60
+
61
+ # incompatible DSL
62
+ Layout/EmptyLinesAroundArguments:
63
+ Enabled: false
64
+
65
+ # my preference :)
66
+ Layout/LineLength:
23
67
  Max: 120
24
68
  Exclude:
25
69
  - spec/**/*
26
70
 
27
- MethodLength:
71
+ # :(
72
+ Metrics/AbcSize:
28
73
  Max: 30
29
74
 
30
- TrailingCommaInLiteral:
31
- EnforcedStyleForMultiline: comma
75
+ # incompatible DSL
76
+ Metrics/BlockLength:
77
+ Enabled: false
78
+
79
+ # incompatible DSL
80
+ Metrics/ClassLength:
81
+ Enabled: false
82
+
83
+ # my preference :(
84
+ Metrics/MethodLength:
85
+ Max: 25
86
+
87
+ Metrics/ParameterLists:
88
+ CountKeywordArgs: false
32
89
 
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in html-pipeline-nico_link_filter.gemspec
data/LICENSE.txt CHANGED
File without changes
data/README.md CHANGED
@@ -1,7 +1,5 @@
1
1
  # Html::Pipeline::NicoLink
2
2
 
3
- [![Build Status](https://travis-ci.org/rutan/html-pipeline-nico_link.svg?branch=master)](https://travis-ci.org/rutan/html-pipeline-nico_link)
4
-
5
3
  An HTML::Pipeline filter for niconico(http://www.nicovideo.jp) description links.
6
4
 
7
5
  niconicoの動画説明文中のオートリンクです。mylist2.jsの定義を参考にしています。
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
2
4
  require 'rspec/core/rake_task'
3
5
 
@@ -1,5 +1,6 @@
1
+ # frozen_string_literal: true
1
2
 
2
- lib = File.expand_path('../lib', __FILE__)
3
+ lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'html/pipeline/nico_link/version'
5
6
 
@@ -19,8 +20,8 @@ Gem::Specification.new do |spec|
19
20
 
20
21
  spec.add_dependency 'html-pipeline', '~> 2.4'
21
22
 
22
- spec.add_development_dependency 'bundler', '~> 1.7'
23
- spec.add_development_dependency 'rake', '~> 10.0'
24
- spec.add_development_dependency 'rspec', '~> 3.1.0'
25
- spec.add_development_dependency 'rubocop'
23
+ spec.add_development_dependency 'bundler'
24
+ spec.add_development_dependency 'rake'
25
+ spec.add_development_dependency 'rspec'
26
+ spec.add_development_dependency 'rubocop', '0.79.0'
26
27
  end
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'html/pipeline/nico_link/version'
2
4
  require 'html/pipeline/nico_link/filter'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'html/pipeline'
2
4
  require 'erb'
3
5
 
@@ -12,9 +14,11 @@ module HTML
12
14
  def call
13
15
  doc.xpath('.//text()').each do |node|
14
16
  next if has_ancestor?(node, IGNORE_PARENTS)
17
+
15
18
  content = node.to_html
16
19
  html = apply_filter(content)
17
20
  next if html == content
21
+
18
22
  node.replace(html)
19
23
  end
20
24
  doc
@@ -23,7 +27,7 @@ module HTML
23
27
  def apply_filter(content)
24
28
  content = content.dup
25
29
  content.gsub!(merged_pattern) do |text|
26
- index = $~.captures.index { |n| n }
30
+ index = Regexp.last_match.captures.index { |n| n }
27
31
  pattern_set = patterns[index]
28
32
  value = pattern_set[:convert] ? pattern_set[:convert].call(text) : text
29
33
  url = pattern_set[:link].gsub('%s', value)
@@ -37,7 +41,7 @@ module HTML
37
41
  {
38
42
  pattern: pattern_set[:pattern],
39
43
  link: pattern_set[:link],
40
- convert: pattern_set[:convert],
44
+ convert: pattern_set[:convert]
41
45
  }
42
46
  end
43
47
  end
@@ -51,93 +55,85 @@ module HTML
51
55
  DEFAULT_PATTERNS = [
52
56
  {
53
57
  pattern: /(?:sm|nm|so|ca|ax|yo|nl|ig|na|cw|z[a-e]|om|sk|yk)\d{1,14}/,
54
- link: 'http://www.nicovideo.jp/watch/%s',
58
+ link: 'http://www.nicovideo.jp/watch/%s'
55
59
  },
56
60
  {
57
- pattern: %r{(?:watch|user|myvideo|mylist)/\d{1,10}},
58
- link: 'http://www.nicovideo.jp/%s',
61
+ pattern: %r{(?:watch|user|myvideo|mylist|series)/\d{1,10}},
62
+ link: 'http://www.nicovideo.jp/%s'
59
63
  },
60
64
  {
61
65
  pattern: /co\d{1,14}/,
62
- link: 'http://com.nicovideo.jp/%s',
66
+ link: 'http://com.nicovideo.jp/%s'
63
67
  },
64
68
  {
65
69
  pattern: /ch\d{1,14}/,
66
- link: 'http://ch.nicovideo.jp/%s',
70
+ link: 'http://ch.nicovideo.jp/%s'
67
71
  },
68
72
  {
69
73
  pattern: /ar\d{1,14}/,
70
- link: 'http://ch.nicovideo.jp/article/%s',
74
+ link: 'http://ch.nicovideo.jp/article/%s'
71
75
  },
72
76
  {
73
77
  pattern: /td\d+/,
74
- link: 'http://3d.nicovideo.jp/works/%s',
78
+ link: 'http://3d.nicovideo.jp/works/%s'
75
79
  },
76
80
  {
77
81
  pattern: /nc\d{1,14}/,
78
- link: 'http://commons.nicovideo.jp/material/%s',
82
+ link: 'http://commons.nicovideo.jp/material/%s'
79
83
  },
80
84
  {
81
85
  pattern: /(?:dw\d+|az[A-Z0-9]{10}|ys[a-zA-Z0-9-]+_[a-zA-Z0-9-]+|ga\d+|ip[\d_]+|gg[a-zA-Z0-9]+-[a-zA-Z0-9-]+)/,
82
- link: 'http://ichiba.nicovideo.jp/item/%s',
86
+ link: 'http://ichiba.nicovideo.jp/item/%s'
83
87
  },
84
88
  {
85
89
  pattern: /lv\d{1,14}/,
86
- link: 'http://live.nicovideo.jp/watch/%s',
90
+ link: 'http://live.nicovideo.jp/watch/%s'
87
91
  },
88
92
  {
89
93
  pattern: /[sm]g\d{1,14}/,
90
- link: 'http://seiga.nicovideo.jp/watch/%s',
94
+ link: 'http://seiga.nicovideo.jp/watch/%s'
91
95
  },
92
96
  {
93
97
  pattern: /bk\d{1,14}/,
94
- link: 'http://seiga.nicovideo.jp/watch/%s',
98
+ link: 'http://seiga.nicovideo.jp/watch/%s'
95
99
  },
96
100
  {
97
101
  pattern: /im\d{1,14}/,
98
- link: 'http://seiga.nicovideo.jp/seiga/%s',
102
+ link: 'http://seiga.nicovideo.jp/seiga/%s'
99
103
  },
100
104
  {
101
105
  pattern: %r{commons\.nicovideo\.jp/user/\d+},
102
- link: 'http://%s',
106
+ link: 'http://%s'
103
107
  },
104
108
  {
105
109
  pattern: %r{niconicommons\.jp/user/\d+},
106
- link: 'http://www.%s',
110
+ link: 'http://www.%s'
107
111
  },
108
112
  {
109
113
  pattern: %r{user/illust/\d+},
110
- link: 'http://seiga.nicovideo.jp/%s',
114
+ link: 'http://seiga.nicovideo.jp/%s'
111
115
  },
112
116
  {
113
117
  pattern: %r{clip/\d+},
114
- link: 'http://seiga.nicovideo.jp/%s',
118
+ link: 'http://seiga.nicovideo.jp/%s'
115
119
  },
116
120
  {
117
121
  pattern: %r{ch\.nicovideo\.jp/[a-zA-Z0-9][-_a-zA-Z0-9]+(?=[^\-_A-Za-z0-9/]|$)},
118
- link: 'http://%s',
122
+ link: 'http://%s'
119
123
  },
120
124
  {
121
125
  pattern: /jps\d{1,14}/,
122
126
  link: 'http://jpstore.dwango.jp/products/detail.php?product_id=%s',
123
- convert: ->(str) { str.sub('jps', '') },
124
- },
125
- {
126
- pattern: /kn\d+/,
127
- link: 'https://niconare.nicovideo.jp/watch/%s',
127
+ convert: ->(str) { str.sub('jps', '') }
128
128
  },
129
129
  {
130
130
  pattern: /gm\d+/,
131
- link: 'https://game.nicovideo.jp/atsumaru/games/%s',
132
- },
133
- {
134
- pattern: /mt\d+/,
135
- link: 'https://mtm.nicovideo.jp/watch/%s',
131
+ link: 'https://game.nicovideo.jp/atsumaru/games/%s'
136
132
  },
137
133
  {
138
134
  pattern: /nq\d+/,
139
- link: 'https://q.nicovideo.jp/watch/%s',
140
- },
135
+ link: 'https://q.nicovideo.jp/watch/%s'
136
+ }
141
137
  ].freeze
142
138
  end
143
139
  end
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module HTML
2
4
  class Pipeline
3
5
  module NicoLink
4
- VERSION = '0.4.0'.freeze
6
+ VERSION = '0.5.0'
5
7
  end
6
8
  end
7
9
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  require 'spec_helper'
3
4
 
@@ -63,9 +64,9 @@ describe 'NicoLinkFilter' do
63
64
  sm123 watch/5321 co9999 ch1414 ar56789 td3232 nc9284 dw111 lv8864 sg9123 bk1313 im58
64
65
  commons.nicovideo.jp/user/1 niconicommons.jp/user/2
65
66
  user/illust/3 clip/555 ch.nicovideo.jp/h-p
66
- jps1111 kn1567 gm54321 nq2525
67
+ jps1111 gm54321 nq2525
67
68
  ].join(' ')
68
69
  end
69
- it { expect(subject).to eq '<a href="http://www.nicovideo.jp/watch/sm123">sm123</a> <a href="http://www.nicovideo.jp/watch/5321">watch/5321</a> <a href="http://com.nicovideo.jp/co9999">co9999</a> <a href="http://ch.nicovideo.jp/ch1414">ch1414</a> <a href="http://ch.nicovideo.jp/article/ar56789">ar56789</a> <a href="http://3d.nicovideo.jp/works/td3232">td3232</a> <a href="http://commons.nicovideo.jp/material/nc9284">nc9284</a> <a href="http://ichiba.nicovideo.jp/item/dw111">dw111</a> <a href="http://live.nicovideo.jp/watch/lv8864">lv8864</a> <a href="http://seiga.nicovideo.jp/watch/sg9123">sg9123</a> <a href="http://seiga.nicovideo.jp/watch/bk1313">bk1313</a> <a href="http://seiga.nicovideo.jp/seiga/im58">im58</a> <a href="http://commons.nicovideo.jp/user/1">commons.nicovideo.jp/user/1</a> <a href="http://www.niconicommons.jp/user/2">niconicommons.jp/user/2</a> <a href="http://seiga.nicovideo.jp/user/illust/3">user/illust/3</a> <a href="http://seiga.nicovideo.jp/clip/555">clip/555</a> <a href="http://ch.nicovideo.jp/h-p">ch.nicovideo.jp/h-p</a> <a href="http://jpstore.dwango.jp/products/detail.php?product_id=1111">jps1111</a> <a href="https://niconare.nicovideo.jp/watch/kn1567">kn1567</a> <a href="https://game.nicovideo.jp/atsumaru/games/gm54321">gm54321</a> <a href="https://q.nicovideo.jp/watch/nq2525">nq2525</a>' }
70
+ it { expect(subject).to eq '<a href="http://www.nicovideo.jp/watch/sm123">sm123</a> <a href="http://www.nicovideo.jp/watch/5321">watch/5321</a> <a href="http://com.nicovideo.jp/co9999">co9999</a> <a href="http://ch.nicovideo.jp/ch1414">ch1414</a> <a href="http://ch.nicovideo.jp/article/ar56789">ar56789</a> <a href="http://3d.nicovideo.jp/works/td3232">td3232</a> <a href="http://commons.nicovideo.jp/material/nc9284">nc9284</a> <a href="http://ichiba.nicovideo.jp/item/dw111">dw111</a> <a href="http://live.nicovideo.jp/watch/lv8864">lv8864</a> <a href="http://seiga.nicovideo.jp/watch/sg9123">sg9123</a> <a href="http://seiga.nicovideo.jp/watch/bk1313">bk1313</a> <a href="http://seiga.nicovideo.jp/seiga/im58">im58</a> <a href="http://commons.nicovideo.jp/user/1">commons.nicovideo.jp/user/1</a> <a href="http://www.niconicommons.jp/user/2">niconicommons.jp/user/2</a> <a href="http://seiga.nicovideo.jp/user/illust/3">user/illust/3</a> <a href="http://seiga.nicovideo.jp/clip/555">clip/555</a> <a href="http://ch.nicovideo.jp/h-p">ch.nicovideo.jp/h-p</a> <a href="http://jpstore.dwango.jp/products/detail.php?product_id=1111">jps1111</a> <a href="https://game.nicovideo.jp/atsumaru/games/gm54321">gm54321</a> <a href="https://q.nicovideo.jp/watch/nq2525">nq2525</a>' }
70
71
  end
71
72
  end
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rspec'
2
4
  require 'html/pipeline/nico_link'
3
5
 
4
- Dir.glob('./support/**/*.rb').each { |f| require f }
6
+ Dir.glob('./support/**/*.rb').sort.each { |f| require f }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: html-pipeline-nico_link
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ru_shalm
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-18 00:00:00.000000000 Z
11
+ date: 2020-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: html-pipeline
@@ -28,58 +28,58 @@ dependencies:
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '1.7'
33
+ version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '1.7'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '10.0'
47
+ version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '10.0'
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: 3.1.0
61
+ version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: 3.1.0
68
+ version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rubocop
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - '='
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: 0.79.0
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - '='
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: 0.79.0
83
83
  description:
84
84
  email:
85
85
  - ru_shalm@hazimu.com
@@ -87,9 +87,9 @@ executables: []
87
87
  extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
+ - ".github/workflows/ruby.yml"
90
91
  - ".gitignore"
91
92
  - ".rubocop.yml"
92
- - ".travis.yml"
93
93
  - Gemfile
94
94
  - LICENSE.txt
95
95
  - README.md
@@ -119,8 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
119
  - !ruby/object:Gem::Version
120
120
  version: '0'
121
121
  requirements: []
122
- rubyforge_project:
123
- rubygems_version: 2.7.6
122
+ rubygems_version: 3.0.3
124
123
  signing_key:
125
124
  specification_version: 4
126
125
  summary: niconico link for html-pipeline
data/.travis.yml DELETED
@@ -1,13 +0,0 @@
1
- language: ruby
2
- cache: bundler
3
- rvm:
4
- - 2.2.2
5
- - 2.3.0
6
- - 2.4.0
7
- - ruby-head
8
- before_install:
9
- - gem install bundler
10
- script:
11
- - bundle exec rubocop
12
- - bundle exec rake
13
-