qiita_org 0.1.26 → 0.1.31

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: c2e1fd7e38ef4598de9de359b8eb236d097369adf4d40b253f98b668447ed37c
4
- data.tar.gz: d9e6d0603424081e25dfae67c412f6a9f4a03b3bfdca021fdf987ca4286bb09d
3
+ metadata.gz: 1439e34745f6fe0f0711b34b6f231124bb249dd2f1adfa6973686c0ea2e6d6f1
4
+ data.tar.gz: 6ec5897e60ca99aefce238f6208eca57fa069fb89c9dc8da349e6128c78d4cb3
5
5
  SHA512:
6
- metadata.gz: 077a5547ac3bc252752583b329818a198da1738d6d667656c23959f2856bc52028a1797f1459e2ed228137f43be509c79a4f5c2ae9851ce7b9a8e3a55cc19f1d
7
- data.tar.gz: ad7c58041f824bd8c750e6e09aa5fcec8a79c29c2b714bc284267474451776802f432b2136281dd3558ce5775e06b4dcd894513ef8ff3793e447a89d0778c0ae
6
+ metadata.gz: 5638354fdec6cb35903bab5ae2b02b9843eb7ae78355e81c35402a597f5452998c46c28352fa4269b89775c4aa003f0d215b1005a5614a25da19a7aa4df2e388
7
+ data.tar.gz: d904ef610f7a455fe48bc761b80aa129adeb69be7ea1ea3536cedc9d3bd3dbac7ef4dc9b96f19328519d338aab5926031daa7016945cc8940d89266c4030360b
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.25)
4
+ qiita_org (0.1.30)
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 = QiitaFileUpLoad.new(file, mode, os).upload()
77
77
  end
78
78
  =begin
79
79
  getpath = GetFilePath.new(file)
@@ -117,15 +117,17 @@ module QiitaOrg
117
117
  def template(*argv)
118
118
  checkos = CheckPcOs.new
119
119
  os = checkos.return_os()
120
+ filename = argv[0] || "template.org"
121
+ filename = (filename.include?(".org"))? filename : "#{filename}.org"
120
122
 
121
- template = QiitaGetTemplate.new(os).run()
123
+ template = QiitaGetTemplate.new(os, filename).run()
122
124
  end
123
125
 
124
- desc "all", "post all org files in the directory"
126
+ desc "all [teams/public/private] [options]", "post all org files in the directory"
125
127
 
126
128
  def all(*argv)
127
- mode = argv[0] || false
128
- All.new(mode).run()
129
+ #mode = argv[0] || false
130
+ QiitaAll.new(argv).run()
129
131
  end
130
132
 
131
133
  desc "list [qiita/teams]", "view qiita report list"
@@ -1,14 +1,21 @@
1
1
  require "colorize"
2
2
 
3
- class All
4
- def initialize(mode)
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
@@ -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
@@ -31,7 +31,7 @@ class GetMultipleFiles
31
31
  qiita.run
32
32
  end
33
33
  elsif @type == "upload"
34
- UpLoad.new(file, mode, @os).upload()
34
+ QiitaFileUpLoad.new(file, mode, @os).upload()
35
35
  end
36
36
  end
37
37
  end
@@ -5,8 +5,9 @@ require "qiita_org/search_conf_path"
5
5
  require "qiita_org/error_message.rb"
6
6
 
7
7
  class QiitaGetTemplate
8
- def initialize(os)
8
+ def initialize(os, filename)
9
9
  @os = os
10
+ @filename = filename
10
11
  search = SearchConfPath.new(Dir.pwd, Dir.home)
11
12
  @conf_dir = search.search_conf_path()
12
13
  # check_write_header()
@@ -18,9 +19,9 @@ class QiitaGetTemplate
18
19
  m = []
19
20
  m = version.match(/ProductName:\t(.+)\nProductVersion:\t(.+)\nBuildVersion:\t(.+)\n/)
20
21
  system 'rm hoge.txt'
21
- conts = File.read("template.org")
22
+ conts = File.read(@filename)
22
23
  conts << "![#{m[1]}-#{m[2]}](https://img.shields.io/badge/#{m[1].gsub(" ", "")}-#{m[2]}-brightgreen) "
23
- File.write("template.org", conts) # + "# {m[1]}: # {m[2]}\n")
24
+ File.write(@filename, conts) # + "# {m[1]}: # {m[2]}\n")
24
25
  end
25
26
 
26
27
  def get_windowsos_version()
@@ -33,9 +34,9 @@ class QiitaGetTemplate
33
34
  m2 = version2.match(/OSArchitecture\n(.+)-bit/)
34
35
  system 'rm hoge1.txt'
