helpline 0.1.16 → 0.1.17

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/exe/helpline +122 -87
  3. data/lib/helpline/version.rb +1 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f13cbb8ab1cdc392967b923b617a74f32fecf8611a773a5e3e90ebdb00780a8c
4
- data.tar.gz: f79fc13c44a79abab9e47777dc79addd7969d528020f0998629c3e16c0d91935
3
+ metadata.gz: 3b2bc48034db45fc57d3f69b5d992dc7ab045e7acf82d48fe0f225398ee6fdb9
4
+ data.tar.gz: f2f1cfcfb59fd2c7cbafd8ac650cf569caac793d3ebf3821b8032a9529370acf
5
5
  SHA512:
6
- metadata.gz: e63285e9c8bd43c2b9a5be748a23c48dda8188f88867f9fcce595d3863faf591d17abc155a281178b51fe9ac2db75ad810ce7ec0f2cf84901d3ba007c8558d69
7
- data.tar.gz: 339f2677a690a08a7a2ea7c4fb76737451f64ceae9dde0efb437c64016f40c68aba379564867ca3334ebfbdaee4e0d9765ce60f1df22c1344a70f87847eba8c4
6
+ metadata.gz: 3c646c3edc7b3c5ca9120db0802e446ffdae29e76e475d228feb23fcc5a43568a7f237be646f2f8e1ff1399d6b43dbe69e0d186324d4c3ad6456528cfda4a19a
7
+ data.tar.gz: 791d893b90bc215c7ee063db030d17f7b0549af829683d59d59a7af54e3a4bc4650462a1854f261681e39211d17695af2b3f940039ce19682f035a8dfb13ef5f
@@ -20,74 +20,100 @@ class HelpLine
20
20
  end
21
21
 
22
22
  def initialize
23
- @pagedata = {}
24
- @project = Scrapbox::Project.new("HelpLine")
23
+ # @pagedata = {}
24
+ # @project = Scrapbox::Project.new("HelpLine")
25
25
  end
26
26
 
27
- def getdata
28
- #
29
- # ページデータ取得
30
- #
31
- puts "-----------------ページデータを取得"
32
- @project.pages.each { |title,page|
33
- puts "...#{title}"
34
- @pagedata[title] = page.text.split(/\n/)
35
- }
36
-
27
+ def update(sources) # sources = ['HelpLine', '~/ScrapboxData/masui.json', ...]
37
28
  dumpdata = {}
38
29
  dumpdata['codes'] = []
39
30
  dumpdata['defs'] = []
40
31
  dumpdata['pages'] = []
41
32
 
