source2md 0.0.1 → 0.0.2

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: a9d5d290b79e8ad279ee4bda3e6266211431849d716d50a5af30619c86bb4dd5
4
- data.tar.gz: 90a98c2ce160304af7782b82bc48869a57fb6962ba77ade63d0f5a107dac19fd
3
+ metadata.gz: 804f40a21fe77faa747a631bd93fa6592d7bf035858fd4a8ba795f776dcb512b
4
+ data.tar.gz: 5f6d342b20388915027fa33c6d1d1a644ac5c28c56febd4e612ba318c14df375
5
5
  SHA512:
6
- metadata.gz: 5719beeb1cbc4cfd30bf5e2620dc7f23a538f283011a3c801a1a9ce50ba5d9f8c1cd34c544528743192cfbf506ed500c95f416ac9703dcabb0251f0e0763ef39
7
- data.tar.gz: 564b9a9582860c1fee3d7c6b8aac8a44a6bfffc5f898c2d4a1f634b2f23edf86523924a86df15a0d9e35e64f5f379cb27759ba2f98a90c1088cdf4a81899eab3
6
+ metadata.gz: 7dabbca4c2adf8136803fa1c1184975e1e41484620ac1350507fa196254202fcc3b5dde0f59fe31206472782274b4785048fad1b92e6ebee0873839b12b68a46
7
+ data.tar.gz: e46f3cf966becc687447b2394e9a02ba26ecd8d6ea2463049cfaf3a596f99bf5de3d5de2fbfede43db2ca2ca2c5fb206025731415ac78f5eeb93532193d03132
data/README.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Source2MD: Markdown generator from source code
2
2
 
3
+ ## Install ##
4
+
5
+ ```
6
+ $ gem i source2md
7
+ ```
8
+
9
+ ## Example ##
10
+
3
11
  input.rb:
4
12
 
5
13
  ```ruby
@@ -3,6 +3,20 @@ require "./setup"
3
3
  puts Source2MD::Element.new(<<~EOS).to_md
4
4
  ## foo
5
5
  EOS
6
+ # >> --------------------------------------------------------------------------------
7
+ # >> Source2MD::Type::ElementDeepComment
8
+ # >>
9
+ # >> head:
10
+ # >> {}
11
+ # >>
12
+ # >> in:
13
+ # >> ## foo
14
+ # >>
15
+ # >> out:
16
+ # >> ```ruby
17
+ # >> # foo
18
+ # >> ```
19
+ # >> --------------------------------------------------------------------------------
6
20
  # >> ```ruby
7
21
  # >> # foo
8
22
  # >> ```
@@ -5,6 +5,22 @@ puts Source2MD::Element.new(<<~EOS).to_md
5
5
  foo
6
6
  ---
7
7
  EOS
8
+ # >> --------------------------------------------------------------------------------
9
+ # >> Source2MD::Type::ElementMdHeader
10
+ # >>
11
+ # >> head:
12
+ # >> {}
13
+ # >>
14
+ # >> in:
15
+ # >> ---
16
+ # >> foo
17
+ # >> ---
18
+ # >>
19
+ # >> out:
20
+ # >> ---
21
+ # >> foo
22
+ # >> ---
23
+ # >> --------------------------------------------------------------------------------
8
24
  # >> ---
9
25
  # >> foo
10
26
  # >> ---
@@ -8,6 +8,30 @@ code1
8
8
  #
9
9
  code2
10
10
  EOS
11
+ # >> --------------------------------------------------------------------------------
12
+ # >> Source2MD::Type::ElementMethod
13
+ # >>
14
+ # >> head:
15
+ # >> {:name=>"(name)", :desc=>"(desc)", :comment=>"(comment)"}
16
+ # >>
17
+ # >> in:
18
+ # >> code1
19
+ # >> #
20
+ # >> code2
21
+ # >>
22
+ # >> out:
23
+ # >> ### (name)
24
+ # >>
25
+ # >> (desc)
26
+ # >>
27
+ # >> ```ruby
28
+ # >> code1
29
+ # >>
30
+ # >> code2
31
+ # >> ```
32
+ # >>
33
+ # >> (comment)
34
+ # >> --------------------------------------------------------------------------------
11
35
  # >> ### (name)
12
36
  # >>
13
37
  # >> (desc)
@@ -3,6 +3,20 @@ require "./setup"
3
3
  puts Source2MD::Element.new(<<~EOS).to_md
4
4
  code
5
5
  EOS
6
+ # >> --------------------------------------------------------------------------------
7
+ # >> Source2MD::Type::ElementPre
8
+ # >>
9
+ # >> head:
10
+ # >> {}
11
+ # >>
12
+ # >> in:
13
+ # >> code
14
+ # >>
15
+ # >> out:
16
+ # >> ```ruby
17
+ # >> code
18
+ # >> ```
19
+ # >> --------------------------------------------------------------------------------
6
20
  # >> ```ruby
7
21
  # >> code
8
22
  # >> ```
@@ -3,4 +3,15 @@ require "./setup"
3
3
  puts Source2MD::Element.new(<<~EOS).to_md
4
4
  require "setup"
5
5
  EOS
6
+ # >> --------------------------------------------------------------------------------
7
+ # >> Source2MD::Type::ElementReject
8
+ # >>
9
+ # >> head:
10
+ # >> {}
11
+ # >>
12
+ # >> in:
13
+ # >> require "setup"
14
+ # >>
15
+ # >> out:
16
+ # >> --------------------------------------------------------------------------------
6
17
  # >>
@@ -8,6 +8,26 @@ puts Source2MD::Element.new(<<~EOS).to_md
8
8
  # | x | x | x |
9
9
  # |---+---+---|
10
10
  EOS
11
+ # >> --------------------------------------------------------------------------------
12
+ # >> Source2MD::Type::ElementTable
13
+ # >>
14
+ # >> head:
15
+ # >> {}
16
+ # >>
17
+ # >> in:
18
+ # >> # |---+---+---|
19
+ # >> # | x | x | x |
20
+ # >> # |---+---+---|
21
+ # >> # | x | x | x |
22
+ # >> # | x | x | x |
23
+ # >> # |---+---+---|
24
+ # >>
25
+ # >> out:
26
+ # >> | x | x | x |
27
+ # >> |---|---|---|
28
+ # >> | x | x | x |
29
+ # >> | x | x | x |
30
+ # >> --------------------------------------------------------------------------------
11
31
  # >> | x | x | x |
12
32
  # >> |---|---|---|
13
33
  # >> | x | x | x |
@@ -4,5 +4,19 @@ puts Source2MD::Element.new(<<~EOS).to_md
4
4
  # - foo
5
5
  # https://example.com/
6
6
  EOS
7
+ # >> --------------------------------------------------------------------------------
8
+ # >> Source2MD::Type::ElementText
9
+ # >>
10
+ # >> head:
11
+ # >> {}
12
+ # >>
13
+ # >> in:
14
+ # >> # - foo
15
+ # >> # https://example.com/
16
+ # >>
17
+ # >> out:
18
+ # >> - foo
19
+ # >> https://example.com/
20
+ # >> --------------------------------------------------------------------------------
7
21
  # >> - foo
8
22
  # >> https://example.com/
@@ -3,4 +3,18 @@ require "./setup"
3
3
  puts Source2MD::Element.new(<<~EOS).to_md
4
4
  # title2: (foo)
5
5
  EOS
6
- # >> ## (foo)
6
+ # >> title2: (foo)
7
+ # >> --------------------------------------------------------------------------------
8
+ # >> Source2MD::Type::ElementTitle2
9
+ # >>
10
+ # >> head:
11
+ # >> {:title2=>"(foo)"}
12
+ # >>
13
+ # >> in:
14
+ # >>
15
+ # >>
16
+ # >> out:
17
+ # >> ## (foo) ##
18
+ # >> --------------------------------------------------------------------------------
19
+ # >> title2: (foo)
20
+ # >> ## (foo) ##
data/examples/output.md CHANGED
@@ -1,4 +1,4 @@
1
- ## (title)
1
+ ## (title) ##
2
2
 
3
3
  ### (name1)
4
4
 
data/examples/setup.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  $LOAD_PATH.unshift("#{__dir__}/../lib")
2
2
  require "source2md"
3
- Source2MD.quiet = true
3
+ Source2MD.logger.level = :debug
data/lib/source2md/cli.rb CHANGED
@@ -1,9 +1,18 @@
1
1
  module Source2MD
2
2
  class Cli < Thor
3
- class_option :debug, type: :boolean
4
- class_option :quiet, type: :boolean
3
+ class_option :debug, type: :boolean, aliases: "-d", default: false
5
4
 
6
- desc "generate [files]", "生成"
5
+ def initialize(...)
6
+ super
7
+
8
+ if options[:debug]
9
+ Source2MD.logger.level = :debug
10
+ Source2MD.debug = true
11
+ end
12
+ end
13
+
14
+ map "g" => :generate
15
+ desc "generate [files]", "Markdown generation"
7
16
  option :output_file, type: :string, aliases: "-o", default: "output.md"
8
17
  def generate(*files)
9
18
  Generator.new(options.to_options.merge(files: files)).call
@@ -0,0 +1,3 @@
1
+ module Source2MD
2
+ mattr_accessor(:logger) { ActiveSupport::Logger.new(STDOUT, level: :info) }
3
+ end
@@ -1,5 +1,5 @@
1
1
  desc "About"
2
2
  task :about do
3
3
  require "source2md"
4
- tp Source2MD::VERSION
4
+ puts Source2MD::VERSION
5
5
  end
@@ -9,6 +9,23 @@ module Source2MD
9
9
 
10
10
  def initialize(element)
11
11
  @element = element
12
+
13
+ Source2MD.logger.debug do
14
+ o = []
15
+ o << "-" * 80
16
+ o << self.class.name
17
+ o << ""
18
+ o << "head:"
19
+ o << element.head
20
+ o << ""
21
+ o << "in:"
22
+ o << element.body
23
+ o << ""
24
+ o << "out:"
25
+ o << to_md
26
+ o << "-" * 80
27
+ o.compact * "\n"
28
+ end
12
29
  end
13
30
 
14
31
  def to_md
@@ -6,10 +6,8 @@ module Source2MD
6
6
  end
7
7
 
8
8
  def to_md
9
- unless Source2MD.quiet
10
- p element.head[:title2]
11
- end
12
- "## #{element.head[:title2]}"
9
+ Source2MD.logger.info { "title2: #{element.head[:title2]}" }
10
+ "## #{element.head[:title2]} ##"
13
11
  end
14
12
  end
15
13
  end
@@ -1,3 +1,3 @@
1
1
  module Source2MD
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/source2md.rb CHANGED
@@ -1,22 +1,27 @@
1
+ require "active_support/logger"
2
+ require "active_support/isolated_execution_state"
3
+
1
4
  require "active_support/core_ext/hash"
5
+ require "active_support/core_ext/string"
6
+
2
7
  require "active_support/configurable"
3
- require "zeitwerk"
4
- require "table_format"
8
+
5
9
  require "pathname"
6
10
  require "thor"
7
11
 
8
12
  module Source2MD
9
13
  include ActiveSupport::Configurable
10
14
  config_accessor(:debug) { false }
11
- config_accessor(:quiet) { false }
12
15
  end
13
16
 
17
+ require "zeitwerk"
14
18
  loader = Zeitwerk::Loader.for_gem
19
+ loader.ignore("#{__dir__}/source2md/logger.rb")
15
20
  loader.ignore("#{__dir__}/source2md/**/_*.rb")
16
-
17
21
  loader.inflector.inflect("source2md" => "Source2MD")
18
-
19
22
  loader.log! if false
20
23
  loader.setup
21
24
 
25
+ require "source2md/logger"
26
+
22
27
  loader.eager_load if true
data/source2md.gemspec CHANGED
@@ -18,14 +18,13 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_development_dependency "bundler"
22
- spec.add_development_dependency "rake"
23
- spec.add_development_dependency "rspec"
24
- spec.add_development_dependency "test-unit"
25
-
26
21
  spec.add_dependency "zeitwerk"
27
22
  spec.add_dependency "activesupport"
28
23
  spec.add_dependency "pathname"
29
24
  spec.add_dependency "thor"
30
- spec.add_dependency "table_format"
25
+
26
+ spec.add_development_dependency "bundler"
27
+ spec.add_development_dependency "rake"
28
+ spec.add_development_dependency "rspec"
29
+ spec.add_development_dependency "test-unit"
31
30
  end
data/spec/spec_helper.rb CHANGED
@@ -8,7 +8,7 @@ Pathname.glob("#{__dir__}/support/**/*.rb") { |e| require e.to_s }
8
8
 
9
9
  Zeitwerk::Loader.eager_load_all
10
10
 
11
- Source2MD.quiet = true
11
+ Source2MD.logger.level = :error
12
12
 
13
13
  RSpec.configure do |config|
14
14
  config.expect_with :rspec do |c|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: source2md
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akira Ikeda
@@ -11,27 +11,13 @@ cert_chain: []
11
11
  date: 2023-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: bundler
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: rake
14
+ name: zeitwerk
29
15
  requirement: !ruby/object:Gem::Requirement
30
16
  requirements:
31
17
  - - ">="
32
18
  - !ruby/object:Gem::Version
33
19
  version: '0'
34
- type: :development
20
+ type: :runtime
35
21
  prerelease: false
36
22
  version_requirements: !ruby/object:Gem::Requirement
37
23
  requirements:
@@ -39,13 +25,13 @@ dependencies:
39
25
  - !ruby/object:Gem::Version
40
26
  version: '0'
41
27
  - !ruby/object:Gem::Dependency
42
- name: rspec
28
+ name: activesupport
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
31
  - - ">="
46
32
  - !ruby/object:Gem::Version
47
33
  version: '0'
48
- type: :development
34
+ type: :runtime
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
@@ -53,13 +39,13 @@ dependencies:
53
39
  - !ruby/object:Gem::Version
54
40
  version: '0'
55
41
  - !ruby/object:Gem::Dependency
56
- name: test-unit
42
+ name: pathname
57
43
  requirement: !ruby/object:Gem::Requirement
58
44
  requirements:
59
45
  - - ">="
60
46
  - !ruby/object:Gem::Version
61
47
  version: '0'
62
- type: :development
48
+ type: :runtime
63
49
  prerelease: false
64
50
  version_requirements: !ruby/object:Gem::Requirement
65
51
  requirements:
@@ -67,7 +53,7 @@ dependencies:
67
53
  - !ruby/object:Gem::Version
68
54
  version: '0'
69
55
  - !ruby/object:Gem::Dependency
70
- name: zeitwerk
56
+ name: thor
71
57
  requirement: !ruby/object:Gem::Requirement
72
58
  requirements:
73
59
  - - ">="
@@ -81,13 +67,13 @@ dependencies:
81
67
  - !ruby/object:Gem::Version
82
68
  version: '0'
83
69
  - !ruby/object:Gem::Dependency
84
- name: activesupport
70
+ name: bundler
85
71
  requirement: !ruby/object:Gem::Requirement
86
72
  requirements:
87
73
  - - ">="
88
74
  - !ruby/object:Gem::Version
89
75
  version: '0'
90
- type: :runtime
76
+ type: :development
91
77
  prerelease: false
92
78
  version_requirements: !ruby/object:Gem::Requirement
93
79
  requirements:
@@ -95,13 +81,13 @@ dependencies:
95
81
  - !ruby/object:Gem::Version
96
82
  version: '0'
97
83
  - !ruby/object:Gem::Dependency
98
- name: pathname
84
+ name: rake
99
85
  requirement: !ruby/object:Gem::Requirement
100
86
  requirements:
101
87
  - - ">="
102
88
  - !ruby/object:Gem::Version
103
89
  version: '0'
104
- type: :runtime
90
+ type: :development
105
91
  prerelease: false
106
92
  version_requirements: !ruby/object:Gem::Requirement
107
93
  requirements:
@@ -109,13 +95,13 @@ dependencies:
109
95
  - !ruby/object:Gem::Version
110
96
  version: '0'
111
97
  - !ruby/object:Gem::Dependency
112
- name: thor
98
+ name: rspec
113
99
  requirement: !ruby/object:Gem::Requirement
114
100
  requirements:
115
101
  - - ">="
116
102
  - !ruby/object:Gem::Version
117
103
  version: '0'
118
- type: :runtime
104
+ type: :development
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
107
  requirements:
@@ -123,13 +109,13 @@ dependencies:
123
109
  - !ruby/object:Gem::Version
124
110
  version: '0'
125
111
  - !ruby/object:Gem::Dependency
126
- name: table_format
112
+ name: test-unit
127
113
  requirement: !ruby/object:Gem::Requirement
128
114
  requirements:
129
115
  - - ">="
130
116
  - !ruby/object:Gem::Version
131
117
  version: '0'
132
- type: :runtime
118
+ type: :development
133
119
  prerelease: false
134
120
  version_requirements: !ruby/object:Gem::Requirement
135
121
  requirements:
@@ -144,7 +130,6 @@ extensions: []
144
130
  extra_rdoc_files: []
145
131
  files:
146
132
  - ".gitignore"
147
- - ".rspec"
148
133
  - Gemfile
149
134
  - README.md
150
135
  - Rakefile
@@ -167,10 +152,10 @@ files:
167
152
  - lib/source2md/element.rb
168
153
  - lib/source2md/file_block.rb
169
154
  - lib/source2md/generator.rb
155
+ - lib/source2md/logger.rb
170
156
  - lib/source2md/tasks/about.rake
171
157
  - lib/source2md/tasks/test.rake
172
158
  - lib/source2md/text_helper.rb
173
- - lib/source2md/type/__element_header_comment.rb
174
159
  - lib/source2md/type/base.rb
175
160
  - lib/source2md/type/element_deep_comment.rb
176
161
  - lib/source2md/type/element_md_header.rb
data/.rspec DELETED
@@ -1 +0,0 @@
1
- --color
@@ -1,40 +0,0 @@
1
- #
2
- # #- foo
3
- # 1 + 2
4
- #
5
- # ↓
6
- #
7
- # foo
8
- #
9
- # ```ruby
10
- # 1 + 2
11
- # ```
12
- #
13
- module Source2MD
14
- module Type
15
- class ElementHeaderComment < Base
16
- def self.accept?(element)
17
- element.body.match?(/^#-/)
18
- end
19
-
20
- def to_md
21
- [
22
- message,
23
- "```ruby",
24
- body,
25
- "```",
26
- ] * "\n"
27
- end
28
-
29
- private
30
-
31
- def message
32
- element.body.scan(/^#-\s*(.*)/).join
33
- end
34
-
35
- def body
36
- element.body.gsub(/^#-.*\R/, "")
37
- end
38
- end
39
- end
40
- end