pandocomatic 0.2.5.0.betac → 0.2.5.0.betad
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pandocomatic/command/convert_file_command.rb +3 -1
- data/lib/pandocomatic/command/convert_file_multiple_command.rb +1 -1
- data/lib/pandocomatic/input.rb +10 -0
- data/lib/pandocomatic/multiple_files_input.rb +10 -27
- data/lib/pandocomatic/pandoc_metadata.rb +30 -7
- data/lib/pandocomatic/pandocomatic.rb +9 -1
- metadata +13 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c46b6b2c7d745668a59b28bb2f38823ece50c90f24bd53e31c586489e429cb88
|
4
|
+
data.tar.gz: 336889e4f77b7511034f62cb21ab42c01095818e79ebd3d758f30aecc8e10278
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1f6304e2838a32387b88fd4a18f855e1ee90159262635b9f2cd2b3f568523868dcb157499dcd6fb886f77769ca5a687f68427f24ffb233cb8e6f914e0de9e00
|
7
|
+
data.tar.gz: 5f13e1a64e6b012726d55053df8bf0eb9a7bca879201f3c71d164ae526f6ad7db721b0032616471223e7910d88b202cc44791361ec1812e1fc06ae459e16bcc1
|
@@ -90,7 +90,9 @@ module Pandocomatic
|
|
90
90
|
#
|
91
91
|
# @return [String]
|
92
92
|
def to_s
|
93
|
-
"convert #{File.basename @src} #{"-> #{File.basename @dst}" unless @dst.nil?}"
|
93
|
+
str = "convert #{File.basename @src} #{"-> #{File.basename @dst}" unless @dst.nil?}"
|
94
|
+
str += "\n\t encountered multiple pandocomatic properties in the metadata. Only the last occurring pandocomatic property is being used." unless @metadata.unique?
|
95
|
+
str
|
94
96
|
end
|
95
97
|
|
96
98
|
private
|
data/lib/pandocomatic/input.rb
CHANGED
@@ -23,11 +23,14 @@ module Pandocomatic
|
|
23
23
|
# Generic class to handle input files and directories in a general manner.
|
24
24
|
class Input
|
25
25
|
|
26
|
+
attr_reader :errors
|
27
|
+
|
26
28
|
# Create a new Input
|
27
29
|
#
|
28
30
|
# @param input [String[]] a list of input files
|
29
31
|
def initialize(input)
|
30
32
|
@input_files = input
|
33
|
+
@errors = []
|
31
34
|
end
|
32
35
|
|
33
36
|
# The absolute path to this Input
|
@@ -57,6 +60,13 @@ module Pandocomatic
|
|
57
60
|
def directory?()
|
58
61
|
File.directory? @input_files.first
|
59
62
|
end
|
63
|
+
|
64
|
+
# Does this input have encountered any errors?
|
65
|
+
#
|
66
|
+
# @return Boolean
|
67
|
+
def has_errors?()
|
68
|
+
not @errors.empty?
|
69
|
+
end
|
60
70
|
|
61
71
|
# A string representation of this Input
|
62
72
|
#
|
@@ -38,7 +38,7 @@ module Pandocomatic
|
|
38
38
|
#
|
39
39
|
# @return String
|
40
40
|
def name()
|
41
|
-
@tmp_file
|
41
|
+
@tmp_file.path
|
42
42
|
end
|
43
43
|
|
44
44
|
# Is this input a directory? A MultipleFilesInput cannot be a
|
@@ -83,35 +83,18 @@ module Pandocomatic
|
|
83
83
|
# created in the same directory as the first input file
|
84
84
|
@tmp_file = Tempfile.new(@input_files.first, File.dirname(self.absolute_path))
|
85
85
|
|
86
|
-
|
87
|
-
|
86
|
+
contents = @input_files.map{|file|
|
87
|
+
@errors.push IOError.new(:file_does_not_exist, nil, file) unless File.exist? file
|
88
|
+
@errors.push IOError.new(:file_is_not_a_file, nil, file) unless File.file? file
|
89
|
+
@errors.push IOError.new(:file_is_not_readable, nil, file) unless File.readable? file
|
90
|
+
File.read File.absolute_path(file)
|
91
|
+
}.join("\n\n")
|
88
92
|
|
89
|
-
|
90
|
-
"
|
91
|
-
metadata.pandoc_options["from"]
|
92
|
-
else
|
93
|
-
template = @config.determine_template @input_files.first
|
94
|
-
if not template.nil? and not template.dig("pandoc", "from").nil? then
|
95
|
-
template["pandoc"]["from"]
|
96
|
-
else
|
97
|
-
if @config.is_markdown_file? @input_files.first then
|
98
|
-
"markdown"
|
99
|
-
else
|
100
|
-
"unknown"
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
@input_files.each_with_index do |filename, index|
|
106
|
-
input = File.read File.absolute_path(filename)
|
107
|
-
input = if 0 == index or not strip_metadata or not @config.is_markdown_file? filename then
|
108
|
-
input
|
109
|
-
else
|
110
|
-
PandocMetadata.remove_metadata(input)
|
111
|
-
end
|
112
|
-
@tmp_file.write input
|
93
|
+
if not PandocMetadata.unique_pandocomatic_property? contents
|
94
|
+
warn "\nWarning: Encountered the pandocomatic metadata property more than once. Only the last occurrence of the pandocomatic metadata property is being used. Most likely you only want to use a pandocomatic metadata property in the first input file.\n\n"
|
113
95
|
end
|
114
96
|
|
97
|
+
@tmp_file.write contents
|
115
98
|
@tmp_file.rewind
|
116
99
|
end
|
117
100
|
end
|
@@ -36,7 +36,7 @@ module Pandocomatic
|
|
36
36
|
#
|
37
37
|
# @param input_document [String] a path to an input file
|
38
38
|
# @return [String] the input document's metadata in the YAML format.
|
39
|
-
def self.extract_metadata
|
39
|
+
def self.extract_metadata(input_document)
|
40
40
|
begin
|
41
41
|
pandoc2yaml File.read(input_document)
|
42
42
|
rescue StandardError => e
|
@@ -65,19 +65,31 @@ module Pandocomatic
|
|
65
65
|
.join("\n")
|
66
66
|
end
|
67
67
|
|
68
|
+
# Does the pandocomatic metadata property occur at most once?
|
69
|
+
#
|
70
|
+
# @return [Boolean] False if the pandocomatic metadata property does
|
71
|
+
# occur multiple times.
|
72
|
+
def self.unique_pandocomatic_property?(input)
|
73
|
+
1 >= input
|
74
|
+
.scan(METADATA_BLOCK)
|
75
|
+
.map {|match| YAML.load "---#{match.join()}..."}
|
76
|
+
.count {|yaml| yaml.key? "pandocomatic_" or yaml.key? "pandocomatic"}
|
77
|
+
end
|
78
|
+
|
68
79
|
# Collect the metadata embedded in the src file and create a new
|
69
80
|
# PandocMetadata instance
|
70
81
|
#
|
71
82
|
# @param src [String] the path to the file to load metadata from
|
72
83
|
# @return [PandocMetadata] the metadata in the source file, or an empty
|
73
84
|
# one if no such metadata is contained in the source file.
|
74
|
-
def self.load_file
|
75
|
-
|
85
|
+
def self.load_file(src)
|
86
|
+
input = File.read src
|
87
|
+
yaml_metadata = pandoc2yaml input
|
76
88
|
|
77
89
|
if yaml_metadata.empty? then
|
78
|
-
|
90
|
+
PandocMetadata.new
|
79
91
|
else
|
80
|
-
|
92
|
+
PandocMetadata.new YAML.load(yaml_metadata), unique_pandocomatic_property?(input)
|
81
93
|
end
|
82
94
|
end
|
83
95
|
|
@@ -86,10 +98,21 @@ module Pandocomatic
|
|
86
98
|
#
|
87
99
|
# @param hash [Hash] initial properties for this new PandocMetadata
|
88
100
|
# object
|
101
|
+
# @param unique [Boolean = true] the pandocomatic property did occur
|
102
|
+
# at most once.
|
89
103
|
# @return [PandocMetadata]
|
90
|
-
def initialize
|
91
|
-
super
|
104
|
+
def initialize(hash = {}, unique = true)
|
105
|
+
super()
|
92
106
|
merge! hash
|
107
|
+
@unique = unique
|
108
|
+
end
|
109
|
+
|
110
|
+
# Did the metadata contain multiple pandocomatic blocks?
|
111
|
+
#
|
112
|
+
# @return [Boolean] True if at most one pandocomatic block was present
|
113
|
+
# in the metadata
|
114
|
+
def unique?()
|
115
|
+
@unique
|
93
116
|
end
|
94
117
|
|
95
118
|
# Does this PandocMetadata object use a template?
|
@@ -66,6 +66,14 @@ module Pandocomatic
|
|
66
66
|
# version option. If given, the help is printed.
|
67
67
|
HelpPrinter.new().print
|
68
68
|
else
|
69
|
+
# When using multiple input files, errors reading these
|
70
|
+
# files are already encountered at this point. If there
|
71
|
+
# are any errors, there is no reason to continue.
|
72
|
+
if configuration.input.has_errors?
|
73
|
+
ConfigurationErrorsPrinter.new(configuration.input.all_errors).print
|
74
|
+
exit ERROR_STATUS
|
75
|
+
end
|
76
|
+
|
69
77
|
# Run the pandocomatic converter configured according to the options
|
70
78
|
# given.
|
71
79
|
#
|
@@ -108,7 +116,7 @@ module Pandocomatic
|
|
108
116
|
warn "An unexpected error has occurred. You can report this bug via https://github.com/htdebeer/pandocomatic/issues/new."
|
109
117
|
raise e
|
110
118
|
ensure
|
111
|
-
configuration.clean_up!
|
119
|
+
configuration.clean_up! unless configuration.nil?
|
112
120
|
end
|
113
121
|
end
|
114
122
|
end
|
metadata
CHANGED
@@ -1,53 +1,53 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pandocomatic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.5.0.
|
4
|
+
version: 0.2.5.0.betad
|
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: 2019-03-
|
11
|
+
date: 2019-03-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: paru
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 0.3.2
|
20
17
|
- - ">="
|
21
18
|
- !ruby/object:Gem::Version
|
22
19
|
version: 0.3.2.0
|
20
|
+
- - "~>"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.3.2
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
|
-
- - "~>"
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: 0.3.2
|
30
27
|
- - ">="
|
31
28
|
- !ruby/object:Gem::Version
|
32
29
|
version: 0.3.2.0
|
30
|
+
- - "~>"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.3.2
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: optimist
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
36
36
|
requirements:
|
37
|
-
- - "
|
37
|
+
- - ">="
|
38
38
|
- !ruby/object:Gem::Version
|
39
39
|
version: 3.0.0
|
40
|
-
- - "
|
40
|
+
- - "~>"
|
41
41
|
- !ruby/object:Gem::Version
|
42
42
|
version: 3.0.0
|
43
43
|
type: :runtime
|
44
44
|
prerelease: false
|
45
45
|
version_requirements: !ruby/object:Gem::Requirement
|
46
46
|
requirements:
|
47
|
-
- - "
|
47
|
+
- - ">="
|
48
48
|
- !ruby/object:Gem::Version
|
49
49
|
version: 3.0.0
|
50
|
-
- - "
|
50
|
+
- - "~>"
|
51
51
|
- !ruby/object:Gem::Version
|
52
52
|
version: 3.0.0
|
53
53
|
- !ruby/object:Gem::Dependency
|
@@ -156,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
156
156
|
requirements:
|
157
157
|
- pandoc, a universal document converer <http://pandoc.org>
|
158
158
|
rubyforge_project:
|
159
|
-
rubygems_version:
|
159
|
+
rubygems_version: 3.0.0.beta1
|
160
160
|
signing_key:
|
161
161
|
specification_version: 4
|
162
162
|
summary: Automating the use of pandoc
|