source2md 0.0.11 → 0.0.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/examples/output.md +26 -7
- data/examples/type_partial_code.rb +22 -0
- data/lib/source2md/cli.rb +12 -9
- data/lib/source2md/code_block.rb +1 -1
- data/lib/source2md/formatter/type_partial_code.rb +11 -1
- data/lib/source2md/generator.rb +22 -8
- data/lib/source2md/version.rb +1 -1
- data/lib/source2md.rb +1 -0
- data/spec/formatter/type_partial_code_spec.rb +3 -0
- data/spec/generator_spec.rb +51 -0
- data/spec/spec_helper.rb +9 -0
- metadata +5 -4
- data/output.md +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 563959d92fa1520a3e09544319ff3eb9a50ac0136cc68edb290b98dc6d005e4e
|
4
|
+
data.tar.gz: 895fe538bd66ae956f5892b8278a4f7936140e78e07231d2cab7e6d926834b78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 83fc8fd71c70f95f3ccdb05b3119ea21dd6a09df913b58b254783189fefd2a370bdffd4d9becf77285ab2c7594a95b8529271f6b1587e94977ee023e4ebffbfb
|
7
|
+
data.tar.gz: 02d4b91d972ce7aeffb30dcd9af76001bbf2d2385e2082cc0db4e0e71d1e6e043930e404651dcff5e63606955b97c28b04d8d2f7b8b34963dd1426ca407528fe
|
data/examples/output.md
CHANGED
@@ -1,11 +1,30 @@
|
|
1
|
+
## (title) ##
|
2
|
+
|
3
|
+
### (name1) ###
|
4
|
+
|
5
|
+
(desc1)
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
"foo1".size # => 4
|
9
|
+
```
|
10
|
+
|
11
|
+
(comment1)
|
12
|
+
|
13
|
+
### (name2) ###
|
14
|
+
|
15
|
+
(desc2)
|
16
|
+
|
1
17
|
```ruby
|
2
|
-
#
|
3
|
-
# frequencies: frequencies1.rb
|
4
|
-
# ```
|
18
|
+
"foo2".size # => 4
|
5
19
|
```
|
6
20
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
21
|
+
(comment2)
|
22
|
+
|
23
|
+
| x | x | x |
|
24
|
+
|---|---|---|
|
25
|
+
| x | x | x |
|
26
|
+
| x | x | x |
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
1 + 2 # => 3
|
11
30
|
```
|
@@ -1,17 +1,38 @@
|
|
1
1
|
#+hidden: true
|
2
2
|
require "./setup"
|
3
3
|
|
4
|
+
Source2MD.data_block_exclude = true
|
5
|
+
|
4
6
|
puts Source2MD::Element.new(<<~EOS).to_md
|
5
7
|
a
|
6
8
|
b
|
7
9
|
c
|
10
|
+
__END__
|
11
|
+
foo
|
8
12
|
EOS
|
13
|
+
# >> head: {}
|
14
|
+
# >> body: "a\n b\nc\n__END__\nfoo\n"
|
15
|
+
# >> Source2MD::Formatter::TypeHidden => false
|
16
|
+
# >> Source2MD::Formatter::TypeCodeInclude =>
|
17
|
+
# >> Source2MD::Formatter::TypeRawInclude =>
|
18
|
+
# >> Source2MD::Formatter::TypeParseInclude =>
|
19
|
+
# >> Source2MD::Formatter::TypeTitle => false
|
20
|
+
# >> Source2MD::Formatter::TypeWarn =>
|
21
|
+
# >> Source2MD::Formatter::TypeAlert =>
|
22
|
+
# >> Source2MD::Formatter::TypeMethod =>
|
23
|
+
# >> Source2MD::Formatter::TypeTable => false
|
24
|
+
# >> Source2MD::Formatter::TypeSourceBlock => false
|
25
|
+
# >> Source2MD::Formatter::TypeText => false
|
26
|
+
# >> Source2MD::Formatter::TypePartialCode => true
|
9
27
|
# >> > -------------------------------------------------------------------------------- Source2MD::Formatter::TypePartialCode
|
10
28
|
# >> > {}
|
11
29
|
# >> > ------------------------------------------------------------ in
|
12
30
|
# >> > a
|
13
31
|
# >> > b
|
14
32
|
# >> > c
|
33
|
+
# >> > __END__
|
34
|
+
# >> > foo
|
35
|
+
# >> >
|
15
36
|
# >> >
|
16
37
|
# >> > ------------------------------------------------------------ out
|
17
38
|
# >> > ```ruby
|
@@ -19,6 +40,7 @@ EOS
|
|
19
40
|
# >> > b
|
20
41
|
# >> > c
|
21
42
|
# >> > ```
|
43
|
+
# >> >
|
22
44
|
# >> > ------------------------------------------------------------
|
23
45
|
# >> ```ruby
|
24
46
|
# >> a
|
data/lib/source2md/cli.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
module Source2MD
|
2
2
|
class Cli < Thor
|
3
|
-
class_option :debug,
|
4
|
-
class_option :xmp_out_exclude,
|
5
|
-
class_option :
|
6
|
-
class_option :
|
7
|
-
class_option :
|
8
|
-
class_option :
|
3
|
+
class_option :debug, type: :boolean, aliases: "-d", default: false
|
4
|
+
class_option :xmp_out_exclude, type: :boolean, aliases: "-x", default: false
|
5
|
+
class_option :data_block_exclude, type: :boolean, default: false
|
6
|
+
class_option :readonly, type: :boolean, aliases: "-r", default: true
|
7
|
+
class_option :default_lang, type: :string, aliases: "-l", default: "ruby"
|
8
|
+
class_option :prefix_re, type: :string
|
9
|
+
class_option :comment_re, type: :string
|
9
10
|
|
10
11
|
def initialize(...)
|
11
12
|
super
|
@@ -15,9 +16,10 @@ module Source2MD
|
|
15
16
|
Source2MD.debug = true
|
16
17
|
end
|
17
18
|
|
18
|
-
Source2MD.xmp_out_exclude
|
19
|
-
Source2MD.
|
20
|
-
Source2MD.
|
19
|
+
Source2MD.xmp_out_exclude = options[:xmp_out_exclude]
|
20
|
+
Source2MD.data_block_exclude = options[:data_block_exclude]
|
21
|
+
Source2MD.readonly = options[:readonly]
|
22
|
+
Source2MD.default_lang = options[:default_lang]
|
21
23
|
|
22
24
|
Source2MD::RE.update do |e|
|
23
25
|
if v = options[:prefix_re]
|
@@ -34,6 +36,7 @@ module Source2MD
|
|
34
36
|
map "g" => :generate
|
35
37
|
desc "generate [files]", "Markdown generation"
|
36
38
|
option :output_file, type: :string, aliases: "-o", default: nil
|
39
|
+
option :glob, type: :string, aliases: "-g"
|
37
40
|
def generate(*files)
|
38
41
|
Generator.new(options.to_options.merge(files: files)).call
|
39
42
|
end
|
data/lib/source2md/code_block.rb
CHANGED
@@ -6,7 +6,17 @@ module Source2MD
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def to_md
|
9
|
-
CodeBlock.new(
|
9
|
+
CodeBlock.new(body).to_md
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def body
|
15
|
+
if Source2MD.data_block_exclude
|
16
|
+
element.body.sub(/^__END__\R.*/m, "")
|
17
|
+
else
|
18
|
+
element.body
|
19
|
+
end
|
10
20
|
end
|
11
21
|
end
|
12
22
|
end
|
data/lib/source2md/generator.rb
CHANGED
@@ -12,14 +12,10 @@ module Source2MD
|
|
12
12
|
end
|
13
13
|
|
14
14
|
if output_file
|
15
|
-
|
16
|
-
|
15
|
+
temporarily_disable_write_protection do
|
16
|
+
output_file.write(to_md)
|
17
|
+
puts "write: #{output_file}"
|
17
18
|
end
|
18
|
-
output_file.write(to_md)
|
19
|
-
if Source2MD.readonly
|
20
|
-
FileUtils.chmod("a-w", output_file)
|
21
|
-
end
|
22
|
-
puts "write: #{output_file}"
|
23
19
|
end
|
24
20
|
end
|
25
21
|
|
@@ -36,7 +32,13 @@ module Source2MD
|
|
36
32
|
end
|
37
33
|
|
38
34
|
def files
|
39
|
-
@files ||=
|
35
|
+
@files ||= yield_self do
|
36
|
+
if params[:glob]
|
37
|
+
Pathname.glob(params[:glob])
|
38
|
+
else
|
39
|
+
Array(params[:files]).collect { |e| Pathname(e).expand_path }
|
40
|
+
end
|
41
|
+
end
|
40
42
|
end
|
41
43
|
|
42
44
|
def output_file
|
@@ -46,5 +48,17 @@ module Source2MD
|
|
46
48
|
end
|
47
49
|
end
|
48
50
|
end
|
51
|
+
|
52
|
+
def temporarily_disable_write_protection
|
53
|
+
if output_file.exist?
|
54
|
+
FileUtils.chmod("a+w", output_file)
|
55
|
+
end
|
56
|
+
|
57
|
+
yield
|
58
|
+
|
59
|
+
if Source2MD.readonly
|
60
|
+
FileUtils.chmod("a-w", output_file)
|
61
|
+
end
|
62
|
+
end
|
49
63
|
end
|
50
64
|
end
|
data/lib/source2md/version.rb
CHANGED
data/lib/source2md.rb
CHANGED
@@ -0,0 +1,51 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module Source2MD
|
4
|
+
describe Generator do
|
5
|
+
before do
|
6
|
+
Pathname("_input.rb").write("# (content)")
|
7
|
+
end
|
8
|
+
|
9
|
+
after do
|
10
|
+
Pathname("_input.rb").delete
|
11
|
+
Pathname("_output.md").delete rescue nil
|
12
|
+
end
|
13
|
+
|
14
|
+
it "files option" do
|
15
|
+
output = capture("stdout") do
|
16
|
+
Generator.new(files: ["_input.rb"]).call
|
17
|
+
end
|
18
|
+
assert { output == "(content)\n" }
|
19
|
+
end
|
20
|
+
|
21
|
+
it "glob option" do
|
22
|
+
output = capture("stdout") do
|
23
|
+
Generator.new(glob: "_i*.rb").call
|
24
|
+
end
|
25
|
+
assert { output == "(content)\n" }
|
26
|
+
end
|
27
|
+
|
28
|
+
it "output file is write protected" do
|
29
|
+
capture("stdout") do
|
30
|
+
Generator.new(files: ["_input.rb"], output_file: "_output.md").call
|
31
|
+
end
|
32
|
+
assert { Pathname("_output.md").stat.writable? == false }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
# >> .F
|
37
|
+
# >>
|
38
|
+
# >> Failures:
|
39
|
+
# >>
|
40
|
+
# >> 1) Source2MD::Generator glob option
|
41
|
+
# >> Failure/Error: Unable to find - to read failed line
|
42
|
+
# >> Test::Unit::AssertionFailedError:
|
43
|
+
# >> # -:25:in `block (2 levels) in <module:Source2MD>'
|
44
|
+
# >>
|
45
|
+
# >> Finished in 0.01412 seconds (files took 0.28313 seconds to load)
|
46
|
+
# >> 2 examples, 1 failure
|
47
|
+
# >>
|
48
|
+
# >> Failed examples:
|
49
|
+
# >>
|
50
|
+
# >> rspec -:21 # Source2MD::Generator glob option
|
51
|
+
# >>
|
data/spec/spec_helper.rb
CHANGED
@@ -10,6 +10,7 @@ Zeitwerk::Loader.eager_load_all
|
|
10
10
|
|
11
11
|
Source2MD.logger.level = :error
|
12
12
|
Source2MD.xmp_out_exclude = true
|
13
|
+
Source2MD.data_block_exclude = true
|
13
14
|
|
14
15
|
RSpec.configure do |config|
|
15
16
|
config.expect_with :rspec do |c|
|
@@ -18,3 +19,11 @@ RSpec.configure do |config|
|
|
18
19
|
config.expect_with :test_unit
|
19
20
|
config.example_status_persistence_file_path = "#{__dir__}/.all_test_result.txt"
|
20
21
|
end
|
22
|
+
|
23
|
+
if true
|
24
|
+
require "tempfile" # for capture
|
25
|
+
require "active_support/testing/stream"
|
26
|
+
RSpec.configure do |config|
|
27
|
+
config.include ActiveSupport::Testing::Stream
|
28
|
+
end
|
29
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: source2md
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Akira Ikeda
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-10-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -212,7 +212,6 @@ files:
|
|
212
212
|
- lib/source2md/tasks/test.rake
|
213
213
|
- lib/source2md/text_helper.rb
|
214
214
|
- lib/source2md/version.rb
|
215
|
-
- output.md
|
216
215
|
- source2md.gemspec
|
217
216
|
- spec/code_block_spec.rb
|
218
217
|
- spec/formatter/sample.yml
|
@@ -228,6 +227,7 @@ files:
|
|
228
227
|
- spec/formatter/type_text_spec.rb
|
229
228
|
- spec/formatter/type_title_spec.rb
|
230
229
|
- spec/formatter/type_warn_spec.rb
|
230
|
+
- spec/generator_spec.rb
|
231
231
|
- spec/scanner_spec.rb
|
232
232
|
- spec/spec_helper.rb
|
233
233
|
- spec/text_helper_spec.rb
|
@@ -250,7 +250,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
250
250
|
- !ruby/object:Gem::Version
|
251
251
|
version: '0'
|
252
252
|
requirements: []
|
253
|
-
rubygems_version: 3.4.
|
253
|
+
rubygems_version: 3.4.19
|
254
254
|
signing_key:
|
255
255
|
specification_version: 4
|
256
256
|
summary: Markdown generator from source code
|
@@ -269,6 +269,7 @@ test_files:
|
|
269
269
|
- spec/formatter/type_text_spec.rb
|
270
270
|
- spec/formatter/type_title_spec.rb
|
271
271
|
- spec/formatter/type_warn_spec.rb
|
272
|
+
- spec/generator_spec.rb
|
272
273
|
- spec/scanner_spec.rb
|
273
274
|
- spec/spec_helper.rb
|
274
275
|
- spec/text_helper_spec.rb
|