pandocomatic 0.2.6 → 0.2.7.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pandocomatic/cli.rb +9 -1
- data/lib/pandocomatic/command/convert_file_command.rb +10 -10
- data/lib/pandocomatic/command/convert_file_multiple_command.rb +0 -1
- data/lib/pandocomatic/configuration.rb +81 -17
- data/lib/pandocomatic/pandocomatic.rb +1 -1
- data/lib/pandocomatic/printer/views/help.txt +18 -2
- data/lib/pandocomatic/printer/views/version.txt +1 -1
- data/lib/pandocomatic/processors/fileinfo_preprocessor.rb +2 -1
- metadata +14 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 01d2cd31cfa5c0a4c078b733202f8236c156d89b6f0f3f089ebc214e7c0ecfda
|
4
|
+
data.tar.gz: 91c1f7b718a51e6c92de550eca8aebc8bbf1870399dc15f2ea0fddbc8bfd0f46
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9615e733f2639c45dc5fae67229e99ae39cb0bd869a2690488e115e847d79cd2c97cb2fbf62695155e602decb6c6d9256bfeac2e4b29626127ce92bf02f5fbb4
|
7
|
+
data.tar.gz: e17f09cad20a7f7b78bd35d2ccfec41f6e15bcd58a5998a25d9b121142de1f26d8f991f84bce296dd5ea3dce6f1e6c0850d0b6583a82361aded382568c425268
|
data/lib/pandocomatic/cli.rb
CHANGED
@@ -66,7 +66,10 @@ module Pandocomatic
|
|
66
66
|
opt :output, 'Output', :short => '-o', :type => String
|
67
67
|
opt :input, 'Input', :short => '-i', :type => String, :multi => true
|
68
68
|
|
69
|
-
#
|
69
|
+
# Experimental
|
70
|
+
opt :root_path, 'Root path', :short => '-r', :type => String
|
71
|
+
|
72
|
+
# Common
|
70
73
|
opt :show_version, 'Version', :short => '-v', :long => 'version'
|
71
74
|
opt :show_help, 'Help', :short => '-h', :long => 'help'
|
72
75
|
end
|
@@ -122,6 +125,11 @@ module Pandocomatic
|
|
122
125
|
raise CLIError.new(:no_output_given) if not multiple_inputs and File.directory? input.first
|
123
126
|
end
|
124
127
|
|
128
|
+
# No check for root_path: a user can supply one that does not exists
|
129
|
+
# at this location and still work on the output location.
|
130
|
+
if options[:root_path_given]
|
131
|
+
end
|
132
|
+
|
125
133
|
# Data dir, if specified, should be an existing and readable directory
|
126
134
|
if options[:data_dir_given]
|
127
135
|
data_dir = File.absolute_path options[:data_dir]
|
@@ -109,6 +109,11 @@ module Pandocomatic
|
|
109
109
|
|
110
110
|
pandoc_options = Configuration.extend_value(pandoc_options, template['pandoc'])
|
111
111
|
end
|
112
|
+
|
113
|
+
# Write out the results of the conversion process to file.
|
114
|
+
if @dst.to_s.empty? and @metadata.pandoc_options.has_key? 'output'
|
115
|
+
@dst = @metadata.pandoc_options['output']
|
116
|
+
end
|
112
117
|
|
113
118
|
template = Configuration.extend_value(@metadata.pandocomatic, template) if @metadata.has_pandocomatic?
|
114
119
|
|
@@ -121,7 +126,7 @@ module Pandocomatic
|
|
121
126
|
# Run the default preprocessors to mix-in information about the file
|
122
127
|
# that is being converted and mix-in the template's metadata section as
|
123
128
|
# well
|
124
|
-
input = FileInfoPreprocessor.run input, @src, pandoc_options
|
129
|
+
input = FileInfoPreprocessor.run input, @src, src_root, pandoc_options
|
125
130
|
input = MetadataPreprocessor.run input, template['metadata'] if template.has_key? 'metadata' and not template['metadata'].empty?
|
126
131
|
|
127
132
|
# Convert the file by preprocessing it, run pandoc on it, and
|
@@ -130,11 +135,6 @@ module Pandocomatic
|
|
130
135
|
input = pandoc input, pandoc_options, File.dirname(@src)
|
131
136
|
output = postprocess input, template
|
132
137
|
|
133
|
-
# Write out the results of the conversion process to file.
|
134
|
-
if @dst.to_s.empty? and @metadata.pandoc_options.has_key? 'output'
|
135
|
-
@dst = @metadata.pandoc_options['output']
|
136
|
-
end
|
137
|
-
|
138
138
|
begin
|
139
139
|
unless use_output_option @dst then
|
140
140
|
File.open(@dst, 'w') do |file|
|
@@ -187,9 +187,9 @@ module Pandocomatic
|
|
187
187
|
if PANDOC_OPTIONS_WITH_PATH.include? option
|
188
188
|
is_executable = option == "filter"
|
189
189
|
if value.is_a? Array
|
190
|
-
value = value.map {|v| @config.update_path(v, src_dir, is_executable)}
|
190
|
+
value = value.map {|v| @config.update_path(v, src_dir, absolute_dst, is_executable)}
|
191
191
|
else
|
192
|
-
value = @config.update_path(value, src_dir, is_executable)
|
192
|
+
value = @config.update_path(value, src_dir, @dst, is_executable)
|
193
193
|
end
|
194
194
|
end
|
195
195
|
|
@@ -264,10 +264,10 @@ module Pandocomatic
|
|
264
264
|
processors = config[type]
|
265
265
|
output = input
|
266
266
|
processors.each do |processor|
|
267
|
-
script = if @config.is_local_path processor
|
267
|
+
script = if @config.is_local_path? processor
|
268
268
|
processor
|
269
269
|
else
|
270
|
-
@config.update_path(processor, File.dirname(@src), true)
|
270
|
+
@config.update_path(processor, File.dirname(@src), @dst, true)
|
271
271
|
end
|
272
272
|
|
273
273
|
command, *parameters = script.shellsplit # split on spaces unless it is preceded by a backslash
|
@@ -55,9 +55,15 @@ module Pandocomatic
|
|
55
55
|
'slideous' => 'html',
|
56
56
|
'dzslides' => 'html',
|
57
57
|
'revealjs' => 'html',
|
58
|
-
's5' => 'html'
|
58
|
+
's5' => 'html',
|
59
|
+
'bibtex' => 'bib',
|
60
|
+
'biblatex' => 'bib'
|
59
61
|
}
|
60
62
|
|
63
|
+
# Indicator for paths that should be treated as "relative to the root
|
64
|
+
# path". These paths start with this ROOT_PATH_INDICATOR.
|
65
|
+
ROOT_PATH_INDICATOR = "$ROOT$"
|
66
|
+
|
61
67
|
# A Configuration object models a pandocomatic configuration.
|
62
68
|
class Configuration
|
63
69
|
|
@@ -90,6 +96,8 @@ module Pandocomatic
|
|
90
96
|
nil
|
91
97
|
end
|
92
98
|
|
99
|
+
@root_path = determine_root_path options
|
100
|
+
|
93
101
|
# Extend the command classes by setting the source tree root
|
94
102
|
# directory, and the options quiet and dry-run, which are used when
|
95
103
|
# executing a command: if dry-run the command is not actually
|
@@ -231,6 +239,13 @@ module Pandocomatic
|
|
231
239
|
@options[:data_dir_given]
|
232
240
|
end
|
233
241
|
|
242
|
+
# Is the root path CLI option given?
|
243
|
+
#
|
244
|
+
# @return [Boolean]
|
245
|
+
def root_path?()
|
246
|
+
@options[:root_path_given]
|
247
|
+
end
|
248
|
+
|
234
249
|
# Is the config CLI option given?
|
235
250
|
#
|
236
251
|
# @return [Boolean]
|
@@ -288,6 +303,7 @@ module Pandocomatic
|
|
288
303
|
# If a temporary file has been created while concatenating
|
289
304
|
# multiple input files, ensure it is removed.
|
290
305
|
if @input.is_a? MultipleFilesInput then
|
306
|
+
warn "CLEAN UP"
|
291
307
|
@input.destroy!
|
292
308
|
end
|
293
309
|
end
|
@@ -528,29 +544,30 @@ module Pandocomatic
|
|
528
544
|
# @param path [String] path to the executable
|
529
545
|
# @param src_dir [String] the source directory from which pandocomatic
|
530
546
|
# conversion process has been started
|
531
|
-
# @param
|
547
|
+
# @param dst [String] the destination path
|
548
|
+
# @param check_executable [Boolean = false] Should the executable be
|
532
549
|
# verified to be executable? Defaults to false.
|
533
550
|
#
|
534
551
|
# @return [String] the updated path.
|
535
|
-
def update_path(path, src_dir, check_executable = false, output = false)
|
552
|
+
def update_path(path, src_dir, dst = "", check_executable = false, output = false)
|
536
553
|
updated_path = path
|
537
554
|
|
538
|
-
if is_local_path path
|
555
|
+
if is_local_path? path
|
539
556
|
# refers to a local dir; strip the './' before appending it to
|
540
557
|
# the source directory as to prevent /some/path/./to/path
|
541
558
|
updated_path = path[2..-1]
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
559
|
+
elsif is_absolute_path? path
|
560
|
+
updated_path = path
|
561
|
+
elsif is_root_relative_path? path
|
562
|
+
updated_path = make_path_root_relative path, dst, @root_path
|
563
|
+
else
|
564
|
+
if check_executable
|
565
|
+
updated_path = Configuration.which path
|
566
|
+
end
|
549
567
|
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
end
|
568
|
+
if updated_path.nil? or not check_executable then
|
569
|
+
# refers to data-dir
|
570
|
+
updated_path = File.join @data_dir, path
|
554
571
|
end
|
555
572
|
end
|
556
573
|
|
@@ -643,7 +660,7 @@ module Pandocomatic
|
|
643
660
|
end
|
644
661
|
end
|
645
662
|
|
646
|
-
def is_local_path(path)
|
663
|
+
def is_local_path?(path)
|
647
664
|
if Gem.win_platform? then
|
648
665
|
path.match("^\\.\\\\\.*$")
|
649
666
|
else
|
@@ -818,7 +835,7 @@ module Pandocomatic
|
|
818
835
|
end
|
819
836
|
|
820
837
|
|
821
|
-
def is_absolute_path(path)
|
838
|
+
def is_absolute_path?(path)
|
822
839
|
if Gem.win_platform? then
|
823
840
|
path.match("^[a-zA-Z]:\\\\\.*$")
|
824
841
|
else
|
@@ -826,6 +843,43 @@ module Pandocomatic
|
|
826
843
|
end
|
827
844
|
end
|
828
845
|
|
846
|
+
def is_root_relative_path?(path)
|
847
|
+
path.start_with? ROOT_PATH_INDICATOR
|
848
|
+
end
|
849
|
+
|
850
|
+
def make_path_root_relative(path, dst, root)
|
851
|
+
# Find how to get to the root directopry from dst directory.
|
852
|
+
# Assumption is that dst is a subdirectory of root.
|
853
|
+
dst_dir = File.dirname(File.absolute_path(dst))
|
854
|
+
|
855
|
+
path.delete_prefix! ROOT_PATH_INDICATOR if is_root_relative_path? path
|
856
|
+
|
857
|
+
if File.exist? root and File.realpath("#{dst_dir}").start_with?(File.realpath(root)) then
|
858
|
+
rel_start = ""
|
859
|
+
|
860
|
+
until File.identical?(File.realpath("#{dst_dir}/#{rel_start}"), File.realpath(root)) do
|
861
|
+
# invariant dst_dir/rel_start <= root
|
862
|
+
rel_start += "../"
|
863
|
+
end
|
864
|
+
|
865
|
+
if rel_start.end_with? "/" and path.start_with? "/" then
|
866
|
+
"#{rel_start}#{path.delete_prefix("/")}"
|
867
|
+
else
|
868
|
+
"#{rel_start}#{path}"
|
869
|
+
end
|
870
|
+
else
|
871
|
+
# Because the destination is not in a subdirectory of root, a
|
872
|
+
# relative path to that root cannot be created. Instead,
|
873
|
+
# the path is assumed to be absolute relative to root
|
874
|
+
root = root.delete_suffix "/" if root.end_with? "/"
|
875
|
+
path = path.delete_prefix "/" if path.start_with? "/"
|
876
|
+
|
877
|
+
"#{root}/#{path}"
|
878
|
+
end
|
879
|
+
|
880
|
+
|
881
|
+
end
|
882
|
+
|
829
883
|
def determine_config_file(options, data_dir = Dir.pwd)
|
830
884
|
config_file = ''
|
831
885
|
|
@@ -884,5 +938,15 @@ module Pandocomatic
|
|
884
938
|
|
885
939
|
path
|
886
940
|
end
|
941
|
+
|
942
|
+
def determine_root_path(options)
|
943
|
+
if options[:root_path_given] then
|
944
|
+
options[:root_path]
|
945
|
+
elsif options[:output_given] then
|
946
|
+
File.absolute_path(File.dirname options[:output])
|
947
|
+
else
|
948
|
+
File.absolute_path "."
|
949
|
+
end
|
950
|
+
end
|
887
951
|
end
|
888
952
|
end
|
@@ -25,6 +25,9 @@ DESCRIPTION
|
|
25
25
|
|
26
26
|
OPTIONS
|
27
27
|
|
28
|
+
|
29
|
+
Required:
|
30
|
+
|
28
31
|
-i PATH, --input PATH
|
29
32
|
Convert PATH. If this option is not given, INPUT is
|
30
33
|
converted. INPUT and --input cannot be used together.
|
@@ -36,7 +39,8 @@ OPTIONS
|
|
36
39
|
-o PATH, --output PATH
|
37
40
|
Create converted files and directories in PATH.
|
38
41
|
|
39
|
-
|
42
|
+
|
43
|
+
Optional:
|
40
44
|
|
41
45
|
-d PATH, --data-dir PATH
|
42
46
|
Configure pandocomatic to use PATH as its data directory.
|
@@ -99,6 +103,18 @@ OPTIONS
|
|
99
103
|
|
100
104
|
-y, --dry-run Configure pandocomatic to run the conversion process, but do
|
101
105
|
not actually run it. Default is FALSE.
|
106
|
+
|
107
|
+
|
108
|
+
Experimental:
|
109
|
+
|
110
|
+
-r PATH, --root-path PATH
|
111
|
+
Set the root path to use with paths that are specified as
|
112
|
+
relative to that root path. It is used mostly with the
|
113
|
+
--css pandoc option. It defaults to the directory of the
|
114
|
+
specified output.
|
115
|
+
|
116
|
+
|
117
|
+
Common:
|
102
118
|
|
103
119
|
-v, --version Show the version. If this option is used, all other options
|
104
120
|
are ignored.
|
@@ -134,7 +150,7 @@ AUTHOR
|
|
134
150
|
|
135
151
|
LICENSE
|
136
152
|
|
137
|
-
Copyright 2014—
|
153
|
+
Copyright 2014—2020 Huub de Beer <huub@heerdebeer.org>
|
138
154
|
|
139
155
|
Pandocomatic is free software: you can redistribute it and/or modify
|
140
156
|
it under the terms of the GNU General Public License as published by the
|
@@ -31,7 +31,7 @@ module Pandocomatic
|
|
31
31
|
# @param path [String] the path to the input document
|
32
32
|
# @param options [Hash] pandoc options collected by pandocomatic to run on
|
33
33
|
# this file
|
34
|
-
def self.run input, path, options
|
34
|
+
def self.run input, path, src_path, options
|
35
35
|
created_at = File.stat(path).ctime
|
36
36
|
modified_at = File.stat(path).mtime
|
37
37
|
output = input
|
@@ -41,6 +41,7 @@ module Pandocomatic
|
|
41
41
|
output << " to: #{options['to']}\n" if options.has_key? 'to'
|
42
42
|
output << " template: #{options['template']}\n" if options.has_key? 'template'
|
43
43
|
output << " path: '#{path}'\n"
|
44
|
+
output << " src_path: '#{src_path}'\n"
|
44
45
|
output << " created: #{created_at.strftime '%Y-%m-%d'}\n"
|
45
46
|
output << " modified: #{modified_at.strftime '%Y-%m-%d'}\n"
|
46
47
|
output << "...\n\n"
|
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.
|
4
|
+
version: 0.2.7.4
|
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:
|
11
|
+
date: 2020-11-04 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.4.0
|
20
17
|
- - "~>"
|
21
18
|
- !ruby/object:Gem::Version
|
22
19
|
version: '0.4'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.4.2.1
|
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.4.0
|
30
27
|
- - "~>"
|
31
28
|
- !ruby/object:Gem::Version
|
32
29
|
version: '0.4'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.4.2.1
|
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
|
@@ -147,7 +147,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
147
147
|
requirements:
|
148
148
|
- - ">="
|
149
149
|
- !ruby/object:Gem::Version
|
150
|
-
version: 2.
|
150
|
+
version: '2.5'
|
151
151
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
152
152
|
requirements:
|
153
153
|
- - ">="
|
@@ -155,8 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
155
155
|
version: '0'
|
156
156
|
requirements:
|
157
157
|
- pandoc, a universal document converter
|
158
|
-
|
159
|
-
rubygems_version: 3.0.0.beta1
|
158
|
+
rubygems_version: 3.1.2
|
160
159
|
signing_key:
|
161
160
|
specification_version: 4
|
162
161
|
summary: Automate the use of pandoc
|