pandocomatic 0.1.1 → 0.1.2

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
  SHA1:
3
- metadata.gz: f407c39ec47d26ed9e8bdbb5452983aba4778824
4
- data.tar.gz: beea9f4b103e36896a83be1cf57be5d279d09cf3
3
+ metadata.gz: a4eb96b887676605773e3929aebac5709f2a70ff
4
+ data.tar.gz: 2815789aeb3065e128606f3dedb338277251134f
5
5
  SHA512:
6
- metadata.gz: b5b33aa1bbf4a007c30b9a270dbd78341d80f3830d5f18f8f4d00beb39f565ab99051f705d480d817aee2209fa7aaa2b47b797c6942ee7dc0918554ce4b96eab
7
- data.tar.gz: f2a4c7b1b5869eafb6ed777b49070fefb1a970329da7f7b9ba26af56584cc90c87b82e9f43ad5201a2ba21f5825d511edb58446a82a14bc085ea1d726b2d45dc
6
+ metadata.gz: 439b66fabcd4f8c9af43c112f16495aa251a71a592ba22b8691fbdfb40ced84dd1abdb859a927be56ad2fd829aede581a4f811749bdb58bcc9e0839a41ce9623
7
+ data.tar.gz: 982c94db04f6e51e0bce760e3028aa8256bd9315d3b7ffab6bfe0609810479a215f7cc5ccb27df428fd0daffb4dd19d0cac76587741b0fcf6dda5a7fef99f78b
@@ -57,7 +57,6 @@ module Pandocomatic
57
57
 
58
58
  def convert_file
59
59
  metadata = PandocMetadata.load_file @src
60
-
61
60
  pandoc_options = metadata.pandoc_options || {}
62
61
  template = {}
63
62
 
@@ -26,18 +26,6 @@ module Pandocomatic
26
26
  require_relative './error/io_error.rb'
27
27
 
28
28
  class PandocMetadata < Hash
29
-
30
- # Paru converters:
31
- # Note. When converting metadata back to the pandoc markdown format, you have
32
- # to use the option 'standalone', otherwise the metadata is skipped
33
- PANDOC_2_JSON = Paru::Pandoc.new {from 'markdown'; to 'json'}
34
- JSON_2_PANDOC = Paru::Pandoc.new {from 'json'; to 'markdown'; standalone}
35
-
36
- # When converting a pandoc document to JSON, or vice versa, the JSON object
37
- # has the following three properties:
38
- VERSION = 'pandoc-api-version'
39
- META = 'meta'
40
- BLOCKS = 'blocks'
41
29
 
42
30
  def self.extract_metadata input_document
43
31
  begin
@@ -48,31 +36,17 @@ module Pandocomatic
48
36
  end
49
37
 
50
38
  def self.pandoc2yaml(input)
51
- yaml = ""
52
- begin
53
- json = JSON.parse(PANDOC_2_JSON << input)
54
-
55
- version, metadata = json.values_at(VERSION, META)
56
-
57
- if not metadata.empty? then
58
- metadata_document = {
59
- VERSION => version,
60
- META => metadata,
61
- BLOCKS => []
62
- }
63
-
64
- yaml = JSON_2_PANDOC << JSON.generate(metadata_document)
65
- end
66
- rescue Paru::Error => e
67
- raise PandocError.new(:error_running_pandoc, e, input_document)
68
- end
69
-
70
- yaml
39
+ input
40
+ .scan(/^---\n(.+?)^(?:---|\.\.\.)\n/m)
41
+ .flatten
42
+ .map{|yaml| yaml.strip}
43
+ .join("\n")
71
44
  end
72
45
 
73
46
  # Collect the metadata embedded in the src file
74
47
  def self.load_file src
75
48
  yaml_metadata = extract_metadata src
49
+
76
50
  if yaml_metadata.empty? then
77
51
  return PandocMetadata.new
78
52
  else
@@ -85,14 +59,13 @@ module Pandocomatic
85
59
  merge! hash
86
60
  end
87
61
 
88
- def has_template?
89
- self['pandocomatic'] and self['pandocomatic']['use-template'] and
90
- not self['pandocomatic']['use-template'].empty?
62
+ def has_template?()
63
+ has_pandocomatic? and pandocomatic.has_key? 'use-template' and not pandocomatic['use-template'].empty?
91
64
  end
92
65
 
93
- def template_name
66
+ def template_name()
94
67
  if has_template? then
95
- self['pandocomatic']['use-template']
68
+ pandocomatic['use-template']
96
69
  else
97
70
  ''
98
71
  end
@@ -101,18 +74,27 @@ module Pandocomatic
101
74
  # TODO: allow a pandoc block outside a pandocomatic block to make
102
75
  # pandocomatic work like paru's do-pandoc.rb.
103
76
 
104
- def has_pandoc_options?
105
- self['pandocomatic'] and self['pandocomatic']['pandoc']
77
+ def has_pandoc_options?()
78
+ has_pandocomatic? and pandocomatic.has_key? 'pandoc'
106
79
  end
107
80
 
108
- def pandoc_options
81
+ def pandoc_options()
109
82
  if has_pandoc_options? then
110
- self['pandocomatic']['pandoc']
83
+ pandocomatic['pandoc']
111
84
  else
112
85
  {}
113
86
  end
114
87
  end
115
88
 
89
+ def has_pandocomatic?()
90
+ has_key? 'pandocomatic' or has_key? 'pandocomatic_'
91
+ end
92
+
93
+ def pandocomatic()
94
+ return self['pandocomatic'] if has_key? 'pandocomatic'
95
+ return self['pandocomatic_'] if has_key? 'pandocomatic_'
96
+ end
97
+
116
98
  end
117
99
 
118
100
  end
@@ -40,7 +40,7 @@ module Pandocomatic
40
40
  require_relative './command/convert_file_command.rb'
41
41
 
42
42
  class Pandocomatic
43
- VERSION = [0, 1, 0]
43
+ VERSION = [0, 1, 2]
44
44
  CONFIG_FILE = 'pandocomatic.yaml'
45
45
 
46
46
  def self.run(args)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pandocomatic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Huub de Beer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-01 00:00:00.000000000 Z
11
+ date: 2017-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: paru