source2md 0.0.8 → 0.0.9

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: f07581e2e1a43897fbabf84171220745ae7ca72f96a19fd0f56e9aac6e73bd5d
4
- data.tar.gz: 62e064eaf58861b1abf0b04739e54715a2efbcc74ced61fb0c949e232bf6e3a0
3
+ metadata.gz: a69cc0fff709a6adfac13be6784fb107d230200b6797391dfd2c970fab4f48ca
4
+ data.tar.gz: 14168fb1b130a4112eb08c4408d6c4bc84b70e5db1b53889201d2c5094343d32
5
5
  SHA512:
6
- metadata.gz: b426db58ee1eda88c7c9174867cdb6dd9e67d951605a74dc0c2fbcaf8d3464819a84042822fc7d99d78513762be1c3de491af6a2f61dd2d755f8a268fcd58bde
7
- data.tar.gz: 2d97f41bc6ab44b7a2019c2008a4845f879c7b91e82a68ed5fc98e158eebb9a660fe7a34ebfc9a7ef2551c389fc0a84360bc67bd57de56e465900f717a6544c1
6
+ metadata.gz: c539724001175e52377e62c132ed15d622fdc854dfc02b20f6aa6018bc108044832c9bd2617f9c198ff3261c70fc2876da0004a9b862c462d0af3b5b32f39148
7
+ data.tar.gz: 12fc867c80e7012e8199264fd7c7c2c90d1a0c6e3ead297317deceaeca66b83176fc23389b2803bf060383341b7a5c2321cb90c2da121d73d6db6806fa36ac26
@@ -0,0 +1,3 @@
1
+ a
2
+ b
3
+ c
@@ -0,0 +1,2 @@
1
+ #!/bin/sh
2
+ source2md generate -d a.rs
@@ -4,20 +4,16 @@ require "./setup"
4
4
  puts Source2MD::Element.new(<<~EOS).to_md
5
5
  #+alert: (foo)
6
6
  EOS
7
- # >> --------------------------------------------------------------------------------
8
- # >> Source2MD::Part::TypeAlert
9
- # >>
10
- # >> head:
11
- # >> {:alert=>"(foo)"}
12
- # >>
13
- # >> in:
14
- # >>
15
- # >>
16
- # >> out:
17
- # >> :::message alert
18
- # >> (foo)
19
- # >> :::
20
- # >> --------------------------------------------------------------------------------
7
+ # >> > -------------------------------------------------------------------------------- Source2MD::Formatter::TypeAlert
8
+ # >> > {"alert"=>"(foo)"}
9
+ # >> > ------------------------------------------------------------ in
10
+ # >> >
11
+ # >> >
12
+ # >> > ------------------------------------------------------------ out
13
+ # >> > :::message alert
14
+ # >> > (foo)
15
+ # >> > :::
16
+ # >> > ------------------------------------------------------------
21
17
  # >> :::message alert
22
18
  # >> (foo)
23
19
  # >> :::
@@ -2,22 +2,26 @@
2
2
  require "./setup"
3
3
 
4
4
  puts Source2MD::Element.new(<<~EOS).to_md
5
- (foo)
5
+ a
6
+ b
7
+ c
6
8
  EOS
7
- # >> --------------------------------------------------------------------------------
8
- # >> Source2MD::Part::TypePartialCode
9
- # >>
10
- # >> head:
11
- # >> {}
12
- # >>
13
- # >> in:
14
- # >> (foo)
15
- # >>
16
- # >> out:
9
+ # >> > -------------------------------------------------------------------------------- Source2MD::Formatter::TypePartialCode
10
+ # >> > {}
11
+ # >> > ------------------------------------------------------------ in
12
+ # >> > a
13
+ # >> > b
14
+ # >> > c
15
+ # >> >
16
+ # >> > ------------------------------------------------------------ out
17
+ # >> > ```ruby
18
+ # >> > a
19
+ # >> > b
20
+ # >> > c
21
+ # >> > ```
22
+ # >> > ------------------------------------------------------------
17
23
  # >> ```ruby
18
- # >> (foo)
19
- # >> ```
20
- # >> --------------------------------------------------------------------------------
21
- # >> ```ruby
22
- # >> (foo)
24
+ # >> a
25
+ # >> b
26
+ # >> c
23
27
  # >> ```
@@ -25,18 +25,18 @@ puts Source2MD::Element.new(<<~EOS).to_md
25
25
  EOS
26
26
 
27
27
  # >> > -------------------------------------------------------------------------------- Source2MD::Formatter::TypeText
28
- # >> > {"oneline"=>"true"}
28
+ # >> > {"squish"=>"true"}
29
29
  # >> > ------------------------------------------------------------ in
30
30
  # >> > # a
31
31
  # >> > # b
32
32
  # >> > #
33
33
  # >> > # c
34
34
  # >> > # d
35
- # >> >
35
+ # >> >
36
36
  # >> > ------------------------------------------------------------ out
37
- # >> > abcd
37
+ # >> > a b c d
38
38
  # >> > ------------------------------------------------------------
39
- # >> abcd
39
+ # >> a b c d
40
40
  # >> > -------------------------------------------------------------------------------- Source2MD::Formatter::TypeText
41
41
  # >> > {"squish"=>"true"}
42
42
  # >> > ------------------------------------------------------------ in
@@ -45,7 +45,7 @@ EOS
45
45
  # >> > #
46
46
  # >> > # c
47
47
  # >> > # d
48
- # >> >
48
+ # >> >
49
49
  # >> > ------------------------------------------------------------ out
50
50
  # >> > a b c d
51
51
  # >> > ------------------------------------------------------------
@@ -54,7 +54,7 @@ EOS
54
54
  # >> > {"hankaku_kana"=>"true"}
55
55
  # >> > ------------------------------------------------------------ in
56
56
  # >> > # アア
57
- # >> >
57
+ # >> >
58
58
  # >> > ------------------------------------------------------------ out
59
59
  # >> > アア
60
60
  # >> > ------------------------------------------------------------
@@ -4,22 +4,14 @@ require "./setup"
4
4
  puts Source2MD::Element.new(<<~EOS).to_md
5
5
  #+title2: (foo)
6
6
  EOS
7
- # >> title2: (foo)
8
- # >> --------------------------------------------------------------------------------
9
- # >> Source2MD::Part::TypeTitle
10
- # >>
11
- # >> head:
12
- # >> {:title2=>"(foo)"}
13
- # >>
14
- # >> in:
15
- # >>
16
- # >>
17
- # >> out:
18
- # >>
19
- # >> (foo)
20
- # >>
21
- # >> --------------------------------------------------------------------------------
22
- # >> title2: (foo)
23
- # >>
24
- # >> (foo)
25
- # >>
7
+ # >> ## (foo) ##
8
+ # >> > -------------------------------------------------------------------------------- Source2MD::Formatter::TypeTitle
9
+ # >> > {"title2"=>"(foo)"}
10
+ # >> > ------------------------------------------------------------ in
11
+ # >> >
12
+ # >> >
13
+ # >> > ------------------------------------------------------------ out
14
+ # >> > ## (foo) ##
15
+ # >> > ------------------------------------------------------------
16
+ # >> ## (foo) ##
17
+ # >> ## (foo) ##
@@ -2,22 +2,18 @@
2
2
  require "./setup"
3
3
 
4
4
  puts Source2MD::Element.new(<<~EOS).to_md
5
- #+info: (foo)
5
+ #+warn: (foo)
6
6
  EOS
7
- # >> --------------------------------------------------------------------------------
8
- # >> Source2MD::Part::ElementInfo
9
- # >>
10
- # >> head:
11
- # >> {:info=>"(foo)"}
12
- # >>
13
- # >> in:
14
- # >>
15
- # >>
16
- # >> out:
17
- # >> :::message
18
- # >> (foo)
19
- # >> :::
20
- # >> --------------------------------------------------------------------------------
7
+ # >> > -------------------------------------------------------------------------------- Source2MD::Formatter::TypeWarn
8
+ # >> > {"warn"=>"(foo)"}
9
+ # >> > ------------------------------------------------------------ in
10
+ # >> >
11
+ # >> >
12
+ # >> > ------------------------------------------------------------ out
13
+ # >> > :::message
14
+ # >> > (foo)
15
+ # >> > :::
16
+ # >> > ------------------------------------------------------------
21
17
  # >> :::message
22
18
  # >> (foo)
23
19
  # >> :::
data/lib/source2md/cli.rb CHANGED
@@ -2,7 +2,7 @@ module Source2MD
2
2
  class Cli < Thor
3
3
  class_option :debug, type: :boolean, aliases: "-d", default: false
4
4
  class_option :xmp_out_exclude, type: :boolean, aliases: "-x", default: false
5
- class_option :readonly, type: :boolean, default: true
5
+ class_option :readonly, type: :boolean, default: true
6
6
 
7
7
  def initialize(...)
8
8
  super
@@ -22,7 +22,7 @@ module Source2MD
22
22
 
23
23
  map "g" => :generate
24
24
  desc "generate [files]", "Markdown generation"
25
- option :output_file, type: :string, aliases: "-o", default: "output.md"
25
+ option :output_file, type: :string, aliases: "-o", default: nil
26
26
  def generate(*files)
27
27
  Generator.new(options.to_options.merge(files: files)).call
28
28
  end
@@ -65,8 +65,16 @@ module Source2MD
65
65
  }
66
66
  end
67
67
 
68
+ def raw_lines
69
+ @raw_lines ||= code.lines.collect(&:rstrip)
70
+ end
71
+
68
72
  def lines
69
- @lines ||= code.strip.lines.collect(&:rstrip)
73
+ @lines ||= yield_self do
74
+ min = raw_lines.collect { |e| e.slice(/^\s*/).size }.min
75
+ re = /^\s{#{min}}/
76
+ raw_lines.collect { |e| e.remove(re) }
77
+ end
70
78
  end
71
79
 
72
80
  def max
@@ -34,7 +34,7 @@ module Source2MD
34
34
  end
35
35
 
36
36
  def body
37
- @body ||= @content.remove(KEY_VALUE_REGEXP).strip.freeze
37
+ @body ||= @content.remove(KEY_VALUE_REGEXP).rstrip.freeze
38
38
  end
39
39
 
40
40
  private
@@ -7,14 +7,20 @@ module Source2MD
7
7
  end
8
8
 
9
9
  def call
10
- if output_file.exist?
11
- FileUtils.chmod("a+w", output_file)
10
+ if !output_file
11
+ puts to_md
12
12
  end
13
- output_file.write(to_md)
14
- if Source2MD.readonly
15
- FileUtils.chmod("a-w", output_file)
13
+
14
+ if output_file
15
+ if output_file.exist?
16
+ FileUtils.chmod("a+w", output_file)
17
+ 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}"
16
23
  end
17
- puts "write: #{output_file}"
18
24
  end
19
25
 
20
26
  def to_md
@@ -34,7 +40,11 @@ module Source2MD
34
40
  end
35
41
 
36
42
  def output_file
37
- @output_file ||= Pathname(params[:output_file]).expand_path
43
+ @output_file ||= yield_self do
44
+ if v = params[:output_file]
45
+ Pathname(v).expand_path
46
+ end
47
+ end
38
48
  end
39
49
  end
40
50
  end
@@ -24,7 +24,7 @@ module Source2MD
24
24
  end
25
25
  v = v + "\n\n"
26
26
  v = v.scan(PARAGRAPH_RE)
27
- v = v.collect(&:strip)
27
+ v = v.collect(&:rstrip)
28
28
  v = v.find_all(&:present?)
29
29
  end
30
30
  end
@@ -1,3 +1,3 @@
1
1
  module Source2MD
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
data/output.md ADDED
@@ -0,0 +1,13 @@
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
+ ```
data/spec/scanner_spec.rb CHANGED
@@ -17,10 +17,17 @@ module Source2MD
17
17
  #+BEGIN_SRC
18
18
  foo
19
19
  #+END_SRC
20
+
20
21
  foo
21
22
  EOS
22
23
 
24
+ ary # => ["foo", "#+BEGIN_SRC\n\nfoo\n\n#+END_SRC", "foo", "#+BEGIN_SRC\nfoo\n#+END_SRC", "foo"]
23
25
  assert { ary == ["foo", "#+BEGIN_SRC\n\nfoo\n\n#+END_SRC", "foo", "#+BEGIN_SRC\nfoo\n#+END_SRC", "foo"] }
24
26
  end
25
27
  end
26
28
  end
29
+ # >> .
30
+ # >>
31
+ # >> Finished in 0.00793 seconds (files took 0.26816 seconds to load)
32
+ # >> 1 example, 0 failures
33
+ # >>
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.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akira Ikeda
@@ -165,6 +165,8 @@ files:
165
165
  - doc/0240_text_hankaku_kana.rb
166
166
  - doc/0250_parse_include.rb
167
167
  - doc/setup.rb
168
+ - examples/cli-test.rs
169
+ - examples/cli-test.sh
168
170
  - examples/cli.rb
169
171
  - examples/element_text.rb
170
172
  - examples/input.rb
@@ -210,6 +212,7 @@ files:
210
212
  - lib/source2md/tasks/test.rake
211
213
  - lib/source2md/text_helper.rb
212
214
  - lib/source2md/version.rb
215
+ - output.md
213
216
  - source2md.gemspec
214
217
  - spec/code_block_spec.rb
215
218
  - spec/formatter/sample.yml