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.
- checksums.yaml +5 -5
- data/.gitignore +9 -39
- data/.rubocop.yml +11 -6
- data/.ruby-version +1 -0
- data/CHANGELOG.md +14 -0
- data/LICENSE +1 -1
- data/README.md +5 -6
- data/Rakefile +5 -20
- data/cucumber.yml +1 -1
- data/exe/indoctrinatr +4 -0
- data/indoctrinatr-tools.gemspec +28 -29
- data/lib/indoctrinatr/templates/documentation/indoctrinatr-technical-documentation-content.tex.erb +4 -4
- data/lib/indoctrinatr/templates/documentation/indoctrinatr-technical-documentation.sty +0 -15
- data/lib/indoctrinatr/tools/command_autocomplete_helpers.rb +9 -0
- data/lib/indoctrinatr/tools/commands/bash_completions.rb +21 -0
- data/lib/indoctrinatr/tools/commands/check.rb +26 -0
- data/lib/indoctrinatr/tools/commands/completion_commands.rb +25 -0
- data/lib/indoctrinatr/tools/commands/demo.rb +22 -0
- data/lib/indoctrinatr/tools/commands/doc.rb +28 -0
- data/lib/indoctrinatr/tools/commands/pack.rb +26 -0
- data/lib/indoctrinatr/tools/commands/parse.rb +26 -0
- data/lib/indoctrinatr/tools/commands/pdf.rb +39 -0
- data/lib/indoctrinatr/tools/commands/pdf_with_field_names.rb +28 -0
- data/lib/indoctrinatr/tools/commands/scaffold.rb +26 -0
- data/lib/indoctrinatr/tools/commands/version.rb +13 -0
- data/lib/indoctrinatr/tools/commands/workflow.rb +38 -0
- data/lib/indoctrinatr/tools/commands/zsh_completions.rb +25 -0
- data/lib/indoctrinatr/tools/commands.rb +21 -0
- data/lib/indoctrinatr/tools/configuration_extractor.rb +11 -13
- data/lib/indoctrinatr/tools/content_for_tex_files.rb +5 -3
- data/lib/indoctrinatr/tools/default_values.rb +1 -3
- data/lib/indoctrinatr/tools/field_name_values.rb +4 -5
- data/lib/indoctrinatr/tools/pdf_generator.rb +3 -3
- data/lib/{redcloth_latex_formatter_patch/patch.rb → indoctrinatr/tools/redcloth_formatters_latex_patch.rb} +17 -19
- data/lib/indoctrinatr/tools/template_documentation_content.rb +72 -23
- data/lib/indoctrinatr/tools/template_documentation_helpers.rb +1 -1
- data/lib/indoctrinatr/tools/template_documentation_source_file.rb +9 -14
- data/lib/indoctrinatr/tools/template_pack_configuration.rb +2 -1
- data/lib/indoctrinatr/tools/transactions/template_pack_default_values_compiler.rb +67 -0
- data/lib/indoctrinatr/tools/transactions/template_pack_default_values_parser.rb +82 -0
- data/lib/indoctrinatr/tools/transactions/template_pack_demo.rb +104 -0
- data/lib/indoctrinatr/tools/transactions/template_pack_documentation.rb +223 -0
- data/lib/indoctrinatr/tools/transactions/template_pack_error_checker.rb +127 -0
- data/lib/indoctrinatr/tools/transactions/template_pack_fieldnames_creator.rb +97 -0
- data/lib/indoctrinatr/tools/transactions/template_pack_packer.rb +73 -0
- data/lib/indoctrinatr/tools/transactions/template_pack_scaffold.rb +73 -0
- data/lib/indoctrinatr/tools/version.rb +1 -1
- data/lib/indoctrinatr_tools.rb +12 -0
- metadata +106 -141
- checksums.yaml.gz.sig +0 -0
- data/.arcconfig +0 -9
- data/.coveralls.yml +0 -1
- data/.travis.yml +0 -15
- data/bin/indoctrinatr +0 -185
- data/certs/dkd-reuschling.pem +0 -22
- data/features/autocompletion_support.feature +0 -9
- data/features/demo.feature +0 -17
- data/features/doc_keepauxfiles.feature +0 -13
- data/features/documentation.feature +0 -20
- data/features/fieldnames_pdf.feature +0 -9
- data/features/fieldnames_pdf_auxfiles.feature +0 -10
- data/features/pack.feature +0 -11
- data/features/parse.feature +0 -6
- data/features/pdf.feature +0 -15
- data/features/pdf_keepauxfiles.feature +0 -11
- data/features/pdf_with_timestamp.feature +0 -8
- data/features/scaffold.feature +0 -23
- data/features/step_definitions/common.rb +0 -3
- data/features/step_definitions/indoctrinatr_cli.rb +0 -11
- data/features/support/env.rb +0 -1
- data/features/version.feature +0 -5
- data/features/workflow.feature +0 -9
- data/lib/indoctrinatr/tools/directory_helpers.rb +0 -18
- data/lib/indoctrinatr/tools/template_pack_default_values_compiler.rb +0 -47
- data/lib/indoctrinatr/tools/template_pack_default_values_parser.rb +0 -55
- data/lib/indoctrinatr/tools/template_pack_demo.rb +0 -23
- data/lib/indoctrinatr/tools/template_pack_documentation.rb +0 -132
- data/lib/indoctrinatr/tools/template_pack_error_checker.rb +0 -104
- data/lib/indoctrinatr/tools/template_pack_fieldnames_creator.rb +0 -79
- data/lib/indoctrinatr/tools/template_pack_helpers.rb +0 -68
- data/lib/indoctrinatr/tools/template_pack_packer.rb +0 -49
- data/lib/indoctrinatr/tools/template_pack_scaffold.rb +0 -57
- data/lib/indoctrinatr/tools.rb +0 -9
- data/spec/fixtures/test/configuration.yaml +0 -26
- data/spec/fixtures/test/test.tex.erb +0 -15
- data/spec/indoctrinatr/templates/configuration_file_spec.rb +0 -9
- data/spec/indoctrinatr/templates/tex_file_spec.rb +0 -9
- data/spec/indoctrinatr/tools/textile_support_spec.rb +0 -18
- data/spec/indoctrinatr/tools/version_spec.rb +0 -8
- data/spec/redcloth_latex_formatter_patch/patch_spec.rb +0 -34
- data/spec/spec_helper.rb +0 -2
- data.tar.gz.sig +0 -0
- metadata.gz.sig +0 -0
@@ -0,0 +1,38 @@
|
|
1
|
+
module Indoctrinatr
|
2
|
+
module Tools
|
3
|
+
module Commands
|
4
|
+
class Workflow < Dry::CLI::Command
|
5
|
+
desc 'Display the suggested workflow.'
|
6
|
+
|
7
|
+
def call(**)
|
8
|
+
puts <<~HEREDOC
|
9
|
+
The workflow for a project (e.g. demo) typically looks like this:
|
10
|
+
|
11
|
+
1. Run in shell: indoctrinatr new demo
|
12
|
+
Creates a new Indoctrinatr Template Pack in the folder demo
|
13
|
+
|
14
|
+
2. Edit demo.tex.erb and configuration.yaml according to needs
|
15
|
+
|
16
|
+
3. Run in shell: indoctrinatr parse demo
|
17
|
+
Parses tex file demo_with_default_values.tex with ERB and default values from configuration.yaml
|
18
|
+
|
19
|
+
4. Run in shell: indoctrinatr pdf demo
|
20
|
+
Compiles PDF from demo_with_default_values.tex
|
21
|
+
|
22
|
+
5. Run in shell: indoctrinatr pdf_with_field_names demo
|
23
|
+
Compiles PDF from demo_with_fieldname_values.tex
|
24
|
+
|
25
|
+
6. Run in shell: indoctrinatr check demo
|
26
|
+
Analyzes your Template Pack for potential errors
|
27
|
+
|
28
|
+
7. Run in shell: indoctrinatr doc demo
|
29
|
+
Creates a technical documentation for the Template Pack
|
30
|
+
|
31
|
+
8. Run in shell: indoctrinatr pack demo
|
32
|
+
Creates demo.zip with all required file for upload to Indoctrinatr server
|
33
|
+
HEREDOC
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Indoctrinatr
|
2
|
+
module Tools
|
3
|
+
module Commands
|
4
|
+
class ZshCompletions < Dry::CLI::Command
|
5
|
+
desc 'Print a guide how to add indoctrinatr-tools integration to .zshrc.'
|
6
|
+
|
7
|
+
def call(**)
|
8
|
+
puts <<~HEREDOC
|
9
|
+
Add this to your .zshrc (and open up a new shell):
|
10
|
+
|
11
|
+
if [[ -n ${ZSH_VERSION-} ]]; then
|
12
|
+
autoload -U +X bashcompinit && bashcompinit
|
13
|
+
fi
|
14
|
+
complete -F get_indoctrinatr_commands indoctrinatr
|
15
|
+
function get_indoctrinatr_commands()
|
16
|
+
{
|
17
|
+
local binary="indoctrinatr"
|
18
|
+
COMPREPLY=(`$binary completions`)
|
19
|
+
}
|
20
|
+
HEREDOC
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Indoctrinatr
|
2
|
+
module Tools
|
3
|
+
module Commands
|
4
|
+
extend Dry::CLI::Registry
|
5
|
+
|
6
|
+
register 'bashcompletion', BashCompletions
|
7
|
+
register 'check', Check
|
8
|
+
register 'commands', CompletionCommands
|
9
|
+
register 'demo', Demo
|
10
|
+
register 'doc', Doc
|
11
|
+
register 'new', Scaffold
|
12
|
+
register 'pack', Pack
|
13
|
+
register 'parse', Parse
|
14
|
+
register 'pdf', Pdf
|
15
|
+
register 'pdf_with_field_names', PdfWithFieldNames
|
16
|
+
register 'version', Version, aliases: %w[v -v --version]
|
17
|
+
register 'workflow', Workflow
|
18
|
+
register 'zshcompletion', ZshCompletions
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -1,26 +1,24 @@
|
|
1
|
-
require '
|
1
|
+
require 'yaml'
|
2
2
|
|
3
3
|
module Indoctrinatr
|
4
4
|
module Tools
|
5
5
|
class ConfigurationExtractor
|
6
|
-
include TemplatePackHelpers
|
7
|
-
|
8
6
|
attr_reader :template_pack_name
|
9
7
|
|
10
|
-
def initialize
|
8
|
+
def initialize(template_pack_name)
|
11
9
|
@template_pack_name = template_pack_name
|
12
10
|
end
|
13
11
|
|
14
12
|
def call
|
15
|
-
config_file = YAML.load_file
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
13
|
+
config_file = YAML.load_file((Pathname.new(Dir.pwd).join template_pack_name).join('configuration.yaml'))
|
14
|
+
TemplatePackConfiguration.new.tap do |configuration|
|
15
|
+
configuration.template_asset_path = ((Pathname.new(Dir.pwd).join template_pack_name).join 'assets').to_s
|
16
|
+
configuration.default_file_name = "#{template_pack_name}_with_default_values.pdf"
|
17
|
+
configuration.output_file_name = config_file.fetch('output_file_name', "#{template_pack_name}_with_default_values.pdf")
|
18
|
+
configuration.template_name = config_file.fetch 'template_name'
|
19
|
+
configuration.textual_description = config_file.fetch('textual_description'), ''
|
20
|
+
configuration.attributes_as_hashes_in_array = config_file.fetch 'fields', []
|
21
|
+
end
|
24
22
|
end
|
25
23
|
end
|
26
24
|
end
|
@@ -5,12 +5,12 @@ module Indoctrinatr
|
|
5
5
|
class ContentForTexFiles
|
6
6
|
# a class that DefaultValues, TemplateDocumentationContent, and field_names_as_variables should inherit from
|
7
7
|
# or to be precise: When we want use variables in an indoctrinatr tex.erb file, we should use this class
|
8
|
-
def initialize
|
8
|
+
def initialize(configuration)
|
9
9
|
@_configuration = configuration
|
10
10
|
_build_from_configuration
|
11
11
|
end
|
12
12
|
|
13
|
-
def textile2latex
|
13
|
+
def textile2latex(textile)
|
14
14
|
RedCloth.new(textile).to_latex
|
15
15
|
end
|
16
16
|
|
@@ -19,7 +19,9 @@ module Indoctrinatr
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def customized_output_file_name
|
22
|
-
@
|
22
|
+
return @customized_output_file_name if defined? @customized_output_file_name
|
23
|
+
|
24
|
+
@customized_output_file_name = eval("\"#{@_output_file_name}\"", binding, __FILE__, __LINE__) # rubocop:disable Security/Eval
|
23
25
|
end
|
24
26
|
|
25
27
|
def template_asset_path
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'indoctrinatr/tools/content_for_tex_files'
|
2
|
-
|
3
1
|
module Indoctrinatr
|
4
2
|
module Tools
|
5
3
|
class DefaultValues < ContentForTexFiles
|
@@ -11,7 +9,7 @@ module Indoctrinatr
|
|
11
9
|
@_default_file_name
|
12
10
|
end
|
13
11
|
|
14
|
-
def _use_default_values
|
12
|
+
def _use_default_values
|
15
13
|
@_configuration.attributes_as_hashes_in_array.each do |attribute_hash|
|
16
14
|
instance_variable_set("@_#{attribute_hash['name']}", attribute_hash['default_value'])
|
17
15
|
|
@@ -1,11 +1,9 @@
|
|
1
|
-
require 'indoctrinatr/tools/content_for_tex_files'
|
2
|
-
|
3
1
|
module Indoctrinatr
|
4
2
|
module Tools
|
5
3
|
# This class defines the content for a document that has the field names as content.
|
6
4
|
class FieldNameValues < ContentForTexFiles
|
7
|
-
# TODO: extensive list of possibilities
|
8
5
|
PICTURE_FILE_ENDINGS = %w[.png .jpeg .jpg .bmp .gif .pdf].freeze
|
6
|
+
|
9
7
|
def _field_names_as_values # rubocop:disable Metrics/AbcSize
|
10
8
|
@_configuration.attributes_as_hashes_in_array.each do |attribute_hash|
|
11
9
|
# Usage of \textless to avoid issues with the < > characters.
|
@@ -29,10 +27,11 @@ module Indoctrinatr
|
|
29
27
|
|
30
28
|
# The LaTeX compilation would fail if the \includegraphics tries to include a file that does not exist.
|
31
29
|
# Because of that it makes sense to simply use the default values again if user sets file names.
|
32
|
-
def overwrite_picture_file_names_output
|
30
|
+
def overwrite_picture_file_names_output(attributes_as_hashes) # rubocop:disable Metrics/AbcSize
|
33
31
|
attributes_as_hashes.each do |attribute_hash|
|
34
32
|
# search for typical picture file endings
|
35
33
|
next unless detect_picture_file_names attribute_hash['default_value']
|
34
|
+
|
36
35
|
instance_variable_set("@_#{attribute_hash['name']}", attribute_hash['default_value'])
|
37
36
|
|
38
37
|
define_singleton_method "raw_#{attribute_hash['name']}".to_sym do
|
@@ -47,7 +46,7 @@ module Indoctrinatr
|
|
47
46
|
|
48
47
|
# Indoctrinatr has no picture data type. This means that the only way to check for pictures is to check for
|
49
48
|
# file endings. If an user has obscure file type the possibility list would have to get updated.
|
50
|
-
def detect_picture_file_names
|
49
|
+
def detect_picture_file_names(string_to_check)
|
51
50
|
PICTURE_FILE_ENDINGS.any? do |picture_file_ending|
|
52
51
|
string_to_check.downcase.include? picture_file_ending # http://stackoverflow.com/a/3686568
|
53
52
|
end
|
@@ -5,7 +5,7 @@ module Indoctrinatr
|
|
5
5
|
# Compiles a PDF from a tex file with XeLaTeX
|
6
6
|
# @param tex_file a Pathname that points to the tex file
|
7
7
|
# @return false if error, nil if system command unknown
|
8
|
-
def make_pdf
|
8
|
+
def make_pdf(tex_file, output_dir = nil, cleanup: true)
|
9
9
|
args = ['-xelatex',
|
10
10
|
'-shell-escape',
|
11
11
|
'-interaction=batchmode', # more silent output
|
@@ -15,14 +15,14 @@ module Indoctrinatr
|
|
15
15
|
args.delete_at 3 # Remove argument if no output dir is wished for. This probably could be done better.
|
16
16
|
end
|
17
17
|
latexmk_successful = system('latexmk', *args) # latexmk instead of running 2.times
|
18
|
-
latex_cleanup output_dir if latexmk_successful
|
18
|
+
latex_cleanup output_dir if latexmk_successful && cleanup
|
19
19
|
latexmk_successful
|
20
20
|
end
|
21
21
|
|
22
22
|
# Cleans up LaTeX helper files in a specific directory
|
23
23
|
# @param working_directory a Pathname that points the directory that should get cleaned up
|
24
24
|
# @return false if error, nil if system command unknown
|
25
|
-
def latex_cleanup
|
25
|
+
def latex_cleanup(working_directory)
|
26
26
|
# latexmk -c apparently cannot cleanup a specified subdirectory. So we have to change the working directory,
|
27
27
|
# run the cleanup command in it and then change back to the directory that we were in. http://tex.stackexchange.com/q/301366/17834
|
28
28
|
current_dir = Dir.getwd
|
@@ -1,21 +1,30 @@
|
|
1
1
|
require 'redcloth'
|
2
2
|
|
3
|
-
module
|
4
|
-
module
|
5
|
-
module
|
3
|
+
module Indoctrinatr
|
4
|
+
module Tools
|
5
|
+
module RedclothFormattersLatexPatch
|
6
|
+
def self.apply
|
7
|
+
const = Kernel.const_get('RedCloth::Formatters::LATEX')
|
8
|
+
const&.prepend(self)
|
9
|
+
rescue NameError => e
|
10
|
+
puts e
|
11
|
+
end
|
12
|
+
|
6
13
|
{
|
7
14
|
h1: 'chapter',
|
8
15
|
h2: 'section',
|
9
16
|
h3: 'subsection',
|
10
|
-
h4: 'subsubsection'
|
17
|
+
h4: 'subsubsection',
|
18
|
+
h5: 'subparagraph',
|
19
|
+
h6: 'textbf'
|
11
20
|
}.each do |m, tag|
|
12
21
|
define_method(m) do |opts|
|
13
22
|
case opts[:align]
|
14
|
-
when 'left'
|
23
|
+
when 'left'
|
15
24
|
"\\begin{flushleft}\\#{tag}{#{opts[:text]}}\\end{flushleft}\n\n"
|
16
|
-
when 'right'
|
25
|
+
when 'right'
|
17
26
|
"\\begin{flushright}\\#{tag}{#{opts[:text]}}\\end{flushright}\n\n"
|
18
|
-
when 'center'
|
27
|
+
when 'center'
|
19
28
|
"\\begin{center}\\#{tag}{#{opts[:text]}}\\end{center}\n\n"
|
20
29
|
else
|
21
30
|
"\\#{tag}{#{opts[:text]}}\n\n"
|
@@ -23,20 +32,9 @@ module RedCloth
|
|
23
32
|
end
|
24
33
|
end
|
25
34
|
|
26
|
-
def del
|
35
|
+
def del(opts)
|
27
36
|
"\\st{#{opts[:text]}}"
|
28
37
|
end
|
29
|
-
|
30
|
-
def table_close _opts
|
31
|
-
output = "\\begin{tabu}{ #{'l ' * @table[0].size}}\n"
|
32
|
-
output << " #{@table[0].join(' & ')} \\\\\n"
|
33
|
-
output << " \\tabletoprule\n"
|
34
|
-
@table[1..-1].each do |row|
|
35
|
-
output << " #{row.join(' & ')} \\\\\n"
|
36
|
-
end
|
37
|
-
output << " \\tablebottomrule\n\\end{tabu}\n"
|
38
|
-
output
|
39
|
-
end
|
40
38
|
end
|
41
39
|
end
|
42
40
|
end
|
@@ -1,20 +1,13 @@
|
|
1
|
-
require 'indoctrinatr/tools/content_for_tex_files'
|
2
|
-
require 'indoctrinatr/tools/template_pack_configuration'
|
3
|
-
require 'indoctrinatr/tools/directory_helpers'
|
4
|
-
require 'indoctrinatr/tools/template_documentation_source_file'
|
5
|
-
require 'indoctrinatr/tools/default_values'
|
6
|
-
|
7
1
|
module Indoctrinatr
|
8
2
|
module Tools
|
9
3
|
class TemplateDocumentationContent < ContentForTexFiles
|
10
|
-
include DirectoryHelpers
|
11
|
-
include TemplatePackHelpers
|
12
|
-
|
13
4
|
attr_accessor :template_pack_name, :list_of_files
|
14
5
|
|
15
6
|
# Overwrite the initialize method because the content is built up much more complex than for the other
|
16
7
|
# ContentForTexFile children.
|
17
|
-
def initialize
|
8
|
+
def initialize(template_pack_name, configuration)
|
9
|
+
super(configuration)
|
10
|
+
|
18
11
|
@configuration = configuration
|
19
12
|
@template_pack_name = template_pack_name
|
20
13
|
@list_of_files = print_dirtree_style @template_pack_name
|
@@ -29,6 +22,9 @@ module Indoctrinatr
|
|
29
22
|
|
30
23
|
def read_template_files_content
|
31
24
|
filenames = list_files_of_type template_pack_name
|
25
|
+
path_name = Pathname.new(Dir.pwd).join template_pack_name
|
26
|
+
pack_documentation_dir_path = path_name.join 'doc'
|
27
|
+
pack_documentation_examples_dir_path = pack_documentation_dir_path.join 'examples'
|
32
28
|
filenames.reject! { |f| f.include?(pack_documentation_examples_dir_path.relative_path_from(Pathname.new(Dir.pwd)).to_s) }
|
33
29
|
filenames.inject [] do |files, filename|
|
34
30
|
files.push TemplateDocumentationSourceFile.new filename
|
@@ -36,27 +32,80 @@ module Indoctrinatr
|
|
36
32
|
end
|
37
33
|
|
38
34
|
def default_values_example
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
35
|
+
Indoctrinatr::Tools::Transactions::TemplatePackDefaultValuesParser.new.call(@template_pack_name) do |result|
|
36
|
+
result.success do |message|
|
37
|
+
puts message
|
38
|
+
Indoctrinatr::Tools::Transactions::TemplatePackDefaultValuesCompiler.new.call(template_pack_name:, keep_aux_files: false) do |result2|
|
39
|
+
result2.success do |message2|
|
40
|
+
puts message2
|
41
|
+
end
|
42
|
+
result2.failure do |message2|
|
43
|
+
puts message2
|
44
|
+
end
|
45
|
+
end
|
46
|
+
pdf_with_default_values_file_path
|
47
|
+
end
|
48
|
+
result.failure do |message|
|
49
|
+
puts message
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# get file path for PDF example with default values:
|
55
|
+
def pdf_with_default_values_file_path
|
56
|
+
path_name = Pathname.new(Dir.pwd).join template_pack_name
|
57
|
+
pack_documentation_dir_path = path_name.join 'doc'
|
58
|
+
pack_documentation_examples_dir_path = pack_documentation_dir_path.join 'examples'
|
59
|
+
default_values = DefaultValues.new @configuration
|
60
|
+
# if there is a change in where the pdf command (DefaultValuesCompiler) saves it's output, this logic needs to be updated
|
61
|
+
if default_values.customized_output_file_name == default_values.default_file_name
|
62
|
+
Pathname.new(Dir.pwd).join pack_documentation_examples_dir_path + default_values.customized_output_file_name
|
63
|
+
else
|
64
|
+
Pathname.new(Dir.pwd).join pack_documentation_examples_dir_path + eval("\"#{default_values.output_file_name}\"", binding, __FILE__, __LINE__) # rubocop:disable Security/Eval
|
65
|
+
# usage of eval to execute the interpolation of a custom filename string with interpolation - e.g. a filename with the current date
|
43
66
|
end
|
44
|
-
pdf_with_default_values_file_path @configuration
|
45
67
|
end
|
46
68
|
|
47
69
|
def fieldname_values_example
|
48
|
-
fieldnames_creator = TemplatePackFieldnamesCreator.new(template_pack_name)
|
49
70
|
# This gives user the option to customize the FieldNameValues Example that is appended in the documentation
|
50
|
-
|
71
|
+
path_name = Pathname.new(Dir.pwd).join template_pack_name
|
72
|
+
fail 'Please specify a template pack name.' if template_pack_name.empty? # rubocop:disable Style/SignalException
|
73
|
+
fail "A folder with name '#{template_pack_name}' does not exist." unless Dir.exist? path_name.to_s # rubocop:disable Style/SignalException
|
51
74
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
75
|
+
pack_documentation_dir_path = path_name.join 'doc'
|
76
|
+
pack_documentation_examples_dir_path = pack_documentation_dir_path.join 'examples'
|
77
|
+
pdf_with_fieldname_values_file_path = "#{pack_documentation_examples_dir_path.join template_pack_name}_with_fieldname_values.pdf"
|
78
|
+
|
79
|
+
return pdf_with_fieldname_values_file_path if File.exist? pdf_with_fieldname_values_file_path
|
80
|
+
|
81
|
+
Indoctrinatr::Tools::Transactions::TemplatePackFieldnamesCreator.new.call(template_pack_name:, keep_aux_files: false) do |result|
|
82
|
+
result.success do
|
83
|
+
puts 'INFO: Example with field names has been automatically generated for the documentation' # More user information and for testing
|
84
|
+
pdf_with_fieldname_values_file_path
|
85
|
+
end
|
86
|
+
result.failure do |message|
|
87
|
+
puts message
|
88
|
+
puts 'ERROR: Example with field names could not be created and is not included in documentation'
|
89
|
+
nil
|
90
|
+
end
|
58
91
|
end
|
59
92
|
end
|
93
|
+
|
94
|
+
# refractored from directory_helpers.rb author: Luka Lüdicke
|
95
|
+
def print_dirtree_style(directory = '.')
|
96
|
+
Dir.glob("#{directory}/**/*").inject [] do |entries, entry| # list entries recursively
|
97
|
+
nesting = entry.count(File::SEPARATOR) + 1 # nesting starts with 2, because for \dirtree 1 is root
|
98
|
+
name = entry.split(File::SEPARATOR).last
|
99
|
+
entries.push ".#{nesting} #{name}. " # formatting for \dirtree: .<level><space><text-node>.<space>
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
# refractored from directory_helpers.rb author: Luka Lüdicke
|
104
|
+
# default file types for template docs
|
105
|
+
def list_files_of_type(directory = '.', types = %w[erb rb yaml sty tex])
|
106
|
+
# found and modified from http://stackoverflow.com/a/3504307/1796645
|
107
|
+
Dir.glob("#{directory}/**/*.{#{types.join(',')}}") # recursively list files of type in types array
|
108
|
+
end
|
60
109
|
end
|
61
110
|
end
|
62
111
|
end
|
@@ -65,7 +65,7 @@ module Indoctrinatr
|
|
65
65
|
private
|
66
66
|
|
67
67
|
def documentation_files_path
|
68
|
-
Pathname.new(File.expand_path(
|
68
|
+
Pathname.new(File.expand_path(__dir__)).join('..', 'templates', 'documentation')
|
69
69
|
end
|
70
70
|
end
|
71
71
|
end
|
@@ -3,7 +3,7 @@ module Indoctrinatr
|
|
3
3
|
class TemplateDocumentationSourceFile
|
4
4
|
attr_reader :name, :content, :language
|
5
5
|
|
6
|
-
def initialize
|
6
|
+
def initialize(filename)
|
7
7
|
@name = filename
|
8
8
|
@content = File.read filename
|
9
9
|
@language = set_programming_language
|
@@ -12,19 +12,14 @@ module Indoctrinatr
|
|
12
12
|
private
|
13
13
|
|
14
14
|
def set_programming_language
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
'Ruby'
|
24
|
-
else # probably YAML
|
25
|
-
'unspecified'
|
26
|
-
end
|
27
|
-
language
|
15
|
+
case File.extname(@name)
|
16
|
+
when '.tex', '.sty', '.erb'
|
17
|
+
'TeX'
|
18
|
+
when '.rb'
|
19
|
+
'Ruby'
|
20
|
+
else # probably YAML
|
21
|
+
'unspecified'
|
22
|
+
end
|
28
23
|
end
|
29
24
|
end
|
30
25
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
module Indoctrinatr
|
2
2
|
module Tools
|
3
|
-
|
3
|
+
# wrapper class for config. See ConfigurationExtractor for details
|
4
|
+
class TemplatePackConfiguration
|
4
5
|
attr_accessor :template_asset_path, :default_file_name, :template_name, :textual_description, :output_file_name, :attributes_as_hashes_in_array
|
5
6
|
end
|
6
7
|
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'dry/transaction'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
module Indoctrinatr
|
5
|
+
module Tools
|
6
|
+
module Transactions
|
7
|
+
class TemplatePackDefaultValuesCompiler
|
8
|
+
include PdfGenerator
|
9
|
+
include Dry::Transaction
|
10
|
+
|
11
|
+
step :setup
|
12
|
+
step :check_setup
|
13
|
+
step :compile_tex_file
|
14
|
+
step :rename_if_necessary
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def setup(template_pack_name:, keep_aux_files:)
|
19
|
+
path_name = Pathname.new(Dir.pwd).join template_pack_name
|
20
|
+
pack_documentation_dir_path = path_name.join 'doc'
|
21
|
+
pack_documentation_examples_dir_path = pack_documentation_dir_path.join('examples')
|
22
|
+
tex_with_default_values_file_path = pack_documentation_examples_dir_path.join("#{template_pack_name}_with_default_values.tex")
|
23
|
+
Success(
|
24
|
+
{
|
25
|
+
template_pack_name:,
|
26
|
+
path_name:,
|
27
|
+
keep_aux_files:,
|
28
|
+
pack_documentation_examples_dir_path:,
|
29
|
+
tex_with_default_values_file_path:
|
30
|
+
}
|
31
|
+
)
|
32
|
+
rescue StandardError => e
|
33
|
+
Failure(e.message)
|
34
|
+
end
|
35
|
+
|
36
|
+
def check_setup(config)
|
37
|
+
return Failure('Please specify a template pack name.') if config[:template_pack_name].empty?
|
38
|
+
return Failure("A folder with name '#{config[:template_pack_name]}' does not exist.") unless Dir.exist? config[:path_name] # rub
|
39
|
+
|
40
|
+
Success(config)
|
41
|
+
rescue StandardError => e
|
42
|
+
Failure(e.message)
|
43
|
+
end
|
44
|
+
|
45
|
+
def compile_tex_file(config)
|
46
|
+
make_pdf config[:tex_with_default_values_file_path], config[:pack_documentation_examples_dir_path], cleanup: !config[:keep_aux_files]
|
47
|
+
Success(config)
|
48
|
+
rescue StandardError => e
|
49
|
+
Failure(e.message)
|
50
|
+
end
|
51
|
+
|
52
|
+
def rename_if_necessary(config) # rubocop:disable Metrics/AbcSize
|
53
|
+
configuration = ConfigurationExtractor.new(config[:template_pack_name]).call # TODO: avoid repeated calling of the ConfigurationExtrator
|
54
|
+
@default_values = DefaultValues.new configuration
|
55
|
+
return Success("The pdf has successfully been created as '#{configuration.output_file_name}.") if @default_values.customized_output_file_name == @default_values.default_file_name
|
56
|
+
|
57
|
+
custom_filepath = config[:pack_documentation_examples_dir_path] + @default_values.customized_output_file_name
|
58
|
+
::FileUtils.rm_f custom_filepath
|
59
|
+
::FileUtils.mv(config[:pack_documentation_examples_dir_path] + @default_values.default_file_name, custom_filepath)
|
60
|
+
Success("A pdf has successfully been created at '#{custom_filepath}.")
|
61
|
+
rescue StandardError => e
|
62
|
+
Failure(e.message)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,82 @@
|
|
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 TemplatePackDefaultValuesParser
|
10
|
+
include Dry::Transaction
|
11
|
+
|
12
|
+
step :setup
|
13
|
+
step :check_setup
|
14
|
+
step :read_config_file
|
15
|
+
step :read_tex_file
|
16
|
+
step :parse_tex_file
|
17
|
+
step :write_tex_file
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def setup(template_pack_name)
|
22
|
+
path_name = Pathname.new(Dir.pwd).join template_pack_name
|
23
|
+
pack_documentation_dir_path = path_name.join 'doc'
|
24
|
+
pack_documentation_examples_dir_path = pack_documentation_dir_path.join('examples')
|
25
|
+
tex_with_default_values_file_path = pack_documentation_examples_dir_path.join("#{template_pack_name}_with_default_values.tex")
|
26
|
+
Success(
|
27
|
+
{
|
28
|
+
template_pack_name:,
|
29
|
+
path_name:,
|
30
|
+
pack_documentation_dir_path:,
|
31
|
+
pack_documentation_examples_dir_path:,
|
32
|
+
tex_with_default_values_file_path:
|
33
|
+
}
|
34
|
+
)
|
35
|
+
end
|
36
|
+
|
37
|
+
def check_setup(config)
|
38
|
+
return Failure('Please specify a template pack name.') if config[:template_pack_name].empty?
|
39
|
+
return Failure("A folder with name '#{config[:template_pack_name]}' does not exist.") unless Dir.exist? config[:path_name] # rub
|
40
|
+
|
41
|
+
Success(config)
|
42
|
+
end
|
43
|
+
|
44
|
+
def read_config_file(config)
|
45
|
+
configuration = ConfigurationExtractor.new(config[:template_pack_name]).call
|
46
|
+
default_values = DefaultValues.new configuration
|
47
|
+
default_values._use_default_values
|
48
|
+
config[:default_values] = default_values
|
49
|
+
Success(config)
|
50
|
+
rescue StandardError => e
|
51
|
+
Failure(e.message)
|
52
|
+
end
|
53
|
+
|
54
|
+
def read_tex_file(config)
|
55
|
+
tex_file_path = config[:path_name].join("#{config[:template_pack_name]}.tex.erb")
|
56
|
+
config[:tex_file_content] = File.read tex_file_path
|
57
|
+
Success(config)
|
58
|
+
rescue StandardError => e
|
59
|
+
Failure(e.message)
|
60
|
+
end
|
61
|
+
|
62
|
+
def parse_tex_file(config)
|
63
|
+
config[:parsed_tex_file_content] = Erubis::Eruby.new(config[:tex_file_content]).result(config[:default_values].retrieve_binding)
|
64
|
+
Success(config)
|
65
|
+
rescue StandardError => e
|
66
|
+
Failure(e.message)
|
67
|
+
end
|
68
|
+
|
69
|
+
def write_tex_file(config)
|
70
|
+
# Create directory to avoid file creation errors
|
71
|
+
::FileUtils.mkdir_p(config[:pack_documentation_dir_path])
|
72
|
+
::FileUtils.mkdir_p(config[:pack_documentation_examples_dir_path])
|
73
|
+
File.write config[:tex_with_default_values_file_path], config[:parsed_tex_file_content]
|
74
|
+
|
75
|
+
Success("The template pack '#{config[:template_pack_name]}' has been successfully parsed with default values.")
|
76
|
+
rescue StandardError => e
|
77
|
+
Failure(e.message)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|