source2md 0.0.12 → 0.0.14

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 562135200c7492a703d690fe621a77ef6341567ef499a0a868033db4c93f0d72
4
- data.tar.gz: 9bb67852ae6ae568edded0478116ea78e9e24ce58d58ce16df0c6b692f515f59
3
+ metadata.gz: 3477e280893742563cabf28b242a48d0efdc0943294c902a0fd7085950213b6a
4
+ data.tar.gz: 6a0c6f3b324fe3cd6b6d6e9fd1c038fba91dcbaf3aff742cf8f80ef2129c49a7
5
5
  SHA512:
6
- metadata.gz: 619ff51efb9c41fe3cbeea92774fc3e853e5c915fde446f9118f1af9c5dc6262ea510430c7e48bf338f822d3f6f58d9f2d69e095c04c035d02d63c84c6f82a1b
7
- data.tar.gz: cf9e28c97304ba30b623a5d7f66a4c79ba47231f5ce8d3ac1c8452e5beeaba9c1f77f379be37412bc94eddceafd53261f5cf6e99020d4d7a4a230a80daf45cf1
6
+ metadata.gz: be3fb7b9ef5f24186a2b613fd10d42d5d0bbad7781d99b9ac72251dda336b13d50737febd993f6d5ecfc0dfe83fb87930c317b3dc21475afe593e1fecea5173b
7
+ data.tar.gz: 0e68f783920b8abb32a1e405cecc4f0f881cf9bc71f4b3b2f13fff444b8272b8361d37389f10c4085b55be51c67a439d6ddbc5061bda776a4255797a9ecf1cd3
data/README.md CHANGED
@@ -32,6 +32,7 @@ puts Source2MD::Section.new(<<~EOS).to_md
32
32
  "Hello, world!"
33
33
  }
34
34
 
35
+ #+code_block_name: (name)
35
36
  hello.call
36
37
  EOS
37
38
  ```
@@ -42,7 +43,7 @@ EOS
42
43
  > }
43
44
  > ```
44
45
 
45
- > ```ruby
46
+ > ```ruby:(name)
46
47
  > hello.call
47
48
  > ```
48
49
 
@@ -11,6 +11,7 @@ puts Source2MD::Section.new(<<~EOS).to_md
11
11
  "Hello, world!"
12
12
  }
13
13
 
14
+ #+code_block_name: (name)
14
15
  hello.call
15
16
  EOS
16
17
  #+END_SRC
@@ -21,9 +22,10 @@ EOS
21
22
  # > }
22
23
  # > ```
23
24
 
24
- # > ```ruby
25
+ # > ```ruby:(name)
25
26
  # > hello.call
26
27
  # > ```
28
+
27
29
  # >> ```ruby
28
30
  # >> hello = -> {
29
31
  # >> "Hello, world!"
@@ -31,6 +33,6 @@ EOS
31
33
  # >> ```
32
34
  # >>
33
35
  # >>
34
- # >> ```ruby
36
+ # >> ```ruby:(name)
35
37
  # >> hello.call
36
38
  # >> ```
@@ -1,26 +1,49 @@
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
7
+ #+code_block_name: foo
5
8
  a
6
9
  b
7
10
  c
11
+ __END__
12
+ foo
8
13
  EOS
14
+ # >> head: {"code_block_name"=>"foo"}
15
+ # >> body: "a\n b\nc\n__END__\nfoo\n"
16
+ # >> Source2MD::Formatter::TypeHidden => false
17
+ # >> Source2MD::Formatter::TypeCodeInclude =>
18
+ # >> Source2MD::Formatter::TypeRawInclude =>
19
+ # >> Source2MD::Formatter::TypeParseInclude =>
20
+ # >> Source2MD::Formatter::TypeTitle => false
21
+ # >> Source2MD::Formatter::TypeWarn =>
22
+ # >> Source2MD::Formatter::TypeAlert =>
23
+ # >> Source2MD::Formatter::TypeMethod =>
24
+ # >> Source2MD::Formatter::TypeTable => false
25
+ # >> Source2MD::Formatter::TypeSourceBlock => false
26
+ # >> Source2MD::Formatter::TypeText => false
27
+ # >> Source2MD::Formatter::TypePartialCode => true
9
28
  # >> > -------------------------------------------------------------------------------- Source2MD::Formatter::TypePartialCode