42
- #
43
- # 関数/定数を評価"
44
- #
45
- puts "-----------------関数/定数を取得"
46
- @pagedata.each { |title,pagedata|
47
- puts "...#{title}"
48
- pagedata. each { |line|
49
- if line =~ /code:(.*\.rb)$/ then
50
- src = $1
51
- puts "=========== #{src}"
52
- page = Scrapbox::Page.new(@project,title)
53
- dumpdata['codes'] << page.code(src)
33
+ sources.each { |source|
34
+ pagedata = {}
35
+ source = File.expand_path(source)
36
+ if File.exist?(source)
37
+ puts "-----------------ページデータをJSONデータ(#{source})から取得"
38
+ data = JSON.parse(File.read(source))
39
+ data['pages'].each { |page|
40
+ title = page['title']
41
+ puts "...#{title}"
42
+ pagedata[title] = page['lines']
43
+ }
44
+ elsif source =~ /^[a-zA-Z\-]+$/ # たぶんHelpLineプロジェクト
45
+ puts "-----------------ページデータをScrapbox(#{source})から取得"
46
+ project = Scrapbox::Project.new(source)
47
+ project.pages.each { |title,page|
48
+ puts "...#{title}"
49
+ pagedata[title] = page.text.split(/\n/)
50
+ }
51
+ else
52
+ next
53
+ end
54
+
55
+ #
56
+ # 関数/定数を評価"
57
+ #
58
+ puts "-----------------関数/定数を取得"
59
+ src = nil
60
+ indent = ''
61
+ code = []
62
+ pagedata.each { |title,lines|
63
+ puts "...#{title}"
64
+ lines.each { |line|
65
+ if src && line =~ /^#{indent}\s+/ then
66
+ code << line
67
+ elsif line =~ /^code:(.*\.rb)$/ then
68
+ src = $2
69
+ indent = $1
70
+ code = []
71
+ elsif src then
72
+ dumpdata['codes'] << code.join("\n")
73
+ src = nil
74
+ indent = ''
75
+ code = []
76
+ else
77
+ end
78
+ }
79
+ if code.length > 0
80
+ dumpdata['codes'] << code.join("\n")
54
81
  end
55
82
  }
56
- }
57
- puts "-----------------HelpLineデータを検出"
58
- @pagedata.each { |title,pagedata|
59
- puts "...#{title}"
60
- dumpdata['pages'] << title
61
- processing_defs = false
62
- codeindent = nil
63
- pagedata.each { |line|
64
- if !codeindent
65
- if line =~ /^(\s*)code:/
66
- codeindent = $1.length
67
- next
68
- end
69
- else
70
- line =~ /^(\s*)/
71
- if line.length < codeindent
72
- codeindent = nil
83
+ puts "-----------------HelpLineデータを検出"
84
+ pagedata.each { |title,pagedata|
85
+ puts "...#{title}"
86
+ dumpdata['pages'] << title
87
+ processing_defs = false
88
+ codeindent = nil
89
+ pagedata.each { |line|
90
+ if !codeindent
91
+ if line =~ /^code:/
92
+ codeindent = $1.length
93
+ next
94
+ end
73
95
  else
74
- next
96
+ line =~ /^(\s*)/
97
+ if line.length < codeindent
98
+ codeindent = nil
99
+ else
100
+ next
101
+ end
75
102
  end
76
- end
77
- if line =~ /^\s*[\$\%\?]/
78
- puts line
79
- if line =~ /^\%/ && !processing_defs
80
- puts "'$'で始まる用例定義なしでコマンドを定義しようとしています"
81
- exit
103
+ if line =~ /^\s*[\$\%\?]/
104
+ if line =~ /^\%/ && !processing_defs
105
+ puts "'$'で始まる用例定義なしでコマンドを定義しようとしています"
106
+ exit
107
+ end
108
+ dumpdata['defs'] << "#{line} {#{dumpdata['pages'].length-1}}"
109
+ processing_defs = true
110
+ else
111
+ processing_defs = false
82
112
  end
83
- dumpdata['defs'] << "#{line} {#{dumpdata['pages'].length-1}}"
84
- processing_defs = true
85
- else
86
- processing_defs = false
87
- end
113
+ }
88
114
  }
89
115
  }
90
-
116
+
91
117
  File.open(datafile,"w"){ |f|
92
118
  f.puts dumpdata.to_json
93
119
  }
@@ -109,14 +135,12 @@ class HelpLine
109
135
  Curses.print " % " + list[i][1]
110
136
  }
111
137
  Curses.move(sel*2,0)
112
- # Curses.down
113
- # Curses.tol
114
138
  end
115
139
 
116
- def helpline(options)
140
+ def helpline(sources,test=nil,debug=nil)
117
141
  data = JSON.parse(File.read(datafile))
118
142
  unless data['pages'] # データ型式変換があったので
119
- getdata
143
+ update sources
120
144
  data = JSON.parse(File.read(datafile))
121
145
  end
122
146
 
@@ -133,23 +157,24 @@ class HelpLine
133
157
  # HelpLineエントリ
134
158
  #
135
159
 
136
- # File.open("/tmp/defs","w"){ |f| # ログを残す場合
137
-
138
- entries = []
139
- data['defs'].each { |line|
140
- if line =~ /^\s*[\$\?]\s*(.*)$/ # $....
141
- entries << $1
142
- elsif line =~ /^\s*\%\s*(.*)$/ # %....
143
- cmd = $1
144
- entries.each { |l|
145
- desc = eval('"' + l + '"')
146
- # f.puts "desc #{desc}"
147
- g.add desc.force_encoding('utf-8'), cmd.force_encoding('utf-8')
148
- }
149
- entries = []
150
- end
160
+ logfile = (debug ? "/tmp/helpline-defs" : "/dev/null")
161
+ File.open(logfile,"w"){ |f| # ログを残す場合
162
+ entries = []
163
+ data['defs'].each { |line|
164
+ if line =~ /^\s*[\$\?]\s*(.*)$/ # $....
165
+ entries << $1
166
+ elsif line =~ /^\s*\%\s*(.*)$/ # %....
167
+ cmd = $1
168
+ entries.each { |l|
169
+ desc = eval('"' + l + '"')
170
+ f.puts "desc: #{desc}"
171
+ g.add desc.force_encoding('utf-8'), cmd.force_encoding('utf-8')
172
+ }
173
+ f.puts "cmd: #{cmd}"
174
+ entries = []
175
+ end
176
+ }
151
177
  }
152
- # }
153
178
 
154
179
  res = g.generate " #{ARGV.join(' ').sub(/\[/,'').sub(/\]/,'')} "
155
180
 
@@ -179,7 +204,8 @@ class HelpLine
179
204
  end
180
205
  }
181
206
 
182
- if options['t'] then
207
+ # if options['t'] || options['test'] then
208
+ if test
183
209
  puts list
184
210
  exit
185
211
  end
@@ -253,23 +279,32 @@ class HelpLine
253
279
  end
254
280
  end
255
281
 
256
- # is_repository = system 'git rev-parse --git-dir > /dev/null >& /dev/null'
257
- # unless is_repository
258
- # STDERR.puts "Gitレポジトリで実行して下さい"
259
- # exit
260
- # end
261
-
262
- options = ARGV.getopts('ut')
282
+ # アップデート
283
+ # % helpline -u
284
+ # データを指定してアップデート
285
+ # % helpline -u -s HelpLine,/Users/masui/ScrapboxData/masui-HelpLine.json
286
+ # テスト
287
+ # % helpline -t
288
+ #
263
289
 
264
290
  helpline = HelpLine.new
265
291
 
266
- if !File.exist?(helpline.datafile) && !options['u']
292
+ options = ARGV.getopts('utds:','update','test','source:','debug')
293
+ update = options['u'] || options['update']
294
+ test = options['t'] || options['test']
295
+ debug = options['d'] || options['debug']
296
+ sources = ['HelpLine']
297
+ if options['s'] || options['source']
298
+ sources = (options['s'] || options['source']).split(/,/)
299
+ end
300
+
301
+ if !File.exist?(helpline.datafile) && !update
267
302
  puts "#{helpline.datafile}を作成します..."
268
- helpline.getdata
303
+ helpline.update sources
269
304
  end
270
305
 
271
- if options['u'] then
272
- helpline.getdata
306
+ if update then
307
+ helpline.update sources
273
308
  else
274
- helpline.helpline(options)
309
+ helpline.helpline sources, test, debug
275
310
  end
@@ -1,3 +1,3 @@
1
1
  module Helpline
2
- VERSION = "0.1.16"
2
+ VERSION = "0.1.17"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: helpline
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.16
4
+ version: 0.1.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Toshiyuki Masui