source2md 0.0.11 → 0.0.12

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: 4cbcbb886c48d226f8864af1134aa3c0bdac15dcb2adf2acfd8aadb1d9b62bcc
4
- data.tar.gz: bdcdb4870afc49aeb7fbb20534a54ba44fd42bd9e1e56c2bb260babe46d9cb74
3
+ metadata.gz: 562135200c7492a703d690fe621a77ef6341567ef499a0a868033db4c93f0d72
4
+ data.tar.gz: 9bb67852ae6ae568edded0478116ea78e9e24ce58d58ce16df0c6b692f515f59
5
5
  SHA512:
6
- metadata.gz: 9fe4bde35b551e33b11a53a10df2941b3828eba7b5e91c470bae0001f26f95ab2ecb006183fb89384be8fe22d3f9b5c461917b1525e3f002800846f19ea2547a
7
- data.tar.gz: ab48da56d8bf0b4ce3755432f9ed281dbceacf67a8cdbb4663b328f614c73bdcc1680a4e03675d8ba547ff638d054f2249644fca5f52c6812b3e17c6474b523c
6
+ metadata.gz: 619ff51efb9c41fe3cbeea92774fc3e853e5c915fde446f9118f1af9c5dc6262ea510430c7e48bf338f822d3f6f58d9f2d69e095c04c035d02d63c84c6f82a1b
7
+ data.tar.gz: cf9e28c97304ba30b623a5d7f66a4c79ba47231f5ce8d3ac1c8452e5beeaba9c1f77f379be37412bc94eddceafd53261f5cf6e99020d4d7a4a230a80daf45cf1
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
- # ```yaml:config.yml
3
- # frequencies: frequencies1.rb
4
- # ```
18
+ "foo2".size # => 4
5
19
  ```
6
20
 
7
- ```ruby:frequencies1.rb
8
- def frequencies(words)
9
- words.tally.sort_by { -_2 }.take(25)
10
- end
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
  ```
data/lib/source2md/cli.rb CHANGED
@@ -34,6 +34,7 @@ module Source2MD
34
34
  map "g" => :generate
35
35
  desc "generate [files]", "Markdown generation"
36
36
  option :output_file, type: :string, aliases: "-o", default: nil
37
+ option :glob, type: :string, aliases: "-g"
37
38
  def generate(*files)
38
39
  Generator.new(options.to_options.merge(files: files)).call
39
40
  end
@@ -1,7 +1,7 @@
1
1
  module Source2MD
2
2
  class CodeBlock
3
3
  PADDING_KEEP = 2
4
- ARROW_MARK = %r{(?:#{RE.comment_re}) =>}
4
+ ARROW_MARK = %r{(?:#{RE.comment_re}) =>}
5
5
 
6
6
  def initialize(text, options = {})
7
7
  @text = text
@@ -12,14 +12,10 @@ module Source2MD
12
12
  end
13
13
 
14
14
  if output_file
15
- if output_file.exist?
16
- FileUtils.chmod("a+w", output_file)
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 ||= Array(params[:files]).collect { |e| Pathname(e).expand_path }
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,15 @@ 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
+ yield
57
+ if Source2MD.readonly
58
+ FileUtils.chmod("a-w", output_file)
59
+ end
60
+ end
49
61
  end
50
62
  end
@@ -1,3 +1,3 @@
1
1
  module Source2MD
2
- VERSION = "0.0.11"
2
+ VERSION = "0.0.12"
3
3
  end
@@ -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
@@ -18,3 +18,11 @@ RSpec.configure do |config|
18
18
  config.expect_with :test_unit
19
19
  config.example_status_persistence_file_path = "#{__dir__}/.all_test_result.txt"
20
20
  end
21
+
22
+ if true
23
+ require "tempfile" # for capture
24
+ require "active_support/testing/stream"
25
+ RSpec.configure do |config|
26
+ config.include ActiveSupport::Testing::Stream
27
+ end
28
+ 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.11
4
+ version: 0.0.12
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-08-13 00:00:00.000000000 Z
11
+ date: 2023-09-16 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.18
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
data/output.md DELETED
@@ -1,13 +0,0 @@
1
- ```ruby
2
- a
3
- ```
4
-
5
- ```ruby
6
- r.xy(); // => Vec2(0.0, 0.0)
7
- r.xy(); // => Vec2(0.0, 0.0)
8
- r.xy(); // => Vec2(0.0, 0.0)
9
- ```
10
-
11
- ```ruby
12
- b
13
- ```