yome 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +22 -0
- data/LICENSE.txt +21 -0
- data/README.ja.md +199 -0
- data/README.md +39 -0
- data/Rakefile +14 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/yome +5 -0
- data/lib/yome.rb +2 -0
- data/lib/yome/chip.rb +54 -0
- data/lib/yome/cli.rb +34 -0
- data/lib/yome/lib.rb +12 -0
- data/lib/yome/parser.rb +40 -0
- data/lib/yome/section.rb +68 -0
- data/lib/yome/version.rb +3 -0
- data/lib/yome/writer.rb +60 -0
- data/yome.gemspec +37 -0
- metadata +110 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b6627a10cab8313680951f6198cde5e02a80b16d
|
4
|
+
data.tar.gz: '09becf528006b7184739b8debfe83c42f16bf8d6'
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 46a0e32afe42fb922264a53ab8b7be4177baaba18bd7cdff6b736318beeb1120e861822b54b00c565af388c2ecbb4b15f447826f99a089b521c6bf2a02599c93
|
7
|
+
data.tar.gz: 5adf0979c3b171a23bc93fe483b5ec76e6ac98d8b1e0a6cb5254515a23be2dcf2f42858d67f01a57b9e64208b0439055e649ef110f4d262475b37c9d2447c0bd
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
yome (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
minitest (5.11.3)
|
10
|
+
rake (10.5.0)
|
11
|
+
|
12
|
+
PLATFORMS
|
13
|
+
x64-mingw32
|
14
|
+
|
15
|
+
DEPENDENCIES
|
16
|
+
bundler (~> 1.16)
|
17
|
+
minitest (~> 5.0)
|
18
|
+
rake (~> 10.0)
|
19
|
+
yome!
|
20
|
+
|
21
|
+
BUNDLED WITH
|
22
|
+
1.16.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 ongaeshi
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.ja.md
ADDED
@@ -0,0 +1,199 @@
|
|
1
|
+
# Yome
|
2
|
+
|
3
|
+
注釈付きコメントを使ってコードリーディング文書を生成するツールです。
|
4
|
+
|
5
|
+
ソースコード内に`YOME:`という形式のマークアップを埋め込むと、テキストとソースコードを順番に並べたマークダウン文章を作成します。
|
6
|
+
|
7
|
+
## インストール
|
8
|
+
|
9
|
+
RubyGemsからインストールできます。
|
10
|
+
|
11
|
+
$ gem install yome
|
12
|
+
|
13
|
+
Windows向けにバイナリも用意しています。
|
14
|
+
ダウンロードしてパスの通った場所に置いてください。
|
15
|
+
|
16
|
+
- [Releases · ongaeshi/yome](https://github.com/ongaeshi/yome/releases/)
|
17
|
+
|
18
|
+
## 使い方
|
19
|
+
ソースコードを読みながら注釈付きコメントを記述していきます。サンプルでは[1ファイルにのみ](https://github.com/ongaeshi/yome/blob/master/test/data/simple/simple.rb)注釈付きコメントを記述していますが複数ファイルにまたがっても構いません。
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
# YOME:title Yome simple test
|
23
|
+
# YOME:summary This is a simple sample
|
24
|
+
# YOME:url https://github.com/ongaeshi/yome/tree/master/test/data/simple
|
25
|
+
|
26
|
+
# YOME:4 require
|
27
|
+
require "dir"
|
28
|
+
|
29
|
+
# YOME:1 Define class
|
30
|
+
class Simple
|
31
|
+
# YOME:3 attr_reader
|
32
|
+
attr_reader :x
|
33
|
+
|
34
|
+
# YOME:1.1 Initialize
|
35
|
+
def initialize(x)
|
36
|
+
@x = x
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
# YOME:2 Method
|
41
|
+
# YOME: The *to_double* method doubles x and returns it.
|
42
|
+
# YOME: double
|
43
|
+
def to_double
|
44
|
+
2 * x
|
45
|
+
end
|
46
|
+
end
|
47
|
+
```
|
48
|
+
|
49
|
+
コメントを付けたらyomeコマンドを実行します。注釈付きコメントと関連するコードを抜粋して数字の順に並べて表示します。
|
50
|
+
|
51
|
+
````bash
|
52
|
+
$ cd ~/src
|
53
|
+
$ yome
|
54
|
+
# Yome simple test
|
55
|
+
This is a simple sample
|
56
|
+
|
57
|
+
https://github.com/ongaeshi/yome/tree/master/test/data/simple
|
58
|
+
|
59
|
+
|
60
|
+
## Define class
|
61
|
+
*simple.rb*
|
62
|
+
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
class Simple
|
66
|
+
```
|
67
|
+
````
|
68
|
+
|
69
|
+
`-o`でファイルに出力します。
|
70
|
+
|
71
|
+
```bash
|
72
|
+
$ yome -o simple.md
|
73
|
+
```
|
74
|
+
|
75
|
+
最終出力結果は[simple.md](https://github.com/ongaeshi/yome/blob/master/test/data/simple/simple.md)です。
|
76
|
+
|
77
|
+
## リファレンスマニュアル
|
78
|
+
### YOME:no (セクション)
|
79
|
+
`YOME:`の後に空白を空けずに数字を記述するとセクションになります。自分よりの下の`YOME: (コメント)`やソースコードを1つにまとめ、数字の順にマークダウンの`##`に変換して出力されます。
|
80
|
+
|
81
|
+
数字には小数点も使えます。数値の途中が空いていてもかまいません。
|
82
|
+
|
83
|
+
```ruby
|
84
|
+
# YOME:1 First section
|
85
|
+
class Simple
|
86
|
+
# YOME:10 Second section
|
87
|
+
def foo
|
88
|
+
end
|
89
|
+
|
90
|
+
# YOME: 3 This is not a section
|
91
|
+
def bar
|
92
|
+
end
|
93
|
+
end
|
94
|
+
```
|
95
|
+
|
96
|
+
### YOME: (コメント)
|
97
|
+
`YOME:`の後に空白を空けるとコメントになります。マークダウンの段落になります。
|
98
|
+
|
99
|
+
```ruby
|
100
|
+
# YOME:1 First section
|
101
|
+
# YOME: First section's comment
|
102
|
+
class Simple
|
103
|
+
# YOME:10 Second section
|
104
|
+
# YOME: Second section's comment
|
105
|
+
# YOME: Next comment
|
106
|
+
def foo
|
107
|
+
end
|
108
|
+
end
|
109
|
+
```
|
110
|
+
|
111
|
+
### YOME:title
|
112
|
+
`YOME:title`の後に空白を空けるとタイトルになります。マークダウンの`#`に変換して出力されます。記述する場所はファイルの先頭でなくてもかまいません。
|
113
|
+
|
114
|
+
```ruby
|
115
|
+
# YOME:title Simple class
|
116
|
+
|
117
|
+
# YOME:1 First section
|
118
|
+
# YOME: First section's comment
|
119
|
+
class Simple
|
120
|
+
end
|
121
|
+
```
|
122
|
+
|
123
|
+
### YOME:summary
|
124
|
+
`YOME:summary`の後に空白を空けるとサマリーになります。マークダウンの`#`の後に段落として出力されます。記述する場所はファイルの先頭でなくてもかまいません。
|
125
|
+
|
126
|
+
```ruby
|
127
|
+
# YOME:title Simple class
|
128
|
+
# YOME:summary Behavior of simple class
|
129
|
+
|
130
|
+
# YOME:1 First section
|
131
|
+
# YOME: First section's comment
|
132
|
+
class Simple
|
133
|
+
end
|
134
|
+
```
|
135
|
+
|
136
|
+
### YOME:url
|
137
|
+
`YOME:url`の後に空白を空けるとURLになります。マークダウンの`#`の後にURLを出力します。記述する場所はファイルの先頭でなくてもかまいません。
|
138
|
+
|
139
|
+
```ruby
|
140
|
+
# YOME:title Simple class
|
141
|
+
# YOME:summary Behavior of simple class
|
142
|
+
# YOME:url https://github.com/ongaeshi/yome
|
143
|
+
|
144
|
+
# YOME:1 First section
|
145
|
+
# YOME: First section's comment
|
146
|
+
class Simple
|
147
|
+
end
|
148
|
+
```
|
149
|
+
|
150
|
+
### YOME:end
|
151
|
+
セクションのコード抜粋範囲は8行もしくは次のセクションまでです。長いコード範囲を抜粋したいときは`YOME:end`を使ってください。
|
152
|
+
|
153
|
+
```ruby
|
154
|
+
# YOME:5 YOME:end
|
155
|
+
# YOME: You can display long distance with `YOME:end`.
|
156
|
+
def long_method
|
157
|
+
1 +
|
158
|
+
2 +
|
159
|
+
3 +
|
160
|
+
4 +
|
161
|
+
5 +
|
162
|
+
6 +
|
163
|
+
7 +
|
164
|
+
8 +
|
165
|
+
9 +
|
166
|
+
10
|
167
|
+
end
|
168
|
+
# YOME:end
|
169
|
+
```
|
170
|
+
|
171
|
+
## コマンドラインオプション
|
172
|
+
ソースコードの位置、出力ファイル名、未対応のソースコード種類などを指定することができます。
|
173
|
+
|
174
|
+
```
|
175
|
+
$ yome -h
|
176
|
+
Usage: yome [DIR] [options]
|
177
|
+
-o FILE Output file name
|
178
|
+
--lang LANG Specify code blocks language
|
179
|
+
```
|
180
|
+
|
181
|
+
## Gitとの連携
|
182
|
+
yomeは単体でも使うことができますが、Gitと組み合わせるとさらに便利になります。
|
183
|
+
|
184
|
+
```
|
185
|
+
# 読みたいソースコードをclone
|
186
|
+
$ git clone https://github.com/mruby/mruby.git
|
187
|
+
$ cd mruby
|
188
|
+
|
189
|
+
# 作業用のブランチを切ると便利
|
190
|
+
$ git checkout -b yome/gc
|
191
|
+
|
192
|
+
# コメントを書き込んだら定期的にコミットしておきましょう
|
193
|
+
$ git commit
|
194
|
+
|
195
|
+
# 他のコードエリアを読むときにブランチを切り替えると
|
196
|
+
# 別のドキュメントとして生成することができます。
|
197
|
+
$ git checkout master
|
198
|
+
$ git checkout -b yome/array
|
199
|
+
```
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# Yome
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/yome`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'yome'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install yome
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/yome.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rake/testtask"
|
3
|
+
|
4
|
+
Rake::TestTask.new(:test) do |t|
|
5
|
+
t.libs << "test"
|
6
|
+
t.libs << "lib"
|
7
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
8
|
+
end
|
9
|
+
|
10
|
+
task :default => :test
|
11
|
+
|
12
|
+
task :ocra do
|
13
|
+
system "ocra exe/yome --output exe/yome.exe"
|
14
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "yome"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/exe/yome
ADDED
data/lib/yome.rb
ADDED
data/lib/yome/chip.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
module Yome
|
2
|
+
class Chip
|
3
|
+
attr_reader :kind
|
4
|
+
attr_reader :content
|
5
|
+
attr_reader :priority
|
6
|
+
attr_reader :path
|
7
|
+
attr_reader :index
|
8
|
+
attr_reader :end_index
|
9
|
+
|
10
|
+
def initialize(line, path, index)
|
11
|
+
@kind, @content = line.scan(/YOME:([\w.,]*) *(.*)/)[0]
|
12
|
+
@path = path
|
13
|
+
@index = index
|
14
|
+
|
15
|
+
if @kind == ""
|
16
|
+
@kind = "text"
|
17
|
+
else
|
18
|
+
# section?
|
19
|
+
begin
|
20
|
+
@priority = Float(@kind)
|
21
|
+
@kind = "section"
|
22
|
+
rescue ArgumentError
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def parse(parser)
|
28
|
+
file = parser.file_hash[path]
|
29
|
+
|
30
|
+
i = index + 1
|
31
|
+
while i < file.length do
|
32
|
+
if file[i] =~ /YOME:([\w.,]*) *(.*)/
|
33
|
+
truncate_using_end = true if $1 == "end"
|
34
|
+
break
|
35
|
+
end
|
36
|
+
i += 1
|
37
|
+
end
|
38
|
+
|
39
|
+
@end_index = i - 1
|
40
|
+
|
41
|
+
unless truncate_using_end
|
42
|
+
@end_index = [end_index, index + 8].min
|
43
|
+
end
|
44
|
+
|
45
|
+
while file[end_index] =~ /^\s*$/
|
46
|
+
@end_index -= 1
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def has_src?
|
51
|
+
index < end_index
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/lib/yome/cli.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require "find"
|
2
|
+
require 'optparse'
|
3
|
+
require "yome/lib"
|
4
|
+
require "yome/parser"
|
5
|
+
require "yome/writer"
|
6
|
+
require "yome/version"
|
7
|
+
|
8
|
+
module Yome
|
9
|
+
class Cli
|
10
|
+
def self.exec(argv = [])
|
11
|
+
opt = {lang: ""}
|
12
|
+
|
13
|
+
parser = OptionParser.new("Usage: yome [DIR] [options]")
|
14
|
+
parser.on('-o FILE', 'Output file name') {|v| opt[:output] = v }
|
15
|
+
parser.on('--lang LANG', 'Specify code blocks language') {|v| opt[:lang] = v }
|
16
|
+
parser.parse!(argv)
|
17
|
+
|
18
|
+
dir = argv[0] || "."
|
19
|
+
main(dir, opt)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.main(dir, opt)
|
23
|
+
parser = Parser.new(dir)
|
24
|
+
writer = Writer.new(parser, opt[:lang])
|
25
|
+
|
26
|
+
if opt[:output]
|
27
|
+
File.write(opt[:output], writer.result)
|
28
|
+
else
|
29
|
+
puts writer.result
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
data/lib/yome/lib.rb
ADDED
data/lib/yome/parser.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require "yome/lib"
|
2
|
+
require "pathname"
|
3
|
+
|
4
|
+
module Yome
|
5
|
+
class Parser
|
6
|
+
attr_reader :file_hash, :chips
|
7
|
+
|
8
|
+
def initialize(dir)
|
9
|
+
@file_hash = {}
|
10
|
+
@chips = []
|
11
|
+
|
12
|
+
collect_chips(dir)
|
13
|
+
end
|
14
|
+
|
15
|
+
def collect_chips(dir)
|
16
|
+
Dir.chdir(dir) do
|
17
|
+
Find.find(".") do |path|
|
18
|
+
Find.prune if Lib::ignore?(File.basename(path))
|
19
|
+
next if FileTest.directory?(path) || Lib::binary?(path)
|
20
|
+
|
21
|
+
begin
|
22
|
+
contents = File.read(path).split("\n")
|
23
|
+
rescue ArgumentError
|
24
|
+
STDERR.puts "Skip: #{path}"
|
25
|
+
next
|
26
|
+
end
|
27
|
+
|
28
|
+
contents.each_with_index do |line, i|
|
29
|
+
if line =~ /YOME:/
|
30
|
+
path = path.gsub(/^\.\//, "")
|
31
|
+
@file_hash[path] = contents
|
32
|
+
@chips << Chip.new(line, path, i)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
data/lib/yome/section.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
module Yome
|
2
|
+
class Section
|
3
|
+
attr_reader :section
|
4
|
+
|
5
|
+
def initialize(chip)
|
6
|
+
@section = chip
|
7
|
+
@texts = []
|
8
|
+
end
|
9
|
+
|
10
|
+
def priority
|
11
|
+
@section.priority
|
12
|
+
end
|
13
|
+
|
14
|
+
def add_text(chip)
|
15
|
+
@texts << chip
|
16
|
+
end
|
17
|
+
|
18
|
+
def result(parser, lang)
|
19
|
+
<<EOS
|
20
|
+
## #{@section.content}
|
21
|
+
*#{@section.path}*
|
22
|
+
|
23
|
+
#{src_code(parser, @section, false, lang)}
|
24
|
+
|
25
|
+
#{@texts.map { |e| src_code(parser, e, true, lang) }.join("\n")}
|
26
|
+
EOS
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def src_code(parser, chip, with_text, lang)
|
32
|
+
lang = detect_lang if lang.empty?
|
33
|
+
r = []
|
34
|
+
|
35
|
+
if with_text
|
36
|
+
r << chip.content
|
37
|
+
end
|
38
|
+
|
39
|
+
if chip.has_src?
|
40
|
+
r << ""
|
41
|
+
r << "```#{lang}"
|
42
|
+
r << parser.file_hash[chip.path][(chip.index + 1)..(chip.end_index)].join("\n")
|
43
|
+
r << "```"
|
44
|
+
end
|
45
|
+
|
46
|
+
r.join("\n")
|
47
|
+
end
|
48
|
+
|
49
|
+
LANG_HASH = {
|
50
|
+
".c" => "c",
|
51
|
+
".cpp" => "cpp",
|
52
|
+
".cs" => "csharp",
|
53
|
+
".go" => "golang",
|
54
|
+
".h" => "cpp",
|
55
|
+
".hpp" => "cpp",
|
56
|
+
".js" => "javascript",
|
57
|
+
".py" => "python",
|
58
|
+
".rb" => "ruby",
|
59
|
+
".sh" => "bash",
|
60
|
+
}
|
61
|
+
|
62
|
+
def detect_lang
|
63
|
+
ext = File.extname(@section.path)
|
64
|
+
LANG_HASH[ext]
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
data/lib/yome/version.rb
ADDED
data/lib/yome/writer.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'yome/section'
|
2
|
+
|
3
|
+
module Yome
|
4
|
+
class Writer
|
5
|
+
def initialize(parser, lang)
|
6
|
+
@title = "NO TITLE"
|
7
|
+
@parser = parser
|
8
|
+
@lang = lang
|
9
|
+
@sections = []
|
10
|
+
@texts = []
|
11
|
+
|
12
|
+
@parser.chips.each do |e|
|
13
|
+
case e.kind
|
14
|
+
when "title"
|
15
|
+
@title = e.content
|
16
|
+
when "summary"
|
17
|
+
@summary = e.content
|
18
|
+
when "url"
|
19
|
+
@url = e.content
|
20
|
+
when "section"
|
21
|
+
@sections << Section.new(e)
|
22
|
+
when "text"
|
23
|
+
@texts << e
|
24
|
+
end
|
25
|
+
|
26
|
+
e.parse(parser)
|
27
|
+
end
|
28
|
+
|
29
|
+
@texts.each do |e|
|
30
|
+
@sections.reverse.each do |sec|
|
31
|
+
if e.path == sec.section.path && e.index > sec.section.index
|
32
|
+
sec.add_text(e)
|
33
|
+
break
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def header
|
40
|
+
str = ""
|
41
|
+
str += "#{@summary}\n\n" if @summary
|
42
|
+
str += "#{@url}\n\n" if @url
|
43
|
+
end
|
44
|
+
|
45
|
+
def sections
|
46
|
+
@sections.sort_by { |e| e.priority }.map do |e|
|
47
|
+
e.result(@parser, @lang) # TODO: Auto detect lang
|
48
|
+
end.join("\n")
|
49
|
+
end
|
50
|
+
|
51
|
+
def result
|
52
|
+
<<EOS
|
53
|
+
\# #{@title}
|
54
|
+
#{header}
|
55
|
+
#{sections}
|
56
|
+
EOS
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
data/yome.gemspec
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "yome/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "yome"
|
8
|
+
spec.version = Yome::VERSION
|
9
|
+
spec.authors = ["ongaeshi"]
|
10
|
+
spec.email = ["ongaeshi0621@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Generate the source code reading document from annotated comment.}
|
13
|
+
spec.description = %q{Generate document when reading source code from annotated comment. It extracts the source code of the place written as YOME: and outputs it in Markdown format.}
|
14
|
+
spec.homepage = "https://github.com/ongaeshi/yome"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
+
"public gem pushes."
|
24
|
+
end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
f.match(%r{^(test|spec|features)/})
|
28
|
+
end
|
29
|
+
spec.bindir = "exe"
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
# spec.add_dependency 'thor'
|
34
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
35
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
36
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yome
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ongaeshi
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-08-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
description: 'Generate document when reading source code from annotated comment. It
|
56
|
+
extracts the source code of the place written as YOME: and outputs it in Markdown
|
57
|
+
format.'
|
58
|
+
email:
|
59
|
+
- ongaeshi0621@gmail.com
|
60
|
+
executables:
|
61
|
+
- yome
|
62
|
+
extensions: []
|
63
|
+
extra_rdoc_files: []
|
64
|
+
files:
|
65
|
+
- ".gitignore"
|
66
|
+
- ".travis.yml"
|
67
|
+
- Gemfile
|
68
|
+
- Gemfile.lock
|
69
|
+
- LICENSE.txt
|
70
|
+
- README.ja.md
|
71
|
+
- README.md
|
72
|
+
- Rakefile
|
73
|
+
- bin/console
|
74
|
+
- bin/setup
|
75
|
+
- exe/yome
|
76
|
+
- lib/yome.rb
|
77
|
+
- lib/yome/chip.rb
|
78
|
+
- lib/yome/cli.rb
|
79
|
+
- lib/yome/lib.rb
|
80
|
+
- lib/yome/parser.rb
|
81
|
+
- lib/yome/section.rb
|
82
|
+
- lib/yome/version.rb
|
83
|
+
- lib/yome/writer.rb
|
84
|
+
- yome.gemspec
|
85
|
+
homepage: https://github.com/ongaeshi/yome
|
86
|
+
licenses:
|
87
|
+
- MIT
|
88
|
+
metadata:
|
89
|
+
allowed_push_host: https://rubygems.org
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options: []
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
requirements: []
|
105
|
+
rubyforge_project:
|
106
|
+
rubygems_version: 2.6.14
|
107
|
+
signing_key:
|
108
|
+
specification_version: 4
|
109
|
+
summary: Generate the source code reading document from annotated comment.
|
110
|
+
test_files: []
|