pandocomatic 0.2.6 → 0.2.7.0

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: 75414fdf8e35a31102fd363f188ab12b5d54c525cc8ca1ab5c79a2343041cf82
4
- data.tar.gz: 8dc07b1983650c1204d616e2b214dbaa42f0de54ba96466aa3d480489b4b4607
3
+ metadata.gz: 6777ab9ccebbe75dff8b2e818b9092604517db7039035a11612f2cc93dd5ad81
4
+ data.tar.gz: eae1fffb172cecd76b805cc1b59e72546a4950d2689356d36bacca0dcd67618f
5
5
  SHA512:
6
- metadata.gz: ae8c9b539d5e4fa08f471b5ffa061401fa6f11a3c2896d4da089e6f93742feea788caef087b153938b949c9a8a5f59ad0fd529449778c0fa74e3973f18dffb7a
7
- data.tar.gz: ad60c65b3b5a7fae21956a2060326034a3e046a663d1c3c8570b0961f29fe21903f848b16f0ce121e181af39bcbf656d9364cb00f3afe1a13a4f990fac2ae707
6
+ metadata.gz: c4b1ff0b99853e723c9f8cdda7d4340e81cf2bc649864e35544a596e4d4d8370507b6a1737e64b754cc77a31f2150759734671a336543b05af07fccb86a1831a
7
+ data.tar.gz: 84320c981c1100d36ac44c575358439899e612652fc82b22e1af3154d7d11e92a23bbbb97759a609c53092898bdf06932ede70a6ae6c275a460bbdf4cc121cce
@@ -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
- # Version and help
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,10 @@ 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
+ if options[:root_path_given]
129
+ options[:root_path] = File.absolute_path options[:root_path]
130
+ end
131
+
125
132
  # Data dir, if specified, should be an existing and readable directory
126
133
  if options[:data_dir_given]
127
134
  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
 
@@ -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]
@@ -528,29 +541,30 @@ module Pandocomatic
528
541
  # @param path [String] path to the executable
529
542
  # @param src_dir [String] the source directory from which pandocomatic
530
543
  # conversion process has been started
531
- # @param check_executable [Booelan = false] Should the executable be
544
+ # @param dst [String] the destination path
545
+ # @param check_executable [Boolean = false] Should the executable be
532
546
  # verified to be executable? Defaults to false.
533
547
  #
534
548
  # @return [String] the updated path.
535
- def update_path(path, src_dir, check_executable = false, output = false)
549
+ def update_path(path, src_dir, dst = "", check_executable = false, output = false)
536
550
  updated_path = path
537
551
 
538
- if is_local_path path
552
+ if is_local_path? path
539
553
  # refers to a local dir; strip the './' before appending it to
540
554
  # the source directory as to prevent /some/path/./to/path
541
555
  updated_path = path[2..-1]
542
- else
543
- if is_absolute_path path
544
- updated_path = path
545
- else
546
- if check_executable
547
- updated_path = Configuration.which path
548
- end
556
+ elsif is_absolute_path? path
557
+ updated_path = path
558
+ elsif is_root_relative_path? path
559
+ updated_path = make_path_root_relative path, dst, @root_path
560
+ else
561
+ if check_executable
562
+ updated_path = Configuration.which path
563
+ end
549
564
 
550
- if updated_path.nil? or not check_executable then
551
- # refers to data-dir
552
- updated_path = File.join @data_dir, path
553
- end
565
+ if updated_path.nil? or not check_executable then
566
+ # refers to data-dir
567
+ updated_path = File.join @data_dir, path
554
568
  end
555
569
  end
556
570
 
@@ -643,7 +657,7 @@ module Pandocomatic
643
657
  end
644
658
  end
645
659
 
646
- def is_local_path(path)
660
+ def is_local_path?(path)
647
661
  if Gem.win_platform? then
648
662
  path.match("^\\.\\\\\.*$")
649
663
  else
@@ -818,7 +832,7 @@ module Pandocomatic
818
832
  end
819
833
 
820
834
 
821
- def is_absolute_path(path)
835
+ def is_absolute_path?(path)
822
836
  if Gem.win_platform? then
823
837
  path.match("^[a-zA-Z]:\\\\\.*$")
824
838
  else
@@ -826,6 +840,44 @@ module Pandocomatic
826
840
  end
827
841
  end
828
842
 
843
+ def is_root_relative_path?(path)
844
+ path.start_with? ROOT_PATH_INDICATOR
845
+ end
846
+
847
+ def make_path_root_relative(path, dst, root)
848
+ # Find how to get to the root directopry from dst directory.
849
+ # Assumption is that dst is a subdirectory of root.
850
+ dst_dir = File.dirname(File.absolute_path(dst))
851
+
852
+ path.delete_prefix! ROOT_PATH_INDICATOR if is_root_relative_path? path
853
+
854
+ if File.realpath("#{dst_dir}").start_with? File.realpath(root) then
855
+ rel_start = ""
856
+
857
+ until File.identical?(File.realpath("#{dst_dir}/#{rel_start}"), File.realpath(root)) do
858
+ # invariant dst_dir/rel_start <= root
859
+ rel_start += "../"
860
+ end
861
+
862
+ if rel_start.end_with? "/" and path.start_with? "/" then
863
+ "#{rel_start}#{path.delete_prefix("/")}"
864
+ else
865
+ "#{rel_start}#{path}"
866
+ end
867
+ else
868
+ # Because the destination is not in a subdirectory of root, a
869
+ # relative path to that root cannot be created. Instead,
870
+ # the path is assumed to be absolute relative to root
871
+ if root.end_with? "/" or path.start_with? "/"
872
+ "#{root}#{path}"
873
+ else
874
+ "#{root}/#{path}"
875
+ end
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
@@ -47,7 +47,7 @@ module Pandocomatic
47
47
  ERROR_STATUS = 1266 # This is the sum of the ascii values of the characters in 'pandocomatic'
48
48
 
49
49
  # Pandocomatic's current version
50
- VERSION = [0, 2, 6]
50
+ VERSION = [0, 2, 7, 0]
51
51
 
52
52
  # Run pandocomatic given options
53
53
  #
@@ -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
- optional arguments:
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.
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.6
4
+ version: 0.2.7.0
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-11-27 00:00:00.000000000 Z
11
+ date: 2020-05-06 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.0
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.0
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.4.4
150
+ version: '2.5'
151
151
  required_rubygems_version: !ruby/object:Gem::Requirement
152
152
  requirements:
153
153
  - - ">="
@@ -156,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
156
156
  requirements:
157
157
  - pandoc, a universal document converter
158
158
  rubyforge_project:
159
- rubygems_version: 3.0.0.beta1
159
+ rubygems_version: 2.7.7
160
160
  signing_key:
161
161
  specification_version: 4
162
162
  summary: Automate the use of pandoc