indoctrinatr-tools 0.15.0 → 0.17.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +9 -39
  3. data/.rubocop.yml +11 -6
  4. data/.ruby-version +1 -0
  5. data/CHANGELOG.md +14 -0
  6. data/LICENSE +1 -1
  7. data/README.md +5 -6
  8. data/Rakefile +5 -20
  9. data/cucumber.yml +1 -1
  10. data/exe/indoctrinatr +4 -0
  11. data/indoctrinatr-tools.gemspec +28 -29
  12. data/lib/indoctrinatr/templates/documentation/indoctrinatr-technical-documentation-content.tex.erb +4 -4
  13. data/lib/indoctrinatr/templates/documentation/indoctrinatr-technical-documentation.sty +0 -15
  14. data/lib/indoctrinatr/tools/command_autocomplete_helpers.rb +9 -0
  15. data/lib/indoctrinatr/tools/commands/bash_completions.rb +21 -0
  16. data/lib/indoctrinatr/tools/commands/check.rb +26 -0
  17. data/lib/indoctrinatr/tools/commands/completion_commands.rb +25 -0
  18. data/lib/indoctrinatr/tools/commands/demo.rb +22 -0
  19. data/lib/indoctrinatr/tools/commands/doc.rb +28 -0
  20. data/lib/indoctrinatr/tools/commands/pack.rb +26 -0
  21. data/lib/indoctrinatr/tools/commands/parse.rb +26 -0
  22. data/lib/indoctrinatr/tools/commands/pdf.rb +39 -0
  23. data/lib/indoctrinatr/tools/commands/pdf_with_field_names.rb +28 -0
  24. data/lib/indoctrinatr/tools/commands/scaffold.rb +26 -0
  25. data/lib/indoctrinatr/tools/commands/version.rb +13 -0
  26. data/lib/indoctrinatr/tools/commands/workflow.rb +38 -0
  27. data/lib/indoctrinatr/tools/commands/zsh_completions.rb +25 -0
  28. data/lib/indoctrinatr/tools/commands.rb +21 -0
  29. data/lib/indoctrinatr/tools/configuration_extractor.rb +11 -13
  30. data/lib/indoctrinatr/tools/content_for_tex_files.rb +5 -3
  31. data/lib/indoctrinatr/tools/default_values.rb +1 -3
  32. data/lib/indoctrinatr/tools/field_name_values.rb +4 -5
  33. data/lib/indoctrinatr/tools/pdf_generator.rb +3 -3
  34. data/lib/{redcloth_latex_formatter_patch/patch.rb → indoctrinatr/tools/redcloth_formatters_latex_patch.rb} +17 -19
  35. data/lib/indoctrinatr/tools/template_documentation_content.rb +72 -23
  36. data/lib/indoctrinatr/tools/template_documentation_helpers.rb +1 -1
  37. data/lib/indoctrinatr/tools/template_documentation_source_file.rb +9 -14
  38. data/lib/indoctrinatr/tools/template_pack_configuration.rb +2 -1
  39. data/lib/indoctrinatr/tools/transactions/template_pack_default_values_compiler.rb +67 -0
  40. data/lib/indoctrinatr/tools/transactions/template_pack_default_values_parser.rb +82 -0
  41. data/lib/indoctrinatr/tools/transactions/template_pack_demo.rb +104 -0
  42. data/lib/indoctrinatr/tools/transactions/template_pack_documentation.rb +223 -0
  43. data/lib/indoctrinatr/tools/transactions/template_pack_error_checker.rb +127 -0
  44. data/lib/indoctrinatr/tools/transactions/template_pack_fieldnames_creator.rb +97 -0
  45. data/lib/indoctrinatr/tools/transactions/template_pack_packer.rb +73 -0
  46. data/lib/indoctrinatr/tools/transactions/template_pack_scaffold.rb +73 -0
  47. data/lib/indoctrinatr/tools/version.rb +1 -1
  48. data/lib/indoctrinatr_tools.rb +12 -0
  49. metadata +106 -141
  50. checksums.yaml.gz.sig +0 -0
  51. data/.arcconfig +0 -9
  52. data/.coveralls.yml +0 -1
  53. data/.travis.yml +0 -15
  54. data/bin/indoctrinatr +0 -185
  55. data/certs/dkd-reuschling.pem +0 -22
  56. data/features/autocompletion_support.feature +0 -9
  57. data/features/demo.feature +0 -17
  58. data/features/doc_keepauxfiles.feature +0 -13
  59. data/features/documentation.feature +0 -20
  60. data/features/fieldnames_pdf.feature +0 -9
  61. data/features/fieldnames_pdf_auxfiles.feature +0 -10
  62. data/features/pack.feature +0 -11
  63. data/features/parse.feature +0 -6
  64. data/features/pdf.feature +0 -15
  65. data/features/pdf_keepauxfiles.feature +0 -11
  66. data/features/pdf_with_timestamp.feature +0 -8
  67. data/features/scaffold.feature +0 -23
  68. data/features/step_definitions/common.rb +0 -3
  69. data/features/step_definitions/indoctrinatr_cli.rb +0 -11
  70. data/features/support/env.rb +0 -1
  71. data/features/version.feature +0 -5
  72. data/features/workflow.feature +0 -9
  73. data/lib/indoctrinatr/tools/directory_helpers.rb +0 -18
  74. data/lib/indoctrinatr/tools/template_pack_default_values_compiler.rb +0 -47
  75. data/lib/indoctrinatr/tools/template_pack_default_values_parser.rb +0 -55
  76. data/lib/indoctrinatr/tools/template_pack_demo.rb +0 -23
  77. data/lib/indoctrinatr/tools/template_pack_documentation.rb +0 -132
  78. data/lib/indoctrinatr/tools/template_pack_error_checker.rb +0 -104
  79. data/lib/indoctrinatr/tools/template_pack_fieldnames_creator.rb +0 -79
  80. data/lib/indoctrinatr/tools/template_pack_helpers.rb +0 -68
  81. data/lib/indoctrinatr/tools/template_pack_packer.rb +0 -49
  82. data/lib/indoctrinatr/tools/template_pack_scaffold.rb +0 -57
  83. data/lib/indoctrinatr/tools.rb +0 -9
  84. data/spec/fixtures/test/configuration.yaml +0 -26
  85. data/spec/fixtures/test/test.tex.erb +0 -15
  86. data/spec/indoctrinatr/templates/configuration_file_spec.rb +0 -9
  87. data/spec/indoctrinatr/templates/tex_file_spec.rb +0 -9
  88. data/spec/indoctrinatr/tools/textile_support_spec.rb +0 -18
  89. data/spec/indoctrinatr/tools/version_spec.rb +0 -8
  90. data/spec/redcloth_latex_formatter_patch/patch_spec.rb +0 -34
  91. data/spec/spec_helper.rb +0 -2
  92. data.tar.gz.sig +0 -0
  93. metadata.gz.sig +0 -0
