qiita_org 0.1.27 → 0.1.28

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
  SHA256:
3
- metadata.gz: 8088b420419a39966c018d452aed8ab5bf063410940a2cdb38a3ae3e38fbf67a
4
- data.tar.gz: e6a0d2ea03049e2749e2f975005183b670f65a69eb8e1ef3623d3607d1c58e42
3
+ metadata.gz: 74ddc5ddc92c8e9414041e6bc9b84b7d96eccf5cc7adba92101440bf70472d65
4
+ data.tar.gz: fb223cc7d3dbbe232067a5f38dcca6d1f953064972f60307ba206b2fdccf8962
5
5
  SHA512:
6
- metadata.gz: 9c7019bfa262be33f3a51211522f2e75398bd7fa7e2bcd0384c343b65293009f144ddb12251db7382ef6fd122b81c5b27c951f42ae4ba49977cb00626a20d8c1
7
- data.tar.gz: 185a1f7d7db810d97dc86b16a2a4fe0dbd214d0be88b923e104c6664f5e8f2bb70d02c03e853d967fe56952dcd73a1c92d84b3448c5bb9980392e9f24198a8f2
6
+ metadata.gz: e4dff3873fccd45d6ee707679bb0204076b402183d59b1f4c9d40bb05fe1a27d1d50b04299ff00bf5ce9461aea560426e508ba7ba291aa80cdb548a5d2c0b494
7
+ data.tar.gz: 72896ad25f227b1cbc0992518a3173b0e2d64ee684be3d2f06db83278ba871abee3331fcd30923a88d4aa6114be93484e6f9dbe096bd5c4e9abfb69db6c1e05e
data/.gitignore CHANGED
@@ -6,6 +6,8 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ /gems/
10
+ /gems/*
9
11
  /doc/*
10
12
  !/doc/.keep
11
13
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- qiita_org (0.1.26)
4
+ qiita_org (0.1.27)
5
5
  colorize
6
6
  command_line (> 2.0.0)
7
7
  fileutils
@@ -73,7 +73,7 @@ module QiitaOrg
73
73
  p file = argv[0] || "README.org"
74
74
  p mode = argv[1] || DecideOption.new(file).decide_option()
75
75
 
76
- qiita = UpLoad.new(file, mode, os).upload()
76
+ qiita = QiitaUpLoad.new(file, mode, os).upload()
77
77
  end
78
78
  =begin
79
79
  getpath = GetFilePath.new(file)
@@ -125,7 +125,7 @@ module QiitaOrg
125
125
 
126
126
  def all(*argv)
127
127
  mode = argv[0] || false
128
- All.new(mode).run()
128
+ QiitaAll.new(mode).run()
129
129
  end
130
130
 
131
131
  desc "list [qiita/teams]", "view qiita report list"
@@ -1,6 +1,6 @@
1
1
  require "colorize"
2
2
 
3
- class All
3
+ class QiitaAll
4
4
  def initialize(mode)
5
5
  @mode = mode
6
6
  @files = Dir.glob("*.org")
@@ -159,7 +159,7 @@ EOS
159
159
  end
160
160
 
161
161
  def run()
162
- @access_token, @teams_url, @ox_qmd_load_path = SetConfig.new().set_config()
162
+ @access_token, @teams_url, @display, @ox_qmd_load_path = SetConfig.new().set_config()
163
163
  if @mode == "teams"
164
164
  ErrorMessage.new().teams_url_error(@teams_url)
165
165
  end
@@ -12,7 +12,7 @@ class GetFileUrl
12
12
  @id = id
13
13
  @file = file
14
14
  @mode = (mode == "qiita" || mode == "open")? "public" : mode
15
- @access_token, @teams_url, @ox_qmd_load_path = SetConfig.new().set_config()
15
+ @access_token, @teams_url, @display, @ox_qmd_load_path = SetConfig.new().set_config()
16
16
  if @mode == "teams"
17
17
  ErrorMessage.new().teams_url_error(@teams_url)
18
18
  end
@@ -10,7 +10,7 @@ require "qiita_org/access_qiita.rb"
10
10
  class QiitaList
11
11
  def initialize(mode)
12
12
  @mode = mode
13
- @access_token, @teams_url, @ox_qmd_load_path = SetConfig.new().set_config()
13
+ @access_token, @teams_url, @display, @ox_qmd_load_path = SetConfig.new().set_config()
14
14
  if @mode == "teams"
15
15
  ErrorMessage.new().teams_url_error(@teams_url)
16
16
  end
@@ -66,18 +66,7 @@ class QiitaPost
66
66
 
67
67
  # check twitter post
68
68
  def select_twitter(conts, option)
69
- m = []
70
- twitter = false
71
- if option == "public"
72
- m = conts.match(/\#\+(twitter|Twitter|TWITTER): (.+)/)
73
- if m[2] == 'on' || m[2] == 'On' || m[2] == 'ON'
74
- twitter = true
75
- else
76
- twitter = false
77
- end
78
- end
79
- twitter
80
- return twitter
69
+ option == "public" && conts.match?(/^\#\+twitter:\s*on$/i)
81
70
  end
82
71
 
83
72
  def select_option(option)
@@ -2,20 +2,25 @@ require "colorize"
2
2
  require "io/console"
3
3
  require "qiita_org/get_file_path.rb"
4
4
  require "qiita_org/show_file_and_url.rb"
5
+ require "qiita_org/file_open.rb"
6
+ require "qiita_org/set_config.rb"
7
+ require "qiita_org/access_qiita.rb"
5
8
 
6
- class UpLoad
9
+ class QiitaUpLoad
7
10
  def initialize(src, option, os)
8
11
  @src = src
9
12
  @option = (option == "qiita" || option == "open")? "public" : option
10
13
  @os = os
14
+ @fileopen = FileOpen.new(@os)
11
15
  end
12
16
 
13
17
  def upload()
14
18
  paths = GetFilePath.new(@src).get_file_path()
19
+ #paths = get_file_path(@src)
15
20
  unless paths.empty?
16
21
  showfile = ShowFile.new(paths, @src, @option, @os)
17
- showfile.open_file_dir()
18
- showfile.open_qiita()
22
+ showfile.open_file_dir() #open_file_dir(paths)
23
+ showfile.open_qiita() #open_qiita()
19
24
 
20
25
  puts "Overwrite file URL's on #{@src}? (y/n)".green
21
26
  ans = STDIN.getch
@@ -23,6 +28,73 @@ class UpLoad
23
28
  if ans == "y"
24
29
  showfile.input_url_to_org()
25
30
  end
31
+ else
32
+ puts "file path is empty.".red
26
33
  end
27
34
  end
35
+
36
+ def get_file_path(src)
37
+ lines = File.readlines(src)
38
+ files = []
39
+ lines.each do |line|
40
+ if path = line.match(/\[\[(.+)\]\[file:(.+)\]\]/) || line.match(/\[\[file:(.+)\]\]/)
41
+ if path[2] == nil
42
+ files << path[1]
43
+ else
44
+ files << path[2]
45
+ end
46
+ end
47
+ end
48
+
49
+ return files
50
+ end
51
+
52
+ def open_file_dir(paths)
53
+ previous_paths = []
54
+ previous_paths << File.join(paths[0].split("/")[0..-2])
55
+ @fileopen.file_open(File.join(paths[0].split("/")[0..-2]))
56
+
57
+ paths.each do |path|
58
+ dir_path = File.join(path.split("/")[0..-2])
59
+ unless previous_paths.include?(dir_path)
60
+ previous_paths << dir_path
61
+ @fileopen.file_open(dir_path)
62
+ end
63
+ end
64
+ end
65
+
66
+ def open_qiita()
67
+ conts = File.read(@src)
68
+ id = conts.match(/\#\+qiita_#{option}: (.+)/)[1]
69
+
70
+ @access_token, @teams_url, @display, @ox_qmd_load_path = SetConfig.new().set_config()
71
+ if @option == "teams"
72
+ ErrorMassage.new().teams_url_error(@teams_url)
73
+ end
74
+
75
+ qiita = (@option == "teams") ? @teams_url : "https://qiita.com/"
76
+ path = "api/v2/items/#{id}"
77
+
78
+ items = AccessQiita.new(@access_token, qiita, path).access_qiita()
79
+
80
+ @fileopen.file_open(items["url"])
81
+ end
82
+
83
+ def input_url_to_org(paths)
84
+ lines = File.readlines(@src)
85
+ conts = File.read(@src)
86
+ id = conts.match(/\#\+qiita_#{@option}: (.+)/)[1]
87
+
88
+ paths.each do |path|
89
+ file_name = File.basename(path).strip
90
+ url = get_file_url(id, file_name)
91
+ lines.each_with_index do |line, i|
92
+ if line.match(/\[\[file:#{path}\]\]/)
93
+ lines[i] = "[[#{url}][file:#{path}]]\n"
94
+ end
95
+ end
96
+ end
97
+
98
+ File.write(@src, lines.join)
99
+ end
28
100
  end
@@ -1,3 +1,3 @@
1
1
  module QiitaOrg
2
- VERSION = "0.1.27"
2
+ VERSION = "0.1.28"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qiita_org
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.27
4
+ version: 0.1.28
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kenta Yamamoto
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-11-18 00:00:00.000000000 Z
11
+ date: 2020-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler