natour 0.7.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6c649407352883c9e93ab6d6470413127d54803bb35dc72beb83292c9e521626
4
- data.tar.gz: dbeb8f8ae4a412d7832c07ab66d717d40bb5e2ecd096fb076655ef65a6840b53
3
+ metadata.gz: 59d15bbec4750fd92158c6cbff64a201bad92792600a03a0f430e0c77ddcbea0
4
+ data.tar.gz: 1b6dedc5f83f66173d77a176d2d20815b4055e2b93c98ecd6d6b26117219c03f
5
5
  SHA512:
6
- metadata.gz: b5a810b2ea0220c9eded025e0f00f8e4f782a42b54128f71a2929a84a535e75f45bb3ddff0cf72f7dad08e047c1aaef3b88800e778901405357efd11336b5db0
7
- data.tar.gz: a928d426c1840cb57fb7ab58064850572fc2a7e14aeda6086b2c9560c8b2d7e3e8253c268a9070bef91e4c7fb2c0f26daf2e5664a043f29b595d192a0299137f
6
+ metadata.gz: 7dd61ac963164d480e626414bef161e1f1a702d26a2ff71e733a796610b18b7942a5f6ce400329a7c9b3f0566ea501d20f7926285d923d85a4eda4835331f14f
7
+ data.tar.gz: 1ad29625fc06e4f738c7e7127d3381aa701ec033618c9d2a5c1b7167b56b1890f3ba4c8035a8bfe4f6dba33ddf5a3d6b842f0650a1da22c19b04b149c51c5977
data/CHANGELOG.adoc CHANGED
@@ -6,90 +6,140 @@ The format is based on https://keepachangelog.com/en/1.0.0/[Keep a Changelog^],
6
6
 
7
7
  == Unreleased
8
8
 
9
+ == 0.9.0 - 2022-10-08
10
+
11
+ === Added
12
+
13
+ - Support colors for GPS tracks, waypoints and routes (`natour map create` command only).
14
+
15
+ === Changed
16
+
17
+ - Omit empty columns of species lists in AsciiDoc output.
18
+
19
+ === Fixed
20
+
21
+ - Fix inconsistent handling of file errors in the command line interface.
22
+ - Fix the creation of map images.
23
+
24
+ == 0.8.0 - 2022-04-22
25
+
26
+ === Added
27
+
28
+ - Add command to create map images from GPS tracks, waypoints and routes.
29
+ - Add command line option to display the version of this gem.
30
+
31
+ === Changed
32
+
33
+ - Rename arguments of `Natour::MapGeoAdmin.save_image`, i.e. `tracks` to `gps_files`, `layers` to `map_layers` and `size` to `image_size`.
34
+ +
35
+ IMPORTANT: This is a breaking change.
36
+ - Improve the error reporting on the command line interface in case of file errors.
37
+ - Rework the configuration; the structure and naming follows the command line interface and the keys are of type Ruby Symbol. For details, see the README file.
38
+ +
39
+ IMPORTANT: This is a breaking change. Adapt the configuration file accordingly.
40
+ - Rework the command line interface. Use `natour --help` to get more information.
41
+ +
42
+ IMPORTANT: This is a breaking change. Adapt the commands accordingly.
43
+ - Change `backend` and `draft_backend` arguments of `Natour::convert_report` to symbols.
44
+ +
45
+ IMPORTANT: This is a breaking change. Adapt the configuration file accordingly.
46
+ - Rename `Natour::create` to `Natour::create_reports` and `Natour::convert` to `Natour::convert_report`.
47
+ +
48
+ IMPORTANT: This is a breaking change.
49
+
50
+ === Fixed
51
+
52
+ - Do not overwrite map images unless otherwise specified.
53
+ - Do not abort if the configuration file is empty.
54
+
9
55
  == 0.7.0 - 2022-02-14
10
56
 
11
57
  === Added
12
58
 