@@ -0,0 +1,104 @@
1
+ require 'dry/transaction'
2
+
3
+ module Indoctrinatr
4
+ module Tools
5
+ module Transactions
6
+ class TemplatePackDemo
7
+ include Dry::Transaction
8
+
9
+ step :scaffold
10
+ step :parse
11
+ step :pdf
12
+ step :pdf_with_field_names
13
+ step :doc
14
+ step :pack
15
+
16
+ private
17
+
18
+ def scaffold(template_pack_name)
19
+ TemplatePackScaffold.new.call(template_pack_name) do |result|
20
+ result.success do |message|
21
+ puts message
22
+ end
23
+
24
+ result.failure do |message|
25
+ puts message
26
+ exit 1
27
+ end
28
+ end
29
+ Success(template_pack_name)
30
+ end
31
+
32
+ def parse(template_pack_name)
33
+ Indoctrinatr::Tools::Transactions::TemplatePackDefaultValuesParser.new.call(template_pack_name) do |result|
34
+ result.success do |message|
35
+ puts message
36
+ end
37
+
38
+ result.failure do |message|
39
+ puts message
40
+ exit 1
41
+ end
42
+ end
43
+ Success(template_pack_name)
44
+ end
45
+
46
+ def pdf(template_pack_name)
47
+ TemplatePackDefaultValuesCompiler.new.call(template_pack_name:, keep_aux_files: false) do |result|
48
+ result.success do |message|
49
+ puts message
50
+ end
51
+
52
+ result.failure do |message|
53
+ puts message
54
+ exit 1
55
+ end
56
+ end
57
+ Success(template_pack_name)
58
+ end
59
+
60
+ def pdf_with_field_names(template_pack_name)
61
+ TemplatePackFieldnamesCreator.new.call(template_pack_name:, keep_aux_files: false) do |result|
62
+ result.success do |message|
63
+ puts message
64
+ end
65
+
66
+ result.failure do |message|
67
+ puts message
68
+ exit 1
69
+ end
70
+ end
71
+ Success(template_pack_name)
72
+ end
73
+
74
+ def doc(template_pack_name)
75
+ TemplatePackDocumentation.new.call(template_pack_name:, keep_aux_files: false) do |result|
76
+ result.success do |message|
77
+ puts message
78
+ end
79
+
80
+ result.failure do |message|
81
+ puts message
82
+ exit 1
83
+ end
84
+ end
85
+ Success(template_pack_name)
86
+ end
87
+
88
+ def pack(template_pack_name)
89
+ TemplatePackPacker.new.call(template_pack_name) do |result|
90
+ result.success do |message|
91
+ puts message
92
+ end
93
+
94
+ result.failure do |message|
95
+ puts message
96
+ exit 1
97
+ end
98
+ end
99
+ Success()
100
+ end
101
+ end
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,223 @@
1
+ require 'dry/transaction'
2
+ require 'erubis'
3
+ require 'to_latex'
4
+ require 'fileutils'
5
+ require 'tmpdir'
6
+
7
+ module Indoctrinatr
8
+ module Tools
9
+ module Transactions
10
+ class TemplatePackDocumentation
11
+ include PdfGenerator
12
+ include Dry::Transaction
13
+
14
+ step :setup
15
+ step :fill_documentation_content
16
+ step :read_content_tex_file
17
+ step :read_main_tex_file
18
+ step :parse_content_tex_file
19
+ step :parse_main_tex_file
20
+ step :create_temp_compile_dir
21
+ step :compile_setup
22
+ step :write_content_tex_file
23
+ step :write_main_tex_file
24
+ step :copy_source_files
25
+ step :compile_documentation_to_pdf
26
+ step :handle_aux_files
27
+ step :generate_success_message
28
+
29
+ private
30
+
31
+ def setup(template_pack_name:, keep_aux_files:)
32
+ documentation_files_path = Pathname.new(File.expand_path(__dir__)).join('..', '..', 'templates', 'documentation')
33
+ content_tex_file_path = documentation_files_path.join 'indoctrinatr-technical-documentation-content.tex.erb'
34
+ source_main_tex_file_path = documentation_files_path.join 'indoctrinatr-technical-documentation.tex.erb'
35
+ path_name = Pathname.new(Dir.pwd).join template_pack_name
36
+ pack_documentation_dir_path = path_name.join 'doc'
37
+ pack_technical_documentation_file_path = pack_documentation_dir_path.join "#{template_pack_name}_technical_documentation.pdf"
38
+ Success(
39
+ {
40
+ content_tex_file_path:,
41
+ template_pack_name:,
42
+ documentation_files_path:,
43
+ keep_aux_files:,
44
+ source_main_tex_file_path:,
45
+ pack_documentation_dir_path:,
46
+ pack_technical_documentation_file_path:,
47
+ path_name:
48
+ }
49
+ )
50
+ end
51
+
52
+ def fill_documentation_content(config)
53
+ configuration = ConfigurationExtractor.new(config[:template_pack_name]).call
54
+ documentation_content = TemplateDocumentationContent.new(config[:template_pack_name], configuration)
55
+ config[:documentation_content] = documentation_content
56
+ Success(config)
57
+ rescue StandardError => e
58
+ Failure(e.message)
59
+ end
60
+
61
+ def read_content_tex_file(config)
62
+ content_tex_file_content = File.read(config[:content_tex_file_path], encoding: 'Utf-8')
63
+ config[:content_tex_file_content] = content_tex_file_content
64
+ Success(config)
65
+ rescue StandardError => e
66
+ Failure(e.message)
67
+ end
68
+
69
+ def read_main_tex_file(config)
70
+ main_tex_file_content = File.read(config[:source_main_tex_file_path], encoding: 'Utf-8')
71
+ config[:main_tex_file_content] = main_tex_file_content
72
+ Success(config)
73
+ rescue StandardError => e
74
+ Failure(e.message)
75
+ end
76
+
77
+ def parse_content_tex_file(config)
78
+ parsed_content_tex_file_content = Erubis::Eruby.new(config[:content_tex_file_content]).result(config[:documentation_content].retrieve_binding)
79
+ config[:parsed_content_tex_file_content] = parsed_content_tex_file_content
80
+ # TODO: more useful error messages for user on errors
81
+ Success(config)
82
+ rescue StandardError => e
83
+ Failure(e.message)
84
+ end
85
+
86
+ def parse_main_tex_file(config)
87
+ parsed_main_tex_file_content = Erubis::Eruby.new(config[:main_tex_file_content]).result(config[:documentation_content].retrieve_binding)
88
+ config[:parsed_main_tex_file_content] = parsed_main_tex_file_content
89
+ Success(config)
90
+ rescue StandardError => e
91
+ Failure(e.message)
92
+ end
93
+
94
+ def create_temp_compile_dir(config)
95
+ documentation_compile_dir_path_name = Pathname.new Dir.mktmpdir 'indoctrinatr_tools_tmp'
96
+ config[:documentation_compile_dir_path_name] = documentation_compile_dir_path_name
97
+ Success(config)
98
+ rescue StandardError => e
99
+ Failure(e.message)
100
+ end
101
+
102
+ def compile_setup(config)
103
+ content_tex_file_destination_path = config[:documentation_compile_dir_path_name].join 'indoctrinatr-technical-documentation-content.tex'
104
+ config[:content_tex_file_destination_path] = content_tex_file_destination_path
105
+
106
+ main_tex_file_destination_path = config[:documentation_compile_dir_path_name].join 'indoctrinatr-technical-documentation.tex'
107
+ config[:main_tex_file_destination_path] = main_tex_file_destination_path
108
+
109
+ source_latex_package_file_path = config[:documentation_files_path].join 'indoctrinatr-technical-documentation.sty'
110
+ config[:source_latex_package_file_path] = source_latex_package_file_path
111
+
112
+ latex_package_destination_path = config[:documentation_compile_dir_path_name].join 'indoctrinatr-technical-documentation.sty'
113
+ config[:latex_package_destination_path] = latex_package_destination_path
114
+
115
+ source_letterpaper_file_path = config[:documentation_files_path].join 'indoctrinatr_letterpaper.pdf'
116
+ config[:source_letterpaper_file_path] = source_letterpaper_file_path
117
+
118
+ letterpaper_file_destination_path = config[:documentation_compile_dir_path_name].join 'indoctrinatr_letterpaper.pdf'
119
+ config[:letterpaper_file_destination_path] = letterpaper_file_destination_path
120
+
121
+ source_image_tools_package_file_path = config[:documentation_files_path].join 'dkd-image-tools.sty'
122
+ config[:source_image_tools_package_file_path] = source_image_tools_package_file_path
123
+
124
+ image_tools_package_destination_path = config[:documentation_compile_dir_path_name].join 'dkd-image-tools.sty'
125
+ config[:image_tools_package_destination_path] = image_tools_package_destination_path
126
+
127
+ latex_log_file = config[:documentation_compile_dir_path_name].join 'indoctrinatr-technical-documentation.log'
128
+ config[:latex_log_file] = latex_log_file
129
+
130
+ latex_log_file_destination = config[:path_name].join "#{config[:template_pack_name]}documentation_latex_failure.log"
131
+ config[:latex_log_file_destination] = latex_log_file_destination
132
+
133
+ documentation_file_path = config[:documentation_compile_dir_path_name].join 'indoctrinatr-technical-documentation.pdf'
134
+ config[:documentation_file_path] = documentation_file_path
135
+ Success(config)
136
+ rescue StandardError => e
137
+ Failure(e.message)
138
+ end
139
+
140
+ def write_content_tex_file(config)
141
+ File.write config[:content_tex_file_destination_path], config[:parsed_content_tex_file_content]
142
+ Success(config)
143
+ rescue StandardError => e
144
+ Failure(e.message)
145
+ end
146
+
147
+ def write_main_tex_file(config)
148
+ File.write config[:main_tex_file_destination_path], config[:parsed_main_tex_file_content]
149
+ Success(config)
150
+ rescue StandardError => e
151
+ Failure(e.message)
152
+ end
153
+
154
+ def copy_source_files(config)
155
+ ::FileUtils.copy_file config[:source_latex_package_file_path], config[:latex_package_destination_path]
156
+ ::FileUtils.copy_file config[:source_letterpaper_file_path], config[:letterpaper_file_destination_path]
157
+ ::FileUtils.copy_file config[:source_image_tools_package_file_path], config[:image_tools_package_destination_path]
158
+ Success(config)
159
+ rescue StandardError => e
160
+ Failure(e.message)
161
+ end
162
+
163
+ def compile_documentation_to_pdf(config)
164
+ make_pdf config[:main_tex_file_destination_path], config[:documentation_compile_dir_path_name], cleanup: !config[:keep_aux_files]
165
+ copy_doc_file_to_template_pack(config)
166
+
167
+ if config[:keep_aux_files]
168
+ copy_helper_files_to_template_pack(config)
169
+ show_temp_directory(config)
170
+ end
171
+ Success(config)
172
+ rescue StandardError => e
173
+ handle_latex_error(config)
174
+ Failure(e.message)
175
+ end
176
+
177
+ def copy_helper_files_to_template_pack(config)
178
+ helper_files_to_copy = [config[:latex_log_file], config[:content_tex_file_destination_path], config[:main_tex_file_destination_path]].freeze
179
+ ::FileUtils.mkdir_p(config[:pack_documentation_dir_path])
180
+ ::FileUtils.copy helper_files_to_copy, config[:pack_documentation_dir_path]
181
+ puts 'TeX files and log file have been copied to doc subdirectory of your template_pack'
182
+ rescue StandardError => e
183
+ Failure(e.message)
184
+ end
185
+
186
+ def copy_doc_file_to_template_pack(config)
187
+ # All the documentation shall go into template_pack/doc
188
+ ::FileUtils.mkdir_p(config[:pack_documentation_dir_path])
189
+ ::FileUtils.copy_file config[:documentation_file_path], config[:pack_technical_documentation_file_path]
190
+ end
191
+
192
+ def handle_aux_files(config)
193
+ if config[:keep_aux_files]
194
+ copy_helper_files_to_template_pack(config)
195
+ show_temp_directory(config)
196
+ else
197
+ delete_temp_dir(config)
198
+ end
199
+ Success(config)
200
+ rescue StandardError => e
201
+ Failure(e.message)
202
+ end
203
+
204
+ def show_temp_directory(config)
205
+ puts "Look into the directory #{config[:documentation_compile_dir_path_name]} to see all files related to the technical documentation compilation"
206
+ end
207
+
208
+ def delete_temp_dir(config)
209
+ ::FileUtils.remove_entry_secure config[:documentation_compile_dir_path_name]
210
+ end
211
+
212
+ def handle_latex_error(config)
213
+ puts "possible LaTeX compilation failure! see #{config[:latex_log_file_destination]} for details. " # idea: process $CHILD_STATUS
214
+ ::FileUtils.copy_file config[:latex_log_file], config[:latex_log_file_destination]
215
+ end
216
+
217
+ def generate_success_message(config)
218
+ Success("A documentation for '#{config[:template_pack_name]}' has been successfully generated.")
219
+ end
220
+ end
221
+ end
222
+ end
223
+ end
@@ -0,0 +1,127 @@
1
+ require 'dry/transaction'
2
+ require 'yaml'
3
+
4
+ module Indoctrinatr
5
+ module Tools
6
+ module ErrorChecker
7
+ class TemplatePackErrorChecker
8
+ include Dry::Transaction
9
+
10
+ # class wide constants
11
+ # needs to match indoctrinatr's TemplateField model
12
+ VALID_PRESENTATIONS = %w[text textarea checkbox radiobutton dropdown date range file].freeze
13
+ REQUIRES_AVAILABLE_OPTIONS = %w[dropdown checkbox radiobutton].freeze
14
+
15
+ step :setup
16
+ step :check_config_file_existence
17
+ step :check_config_file_syntax
18
+ step :check_attributes
19
+
20
+ # TODO: check multiple variable name declaration (low-prio)
21
+
22
+ private
23
+
24
+ def setup(template_pack_name)
25
+ path_name = Pathname.new(Dir.pwd).join template_pack_name
26
+ config_file_path = path_name.join 'configuration.yaml'
27
+ Success(
28
+ {
29
+ template_pack_name:,
30
+ path_name:,
31
+ config_file_path:
32
+ }
33
+ )
34
+ rescue StandardError => e
35
+ Failure(e.message)
36
+ end
37
+
38
+ def check_config_file_existence(config)
39
+ return Failure('The file configuration.yaml does not exist in the template_pack directory') unless File.exist? config[:config_file_path]
40
+
41
+ Success(config)
42
+ rescue StandardError => e
43
+ Failure(e.message)
44
+ end
45
+
46
+ # YAML syntax check
47
+ def check_config_file_syntax(config)
48
+ puts 'Checking YAML syntax...'
49
+ YAML.parse_file config[:config_file_path]
50
+ puts 'YAML syntax ok!'
51
+ Success(config)
52
+ rescue YAML::SyntaxError => e # no program abort when this exception is thrown
53
+ puts 'YAML syntax error in configuration.yaml, see error for details:'
54
+ Failure(e.message)
55
+ rescue StandardError => e
56
+ Failure(e.message)
57
+ end
58
+
59
+ def check_attributes(config)
60
+ configuration = ConfigurationExtractor.new(config[:template_pack_name]).call
61
+ puts 'Checking attributes...'
62
+
63
+ configuration.attributes_as_hashes_in_array.each_with_index do |attribute_hash, index|
64
+ identifier = "Variable number #{index + 1}" # string for the user to localize variable with errors/warnings
65
+ name_field = check_field_attribute attribute_hash, identifier, 'name'
66
+ identifier = "Variable \"#{name_field}\"" if name_field != false
67
+
68
+ check_presentation attribute_hash, identifier
69
+
70
+ check_field_attribute attribute_hash, identifier, 'default_value'
71
+
72
+ check_field_attribute attribute_hash, identifier, 'description'
73
+ # idea: warning if no required attribute?
74
+ end
75
+ Success('Checking complete.')
76
+ rescue StandardError => e
77
+ Failure(e.message)
78
+ end
79
+
80
+ # false if something wrong, otherwise returns the key value
81
+ def check_field_attribute(attribute_hash, field_identifier, key)
82
+ unless attribute_hash.key? key
83
+ puts "The #{field_identifier} has no #{key} type set!"
84
+ return false
85
+ end
86
+ if attribute_hash[key].nil? || attribute_hash[key].empty?
87
+ puts "The #{field_identifier} has an empty #{key}!"
88
+ false
89
+ else
90
+ attribute_hash[key]
91
+ end
92
+ end
93
+
94
+ def check_presentation(attribute_hash, identifier)
95
+ presentation = check_field_attribute attribute_hash, identifier, 'presentation'
96
+ return false unless presentation
97
+
98
+ # check if it is one of the options
99
+ puts "Not an allowed presentation option set for #{identifier}" unless VALID_PRESENTATIONS.include? presentation
100
+ check_available_options attribute_hash, identifier, presentation if REQUIRES_AVAILABLE_OPTIONS.include? presentation
101
+ check_presentation_range attribute_hash, identifier, presentation if presentation == 'range'
102
+ end
103
+
104
+ def check_available_options(attribute_hash, identifier, presentation_type)
105
+ unless attribute_hash.key? 'available_options'
106
+ puts "The #{identifier} has no available_options (needed for #{presentation_type} presentation)"
107
+ return false
108
+ end
109
+ available_options = attribute_hash['available_options']
110
+ if available_options.nil?
111
+ puts("available_options for #{identifier} is empty (needed for #{presentation_type} presentation)")
112
+ false
113
+ else
114
+ puts("available_options for #{identifier} has only one option. That is useless.") if available_options.count(',') == 1
115
+ true
116
+ end
117
+ end
118
+
119
+ def check_presentation_range(attribute_hash, identifier, presentation)
120
+ puts "The #{identifier} has no start_of_range field (needed for #{presentation} presentation)" unless attribute_hash.key? 'start_of_range'
121
+ puts "The #{identifier} has no end_of_range field (needed for #{presentation} presentation)" unless attribute_hash.key? 'end_of_range'
122
+ # TODO: check for content
123
+ end
124
+ end
125
+ end
126
+ end
127
+ end
@@ -0,0 +1,97 @@
1
+ require 'dry/transaction'
2
+ require 'erubis'
3
+ require 'to_latex'
4
+ require 'fileutils'
5
+
6
+ module Indoctrinatr
7
+ module Tools
8
+ module Transactions
9
+ class TemplatePackFieldnamesCreator
10
+ include PdfGenerator
11
+ include Dry::Transaction
12
+
13
+ step :setup
14
+ step :check_setup
15
+ step :read_config_file
16
+ step :read_tex_file
17
+ step :parse_tex_file
18
+ step :write_tex_file
19
+ step :result
20
+
21
+ private
22
+
23
+ def setup(template_pack_name:, keep_aux_files:)
24
+ path_name = Pathname.new(Dir.pwd).join template_pack_name
25
+ pack_documentation_dir_path = path_name.join 'doc'
26
+ pack_documentation_examples_dir_path = pack_documentation_dir_path.join('examples')
27
+ tex_with_default_values_file_path = pack_documentation_examples_dir_path.join("#{template_pack_name}_with_default_values.tex")
28
+ tex_with_fieldname_values_file_path = pack_documentation_examples_dir_path.join("#{template_pack_name}_with_fieldname_values.tex")
29
+ Success(
30
+ {
31
+ template_pack_name:,
32
+ path_name:,
33
+ keep_aux_files:,
34
+ pack_documentation_dir_path:,
35
+ pack_documentation_examples_dir_path:,
36
+ tex_with_default_values_file_path:,
37
+ tex_with_fieldname_values_file_path:
38
+ }
39
+ )
40
+ end
41
+
42
+ def check_setup(config)
43
+ return Failure('Please specify a template pack name.') if config[:template_pack_name].empty?
44
+ return Failure("A folder with name '#{config[:template_pack_name]}' does not exist.") unless Dir.exist? config[:path_name] # rub
45
+
46
+ Success(config)
47
+ end
48
+
49
+ def read_config_file(config)
50
+ configuration = ConfigurationExtractor.new(config[:template_pack_name]).call
51
+ field_name_values = FieldNameValues.new configuration
52
+ field_name_values._field_names_as_values
53
+ config[:configuration] = configuration
54
+ config[:field_name_values] = field_name_values
55
+ Success(config)
56
+ end
57
+
58
+ def read_tex_file(config)
59
+ tex_file_path = config[:path_name].join("#{config[:template_pack_name]}.tex.erb")
60
+ config[:tex_file_content] = File.read tex_file_path
61
+ Success(config)
62
+ rescue StandardError => e
63
+ Failure(e.message)
64
+ end
65
+
66
+ def parse_tex_file(config)
67
+ config[:parsed_tex_file_content] = Erubis::Eruby.new(config[:tex_file_content]).result(config[:field_name_values].retrieve_binding)
68
+ puts "The template pack '#{config[:template_pack_name]}' has been successfully parsed with the variable names."
69
+ puts 'Please check the .tex file and modify it to your needs and compile it again'
70
+ Success(config)
71
+ rescue StandardError => e
72
+ Failure(e.message)
73
+ end
74
+
75
+ def write_tex_file(config)
76
+ # Create directory to avoid file creation errors
77
+ ::FileUtils.mkdir_p(config[:pack_documentation_dir_path])
78
+ ::FileUtils.mkdir_p(config[:pack_documentation_examples_dir_path])
79
+ File.write config[:tex_with_fieldname_values_file_path], config[:parsed_tex_file_content]
80
+ Success(config)
81
+ rescue StandardError => e
82
+ Failure(e.message)
83
+ end
84
+
85
+ def result(config)
86
+ make_pdf config[:tex_with_fieldname_values_file_path], config[:pack_documentation_examples_dir_path], cleanup: !config[:keep_aux_files]
87
+ rescue StandardError => e
88
+ puts 'possible LaTeX compilation failure!' # see #{latex_log_file_destination} for details. " # idea: process $CHILD_STATUS
89
+ # FileUtils.copy_file latex_log_file, latex_log_file_destination
90
+ Failure(e.message)
91
+ else
92
+ Success('A pdf including variable names has successfully been created.')
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,73 @@
1
+ require 'dry/transaction'
2
+ require 'zip'
3
+ require 'fileutils'
4
+
5
+ module Indoctrinatr
6
+ module Tools
7
+ module Transactions
8
+ class TemplatePackPacker
9
+ include Dry::Transaction
10
+
11
+ step :setup
12
+ step :validate_setup
13
+ step :remove_existing_zip
14
+ step :zip_template_folder
15
+ step :show_success
16
+
17
+ private
18
+
19
+ def setup(template_pack_name)
20
+ Success(
21
+ {
22
+ template_pack_name:,
23
+ path_name: Pathname.new(Dir.pwd).join(template_pack_name)
24
+ }
25
+ )
26
+ rescue StandardError => e
27
+ Failure(e.message)
28
+ end
29
+
30
+ def validate_setup(config)
31
+ return Failure('Please specify a template pack name.') if config[:template_pack_name].nil? || config[:template_pack_name].empty?
32
+ return Failure("A folder with name '#{config[:template_pack_name]}' does not exist.") unless Dir.exist? config[:path_name]
33
+
34
+ Success(config)
35
+ rescue StandardError => e
36
+ Failure(e.message)
37
+ end
38
+
39
+ def remove_existing_zip(config)
40
+ ::FileUtils.rm destination_zip_file(config[:template_pack_name]), force: true
41
+ Success(config)
42
+ rescue StandardError => e
43
+ Failure(e.message)
44
+ end
45
+
46
+ def zip_template_folder(config)
47
+ Zip::File.open(destination_zip_file(config[:template_pack_name]), Zip::File::CREATE) do |zipfile|
48
+ Dir[File.join(config[:path_name], '**', '**')].each do |file|
49
+ zipfile.add(internal_file_name(file, config[:template_pack_name], config[:path_name]), file)
50
+ end
51
+ end
52
+ Success(config)
53
+ rescue StandardError => e
54
+ Failure(e.message)
55
+ end
56
+
57
+ def show_success(config)
58
+ Success("The template pack '#{config[:template_pack_name]}.zip' was created successfully.")
59
+ rescue StandardError => e
60
+ Failure(e.message)
61
+ end
62
+
63
+ def destination_zip_file(template_pack_name)
64
+ Pathname.new(Dir.pwd).join "#{template_pack_name}.zip"
65
+ end
66
+
67
+ def internal_file_name(file_name, template_pack_name, path_name)
68
+ "#{template_pack_name}/#{file_name.sub(path_name.to_s, '')[1..]}" # remove leading /
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end