source2md 0.0.14 → 0.0.15

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: 3477e280893742563cabf28b242a48d0efdc0943294c902a0fd7085950213b6a
4
- data.tar.gz: 6a0c6f3b324fe3cd6b6d6e9fd1c038fba91dcbaf3aff742cf8f80ef2129c49a7
3
+ metadata.gz: e6729b84590ef4ebe43528414aa73d6acd79d9171c813c4a8de9acd7148c9115
4
+ data.tar.gz: 0b5d54093161840a33b2ce104752883e50e582dda9e7dc925767c83ef6f8ab05
5
5
  SHA512:
6
- metadata.gz: be3fb7b9ef5f24186a2b613fd10d42d5d0bbad7781d99b9ac72251dda336b13d50737febd993f6d5ecfc0dfe83fb87930c317b3dc21475afe593e1fecea5173b
7
- data.tar.gz: 0e68f783920b8abb32a1e405cecc4f0f881cf9bc71f4b3b2f13fff444b8272b8361d37389f10c4085b55be51c67a439d6ddbc5061bda776a4255797a9ecf1cd3
6
+ metadata.gz: 81e2f855af240b3ea35c887f6bb6275eb699702934f62a8f13b86e5c0abfe4dcf0b77e7ffd17d2f17784565da8f92795ee1a35416226813c91269b247b2fe8f5
7
+ data.tar.gz: 51272d19c77da2481488acecc3a30eb97b8073ce8e2b1c9264252e0d738974223327f8a30eadc7146feefe20b4e6a76dd63a523b1345f3f149125cb950026678
data/README.md CHANGED
@@ -32,7 +32,8 @@ puts Source2MD::Section.new(<<~EOS).to_md
32
32
  "Hello, world!"
33
33
  }
34
34
 
35
- #+code_block_name: (name)
35
+ #+partial_code_name: (name)
36
+ #+partial_code_lang: (ruby)
36
37
  hello.call
37
38
  EOS
38
39
  ```
@@ -43,7 +44,7 @@ EOS
43
44
  > }
44
45
  > ```
45
46
 
46
- > ```ruby:(name)
47
+ > ```(ruby):(name)
47
48
  > hello.call
48
49
  > ```
49
50
 
@@ -316,3 +317,13 @@ EOS
316
317
  ```
317
318
 
318
319
  > foo
320
+
321
+ ### Eval ###
322
+
323
+ Function for changing internal variables
324
+
325
+ ```ruby
326
+ puts Source2MD::Section.new(<<~EOS).to_md
327
+ #+eval: Source2MD.lang_default = "shell"
328
+ EOS
329
+ ```
@@ -11,7 +11,8 @@ puts Source2MD::Section.new(<<~EOS).to_md
11
11
  "Hello, world!"
12
12
  }
13
13
 
14
- #+code_block_name: (name)
14
+ #+partial_code_name: (name)
15
+ #+partial_code_lang: (ruby)
15
16
  hello.call
16
17
  EOS
17
18
  #+END_SRC
@@ -22,7 +23,7 @@ EOS
22
23
  # > }
23
24
  # > ```
24
25
 
25
- # > ```ruby:(name)
26
+ # > ```(ruby):(name)
26
27
  # > hello.call
27
28
  # > ```
28
29
 
@@ -33,6 +34,6 @@ EOS
33
34
  # >> ```
34
35
  # >>
35
36
  # >>
36
- # >> ```ruby:(name)
37
+ # >> ```(ruby):(name)
37
38
  # >> hello.call
38
39
  # >> ```
data/doc/0250_eval.rb ADDED
@@ -0,0 +1,12 @@
1
+ #+hidden: true
2
+ require "./setup"
3
+
4
+ #+title3: Eval
5
+
6
+ # Function for changing internal variables
7
+
8
+ #+BEGIN_SRC
9
+ puts Source2MD::Section.new(<<~EOS).to_md
10
+ #+eval: Source2MD.lang_default = "shell"
11
+ EOS
12
+ #+END_SRC
@@ -0,0 +1,18 @@
1
+ #+hidden: true
2
+ require "./setup"
3
+
4
+ puts Source2MD::Element.new(<<~EOS).to_md
5
+ #+eval: Source2MD.lang_default = "lisp"
6
+ EOS
7
+ # >> head: {"eval"=>"Source2MD.lang_default = \"lisp\""}
8
+ # >> body: ""
9
+ # >> Source2MD::Formatter::TypeEval => Source2MD.lang_default = "lisp"
10
+ # >> > -------------------------------------------------------------------------------- Source2MD::Formatter::TypeEval
11
+ # >> > {"eval"=>"Source2MD.lang_default = \"lisp\""}
12
+ # >> > ------------------------------------------------------------ in
13
+ # >> >
14
+ # >> >
15
+ # >> > ------------------------------------------------------------ out
16
+ # >> >
17
+ # >> > ------------------------------------------------------------
18
+ # >>
@@ -4,14 +4,14 @@ require "./setup"
4
4
  Source2MD.data_block_exclude = true
5
5
 
6
6
  puts Source2MD::Element.new(<<~EOS).to_md
7
- #+code_block_name: foo
7
+ #+partial_code_name: foo
8
8
  a
9
9
  b
10
10
  c
11
11
  __END__
12
12
  foo
13
13
  EOS
14
- # >> head: {"code_block_name"=>"foo"}
14
+ # >> head: {"partial_code_name"=>"foo"}
15
15
  # >> body: "a\n b\nc\n__END__\nfoo\n"
16
16
  # >> Source2MD::Formatter::TypeHidden => false
17
17
  # >> Source2MD::Formatter::TypeCodeInclude =>
@@ -26,7 +26,7 @@ EOS
26
26
  # >> Source2MD::Formatter::TypeText => false
27
27
  # >> Source2MD::Formatter::TypePartialCode => true
28
28
  # >> > -------------------------------------------------------------------------------- Source2MD::Formatter::TypePartialCode
29
- # >> > {"code_block_name"=>"foo"}
29
+ # >> > {"partial_code_name"=>"foo"}
30
30
  # >> > ------------------------------------------------------------ in
31
31
  # >> > a
32
32
  # >> > b
data/lib/source2md/cli.rb CHANGED
@@ -4,7 +4,7 @@ module Source2MD
4
4
  class_option :xmp_out_exclude, type: :boolean, aliases: "-x", default: false
5
5
  class_option :data_block_exclude, type: :boolean, default: false
6
6
  class_option :readonly, type: :boolean, aliases: "-r", default: true
7
- class_option :default_lang, type: :string, aliases: "-l", default: "ruby"
7
+ class_option :lang_default, type: :string, aliases: "-l", default: "ruby"
8
8
  class_option :prefix_re, type: :string
9
9
  class_option :comment_re, type: :string
10
10
 
@@ -19,7 +19,7 @@ module Source2MD
19
19
  Source2MD.xmp_out_exclude = options[:xmp_out_exclude]
20
20
  Source2MD.data_block_exclude = options[:data_block_exclude]
21
21
  Source2MD.readonly = options[:readonly]
22
- Source2MD.default_lang = options[:default_lang]
22
+ Source2MD.lang_default = options[:lang_default]
23
23
 
24
24
  Source2MD::RE.update do |e|
25
25
  if v = options[:prefix_re]
@@ -6,7 +6,9 @@ module Source2MD
6
6
  def initialize(text, options = {})
7
7
  @text = text
8
8
  @options = {
9
+ :desc => nil,
9
10
  :lang => nil,
11
+ :name => nil,
10
12
  # :single_sharp_replace_to_blank_line => false,
11
13
  }.merge(options)
12
14
  end
@@ -21,6 +23,8 @@ module Source2MD
21
23
 
22
24
  private
23
25
 
26
+ # <-------------------> desc
27
+ # <- lang ->:<- name ->
24
28
  def code_block_head
25
29
  o = []
26
30
  if s = @options[:desc]
@@ -78,7 +82,7 @@ module Source2MD
78
82
  end
79
83
 
80
84
  def lang
81
- @options[:lang] || ENV["DEFAULT_LANG"] || Source2MD.default_lang
85
+ @options[:lang] || ENV["DEFAULT_LANG"] || Source2MD.lang_default
82
86
  end
83
87
  end
84
88
  end
@@ -2,6 +2,7 @@ module Source2MD
2
2
  class Element
3
3
  PLUGINS = [
4
4
  Formatter::TypeHidden, # #+hidden: true
5
+ Formatter::TypeEval, # #+eval:
5
6
  Formatter::TypeCodeInclude, # #+code_include: path/to/foo.html xml:SAMPLE.xml
6
7
  Formatter::TypeRawInclude, # #+raw_include: path/to/file.txt
7
8
  Formatter::TypeParseInclude, # #+parse_include: path/to/file.txt
@@ -0,0 +1,14 @@
1
+ module Source2MD
2
+ module Formatter
3
+ class TypeEval < Base
4
+ def self.accept?(element)
5
+ element.head["eval"]
6
+ end
7
+
8
+ def to_md
9
+ eval(element.head["eval"])
10
+ ""
11
+ end
12
+ end
13
+ end
14
+ end
@@ -6,7 +6,7 @@ module Source2MD
6
6
  end
7
7
 
8
8
  def to_md
9
- CodeBlock.new(body, name: element.head["code_block_name"]).to_md
9
+ CodeBlock.new(body, code_block_options).to_md
10
10
  end
11
11
 
12
12
  private
@@ -18,6 +18,14 @@ module Source2MD
18
18
  element.body
19
19
  end
20
20
  end
21
+
22
+ def code_block_options
23
+ {
24
+ lang: element.head["partial_code_lang"],
25
+ name: element.head["partial_code_name"],
26
+ desc: element.head["partial_code_desc"],
27
+ }
28
+ end
21
29
  end
22
30
  end
23
31
  end
@@ -1,3 +1,3 @@
1
1
  module Source2MD
2
- VERSION = "0.0.14"
2
+ VERSION = "0.0.15"
3
3
  end
data/lib/source2md.rb CHANGED
@@ -15,7 +15,7 @@ module Source2MD
15
15
  config_accessor(:debug) { false }
16
16
  config_accessor(:xmp_out_exclude) { false }
17
17
  config_accessor(:readonly) { true }
18
- config_accessor(:default_lang) { "ruby" }
18
+ config_accessor(:lang_default) { "ruby" }
19
19
  config_accessor(:data_block_exclude) { false }
20
20
  end
21
21
 
@@ -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
+ #+eval: 1 + 2
8
+ EOS
9
+ end
10
+ end
11
+ end
12
+ # >> .
13
+ # >>
14
+ # >> Finished in 0.00398 seconds (files took 0.34568 seconds to load)
15
+ # >> 1 example, 0 failures
16
+ # >>
@@ -4,14 +4,15 @@ 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
+ #+partial_code_name: xxx
8
+ #+partial_code_lang: yyy
8
9
  (foo)
9
10
  __END__
10
11
  1
11
12
  2
12
13
  EOS
13
14
  actual.should == <<~EOS
14
- ```ruby:xxx
15
+ ```yyy:xxx
15
16
  (foo)
16
17
  ```
17
18
  EOS
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.14
4
+ version: 0.0.15
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-10-24 00:00:00.000000000 Z
11
+ date: 2023-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -163,6 +163,7 @@ files:
163
163
  - doc/0220_text_squish.rb
164
164
  - doc/0230_text_hankaku_kana.rb
165
165
  - doc/0240_parse_include.rb
166
+ - doc/0250_eval.rb
166
167
  - doc/setup.rb
167
168
  - examples/cli-test.rs
168
169
  - examples/cli-test.sh
@@ -175,6 +176,7 @@ files:
175
176
  - examples/setup.rb
176
177
  - examples/type_alert.rb
177
178
  - examples/type_code_include.rb
179
+ - examples/type_eval.rb
178
180
  - examples/type_hidden.rb
179
181
  - examples/type_method.rb
180
182
  - examples/type_partial_code.rb
@@ -191,6 +193,7 @@ files:
191
193
  - lib/source2md/formatter/type_alert.rb
192
194
  - lib/source2md/formatter/type_code_include.rb
193
195
  - lib/source2md/formatter/type_else.rb
196
+ - lib/source2md/formatter/type_eval.rb
194
197
  - lib/source2md/formatter/type_hidden.rb
195
198
  - lib/source2md/formatter/type_method.rb
196
199
  - lib/source2md/formatter/type_nop.rb
@@ -217,6 +220,7 @@ files:
217
220
  - spec/formatter/sample.yml
218
221
  - spec/formatter/type_alert_spec.rb
219
222
  - spec/formatter/type_code_include_spec.rb
223
+ - spec/formatter/type_eval_spec.rb
220
224
  - spec/formatter/type_hidden_spec.rb
221
225
  - spec/formatter/type_method_spec.rb
222
226
  - spec/formatter/type_parse_include_spec.rb
@@ -250,7 +254,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
250
254
  - !ruby/object:Gem::Version
251
255
  version: '0'
252
256
  requirements: []
253
- rubygems_version: 3.4.20
257
+ rubygems_version: 3.4.22
254
258
  signing_key:
255
259
  specification_version: 4
256
260
  summary: Markdown generator from source code
@@ -259,6 +263,7 @@ test_files:
259
263
  - spec/formatter/sample.yml
260
264
  - spec/formatter/type_alert_spec.rb
261
265
  - spec/formatter/type_code_include_spec.rb
266
+ - spec/formatter/type_eval_spec.rb
262
267
  - spec/formatter/type_hidden_spec.rb
263
268
  - spec/formatter/type_method_spec.rb
264
269
  - spec/formatter/type_parse_include_spec.rb