13
- - Add support for Ruby 3.0 and 3.1
14
- - Support species lists from Vogelführer Birdlife Schweiz
59
+ - Add support for Ruby 3.0 and 3.1.
60
+ - Support species lists from https://www.birdlife.ch/de/content/eine-neue-moderne-vogel-app-fuer-die-schweiz[Vogelführer Birdlife Schweiz^].
15
61
 
16
62
  === Changed
17
63
 
18
- - Return the filenames from `create` and `convert`
64
+ - Return the filenames from `Natour::create` and `Natour::convert`.
19
65
 
20
66
  === Removed
21
67
 
22
- - Drop support for Ruby 2.5
68
+ - Drop support for Ruby 2.5.
23
69
 
24
70
  === Fixed
25
71
 
26
- - Add revision date to the AsciiDoc output regardless of the author
27
- - Prevent conversion from being aborted if a built-in date/time attribute is missing
72
+ - Add revision date to the AsciiDoc output regardless of the author.
73
+ - Prevent conversion from being aborted if a built-in date/time attribute is missing.
28
74
 
29
75
  == 0.6.0 - 2021-11-20
30
76
 
31
77
  === Fixed
32
78
 
33
- - Support GPX files containing only mandatory elements (i.e. no extensions)
34
- - Consider also the image dimensions to determine the orientation, even if the tag is present
79
+ - Support GPX files containing only mandatory elements (i.e. no extensions).
80
+ - Consider also the image dimensions to determine the orientation, even if the tag is present.
35
81
 
36
82
  == 0.5.0 - 2021-08-16
37
83
 
38
84
  === Added
39
85
 
40
- - Reflect the date of the last update in the revision date
41
- - Add captions to species lists in the AsciiDoc output
42
- - Group species lists by taxonomic groups in the AsciiDoc output
86
+ - Reflect the date of the last update in the revision date.
87
+ - Add captions to species lists in the AsciiDoc output.
88
+ - Group species lists by taxonomic groups in the AsciiDoc output.
43
89
 
44
90
  === Fixed
45
91
 
46
- - Support species lists of Flora Helvetica exported from Favoriten
47
- - Consider botanical names with the authority name preceding the subspecies
92
+ - Support species lists of https://www.flora-helvetica.ch/[Flora Helvetica^] exported from _Favoriten_.
93
+ - Consider botanical names with the authority name preceding the subspecies.
48
94
 
49
95
  == 0.4.0 - 2021-05-02
50
96
 
51
97
  === Added
52
98
 
53
- - Show date/time of images in draft output
54
- - Support preferred conversion backend for draft output
99
+ - Show date/time of images in draft output.
100
+ - Support preferred conversion backend for draft output.
55
101
 
56
- === Changed
102
+ === Removed
57
103
 
58
- - Remove redundant method `Image.portrait?`
104
+ - Remove redundant method `Natour::Image.portrait?`.
105
+ +
106
+ IMPORTANT: This is a breaking change. Use `Natour::Image.landscape?` instead.
59
107
 
60
108
  == 0.3.0 - 2021-03-07
61
109
 
62
110
  === Changed
63
111
 
64
- - Sort the reports according to their GPS track
65
- - Bump minimum required Ruby version to 2.5
66
- - Change font in PDF output to support ♀ and ♂ symbols
112
+ - Sort the reports according to their GPS track.
113
+ - Bump minimum required Ruby version to 2.5.
114
+ - Change font in PDF output to support ♀ and ♂ symbols.
67
115
 
68
116
  === Fixed
69
117
 
70
- - Make source code compatible with Ruby version 2.5
118
+ - Make source code compatible with Ruby 2.5.
71
119
 
72
120
  == 0.2.0 - 2021-01-24
73
121
 
74
122
  === Added
75
123
 
76
- - Add this gem's name to the footer of the PDF output
77
- - Support species lists from https://www.ornitho.ch/[ornitho.ch^] (KML format only)
78
- - Classify species lists by taxonomic groups (i.e. `SpeciesList.group`)
124
+ - Add this gem's name to the footer of the PDF output.
125
+ - Support species lists from https://www.ornitho.ch/[ornitho.ch^] (KML format only).
126
+ - Classify species lists by taxonomic groups (i.e. `Natour::SpeciesList.group`).
79
127
 
80
128
  === Changed
81
129
 
82
- - Change `SpeciesList.name` to `SpeciesList.title`
83
- - Return an empty array from `SpeciesList.load_file` if the format is unknown
84
- - Change the format of the start time in the AsciiDoc output from _12:30_ to _12:30 Uhr_
85
- - Change the format of the duration in the AsciiDoc output from _1h30_ to _1:30 h_
130
+ - Rename `Natour::SpeciesList.name` to `Natour::SpeciesList.title`.
131
+ +
132
+ IMPORTANT: This is a breaking change.
133
+ - Return an empty array from `Natour::SpeciesList.load_file` if the format is unknown.
134
+ - Change the format of the start time in the AsciiDoc output from _12:30_ to _12:30 Uhr_.
135
+ - Change the format of the duration in the AsciiDoc output from _1h30_ to _1:30 h_.
86
136
 
87
137
  === Fixed
88
138
 
89
- - Get the date from images even if the orientation tag is missing
90
- - Fix typo in help message
139
+ - Get the date from images even if the orientation tag is missing.
140
+ - Fix typo in help message.
91
141
 
92
142
  == 0.1.0 - 2020-12-04
93
143
 
94
144
  === Added
95
- - First release
145
+ - First release.
data/README.adoc CHANGED
@@ -1,6 +1,6 @@
1
1
  = natour
2
2
 
3
- This https://rubygems.org/gems/natour[RubyGem^] provides an application and a library for reports on nature activities.
3
+ This https://rubygems.org/gems/natour[RubyGem^] provides an application and a library to document nature activities.
4
4
 
5
5
  == Installation
6
6
 
@@ -58,49 +58,102 @@ sudo apt install ./google-chrome-stable_current_amd64.deb
58
58
 
59
59
  == Application
60
60
 
61
- [cols="1,4",options=header]
62
- |===
63
- |Command
64
- |Description
61
+ Create reports in https://asciidoc.org/[AsciiDoc^] format from a directory with GPS tracks, images and species lists. After editing the AsciiDoc files (e.g. selecting the images and describing the adventure), they can be converted to various formats, including PDF and HTML. A typical directory structure and the necessary commands are shown in the following example.
62
+
63
+ ....
64
+ └─ 2022-02-26 Monte Caslano < Root directory
65
+ ├─ Bilder < Directory containing images
66
+ │ ├─ IMG_7687.JPG
67
+ │ ├─ IMG_7688.JPG
68
+ │ ├─ ...
69
+ │ └─ IMG_7870.JPG
70
+ ├─ 2022-02-26 14.45.27.fit < GPS track exported by GPS device
71
+ ├─ 2022-02-26 14.45.27.gpx < GPS track exported by GPS device
72
+ ├─ 2022-02-26 14.45.27.jpg < Image of the map section created
73
+ ├─ 2022-02-26 Monte Caslano.adoc < Report in AsciiDoc format created
74
+ ├─ 2022-02-26 Monte Caslano.pdf < Report converted from AsciiDoc to PDF
75
+ ├─ 2022-02-26MonteCaslano.csv < Species list exported from Kosmos Vogelführer
76
+ └─ flora_helvetica_sammlungen.csv < Species list exported from Flora Helvetica
77
+ ....
65
78
 
66
- |`natour`
67
- |Create reports in https://asciidoc.org/[AsciiDoc^] format from a directory with GPS tracks, images and species lists. After editing the AsciiDoc files, they can be converted to various formats, including PDF and HTML. Use `natour --help` to get more information.
68
- |===
79
+ [source,shell]
80
+ ----
81
+ natour report create "2022-02-26 Monte Caslano"
82
+ ----
83
+
84
+ [source,shell]
85
+ ----
86
+ natour report convert "2022-02-26 Monte Caslano/2022-02-26 Monte Caslano.adoc"
87
+ ----
88
+
89
+ NOTE: Use `natour --help` to get more information.
69
90
 
70
91
  === Configuration
71
92
 
72
- The configuration is built by loading https://yaml.org/[YAML^] files in hierarchical order. The files must be named `natour.yml` and are loaded first from the home directory of the current user and then from the current working directory. The values of the previously loaded files are overwritten by the values of the files loaded later. The key-value pairs are stored internally in a Ruby Hash, where the keys correspond to the command line arguments without leading dashes and without `no-` prefix for boolean switches.
93
+ The configuration is built by loading https://yaml.org/[YAML^] files in hierarchical order. The files must be named `natour.yml` and are loaded first from the home directory of the current user and then from the current working directory. The values of the previously loaded files are overwritten by the values of the files loaded later. The values are stored internally in nested, dictionary-like collections (Ruby `Hash`), where the structure follows to the command line interface. All keys are of type Ruby `Symbol` and correspond to the commands and options, with middle hyphens replaced by underscores, leading hyphens removed, and without the `no-` prefix for boolean switches. The following configuration file shows all entries and their default values.
94
+
95
+ [source,yml]
96
+ ----
97
+ ---
98
+ :report:
99
+ :create:
100
+ :out_dir: null
101
+ :out_file: null
102
+ :overwrite: false
103
+ :track_formats:
104
+ - :gpx
105
+ - :fit
106
+ :map: true
107
+ :map_layers: []
108
+ :adoc_author: null
109
+ :convert:
110
+ :out_dir: null
111
+ :out_file: null
112
+ :overwrite: false
113
+ :backend: :pdf
114
+ :draft: false
115
+ :draft_backend: null
116
+ :image_maxdim: 1800
117
+ :map:
118
+ :create:
119
+ :out_dir: null
120
+ :out_file: null
121
+ :overwrite: false
122
+ :gps_colors: []
123
+ :map_layers: []
124
+ :image_size: [1200, 900]
125
+ ----
73
126
 
74
127
  How to restrict GPS tracks to the FIT format (see https://developer.garmin.com/fit/[FIT SDK^]) and add additional map layers (see https://api3.geo.admin.ch/api/faq/index.html#which-layers-are-available[API FAQ - GeoAdmin API 3.0 documentation^]) is shown in the example below.
75
128
 
76
129
  [source,yml]
77
130
  ----
78
131
  ---
79
- track-formats:
80
- - !ruby/sym fit
81
- map-layers:
82
- - ch.swisstopo.swisstlm3d-wanderwege
83
- - ch.bav.haltestellen-oev
132
+ :report:
133
+ :create:
134
+ :track_formats:
135
+ - :fit
136
+ :map_layers:
137
+ - ch.swisstopo.swisstlm3d-wanderwege
138
+ - ch.bav.haltestellen-oev
84
139
  ----
85
140
 
86
141
  == Library
87
142
 
88
- === Basic Use
89
-
90
143
  The basic use is shown in the following example. For details, see the source code and the unit tests.
91
144
 
92
145
  [source,ruby]
93
146
  ----
94
147
  require 'natour'
95
148
 
96
- Natour::create('path/to/dir')
149
+ Natour::create_reports('path/to/dir')
97
150
  ----
98
151
 
99
152
  [source,ruby]
100
153
  ----
101
154
  require 'natour'
102
155
 
103
- Natour::convert('path/to/dir/report.adoc')
156
+ Natour::convert_report('path/to/dir/report.adoc')
104
157
  ----
105
158
 
106
159
  === Testing
data/bin/natour CHANGED
@@ -1,117 +1,168 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'word_wrap'
4
- require 'pathname'
5
- require 'optparse'
3
+ require 'clamp'
6
4
  require 'natour'
5
+ require 'pathname'
6
+ require 'word_wrap'
7
7
 
8
- config = Natour::Config.load_file(
9
- Pathname($PROGRAM_NAME).basename.sub_ext('.yml'),
10
- default: {
11
- 'out-dir' => nil,
12
- 'out-file' => nil,
13
- 'overwrite' => false,
14
- 'track-formats' => %i[gpx fit],
15
- 'map' => true,
16
- 'map-layers' => [],
17
- 'adoc-author' => nil,
18
- 'backend' => 'pdf',
19
- 'draft' => false,
20
- 'draft-backend' => nil,
21
- 'image-maxdim' => 1800
22
- }
23
- )
8
+ class NatourCmd < Clamp::Command
9
+ class ReportCmd < Clamp::Command
10
+ class CreateCmd < Clamp::Command
11
+ banner(WordWrap.ww(
12
+ 'Create reports in AsciiDoc format from a directory. GPS tracks, images and species ' \
13
+ 'lists (Kosmos Vogelführer, Vogelführer Birdlife Schweiz, ornitho.ch, Flora Helvetica, ' \
14
+ 'Info Flora Online-Feldbuch) are included. Images of the map section covered by the GPS ' \
15
+ 'tracks are also created and included.'
16
+ ))
17
+ option(%w[-d --out-dir], 'DIR', 'Output directory')
18
+ option(%w[-f --out-file], 'FILE', 'Output filename')
19
+ option(%W[--\[no-\]overwrite], :flag, 'Overwrite existing files')
20
+ option(%w[--track-formats], 'FORMATS', 'GPS track formats (gpx, fit)') { |s| s.split(',').map(&:to_sym) }
21
+ option(%W[--\[no-\]map], :flag, 'Create map images')
22
+ option(%w[--map-layers], 'LAYERS', 'Add additional layers to map images') { |s| s.split(',') }
23
+ option(%w[--adoc-author], 'AUTHOR', 'AsciiDoc author (name <email>[; name2 <email2>...])')
24
+ parameter('PATH', 'Path to directory')
24
25
 
25
- option_parser = OptionParser.new do |opts|
26
- opts.banner = "Usage: #{Pathname($PROGRAM_NAME).basename('.*')} [OPTIONS]... PATH"
27
- opts.separator('')
28
- opts.separator(WordWrap.ww(
29
- 'If PATH refers to a directory, one or more reports are created in ' \
30
- 'AsciiDoc format. GPS tracks, images and species lists (Kosmos ' \
31
- 'Vogelführer, Vogelführer Birdlife Schweiz, ornitho.ch, Flora Helvetica,' \
32
- ' Info Flora Online-Feldbuch) are included. Images of the map section ' \
33
- 'covered by the GPS tracks are also created and included. If PATH refers' \
34
- ' to an AsciiDoc file, it is converted to PDF (or any other supported ' \
35
- 'format).'
36
- ))
37
- opts.separator('')
38
- opts.separator('General:')
39
- opts.on('-h', '--help', 'Display this help screen') do
40
- $stdout.puts(opts)
41
- exit
42
- end
43
- opts.on('-d', '--out-dir DIR', 'Output directory') do |value|
44
- config['out-dir'] = value
45
- end
46
- opts.on('-f', '--out-file FILE', 'Output filename') do |value|
47
- config['out-file'] = value
48
- end
49
- opts.on('--[no-]overwrite', 'Overwrite existing files') do |value|
50
- config['overwrite'] = value
51
- end
52
- opts.separator('')
53
- opts.separator('Creation:')
54
- opts.on('--track-formats FORMATS', Array, 'GPS track formats (gpx, fit)') do |value|
55
- config['track-formats'] = value.map(&:to_sym)
56
- end
57
- opts.on('--[no-]map', 'Create map images') do |value|
58
- config['map'] = value
59
- end
60
- opts.on('--map-layers LAYERS', Array, 'Add additional layers to map images') do |value|
61
- config['map-layers'] = value
62
- end
63
- opts.on('--adoc-author AUTHOR', 'AsciiDoc author (name <email>[; name2 <email2>...])') do |value|
64
- config['adoc-author'] = value
65
- end
66
- opts.separator('')
67
- opts.separator('Conversion:')
68
- opts.on('-b', '--backend BACKEND', 'Conversion backend (pdf, html5 ...)') do |value|
69
- config['backend'] = value
70
- end
71
- opts.on('--[no-]draft', 'Show additional information (e.g. image paths)') do |value|
72
- config['draft'] = value
73
- end
74
- opts.on('--draft-backend BACKEND', 'Preferred conversion backend for draft (pdf, html5 ...)') do |value|
75
- config['draft-backend'] = value
76
- end
77
- opts.on('--image-maxdim DIM', 'Shrink oversized images (PDF only)') do |value|
78
- config['image-maxdim'] = value.to_i
26
+ def execute
27
+ config = context[:config][:report][:create]
28
+ Natour.create_reports(
29
+ path.encode('utf-8').delete_suffix('"').gsub('\\', '/'),
30
+ out_dir: out_dir || config[:out_dir],
31
+ out_file: out_file || config[:out_file],
32
+ overwrite: Natour::BooleanUtils.to_boolean(overwrite?, default_value: config[:overwrite]),
33
+ track_formats: track_formats || config[:track_formats],
34
+ create_map: Natour::BooleanUtils.to_boolean(map?, default_value: config[:map]),
35
+ map_layers: map_layers || config[:map_layers],
36
+ adoc_author: adoc_author || config[:adoc_author]
37
+ )
38
+ rescue Errno::EEXIST, Errno::ENOENT, Errno::EACCES, Errno::EISDIR, Errno::EINVAL => e
39
+ message, _, path = Natour::ErrnoUtils.split_message(e)
40
+ abort("ERROR: #{message} '#{path}'")
41
+ end
42
+ end
43
+
44
+ class ConvertCmd < Clamp::Command
45
+ banner(WordWrap.ww(
46
+ 'Convert a report from AsciiDoc to PDF or HTML (or any other supported format).'
47
+ ))
48
+ option(%w[-d --out-dir], 'DIR', 'Output directory')
49
+ option(%w[-f --out-file], 'FILE', 'Output filename')
50
+ option(%W[--\[no-\]overwrite], :flag, 'Overwrite existing files')
51
+ option(%w[-b --backend], 'BACKEND', 'Conversion backend (pdf, html5 ...)', &:to_sym)
52
+ option(%W[--\[no-\]draft], :flag, 'Show additional information (e.g. image paths)')
53
+ option(%w[--draft-backend], 'BACKEND', 'Preferred conversion backend for draft (pdf, html5 ...)', &:to_sym)
54
+ option(%w[--image-maxdim], 'DIM', 'Shrink oversized images (PDF only)') { |s| Integer(s) }
55
+ parameter('PATH', 'Path to AsciiDoc file')
56
+
57
+ def execute
58
+ config = context[:config][:report][:convert]
59
+ Natour.convert_report(
60
+ path.encode('utf-8').delete_suffix('"').gsub('\\', '/'),
61
+ out_dir: out_dir || config[:out_dir],
62
+ out_file: out_file || config[:out_file],
63
+ overwrite: Natour::BooleanUtils.to_boolean(overwrite?, default_value: config[:overwrite]),
64
+ backend: backend || config[:backend],
65
+ draft: Natour::BooleanUtils.to_boolean(draft?, default_value: config[:draft]),
66
+ draft_backend: draft_backend || config[:draft_backend],
67
+ image_maxdim: image_maxdim || config[:image_maxdim]
68
+ )
69
+ rescue Errno::EEXIST, Errno::ENOENT, Errno::EACCES, Errno::EISDIR, Errno::EINVAL => e
70
+ message, _, path = Natour::ErrnoUtils.split_message(e)
71
+ abort("ERROR: #{message} '#{path}'")
72
+ end
73
+ end
74
+
75
+ subcommand('create', 'Create AsciiDoc reports from directory', CreateCmd)
76
+ subcommand('convert', 'Convert AsciiDoc report to PDF or HTML', ConvertCmd)
79
77
  end
80
- end
81
78
 
82
- begin
83
- option_parser.parse!
84
- rescue OptionParser::InvalidArgument,
85
- OptionParser::InvalidOption => e
86
- abort("Error: #{e}")
87
- end
79
+ class MapCmd < Clamp::Command
80
+ class CreateCmd < Clamp::Command
81
+ banner(WordWrap.ww(
82
+ 'Create images of the map section covered by the GPS files. The GPS files must be in GPX' \
83
+ ' or KML format and contain tracks, waypoints or routes. The images are saved in JPG or ' \
84
+ 'PNG format.'
85
+ ))
86
+ option(%w[-d --out-dir], 'DIR', 'Output directory')
87
+ option(%w[-f --out-file], 'FILE', 'Output filename')
88
+ option(%W[--\[no-\]overwrite], :flag, 'Overwrite existing files')
89
+ option(%w[--gps-colors], 'COLORS', 'Colors for elements from GPS files') { |s| s.split(',') }
90
+ option(%w[--map-layers], 'LAYERS', 'Add additional layers to map images') { |s| s.split(',') }
91
+ option(%w[--image-size], 'WIDTH,HEIGHT', 'Image size') do |s|
92
+ s.split(',', 2).map { |v| Integer(v) }
93
+ end
94
+ parameter('PATH ...', 'Paths to GPS files', attribute_name: :paths)
88
95
 
89
- abort('Error: wrong number of arguments') if ARGV.length != 1
96
+ def execute
97
+ config = context[:config][:map][:create]
98
+ Natour::MapGeoAdmin.open do |map|
99
+ filename = Pathname(out_dir || config[:out_dir] || Pathname(paths.first).dirname)
100
+ .join(out_file || config[:out_file] || Pathname(paths.first).basename.sub_ext('.jpg'))
101
+ map.save_image(
102
+ filename,
103
+ overwrite: Natour::BooleanUtils.to_boolean(overwrite?, default_value: config[:overwrite]),
104
+ gps_files: paths,
105
+ gps_colors: gps_colors || config[:gps_colors],
106
+ map_layers: map_layers || config[:map_layers],
107
+ image_size: image_size || config[:image_size]
108
+ )
109
+ end
110
+ rescue Errno::EEXIST, Errno::ENOENT, Errno::EACCES, Errno::EISDIR, Errno::EINVAL => e
111
+ message, _, path = Natour::ErrnoUtils.split_message(e)
112
+ abort("ERROR: #{message} '#{path}'")
113
+ end
114
+ end
90
115
 
91
- path = Pathname(ARGV[0].encode('utf-8')
92
- .delete_suffix('"')
93
- .gsub('\\', '/'))
116
+ subcommand('create', 'Create map images from GPS files', CreateCmd)
117
+ end
94
118
 
95
- if path.directory?
96
- Natour.create(
97
- path,
98
- out_dir: config['out-dir'],
99
- out_file: config['out-file'],
100
- overwrite: config['overwrite'],
101
- track_formats: config['track-formats'],
102
- create_map: config['map'],
103
- map_layers: config['map-layers'],
104
- adoc_author: config['adoc-author']
105
- )
106
- else
107
- Natour.convert(
108
- path,
109
- out_dir: config['out-dir'],
110
- out_file: config['out-file'],
111
- overwrite: config['overwrite'],
112
- backend: config['backend'],
113
- draft: config['draft'],
114
- draft_backend: config['draft-backend'],
115
- image_maxdim: config['image-maxdim']
116
- )
119
+ subcommand('report', 'Create or convert reports', ReportCmd)
120
+ subcommand('map', 'Create map images', MapCmd)
121
+
122
+ option(%w[-v --version], :flag, 'Display the version') do
123
+ $stdout.puts("#{invocation_path} #{Natour::VERSION}")
124
+ exit
125
+ end
117
126
  end
127
+
128
+ config = Natour::Config.load_file(
129
+ Pathname($PROGRAM_NAME).basename.sub_ext('.yml'),
130
+ default: {
131
+ report: {
132
+ create: {
133
+ out_dir: nil,
134
+ out_file: nil,
135
+ overwrite: false,
136
+ track_formats: %i[gpx fit],
137
+ map: true,
138
+ map_layers: [],
139
+ adoc_author: nil
140
+ },
141
+ convert: {
142
+ out_dir: nil,
143
+ out_file: nil,
144
+ overwrite: false,
145
+ backend: :pdf,
146
+ draft: false,
147
+ draft_backend: nil,
148
+ image_maxdim: 1800
149
+ }
150
+ },
151
+ map: {
152
+ create: {
153
+ out_dir: nil,
154
+ out_file: nil,
155
+ overwrite: false,
156
+ gps_colors: [],
157
+ map_layers: [],
158
+ image_size: [1200, 900]
159
+ }
160
+ }
161
+ }
162
+ )
163
+
164
+ NatourCmd.run(
165
+ Pathname($PROGRAM_NAME).basename,
166
+ ARGV,
167
+ { config: config }
168
+ )
@@ -1,6 +1,6 @@
1
1
  require 'fileutils'
2
- require 'pathname'
3
2
  require 'ostruct'
3
+ require 'pathname'
4
4
 
5
5
  module Natour
6
6
  module Asciinurse
@@ -97,14 +97,18 @@ module Natour
97
97
  OpenStruct.new(
98
98
  group: :plants,
99
99
  title: 'Pflanzenarten',
100
- headers: ['Wissenschaftlicher Name', 'Deutscher Name'],
101
- columns: %i[name name_de]
100
+ columns: [
101
+ OpenStruct.new(header: 'Wissenschaftlicher Name', accessor: :name),
102
+ OpenStruct.new(header: 'Deutscher Name', accessor: :name_de)
103
+ ]
102
104
  ),
103
105
  OpenStruct.new(
104
106
  group: :birds,
105
107
  title: 'Vogelarten',
106
- headers: ['Deutscher Name', 'Wissenschaftlicher Name'],
107
- columns: %i[name_de name]
108
+ columns: [
109
+ OpenStruct.new(header: 'Deutscher Name', accessor: :name_de),
110
+ OpenStruct.new(header: 'Wissenschaftlicher Name', accessor: :name)
111
+ ]
108
112
  )
109
113
  ].each do |info|
110
114
  group = groups.fetch(info.group, [])
@@ -115,12 +119,18 @@ module Natour
115
119
  group.each do |species_list|
116
120
  caption = '.Tabelle {counter:species_lists}'
117
121
  caption << ": #{species_list.description}" if species_list.description
122
+ columns = info.columns.select do |column|
123
+ species_list.any? { |species| !species.public_send(column.accessor).nil? }
124
+ end
125
+ cols = [1] + [5 * info.columns.size / columns.size] * columns.size
118
126
  doc << caption
119
- doc << '[cols="1,5,5",options=header]'
127
+ doc << "[cols=\"#{cols.join(',')}\",options=header]"
120
128
  doc << '|==='
121
- doc << "|Nr.|#{info.headers.join('|')}"
129
+ doc << "|Nr.|#{columns.map(&:header).join('|')}"
122
130
  species_list.each do |species|
123
- doc << "|{counter:species_list#{index}}|#{info.columns.map { |method| species.send(method) }.join('|')}"
131
+ doc <<
132
+ "|{counter:species_list#{index}}|#{columns.map { |column| species.public_send(column.accessor) }
133
+ .join('|')}"
124
134
  end
125
135
  doc << '|==='
126
136
  doc << ''