pandocomatic 0.2.5.4 → 0.2.7.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 +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 +78 -16
- 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 +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c5160563dbb3f82d9854f6c822e3e99ab25bd98518baa5628559b2e27b8e46f
|
4
|
+
data.tar.gz: 520905c9a5e69954fbf6f7f8b1217734463f5207e8d1566d2343b4efa40d2dac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 629402536265e66ba416bd93d8515086e1db45752d7bc0168489253350c2e789156eca213105177b8d76b657fa78efd54ee669e8524329099f552ecafa75acca
|
7
|
+
data.tar.gz: 83f696edff0469c550249b41c330b25214f324f349c4295ca43aba7a828cdb2d6a4f93d3c471c3be08da873fbeca2896978d2818300d5d78c14b680b9b8eedf8
|
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
|
@@ -58,6 +58,10 @@ module Pandocomatic
|
|
58
58
|
's5' => 'html'
|
59
59
|
}
|
60
60
|
|
61
|
+
# Indicator for paths that should be treated as "relative to the root
|
62
|
+
# path". These paths start with this ROOT_PATH_INDICATOR.
|
63
|
+
ROOT_PATH_INDICATOR = "$ROOT$"
|
64
|
+
|
61
65
|
# A Configuration object models a pandocomatic configuration.
|
62
66
|
class Configuration
|
63
67
|
|
@@ -90,6 +94,8 @@ module Pandocomatic
|
|
90
94
|
nil
|
91
95
|
end
|
92
96
|
|
97
|
+
@root_path = determine_root_path options
|
98
|
+
|
93
99
|
# Extend the command classes by setting the source tree root
|
94
100
|
# directory, and the options quiet and dry-run, which are used when
|
95
101
|
# executing a command: if dry-run the command is not actually
|
@@ -231,6 +237,13 @@ module Pandocomatic
|
|
231
237
|
@options[:data_dir_given]
|
232
238
|
end
|
233
239
|
|
240
|
+
# Is the root path CLI option given?
|
241
|
+
#
|
242
|
+
# @return [Boolean]
|
243
|
+
def root_path?()
|
244
|
+
@options[:root_path_given]
|
245
|
+
end
|
246
|
+
|
234
247
|
# Is the config CLI option given?
|
235
248
|
#
|
236
249
|
# @return [Boolean]
|
@@ -288,6 +301,7 @@ module Pandocomatic
|
|
288
301
|
# If a temporary file has been created while concatenating
|
289
302
|
# multiple input files, ensure it is removed.
|
290
303
|
if @input.is_a? MultipleFilesInput then
|
304
|
+
warn "CLEAN UP"
|
291
305
|
@input.destroy!
|
292
306
|
end
|
293
307
|
end
|
@@ -528,29 +542,30 @@ module Pandocomatic
|
|
528
542
|
# @param path [String] path to the executable
|
529
543
|
# @param src_dir [String] the source directory from which pandocomatic
|
530
544
|
# conversion process has been started
|
531
|
-
# @param
|
545
|
+
# @param dst [String] the destination path
|
546
|
+
# @param check_executable [Boolean = false] Should the executable be
|
532
547
|
# verified to be executable? Defaults to false.
|
533
548
|
#
|
534
549
|
# @return [String] the updated path.
|
535
|
-
def update_path(path, src_dir, check_executable = false, output = false)
|
550
|
+
def update_path(path, src_dir, dst = "", check_executable = false, output = false)
|
536
551
|
updated_path = path
|
537
552
|
|
538
|
-
if is_local_path path
|
553
|
+
if is_local_path? path
|
539
554
|
# refers to a local dir; strip the './' before appending it to
|
540
555
|
# the source directory as to prevent /some/path/./to/path
|
541
556
|
updated_path = path[2..-1]
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
557
|
+
elsif is_absolute_path? path
|
558
|
+
updated_path = path
|
559
|
+
elsif is_root_relative_path? path
|
560
|
+
updated_path = make_path_root_relative path, dst, @root_path
|
561
|
+
else
|
562
|
+
if check_executable
|
563
|
+
updated_path = Configuration.which path
|
564
|
+
end
|
549
565
|
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
end
|
566
|
+
if updated_path.nil? or not check_executable then
|
567
|
+
# refers to data-dir
|
568
|
+
updated_path = File.join @data_dir, path
|
554
569
|
end
|
555
570
|
end
|
556
571
|
|
@@ -643,7 +658,7 @@ module Pandocomatic
|
|
643
658
|
end
|
644
659
|
end
|
645
660
|
|
646
|
-
def is_local_path(path)
|
661
|
+
def is_local_path?(path)
|
647
662
|
if Gem.win_platform? then
|
648
663
|
path.match("^\\.\\\\\.*$")
|
649
664
|
else
|
@@ -818,7 +833,7 @@ module Pandocomatic
|
|
818
833
|
end
|
819
834
|
|
820
835
|
|
821
|
-
def is_absolute_path(path)
|
836
|
+
def is_absolute_path?(path)
|
822
837
|
if Gem.win_platform? then
|
823
838
|
path.match("^[a-zA-Z]:\\\\\.*$")
|
824
839
|
else
|
@@ -826,6 +841,43 @@ module Pandocomatic
|
|
826
841
|
end
|
827
842
|
end
|
828
843
|
|
844
|
+
def is_root_relative_path?(path)
|
845
|
+
path.start_with? ROOT_PATH_INDICATOR
|
846
|
+
end
|
847
|
+
|
848
|
+
def make_path_root_relative(path, dst, root)
|
849
|
+
# Find how to get to the root directopry from dst directory.
|
850
|
+
# Assumption is that dst is a subdirectory of root.
|
851
|
+
dst_dir = File.dirname(File.absolute_path(dst))
|
852
|
+
|
853
|
+
path.delete_prefix! ROOT_PATH_INDICATOR if is_root_relative_path? path
|
854
|
+
|
855
|
+
if File.exist? root and File.realpath("#{dst_dir}").start_with?(File.realpath(root)) then
|
856
|
+
rel_start = ""
|
857
|
+
|
858
|
+
until File.identical?(File.realpath("#{dst_dir}/#{rel_start}"), File.realpath(root)) do
|
859
|
+
# invariant dst_dir/rel_start <= root
|
860
|
+
rel_start += "../"
|
861
|
+
end
|
862
|
+
|
863
|
+
if rel_start.end_with? "/" and path.start_with? "/" then
|
864
|
+
"#{rel_start}#{path.delete_prefix("/")}"
|
865
|
+
else
|
866
|
+
"#{rel_start}#{path}"
|
867
|
+
end
|
868
|
+
else
|
869
|
+
# Because the destination is not in a subdirectory of root, a
|
870
|
+
# relative path to that root cannot be created. Instead,
|
871
|
+
# the path is assumed to be absolute relative to root
|
872
|
+
root = root.delete_suffix "/" if root.end_with? "/"
|
873
|
+
path = path.delete_prefix "/" if path.start_with? "/"
|
874
|
+
|
875
|
+
"#{root}/#{path}"
|
876
|
+
end
|
877
|
+
|
878
|
+
|
879
|
+
end
|
880
|
+
|
829
881
|
def determine_config_file(options, data_dir = Dir.pwd)
|
830
882
|
config_file = ''
|
831
883
|
|
@@ -884,5 +936,15 @@ module Pandocomatic
|
|
884
936
|
|
885
937
|
path
|
886
938
|
end
|
939
|
+
|
940
|
+
def determine_root_path(options)
|
941
|
+
if options[:root_path_given] then
|
942
|
+
options[:root_path]
|
943
|
+
elsif options[:output_given] then
|
944
|
+
File.absolute_path(File.dirname options[:output])
|
945
|
+
else
|
946
|
+
File.absolute_path "."
|
947
|
+
end
|
948
|
+
end
|
887
949
|
end
|
888
950
|
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,14 +1,14 @@
|
|
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.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:
|
11
|
+
date: 2020-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: paru
|
@@ -16,20 +16,20 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: '0.4'
|
20
20
|
- - ">="
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: 0.
|
22
|
+
version: 0.4.1
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
27
|
- - "~>"
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 0.
|
29
|
+
version: '0.4'
|
30
30
|
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: 0.
|
32
|
+
version: 0.4.1
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: optimist
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -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
|
- - ">="
|