35
36
  system 'rm hoge2.txt'
36
- conts = File.read("template.org")
37
+ conts = File.read(@filename)
37
38
  conts << "![#{m1[1]}-#{m1[2]}](https://img.shields.io/badge/#{m1[1].gsub(" ", "")}#{m1[2]}-#{m2[1]}bit-brightgreen) "
38
- File.write("template.org", conts) # + "# {m[1]}: # {m[2]}\n")
39
+ File.write(@filename, conts) # + "# {m[1]}: # {m[2]}\n")
39
40
  end
40
41
 
41
42
  def get_ubuntu_version()
@@ -44,9 +45,9 @@ class QiitaGetTemplate
44
45
  m = []
45
46
  m = version.match(/(.+) (.+) LTS /)
46
47
  system 'rm hoge.txt'
47
- conts = File.read("template.org")
48
+ conts = File.read(@filename)
48
49
  conts << "![#{m[1]}-#{m[2]}](https://img.shields.io/badge/#{m[1]}-#{m[2]}-brightgreen) "
49
- File.write("template.org", conts)
50
+ File.write(@filename, conts)
50
51
  end
51
52
 
52
53
  def get_ruby_version()
@@ -55,9 +56,9 @@ class QiitaGetTemplate
55
56
  m = []
56
57
  m = version.match(/ruby (.+) \((.+)/)
57
58
  system 'rm hoge.txt'
58
- conts = File.read("template.org")
59
+ conts = File.read(@filename)
59
60
  conts << "![ruby-#{m[1]}](https://img.shields.io/badge/ruby-#{m[1].gsub(" ", "")}-brightgreen) "
60
- File.write("template.org", conts) # + "ruby: # {m[1]}\n")
61
+ File.write(@filename, conts) # + "ruby: # {m[1]}\n")
61
62
  end
62
63
 
63
64
  # cp template.org
@@ -65,11 +66,11 @@ class QiitaGetTemplate
65
66
  lib = File.expand_path("../../../lib", __FILE__)
66
67
  cp_file = File.join(lib, "qiita_org", "template.org")
67
68
 
68
- if File.exists?("./template.org")
69
- puts "template.org exists.".red
69
+ if File.exists?("./#{@filename}")
70
+ puts "#{@filename} exists.".red
70
71
  exit
71
72
  else
72
- FileUtils.cp(cp_file, ".", verbose: true)
73
+ FileUtils.cp(cp_file, @filename, verbose: true)
73
74
  end
74
75
  end
75
76
 
@@ -116,19 +117,19 @@ class QiitaGetTemplate
116
117
  end
117
118
 
118
119
  def get_name()
119
- conts = File.readlines("template.org")
120
+ conts = File.readlines(@filename)
120
121
  p "Type your name"
121
122
  name = STDIN.gets
122
123
  conts[3] = "#+AUTHOR: #{name}"
123
- File.write("template.org", conts.join)
124
+ File.write(@filename, conts.join)
124
125
  end
125
126
 
126
127
  def get_email()
127
- conts = File.readlines("template.org")
128
+ conts = File.readlines(@filename)
128
129
  p "Type your email"
129
130
  email = STDIN.gets
130
131
  conts[4] = "#+EMAIL: (concat \"#{email.chomp}\")\n"
131
- File.write("template.org", conts.join)
132
+ File.write(@filename, conts.join)
132
133
  end
133
134
 
134
135
  def set_name_and_email()
@@ -136,10 +137,10 @@ class QiitaGetTemplate
136
137
  conf = JSON.load(File.read(conf_path))
137
138
  name = conf["name"]
138
139
  email = conf["email"]
139
- conts = File.readlines("template.org")
140
+ conts = File.readlines(@filename)
140
141
  conts[3] = "#+AUTHOR: #{name}\n"
141
142
  conts[4] = "#+EMAIL: (concat \"#{email}\")\n"
142
- File.write("template.org", conts.join)
143
+ File.write(@filename, conts.join)
143
144
  end
144
145
 
145
146
  def run()
@@ -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)
@@ -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)
@@ -52,7 +53,7 @@ class ShowFile
52
53
 
53
54
  @access_token, @teams_url, @display, @ox_qmd_load_path = SetConfig.new().set_config()
54
55
  if @mode == "teams"
55
- ErrorMassage.new().teams_url_error(@teams_url)
56
+ ErrorMessage.new().teams_url_error(@teams_url)
56
57
  end
57
58
 
58
59
  qiita = (@mode == "teams") ? @teams_url : "https://qiita.com/"