10
- # >> > {}
29
+ # >> > {"code_block_name"=>"foo"}
11
30
  # >> > ------------------------------------------------------------ in
12
31
  # >> > a
13
32
  # >> > b
14
33
  # >> > c
34
+ # >> > __END__
35
+ # >> > foo
36
+ # >> >
15
37
  # >> >
16
38
  # >> > ------------------------------------------------------------ out
17
- # >> > ```ruby
39
+ # >> > ```ruby:foo
18
40
  # >> > a
19
41
  # >> > b
20
42
  # >> > c
21
43
  # >> > ```
44
+ # >> >
22
45
  # >> > ------------------------------------------------------------
23
- # >> ```ruby
46
+ # >> ```ruby:foo
24
47
  # >> a
25
48
  # >> b
26
49
  # >> c
data/lib/source2md/cli.rb CHANGED
@@ -1,11 +1,12 @@
1
1
  module Source2MD
2
2
  class Cli < Thor
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 :readonly, type: :boolean, aliases: "-r", default: true
6
- class_option :default_lang, type: :string, aliases: "-l", default: "ruby"
7
- class_option :prefix_re, type: :string
8
- class_option :comment_re, type: :string
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 = options[:xmp_out_exclude]
19
- Source2MD.readonly = options[:readonly]
20
- Source2MD.default_lang = options[:default_lang]
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]
@@ -6,7 +6,17 @@ module Source2MD
6
6
  end
7
7
 
8
8
  def to_md
9
- CodeBlock.new(element.body).to_md
9
+ CodeBlock.new(body, name: element.head["code_block_name"]).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
@@ -53,7 +53,9 @@ module Source2MD
53
53
  if output_file.exist?
54
54
  FileUtils.chmod("a+w", output_file)
55
55
  end
56
+
56
57
  yield
58
+
57
59
  if Source2MD.readonly
58
60
  FileUtils.chmod("a-w", output_file)
59
61
  end
@@ -1,3 +1,3 @@
1
1
  module Source2MD
2
- VERSION = "0.0.12"
2
+ VERSION = "0.0.14"
3
3
  end
data/lib/source2md.rb CHANGED
@@ -1,5 +1,5 @@
1
+ require "active_support"
1
2
  require "active_support/logger"
2
- require "active_support/isolated_execution_state"
3
3
 
4
4
  require "active_support/core_ext/hash"
5
5
  require "active_support/core_ext/string"
@@ -16,6 +16,7 @@ module Source2MD
16
16
  config_accessor(:xmp_out_exclude) { false }
17
17
  config_accessor(:readonly) { true }
18
18
  config_accessor(:default_lang) { "ruby" }
19
+ config_accessor(:data_block_exclude) { false }
19
20
  end
20
21
 
21
22
  require "zeitwerk"
@@ -4,10 +4,14 @@ module Source2MD
4
4
  describe do
5
5
  it "works" do
6
6
  actual = Element.new(<<~EOS).to_md
7
+ #+code_block_name: xxx
7
8
  (foo)
9
+ __END__
10
+ 1
11
+ 2
8
12
  EOS
9
13
  actual.should == <<~EOS
10
- ```ruby
14
+ ```ruby:xxx
11
15
  (foo)
12
16
  ```
13
17
  EOS
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|
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.12
4
+ version: 0.0.14
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-09-16 00:00:00.000000000 Z
11
+ date: 2023-10-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -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.19
253
+ rubygems_version: 3.4.20
254
254
  signing_key:
255
255
  specification_version: 4
256
256
  summary: Markdown generator from source code