qiita_org 0.1.25 → 0.1.30
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/Gemfile.lock +1 -1
- data/lib/qiita_org.rb +4 -4
- data/lib/qiita_org/.qiita.conf +1 -0
- data/lib/qiita_org/all.rb +26 -3
- data/lib/qiita_org/config.json +1 -0
- data/lib/qiita_org/get.rb +1 -1
- data/lib/qiita_org/get_file_url.rb +1 -1
- data/lib/qiita_org/list.rb +1 -1
- data/lib/qiita_org/post.rb +6 -14
- data/lib/qiita_org/set_config.rb +2 -1
- data/lib/qiita_org/show_file_and_url.rb +3 -2
- data/lib/qiita_org/upload.rb +75 -3
- data/lib/qiita_org/version.rb +1 -1
- data/tests/template.org +14 -0
- data/tests/test.org +1 -1
- data/tests/test2.org +1 -0
- data/tests/twitter_test.org +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f288634b1ce2de7e2a34ddc3fd7399cdb2a1b9e63e6d4b2523ec7cf3fc84601
|
4
|
+
data.tar.gz: a08fb2191f4e6cc80e3c40701df53bae8ae983cfaa225dfba57ede608d846c97
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d01c3f1937f7033f7e4a7e2989492251bc53e18e1717ba394a0385afefc217df08a756c61a3cb580e24139199de80ef065d34019d122f00443359879b3cc865
|
7
|
+
data.tar.gz: afd6c322d5d5de441b55b5784e630ca9c401b5f028ce7636d68a8b12dfec8a3b0feb07dd8d458043077e1d3130a65a617f946784be87266a8044c26db18595b7
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
data/lib/qiita_org.rb
CHANGED
@@ -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 =
|
76
|
+
qiita = QiitaUpLoad.new(file, mode, os).upload()
|
77
77
|
end
|
78
78
|
=begin
|
79
79
|
getpath = GetFilePath.new(file)
|
@@ -121,11 +121,11 @@ module QiitaOrg
|
|
121
121
|
template = QiitaGetTemplate.new(os).run()
|
122
122
|
end
|
123
123
|
|
124
|
-
desc "all", "post all org files in the directory"
|
124
|
+
desc "all [teams/public/private] [options]", "post all org files in the directory"
|
125
125
|
|
126
126
|
def all(*argv)
|
127
|
-
mode = argv[0] || false
|
128
|
-
|
127
|
+
#mode = argv[0] || false
|
128
|
+
QiitaAll.new(argv).run()
|
129
129
|
end
|
130
130
|
|
131
131
|
desc "list [qiita/teams]", "view qiita report list"
|
data/lib/qiita_org/.qiita.conf
CHANGED
data/lib/qiita_org/all.rb
CHANGED
@@ -1,14 +1,21 @@
|
|
1
1
|
require "colorize"
|
2
2
|
|
3
|
-
class
|
4
|
-
def initialize(
|
5
|
-
@mode = mode
|
3
|
+
class QiitaAll
|
4
|
+
def initialize(argv)
|
5
|
+
# @mode = mode
|
6
|
+
check_options(argv)
|
6
7
|
@files = Dir.glob("*.org")
|
7
8
|
p @files
|
8
9
|
end
|
9
10
|
|
10
11
|
def run()
|
11
12
|
@files.each do |file|
|
13
|
+
unless @exclude_files.empty?
|
14
|
+
if @exclude_files.include?(file)
|
15
|
+
next
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
12
19
|
unless @mode
|
13
20
|
puts file.blue
|
14
21
|
if File.read(file).match(/#\+qiita_(.+)/)
|
@@ -24,4 +31,20 @@ class All
|
|
24
31
|
end
|
25
32
|
end
|
26
33
|
end
|
34
|
+
|
35
|
+
def check_options(string)
|
36
|
+
["teams", "private", "public"].each do |i|
|
37
|
+
if string.include?(i)
|
38
|
+
@mode = i
|
39
|
+
break
|
40
|
+
else
|
41
|
+
@mode = false
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
@exclude_files = []
|
46
|
+
if string.include?("--exclude")
|
47
|
+
@exclude_files = string.grep(/.org/)
|
48
|
+
end
|
49
|
+
end
|
27
50
|
end
|
data/lib/qiita_org/config.json
CHANGED
data/lib/qiita_org/get.rb
CHANGED
@@ -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
|
data/lib/qiita_org/list.rb
CHANGED
@@ -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
|
data/lib/qiita_org/post.rb
CHANGED
@@ -66,18 +66,7 @@ class QiitaPost
|
|
66
66
|
|
67
67
|
# check twitter post
|
68
68
|
def select_twitter(conts, option)
|
69
|
-
|
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)
|
@@ -144,6 +133,9 @@ class QiitaPost
|
|
144
133
|
end
|
145
134
|
print "%20s %s\n" % [key, cont]
|
146
135
|
end
|
136
|
+
#if @display == "suppress"
|
137
|
+
# puts @res_body["url"].green
|
138
|
+
#end
|
147
139
|
end
|
148
140
|
|
149
141
|
# add qiita_id on src.org
|
@@ -171,7 +163,7 @@ class QiitaPost
|
|
171
163
|
def run()
|
172
164
|
@conts = File.read(@src)
|
173
165
|
@title, @tags = get_title_tags(@conts)
|
174
|
-
@access_token, @teams_url, @ox_qmd_load_path = SetConfig.new().set_config()
|
166
|
+
@access_token, @teams_url, @display, @ox_qmd_load_path = SetConfig.new().set_config()
|
175
167
|
|
176
168
|
if @option == "teams"
|
177
169
|
ErrorMessage.new().teams_url_error(@teams_url)
|
@@ -187,7 +179,7 @@ class QiitaPost
|
|
187
179
|
get_and_print_qiita_return()
|
188
180
|
|
189
181
|
#open_qiita()
|
190
|
-
FileOpen.new(@os).file_open(@res_body["url"])
|
182
|
+
FileOpen.new(@os).file_open(@res_body["url"]) if @display != "suppress"
|
191
183
|
|
192
184
|
add_qiita_id_on_org()
|
193
185
|
|
data/lib/qiita_org/set_config.rb
CHANGED
@@ -18,12 +18,13 @@ class SetConfig
|
|
18
18
|
conf = JSON.load(File.read(conf_path))
|
19
19
|
access_token = conf["access_token"]
|
20
20
|
teams_url = conf["teams_url"]
|
21
|
+
display = conf["display"]
|
21
22
|
ox_qmd_load_path = File.join(@lib, "qiita_org", "ox-qmd", "ox-qmd")
|
22
23
|
|
23
24
|
ErrorMessage.new().access_token_error(access_token) #== false
|
24
25
|
# puts "Please setting ACCESS_TOKEN".red
|
25
26
|
# exit
|
26
27
|
|
27
|
-
return access_token, teams_url, ox_qmd_load_path
|
28
|
+
return access_token, teams_url, display, ox_qmd_load_path
|
28
29
|
end
|
29
30
|
end
|
@@ -3,6 +3,7 @@ require "qiita_org/get_file_url.rb"
|
|
3
3
|
require "qiita_org/set_config.rb"
|
4
4
|
require "qiita_org/access_qiita.rb"
|
5
5
|
require "qiita_org/file_open.rb"
|
6
|
+
require "qiita_org/error_message.rb"
|
6
7
|
|
7
8
|
class ShowFile
|
8
9
|
def initialize(paths, src, mode, os)
|
@@ -50,9 +51,9 @@ class ShowFile
|
|
50
51
|
conts = File.read(@src)
|
51
52
|
id = conts.match(/\#\+qiita_#{@mode}: (.+)/)[1]
|
52
53
|
|
53
|
-
@access_token, @teams_url, @ox_qmd_load_path = SetConfig.new().set_config()
|
54
|
+
@access_token, @teams_url, @display, @ox_qmd_load_path = SetConfig.new().set_config()
|
54
55
|
if @mode == "teams"
|
55
|
-
|
56
|
+
ErrorMessage.new().teams_url_error(@teams_url)
|
56
57
|
end
|
57
58
|
|
58
59
|
qiita = (@mode == "teams") ? @teams_url : "https://qiita.com/"
|
data/lib/qiita_org/upload.rb
CHANGED
@@ -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
|
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
|
data/lib/qiita_org/version.rb
CHANGED
data/tests/template.org
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#+qiita_private: baededc5aa906407da33
|
2
|
+
#+OPTIONS: ^:{}
|
3
|
+
#+STARTUP: indent nolineimages
|
4
|
+
#+TITLE: title
|
5
|
+
#+AUTHOR: Kenta Yamamoto
|
6
|
+
#+EMAIL: (concat "doi35077@kwansei.ac.jp")
|
7
|
+
#+LANGUAGE: jp
|
8
|
+
# +OPTIONS: H:4 toc:t num:2
|
9
|
+
#+OPTIONS: toc:nil
|
10
|
+
#+TAG: tag1, tag2
|
11
|
+
#+TWITTER: off
|
12
|
+
# +SETUPFILE: ~/.emacs.d/org-mode/theme-readtheorg.setup
|
13
|
+
|
14
|
+
![Mac OS X-10.13.3](https://img.shields.io/badge/MacOSX-10.13.3-brightgreen) ![ruby-2.7.0p0](https://img.shields.io/badge/ruby-2.7.0p0-brightgreen)
|
data/tests/test.org
CHANGED
data/tests/test2.org
CHANGED
data/tests/twitter_test.org
CHANGED
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.
|
4
|
+
version: 0.1.30
|
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-
|
11
|
+
date: 2020-11-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -2583,6 +2583,7 @@ files:
|
|
2583
2583
|
- lib/qiita_org/version.rb
|
2584
2584
|
- qiita_org.gemspec
|
2585
2585
|
- tests/hoge.rb
|
2586
|
+
- tests/template.org
|
2586
2587
|
- tests/test.html
|
2587
2588
|
- tests/test.org
|
2588
2589
|
- tests/test2.org
|