@@ -2,27 +2,119 @@ 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 QiitaFileUpLoad
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)
15
+ @access_token, @teams_url, @display, @ox_qmd_load_path = SetConfig.new().set_config()
16
+ if @option == "teams"
17
+ ErrorMessage.new().teams_url_error(@teams_url)
18
+ end
11
19
  end
12
20
 
13
21
  def upload()
14
- paths = GetFilePath.new(@src).get_file_path()
22
+ #paths = GetFilePath.new(@src).get_file_path()
23
+ paths = get_file_path(@src)
15
24
  unless paths.empty?
16
- showfile = ShowFile.new(paths, @src, @option, @os)
17
- showfile.open_file_dir()
18
- showfile.open_qiita()
25
+ #showfile = ShowFile.new(paths, @src, @option, @os)
26
+ #showfile.open_file_dir()
27
+ open_file_dir(paths)
28
+ #showfile.open_qiita()
29
+ open_qiita()
19
30
 
20
31
  puts "Overwrite file URL's on #{@src}? (y/n)".green
21
32
  ans = STDIN.getch
22
33
 
23
34
  if ans == "y"
24
- showfile.input_url_to_org()
35
+ #showfile.input_url_to_org()
36
+ input_url_to_org(paths)
37
+ end
38
+ else
39
+ puts "file path is empty.".red
40
+ end
41
+ end
42
+
43
+ def get_file_path(src)
44
+ lines = File.readlines(src)
45
+ files = []
46
+ lines.each do |line|
47
+ if path = line.match(/\[\[(.+)\]\[file:(.+)\]\]/) || line.match(/\[\[file:(.+)\]\]/)
48
+ if path[2] == nil
49
+ files << path[1]
50
+ else
51
+ files << path[2]
52
+ end
53
+ end
54
+ end
55
+
56
+ return files
57
+ end
58
+
59
+ def open_file_dir(paths)
60
+ previous_paths = []
61
+ previous_paths << File.join(paths[0].split("/")[0..-2])
62
+ @fileopen.file_open(File.join(paths[0].split("/")[0..-2]))
63
+
64
+ paths.each do |path|
65
+ dir_path = File.join(path.split("/")[0..-2])
66
+ unless previous_paths.include?(dir_path)
67
+ previous_paths << dir_path
68
+ @fileopen.file_open(dir_path)
69
+ end
70
+ end
71
+ end
72
+
73
+ def open_qiita()
74
+ conts = File.read(@src)
75
+ id = conts.match(/\#\+qiita_#{@option}: (.+)/)[1]
76
+
77
+ =begin
78
+ @access_token, @teams_url, @display, @ox_qmd_load_path = SetConfig.new().set_config()
79
+ if @option == "teams"
80
+ ErrorMassage.new().teams_url_error(@teams_url)
81
+ end
82
+ =end
83
+
84
+ qiita = (@option == "teams") ? @teams_url : "https://qiita.com/"
85
+ path = "api/v2/items/#{id}"
86
+
87
+ @access = AccessQiita.new(@access_token, qiita, path)
88
+ items = @access.access_qiita()
89
+
90
+ @fileopen.file_open(items["url"])
91
+ end
92
+
93
+ def input_url_to_org(paths)
94
+ lines = File.readlines(@src)
95
+ conts = File.read(@src)
96
+ id = conts.match(/\#\+qiita_#{@option}: (.+)/)[1]
97
+
98
+ paths.each do |path|
99
+ file_name = File.basename(path).strip
100
+ url = get_file_url(id, file_name)
101
+ lines.each_with_index do |line, i|
102
+ if line.match(/\[\[file:#{path}\]\]/)
103
+ lines[i] = "[[#{url}][file:#{path}]]\n"
104
+ end
25
105
  end
26
106
  end
107
+
108
+ File.write(@src, lines.join)
109
+ end
110
+
111
+ def get_file_url(id, file_name)
112
+ qiita = (@option == "teams")? @teams_url : "https://qiita.com/"
113
+ path = "api/v2/items/#{@id}"
114
+
115
+ items = @access.access_qiita()
116
+
117
+ file_url = items["body"].match(/\!\[#{file_name}\]\(((.+))\)/)[2]
118
+ return file_url
27
119
  end
28
120
  end
@@ -1,3 +1,3 @@
1
1
  module QiitaOrg
2
- VERSION = "0.1.26"
2
+ VERSION = "0.1.31"
3
3
  end
@@ -1,3 +1,4 @@
1
+ #+qiita_teams: 7e95d62ebdbedd022256
1
2
  #+qiita_private: 6ce39fa8ae7f7a472cf2
2
3
  #+OPTIONS: ^:{}
3
4
  #+STARTUP: indent nolineimages
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.26
4
+ version: 0.1.31
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-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler