source2md 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +4 -0
  3. data/.rspec +1 -0
  4. data/Gemfile +2 -0
  5. data/README.md +61 -0
  6. data/Rakefile +3 -0
  7. data/bin/source2md +3 -0
  8. data/examples/cli.rb +3 -0
  9. data/examples/element_deep_comment.rb +8 -0
  10. data/examples/element_md_header.rb +10 -0
  11. data/examples/element_method.rb +21 -0
  12. data/examples/element_pre.rb +8 -0
  13. data/examples/element_reject.rb +6 -0
  14. data/examples/element_table.rb +14 -0
  15. data/examples/element_text.rb +8 -0
  16. data/examples/element_title2.rb +6 -0
  17. data/examples/input.rb +18 -0
  18. data/examples/output.md +26 -0
  19. data/examples/setup.rb +3 -0
  20. data/lib/source2md/cli.rb +12 -0
  21. data/lib/source2md/code_block.rb +56 -0
  22. data/lib/source2md/element.rb +38 -0
  23. data/lib/source2md/file_block.rb +20 -0
  24. data/lib/source2md/generator.rb +34 -0
  25. data/lib/source2md/tasks/about.rake +5 -0
  26. data/lib/source2md/tasks/test.rake +5 -0
  27. data/lib/source2md/text_helper.rb +13 -0
  28. data/lib/source2md/type/__element_header_comment.rb +40 -0
  29. data/lib/source2md/type/base.rb +18 -0
  30. data/lib/source2md/type/element_deep_comment.rb +19 -0
  31. data/lib/source2md/type/element_md_header.rb +13 -0
  32. data/lib/source2md/type/element_method.rb +24 -0
  33. data/lib/source2md/type/element_pre.rb +13 -0
  34. data/lib/source2md/type/element_reject.rb +12 -0
  35. data/lib/source2md/type/element_table.rb +17 -0
  36. data/lib/source2md/type/element_text.rb +26 -0
  37. data/lib/source2md/type/element_title2.rb +16 -0
  38. data/lib/source2md/version.rb +3 -0
  39. data/lib/source2md.rb +22 -0
  40. data/source2md.gemspec +31 -0
  41. data/spec/code_block_spec.rb +22 -0
  42. data/spec/spec_helper.rb +19 -0
  43. data/spec/type/element_deep_comment_spec.rb +16 -0
  44. data/spec/type/element_md_header_spec.rb +34 -0
  45. data/spec/type/element_method_spec.rb +29 -0
  46. data/spec/type/element_pre_spec.rb +16 -0
  47. data/spec/type/element_reject_spec.rb +12 -0
  48. data/spec/type/element_table_spec.rb +22 -0
  49. data/spec/type/element_text_spec.rb +18 -0
  50. data/spec/type/element_title2_spec.rb +14 -0
  51. metadata +228 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a9d5d290b79e8ad279ee4bda3e6266211431849d716d50a5af30619c86bb4dd5
4
+ data.tar.gz: 90a98c2ce160304af7782b82bc48869a57fb6962ba77ade63d0f5a107dac19fd
5
+ SHA512:
6
+ metadata.gz: 5719beeb1cbc4cfd30bf5e2620dc7f23a538f283011a3c801a1a9ce50ba5d9f8c1cd34c544528743192cfbf506ed500c95f416ac9703dcabb0251f0e0763ef39
7
+ data.tar.gz: 564b9a9582860c1fee3d7c6b8aac8a44a6bfffc5f898c2d4a1f634b2f23edf86523924a86df15a0d9e35e64f5f379cb27759ba2f98a90c1088cdf4a81899eab3
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ /Gemfile.lock
2
+ /*.gem
3
+ /pkg
4
+ /spec/.all_test_result.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "https://rubygems.org"
2
+ gemspec
data/README.md ADDED
@@ -0,0 +1,61 @@
1
+ # Source2MD: Markdown generator from source code
2
+
3
+ input.rb:
4
+
5
+ ```ruby
6
+ # title2: (title)
7
+
8
+ # name: (name1)
9
+ # desc: (desc1)
10
+ # comment: (comment1)
11
+ "foo1".size # => 4
12
+
13
+ # name: (name2)
14
+ # desc: (desc2)
15
+ # comment: (comment2)
16
+ "foo2".size # => 4
17
+
18
+ # |---+---+---|
19
+ # | x | x | x |
20
+ # |---+---+---|
21
+ # | x | x | x |
22
+ # | x | x | x |
23
+ # |---+---+---|
24
+ ```
25
+
26
+
27
+
28
+ ```shell
29
+ $ source2md generate -o output.md input.rb
30
+ read: input.rb
31
+ write: output.md
32
+ ```
33
+
34
+
35
+
36
+ ## (title)
37
+
38
+ ### (name1)
39
+
40
+ (desc1)
41
+
42
+ ```ruby
43
+ "foo1".size # => 4
44
+ ```
45
+
46
+ (comment1)
47
+
48
+ ### (name2)
49
+
50
+ (desc2)
51
+
52
+ ```ruby
53
+ "foo2".size # => 4
54
+ ```
55
+
56
+ (comment2)
57
+
58
+ | x | x | x |
59
+ |---|---|---|
60
+ | x | x | x |
61
+ | x | x | x |
data/Rakefile ADDED
@@ -0,0 +1,3 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ Pathname.glob("lib/source2md/tasks/**/*.rake").each { |file| load(file) }
data/bin/source2md ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require "source2md"
3
+ Source2MD::Cli.start
data/examples/cli.rb ADDED
@@ -0,0 +1,3 @@
1
+ require "./setup"
2
+
3
+ Source2MD::Generator.new(files: ["input.rb"], output_file: "output.md").call
@@ -0,0 +1,8 @@
1
+ require "./setup"
2
+
3
+ puts Source2MD::Element.new(<<~EOS).to_md
4
+ ## foo
5
+ EOS
6
+ # >> ```ruby
7
+ # >> # foo
8
+ # >> ```
@@ -0,0 +1,10 @@
1
+ require "./setup"
2
+
3
+ puts Source2MD::Element.new(<<~EOS).to_md
4
+ ---
5
+ foo
6
+ ---
7
+ EOS
8
+ # >> ---
9
+ # >> foo
10
+ # >> ---
@@ -0,0 +1,21 @@
1
+ require "./setup"
2
+
3
+ puts Source2MD::Element.new(<<~EOS).to_md
4
+ # name: (name)
5
+ # desc: (desc)
6
+ # comment: (comment)
7
+ code1
8
+ #
9
+ code2
10
+ EOS
11
+ # >> ### (name)
12
+ # >>
13
+ # >> (desc)
14
+ # >>
15
+ # >> ```ruby
16
+ # >> code1
17
+ # >>
18
+ # >> code2
19
+ # >> ```
20
+ # >>
21
+ # >> (comment)
@@ -0,0 +1,8 @@
1
+ require "./setup"
2
+
3
+ puts Source2MD::Element.new(<<~EOS).to_md
4
+ code
5
+ EOS
6
+ # >> ```ruby
7
+ # >> code
8
+ # >> ```
@@ -0,0 +1,6 @@
1
+ require "./setup"
2
+
3
+ puts Source2MD::Element.new(<<~EOS).to_md
4
+ require "setup"
5
+ EOS
6
+ # >>
@@ -0,0 +1,14 @@
1
+ require "./setup"
2
+
3
+ puts Source2MD::Element.new(<<~EOS).to_md
4
+ # |---+---+---|
5
+ # | x | x | x |
6
+ # |---+---+---|
7
+ # | x | x | x |
8
+ # | x | x | x |
9
+ # |---+---+---|
10
+ EOS
11
+ # >> | x | x | x |
12
+ # >> |---|---|---|
13
+ # >> | x | x | x |
14
+ # >> | x | x | x |
@@ -0,0 +1,8 @@
1
+ require "./setup"
2
+
3
+ puts Source2MD::Element.new(<<~EOS).to_md
4
+ # - foo
5
+ # https://example.com/
6
+ EOS
7
+ # >> - foo
8
+ # >> https://example.com/
@@ -0,0 +1,6 @@
1
+ require "./setup"
2
+
3
+ puts Source2MD::Element.new(<<~EOS).to_md
4
+ # title2: (foo)
5
+ EOS
6
+ # >> ## (foo)
data/examples/input.rb ADDED
@@ -0,0 +1,18 @@
1
+ # title2: (title)
2
+
3
+ # name: (name1)
4
+ # desc: (desc1)
5
+ # comment: (comment1)
6
+ "foo1".size # => 4
7
+
8
+ # name: (name2)
9
+ # desc: (desc2)
10
+ # comment: (comment2)
11
+ "foo2".size # => 4
12
+
13
+ # |---+---+---|
14
+ # | x | x | x |
15
+ # |---+---+---|
16
+ # | x | x | x |
17
+ # | x | x | x |
18
+ # |---+---+---|
@@ -0,0 +1,26 @@
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
+
17
+ ```ruby
18
+ "foo2".size # => 4
19
+ ```
20
+
21
+ (comment2)
22
+
23
+ | x | x | x |
24
+ |---|---|---|
25
+ | x | x | x |
26
+ | x | x | x |
data/examples/setup.rb ADDED
@@ -0,0 +1,3 @@
1
+ $LOAD_PATH.unshift("#{__dir__}/../lib")
2
+ require "source2md"
3
+ Source2MD.quiet = true
@@ -0,0 +1,12 @@
1
+ module Source2MD
2
+ class Cli < Thor
3
+ class_option :debug, type: :boolean
4
+ class_option :quiet, type: :boolean
5
+
6
+ desc "generate [files]", "生成"
7
+ option :output_file, type: :string, aliases: "-o", default: "output.md"
8
+ def generate(*files)
9
+ Generator.new(options.to_options.merge(files: files)).call
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,56 @@
1
+ module Source2MD
2
+ class CodeBlock
3
+ PADDING_KEEP = 2
4
+ MARK = "# =>"
5
+
6
+ attr_accessor :code
7
+
8
+ def initialize(code)
9
+ @code = code
10
+ end
11
+
12
+ def to_md
13
+ [
14
+ "```ruby",
15
+ normalized_code,
16
+ "```",
17
+ ] * "\n"
18
+ end
19
+
20
+ private
21
+
22
+ def normalized_code
23
+ lines.collect(&method(:normalize)) * "\n"
24
+ end
25
+
26
+ def normalize(line)
27
+ line = single_sharp_replace_to_blank_line(line)
28
+ line = comment_mark_justfiy(line)
29
+ end
30
+
31
+ def single_sharp_replace_to_blank_line(line)
32
+ line.gsub(/\A#\z/, "")
33
+ end
34
+
35
+ def comment_mark_justfiy(line)
36
+ line.gsub(/(.*?)\s*#{MARK}(.*)/) {
37
+ a, b = Regexp.last_match.captures
38
+ space = " " * (PADDING_KEEP + (max - a.size))
39
+ [a, space, MARK, b].join
40
+ }
41
+ end
42
+
43
+ def lines
44
+ @lines ||= code.strip.lines.collect(&:rstrip)
45
+ end
46
+
47
+ def max
48
+ @max ||= yield_self do
49
+ av = lines
50
+ av = av.find_all { |e| e.include?(MARK) }
51
+ av = av.collect { |e| e.gsub(/\s*#{MARK}.*/, "").size }
52
+ av.max
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,38 @@
1
+ module Source2MD
2
+ class Element
3
+ KEY_VALUE = /^# (\w+):\s+(.*)\R?/
4
+
5
+ PLUGINS = [
6
+ Type::ElementReject,
7
+ Type::ElementMdHeader,
8
+ Type::ElementTitle2,
9
+ Type::ElementMethod,
10
+ Type::ElementTable,
11
+ Type::ElementDeepComment,
12
+ Type::ElementText,
13
+ Type::ElementPre,
14
+ ]
15
+
16
+ def initialize(content)
17
+ @content = content
18
+ end
19
+
20
+ def to_md
21
+ support_klass.new(self).to_md
22
+ end
23
+
24
+ def head
25
+ @content.scan(KEY_VALUE).to_h.symbolize_keys
26
+ end
27
+
28
+ def body
29
+ @content.remove(KEY_VALUE).strip
30
+ end
31
+
32
+ private
33
+
34
+ def support_klass
35
+ PLUGINS.find { |e| e.accept?(self) }
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,20 @@
1
+ module Source2MD
2
+ class FileBlock
3
+ def initialize(file)
4
+ @file = file
5
+ puts "read: #{file}"
6
+ end
7
+
8
+ def to_md
9
+ elements.collect(&:to_md).compact * "\n\n"
10
+ end
11
+
12
+ private
13
+
14
+ def elements
15
+ @elements ||= @file.read.strip.split(/\n{2,}/).collect do |e|
16
+ Element.new(e)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,34 @@
1
+ module Source2MD
2
+ class Generator
3
+ attr_accessor :params
4
+
5
+ def initialize(params = {})
6
+ @params = params
7
+ end
8
+
9
+ def call
10
+ output_file.write(to_md)
11
+ puts "write: #{output_file}"
12
+ end
13
+
14
+ private
15
+
16
+ def to_md
17
+ s = file_blocks.collect(&:to_md) * "\n\n"
18
+ s = TextHelper.text_squish(s)
19
+ s = TextHelper.add_newline_at_end_of_text(s)
20
+ end
21
+
22
+ def file_blocks
23
+ @file_blocks ||= files.collect { |e| FileBlock.new(e) }
24
+ end
25
+
26
+ def files
27
+ @files ||= params[:files].collect { |e| Pathname(e) }
28
+ end
29
+
30
+ def output_file
31
+ @output_file ||= Pathname(params[:output_file]).expand_path
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,5 @@
1
+ desc "About"
2
+ task :about do
3
+ require "source2md"
4
+ tp Source2MD::VERSION
5
+ end
@@ -0,0 +1,5 @@
1
+ require "rspec/core/rake_task"
2
+
3
+ task :default => :test
4
+
5
+ RSpec::Core::RakeTask.new(:test)
@@ -0,0 +1,13 @@
1
+ module Source2MD
2
+ module TextHelper
3
+ extend self
4
+
5
+ def text_squish(text)
6
+ text.gsub(/\n{2,}/, "\n\n")
7
+ end
8
+
9
+ def add_newline_at_end_of_text(text)
10
+ text.strip + "\n"
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,40 @@
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
@@ -0,0 +1,18 @@
1
+ module Source2MD
2
+ module Type
3
+ class Base
4
+ def self.accept?(element)
5
+ false
6
+ end
7
+
8
+ attr_reader :element
9
+
10
+ def initialize(element)
11
+ @element = element
12
+ end
13
+
14
+ def to_md
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,19 @@
1
+ module Source2MD
2
+ module Type
3
+ class ElementDeepComment < Base
4
+ def self.accept?(element)
5
+ element.body.match?(/^##/)
6
+ end
7
+
8
+ def to_md
9
+ CodeBlock.new(body).to_md
10
+ end
11
+
12
+ private
13
+
14
+ def body
15
+ element.body.gsub(/^##/, "#")
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,13 @@
1
+ module Source2MD
2
+ module Type
3
+ class ElementMdHeader < Base
4
+ def self.accept?(element)
5
+ element.body.to_s.start_with?("---")
6
+ end
7
+
8
+ def to_md
9
+ element.body
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,24 @@
1
+ module Source2MD
2
+ module Type
3
+ class ElementMethod < Base
4
+ def self.accept?(element)
5
+ element.head[:name]
6
+ end
7
+
8
+ def to_md
9
+ [
10
+ "### #{element.head[:name]}",
11
+ element.head[:desc],
12
+ body ? CodeBlock.new(body).to_md : nil,
13
+ element.head[:comment],
14
+ ].compact * "\n\n"
15
+ end
16
+
17
+ private
18
+
19
+ def body
20
+ element.body.gsub(/^\#$/, "").presence
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,13 @@
1
+ module Source2MD
2
+ module Type
3
+ class ElementPre < Base
4
+ def self.accept?(element)
5
+ element.body.present?
6
+ end
7
+
8
+ def to_md
9
+ CodeBlock.new(element.body).to_md
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,12 @@
1
+ module Source2MD
2
+ module Type
3
+ class ElementReject < Base
4
+ def self.accept?(element)
5
+ element.body.match?(/^require.*setup/)
6
+ end
7
+
8
+ def to_md
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,17 @@
1
+ module Source2MD
2
+ module Type
3
+ class ElementTable < Base
4
+ def self.accept?(element)
5
+ element.body.lines.all? { |e| e.match?(/^# \|.*\|$/) }
6
+ end
7
+
8
+ def to_md
9
+ element.body
10
+ .gsub(/^# /, "")
11
+ .sub(/\A\|.*?\|\R?/, "")
12
+ .sub(/^\|.*?\|\z/, "")
13
+ .gsub(/-\+-/, "-|-").strip
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,26 @@
1
+ # > # foo
2
+ # > # bar
3
+ # > ↓
4
+ # > foo
5
+ # > bar
6
+ module Source2MD
7
+ module Type
8
+ class ElementText < Base
9
+ def self.accept?(element)
10
+ if element.head.blank?
11
+ element.body.lines.all? { |e| e.start_with?("# ") }
12
+ end
13
+ end
14
+
15
+ def to_md
16
+ body
17
+ end
18
+
19
+ private
20
+
21
+ def body
22
+ element.body.gsub(/^# /, "")
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,16 @@
1
+ module Source2MD
2
+ module Type
3
+ class ElementTitle2 < Base
4
+ def self.accept?(element)
5
+ element.head[:title2]
6
+ end
7
+
8
+ def to_md
9
+ unless Source2MD.quiet
10
+ p element.head[:title2]
11
+ end
12
+ "## #{element.head[:title2]}"
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ module Source2MD
2
+ VERSION = "0.0.1"
3
+ end
data/lib/source2md.rb ADDED
@@ -0,0 +1,22 @@
1
+ require "active_support/core_ext/hash"
2
+ require "active_support/configurable"
3
+ require "zeitwerk"
4
+ require "table_format"
5
+ require "pathname"
6
+ require "thor"
7
+
8
+ module Source2MD
9
+ include ActiveSupport::Configurable
10
+ config_accessor(:debug) { false }
11
+ config_accessor(:quiet) { false }
12
+ end
13
+
14
+ loader = Zeitwerk::Loader.for_gem
15
+ loader.ignore("#{__dir__}/source2md/**/_*.rb")
16
+
17
+ loader.inflector.inflect("source2md" => "Source2MD")
18
+
19
+ loader.log! if false
20
+ loader.setup
21
+
22
+ loader.eager_load if true
data/source2md.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) if !$LOAD_PATH.include?(lib)
3
+ require 'source2md/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "source2md"
7
+ spec.version = Source2MD::VERSION
8
+ spec.author = "Akira Ikeda"
9
+ spec.email = "pinpon.ikeda@gmail.com"
10
+ spec.homepage = "https://github.com/akicho8/source2md"
11
+ spec.summary = "Markdown generator from source code"
12
+ spec.description = "Markdown generator from source code"
13
+ spec.platform = Gem::Platform::RUBY
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
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
+ spec.add_dependency "zeitwerk"
27
+ spec.add_dependency "activesupport"
28
+ spec.add_dependency "pathname"
29
+ spec.add_dependency "thor"
30
+ spec.add_dependency "table_format"
31
+ end
@@ -0,0 +1,22 @@
1
+ require "spec_helper"
2
+
3
+ module Source2MD
4
+ describe CodeBlock do
5
+ it "works" do
6
+ s = CodeBlock.new(<<~EOS).to_md
7
+ a # => 1
8
+ #
9
+ bb # => 2
10
+ cccc
11
+ EOS
12
+ assert { s == <<~EOS.strip }
13
+ ```ruby
14
+ a # => 1
15
+
16
+ bb # => 2
17
+ cccc
18
+ ```
19
+ EOS
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,19 @@
1
+ $LOAD_PATH.unshift("#{__dir__}/../lib")
2
+ $LOAD_PATH.unshift(__dir__)
3
+ require "source2md"
4
+ require "rspec"
5
+
6
+ Pathname.glob("#{__dir__}/**/*_support.rb") { |e| require e.to_s }
7
+ Pathname.glob("#{__dir__}/support/**/*.rb") { |e| require e.to_s }
8
+
9
+ Zeitwerk::Loader.eager_load_all
10
+
11
+ Source2MD.quiet = true
12
+
13
+ RSpec.configure do |config|
14
+ config.expect_with :rspec do |c|
15
+ c.syntax = [:should, :expect]
16
+ end
17
+ config.expect_with :test_unit
18
+ config.example_status_persistence_file_path = "#{__dir__}/.all_test_result.txt"
19
+ end
@@ -0,0 +1,16 @@
1
+ require "spec_helper"
2
+
3
+ module Source2MD
4
+ describe do
5
+ it "works" do
6
+ actual = Element.new(<<~EOS).to_md
7
+ ## foo
8
+ EOS
9
+ assert { actual == <<~EOS.strip }
10
+ ```ruby
11
+ # foo
12
+ ```
13
+ EOS
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,34 @@
1
+ require "spec_helper"
2
+
3
+ module Source2MD
4
+ describe do
5
+ it "works" do
6
+ actual = Element.new(<<~EOS).to_md
7
+ ---
8
+ foo: 1
9
+ ---
10
+ EOS
11
+ assert { actual == <<~EOS.strip }
12
+ ---
13
+ foo: 1
14
+ ---
15
+ EOS
16
+ end
17
+ end
18
+ end
19
+ # >> F
20
+ # >>
21
+ # >> Failures:
22
+ # >>
23
+ # >> 1) works
24
+ # >> Failure/Error: Unable to find - to read failed line
25
+ # >> Test::Unit::AssertionFailedError:
26
+ # >> # -:14:in `block (2 levels) in <module:Source2MD>'
27
+ # >>
28
+ # >> Finished in 0.0113 seconds (files took 0.26182 seconds to load)
29
+ # >> 1 example, 1 failure
30
+ # >>
31
+ # >> Failed examples:
32
+ # >>
33
+ # >> rspec -:5 # works
34
+ # >>
@@ -0,0 +1,29 @@
1
+ require "spec_helper"
2
+
3
+ module Source2MD
4
+ describe do
5
+ it "works" do
6
+ actual = Element.new(<<~EOS).to_md
7
+ # name: (name)
8
+ # desc: (desc)
9
+ # comment: (comment)
10
+ (code1)
11
+ #
12
+ (code2)
13
+ EOS
14
+ assert { actual == <<~EOS.strip }
15
+ ### (name)
16
+
17
+ (desc)
18
+
19
+ ```ruby
20
+ (code1)
21
+
22
+ (code2)
23
+ ```
24
+
25
+ (comment)
26
+ EOS
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,16 @@
1
+ require "spec_helper"
2
+
3
+ module Source2MD
4
+ describe do
5
+ it "works" do
6
+ actual = Element.new(<<~EOS).to_md
7
+ code
8
+ EOS
9
+ assert { actual == <<~EOS.strip }
10
+ ```ruby
11
+ code
12
+ ```
13
+ EOS
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,12 @@
1
+ require "spec_helper"
2
+
3
+ module Source2MD
4
+ describe do
5
+ it "works" do
6
+ actual = Element.new(<<~EOS).to_md
7
+ require "./setup"
8
+ EOS
9
+ assert { actual.blank? }
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,22 @@
1
+ require "spec_helper"
2
+
3
+ module Source2MD
4
+ describe do
5
+ it "works" do
6
+ actual = Element.new(<<~EOS).to_md
7
+ # |---+---+---|
8
+ # | h | h | h |
9
+ # |---+---+---|
10
+ # | d | d | d |
11
+ # | d | d | d |
12
+ # |---+---+---|
13
+ EOS
14
+ assert { actual == <<~EOS.strip }
15
+ | h | h | h |
16
+ |---|---|---|
17
+ | d | d | d |
18
+ | d | d | d |
19
+ EOS
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,18 @@
1
+ require "spec_helper"
2
+
3
+ module Source2MD
4
+ describe do
5
+ it "works" do
6
+ actual = Element.new(<<~EOS).to_md
7
+ # - foo
8
+ # http://example.com/
9
+ # - bar: http://example.com/
10
+ EOS
11
+ assert { actual == <<~EOS.strip }
12
+ - foo
13
+ http://example.com/
14
+ - bar: http://example.com/
15
+ EOS
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,14 @@
1
+ require "spec_helper"
2
+
3
+ module Source2MD
4
+ describe do
5
+ it "works" do
6
+ actual = Element.new(<<~EOS).to_md
7
+ # title2: foo
8
+ EOS
9
+ assert { actual == <<~EOS.strip }
10
+ ## foo
11
+ EOS
12
+ end
13
+ end
14
+ end
metadata ADDED
@@ -0,0 +1,228 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: source2md
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Akira Ikeda
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-07-13 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: '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
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: test-unit
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: zeitwerk
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: activesupport
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pathname
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: thor
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: table_format
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: Markdown generator from source code
140
+ email: pinpon.ikeda@gmail.com
141
+ executables:
142
+ - source2md
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - ".gitignore"
147
+ - ".rspec"
148
+ - Gemfile
149
+ - README.md
150
+ - Rakefile
151
+ - bin/source2md
152
+ - examples/cli.rb
153
+ - examples/element_deep_comment.rb
154
+ - examples/element_md_header.rb
155
+ - examples/element_method.rb
156
+ - examples/element_pre.rb
157
+ - examples/element_reject.rb
158
+ - examples/element_table.rb
159
+ - examples/element_text.rb
160
+ - examples/element_title2.rb
161
+ - examples/input.rb
162
+ - examples/output.md
163
+ - examples/setup.rb
164
+ - lib/source2md.rb
165
+ - lib/source2md/cli.rb
166
+ - lib/source2md/code_block.rb
167
+ - lib/source2md/element.rb
168
+ - lib/source2md/file_block.rb
169
+ - lib/source2md/generator.rb
170
+ - lib/source2md/tasks/about.rake
171
+ - lib/source2md/tasks/test.rake
172
+ - lib/source2md/text_helper.rb
173
+ - lib/source2md/type/__element_header_comment.rb
174
+ - lib/source2md/type/base.rb
175
+ - lib/source2md/type/element_deep_comment.rb
176
+ - lib/source2md/type/element_md_header.rb
177
+ - lib/source2md/type/element_method.rb
178
+ - lib/source2md/type/element_pre.rb
179
+ - lib/source2md/type/element_reject.rb
180
+ - lib/source2md/type/element_table.rb
181
+ - lib/source2md/type/element_text.rb
182
+ - lib/source2md/type/element_title2.rb
183
+ - lib/source2md/version.rb
184
+ - source2md.gemspec
185
+ - spec/code_block_spec.rb
186
+ - spec/spec_helper.rb
187
+ - spec/type/element_deep_comment_spec.rb
188
+ - spec/type/element_md_header_spec.rb
189
+ - spec/type/element_method_spec.rb
190
+ - spec/type/element_pre_spec.rb
191
+ - spec/type/element_reject_spec.rb
192
+ - spec/type/element_table_spec.rb
193
+ - spec/type/element_text_spec.rb
194
+ - spec/type/element_title2_spec.rb
195
+ homepage: https://github.com/akicho8/source2md
196
+ licenses:
197
+ - MIT
198
+ metadata: {}
199
+ post_install_message:
200
+ rdoc_options: []
201
+ require_paths:
202
+ - lib
203
+ required_ruby_version: !ruby/object:Gem::Requirement
204
+ requirements:
205
+ - - ">="
206
+ - !ruby/object:Gem::Version
207
+ version: '0'
208
+ required_rubygems_version: !ruby/object:Gem::Requirement
209
+ requirements:
210
+ - - ">="
211
+ - !ruby/object:Gem::Version
212
+ version: '0'
213
+ requirements: []
214
+ rubygems_version: 3.4.16
215
+ signing_key:
216
+ specification_version: 4
217
+ summary: Markdown generator from source code
218
+ test_files:
219
+ - spec/code_block_spec.rb
220
+ - spec/spec_helper.rb
221
+ - spec/type/element_deep_comment_spec.rb
222
+ - spec/type/element_md_header_spec.rb
223
+ - spec/type/element_method_spec.rb
224
+ - spec/type/element_pre_spec.rb
225
+ - spec/type/element_reject_spec.rb
226
+ - spec/type/element_table_spec.rb
227
+ - spec/type/element_text_spec.rb
228
+ - spec/type/element_title2_spec.rb