indoctrinatr-tools 0.11.0 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.arcconfig +3 -3
  3. data/.rubocop.yml +3 -0
  4. data/.rvmrc +1 -1
  5. data/.travis.yml +2 -2
  6. data/README.md +12 -3
  7. data/bin/indoctrinatr +40 -10
  8. data/features/demo.feature +7 -7
  9. data/features/doc_keepauxfiles.feature +13 -0
  10. data/features/documentation.feature +13 -4
  11. data/features/fieldnames_pdf.feature +9 -0
  12. data/features/fieldnames_pdf_auxfiles.feature +10 -0
  13. data/features/parse.feature +1 -1
  14. data/features/pdf.feature +2 -1
  15. data/features/pdf_keepauxfiles.feature +11 -0
  16. data/features/version.feature +1 -1
  17. data/features/workflow.feature +1 -0
  18. data/indoctrinatr-tools.gemspec +10 -10
  19. data/lib/indoctrinatr/templates/configuration.yaml +11 -3
  20. data/lib/indoctrinatr/templates/documentation/dkd-image-tools.sty +72 -0
  21. data/lib/indoctrinatr/templates/documentation/indoctrinatr-technical-documentation-content.tex.erb +17 -12
  22. data/lib/indoctrinatr/templates/documentation/indoctrinatr-technical-documentation.tex.erb +8 -0
  23. data/lib/indoctrinatr/templates/template.tex.erb +10 -3
  24. data/lib/indoctrinatr/tools/configuration_extractor.rb +1 -1
  25. data/lib/indoctrinatr/tools/content_for_tex_files.rb +36 -0
  26. data/lib/indoctrinatr/tools/default_values.rb +3 -28
  27. data/lib/indoctrinatr/tools/field_name_values.rb +57 -0
  28. data/lib/indoctrinatr/tools/pdf_generator.rb +36 -0
  29. data/lib/indoctrinatr/tools/template_documentation_content.rb +26 -16
  30. data/lib/indoctrinatr/tools/template_documentation_helpers.rb +13 -0
  31. data/lib/indoctrinatr/tools/template_documentation_source_file.rb +12 -12
  32. data/lib/indoctrinatr/tools/template_pack_configuration.rb +1 -1
  33. data/lib/indoctrinatr/tools/template_pack_default_values_compiler.rb +12 -4
  34. data/lib/indoctrinatr/tools/template_pack_default_values_parser.rb +4 -0
  35. data/lib/indoctrinatr/tools/template_pack_documentation.rb +32 -11
  36. data/lib/indoctrinatr/tools/template_pack_error_checker.rb +104 -0
  37. data/lib/indoctrinatr/tools/template_pack_fieldnames_creator.rb +79 -0
  38. data/lib/indoctrinatr/tools/template_pack_helpers.rb +34 -4
  39. data/lib/indoctrinatr/tools/template_pack_scaffold.rb +2 -2
  40. data/lib/indoctrinatr/tools/version.rb +1 -1
  41. data/lib/redcloth_latex_formatter_patch/patch.rb +2 -1
  42. data/spec/indoctrinatr/templates/configuration_file_spec.rb +1 -1
  43. data/spec/indoctrinatr/templates/tex_file_spec.rb +1 -1
  44. data/spec/indoctrinatr/tools/version_spec.rb +1 -1
  45. metadata +33 -17
@@ -22,15 +22,20 @@
22
22
 
23
23
  <% end %>
24
24
 
25
- \chapter{Variables}
26
-
27
- \begin{tabu}{ l l X l X }
28
- \textbf{Variable} & \textbf{Presentation} & \textbf{Default Value} & \textbf{Required} & \textbf{Description} \\
29
- <% @attributes.each do |attribute| %>
30
- \texttt{<%= attribute['name'].to_latex -%>}
31
- & <%= attribute['presentation'].to_latex -%>
32
- & <%= attribute['default_value'].to_latex -%>
33
- & <%= 'true' if attribute['required'] == 'true' -%> <%# empty if false or not set. Wish by Søren for better readability-%>
34
- & <%= attribute['description'].to_latex -%>\\
35
- <% end %>
36
- \end{tabu}
25
+ \begin{landscape}
26
+ \chapter{Variables}
27
+
28
+ \begin{longtabu}{ l l X l X }
29
+ \tabletoprule
30
+ \textbf{Variable} & \textbf{Presentation} & \textbf{Default Value} & \textbf{Required} & \textbf{Description} \\
31
+ \tabletoprule
32
+ \endhead
33
+ <% @attributes.each do |attribute| %>
34
+ \texttt{<%= attribute['name'].to_latex -%>}
35
+ & <%= attribute['presentation'].to_latex if attribute['presentation'] -%>
36
+ & <%= attribute['default_value'].to_latex -%>
37
+ & <%= 'true' if attribute['required'] == 'true' -%> <%# empty if false or not set. Wish by Søren for better readability-%>
38
+ & <%= attribute['description'].to_latex if attribute['description'] -%>\\ <%# if condition to ignore errors on empty description field -%>
39
+ <% end %>
40
+ \end{longtabu}
41
+ \end{landscape}
@@ -9,7 +9,11 @@
9
9
 
10
10
  % use dkd-letter style to apply design styles
11
11
  \usepackage{indoctrinatr-technical-documentation}
12
+ % use custom image macros to show image placeholders
13
+ \usepackage{dkd-image-tools}
12
14
 
15
+ % use "pdflscape" package to be able to have several landscape pages in the document
16
+ \usepackage{pdflscape}
13
17
 
14
18
  %define labels to use in this document
15
19
  \newcommand{\dkd}{\emph{dkd}}
@@ -72,6 +76,10 @@
72
76
  % include the prerendered template
73
77
  % pages=- selects all pages
74
78
  \includepdf[pages=-]{<%= @default_values_pdf_path -%>} % template_with_default_values.pdf "#{@template_name}_with_default_values.pdf"
79
+ <% if @pdf_with_field_names_path %>
80
+ \chapter{Templated filled with field names}
81
+ \includepdf[pages=-]{<%= @pdf_with_field_names_path -%>}
82
+ <% end %>
75
83
  % restore wallpaper
76
84
  \ULCornerWallPaper{1}{indoctrinatr_letterpaper.pdf}
77
85
 
@@ -2,7 +2,14 @@
2
2
  \documentclass{article}
3
3
 
4
4
  \begin{document}
5
- \section{Hello <%= variable1 -%>}
6
-
7
- The <%= variable1 -%> is <%= variable2 -%>!
5
+ \section{Hello <%= variable1 -%>}
6
+
7
+ The <%= variable1 -%> is <%= variable2 -%>!
8
+
9
+ Today is \textbf{<%= date -%>}.
10
+
11
+ % This is is the raw, unescaped input of \texttt{variable1}:
12
+ \begin{verbatim}
13
+ <%= raw_variable1 -%>
14
+ \end{verbatim}
8
15
  \end{document}
@@ -11,7 +11,7 @@ module Indoctrinatr
11
11
  @template_pack_name = template_pack_name
12
12
  end
13
13
 
14
- def call # rubocop:disable Metrics/AbcSize
14
+ def call
15
15
  config_file = YAML.load_file config_file_path
16
16
  configuration = TemplatePackConfiguration.new
17
17
  configuration.template_asset_path = assets_path.to_s
@@ -0,0 +1,36 @@
1
+ require 'redcloth'
2
+
3
+ module Indoctrinatr
4
+ module Tools
5
+ class ContentForTexFiles
6
+ # a class that DefaultValues, TemplateDocumentationContent, and field_names_as_variables should inherit from
7
+ # or to be precise: When we want use variables in an indoctrinatr tex.erb file, we should use this class
8
+ def initialize configuration
9
+ @_configuration = configuration
10
+ _build_from_configuration
11
+ end
12
+
13
+ def textile2latex textile
14
+ RedCloth.new(textile).to_latex
15
+ end
16
+
17
+ def retrieve_binding
18
+ binding
19
+ end
20
+
21
+ def customized_output_file_name
22
+ @_customized_output_file_name ||= eval('"' + @_output_file_name + '"') # rubocop:disable Lint/Eval
23
+ end
24
+
25
+ def template_asset_path
26
+ @_template_asset_path
27
+ end
28
+
29
+ def _build_from_configuration
30
+ @_template_asset_path = @_configuration.template_asset_path
31
+ @_output_file_name = @_configuration.output_file_name # does this fit here?
32
+ @_default_file_name = @_configuration.default_file_name # does this fit here?
33
+ end
34
+ end
35
+ end
36
+ end
@@ -1,29 +1,8 @@
1
- require 'redcloth'
1
+ require 'indoctrinatr/tools/content_for_tex_files'
2
2
 
3
3
  module Indoctrinatr
4
4
  module Tools
5
- class DefaultValues
6
- def initialize configuration
7
- @_configuration = configuration
8
- _build_from_configuration
9
- end
10
-
11
- def textile2latex textile
12
- RedCloth.new(textile).to_latex
13
- end
14
-
15
- def retrieve_binding
16
- binding
17
- end
18
-
19
- def customized_output_file_name
20
- @_customized_output_file_name ||= eval('"' + @_output_file_name + '"') # rubocop:disable Lint/Eval
21
- end
22
-
23
- def template_asset_path
24
- @_template_asset_path
25
- end
26
-
5
+ class DefaultValues < ContentForTexFiles
27
6
  def output_file_name
28
7
  @_output_file_name
29
8
  end
@@ -32,11 +11,7 @@ module Indoctrinatr
32
11
  @_default_file_name
33
12
  end
34
13
 
35
- def _build_from_configuration # rubocop:disable Metrics/AbcSize
36
- @_template_asset_path = @_configuration.template_asset_path
37
- @_output_file_name = @_configuration.output_file_name
38
- @_default_file_name = @_configuration.default_file_name
39
-
14
+ def _use_default_values # rubocop:disable Metrics/AbcSize
40
15
  @_configuration.attributes_as_hashes_in_array.each do |attribute_hash|
41
16
  instance_variable_set("@_#{attribute_hash['name']}", attribute_hash['default_value'])
42
17
 
@@ -0,0 +1,57 @@
1
+ require 'indoctrinatr/tools/content_for_tex_files'
2
+
3
+ module Indoctrinatr
4
+ module Tools
5
+ # This class defines the content for a document that has the field names as content.
6
+ class FieldNameValues < ContentForTexFiles
7
+ # TODO: extensive list of possibilities
8
+ PICTURE_FILE_ENDINGS = %w(.png .jpeg .jpg .bmp .gif .pdf).freeze
9
+ def _field_names_as_values # rubocop:disable Metrics/AbcSize
10
+ @_configuration.attributes_as_hashes_in_array.each do |attribute_hash|
11
+ # Usage of \textless to avoid issues with the < > characters.
12
+ # Usage of * character because it does not produce any issues when it's used in arguments of LaTeX commands.
13
+ # Initially the intention was to use texttt, but that had this problem.
14
+ instance_variable_set("@_#{attribute_hash['name']}",
15
+ "\\textless***#{attribute_hash['name'].to_latex}***\\textgreater")
16
+
17
+ define_singleton_method "raw_#{attribute_hash['name']}".to_sym do
18
+ "raw\\_#{instance_variable_get("@_#{attribute_hash['name']}")}"
19
+ end
20
+
21
+ define_singleton_method attribute_hash['name'].to_sym do
22
+ # No usage of to_latex because we escaped variable name already and want no escaping for the other stuff
23
+ instance_variable_get("@_#{attribute_hash['name']}")
24
+ end
25
+ end
26
+ # This overwrites the instance attributes and methods again
27
+ overwrite_picture_file_names_output @_configuration.attributes_as_hashes_in_array
28
+ end
29
+
30
+ # The LaTeX compilation would fail if the \includegraphics tries to include a file that does not exist.
31
+ # 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 attributes_as_hashes # rubocop:disable Metrics/AbcSize
33
+ attributes_as_hashes.each do |attribute_hash|
34
+ # search for typical picture file endings
35
+ next unless detect_picture_file_names attribute_hash['default_value']
36
+ instance_variable_set("@_#{attribute_hash['name']}", attribute_hash['default_value'])
37
+
38
+ define_singleton_method "raw_#{attribute_hash['name']}".to_sym do
39
+ "raw\\_#{instance_variable_get("@_#{attribute_hash['name']}")}"
40
+ end
41
+
42
+ define_singleton_method attribute_hash['name'].to_sym do
43
+ instance_variable_get("@_#{attribute_hash['name']}").to_latex
44
+ end
45
+ end
46
+ end
47
+
48
+ # Indoctrinatr has no picture data type. This means that the only way to check for pictures is to check for
49
+ # file endings. If an user has obscure file type the possibility list would have to get updated.
50
+ def detect_picture_file_names string_to_check
51
+ PICTURE_FILE_ENDINGS.any? do |picture_file_ending|
52
+ string_to_check.downcase.include? picture_file_ending # http://stackoverflow.com/a/3686568
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,36 @@
1
+ # Unify the command usage for all pdf creation features
2
+ module Indoctrinatr
3
+ module Tools
4
+ module PdfGenerator
5
+ # Compiles a PDF from a tex file with XeLaTeX
6
+ # @param tex_file a Pathname that points to the tex file
7
+ # @return false if error, nil if system command unknown
8
+ def make_pdf tex_file, output_dir = nil, cleanup = true
9
+ args = ['-xelatex',
10
+ '-shell-escape',
11
+ '-interaction=batchmode', # more silent output
12
+ "-output-directory=#{output_dir}", # without this xelatex tries to use the current working directory
13
+ tex_file.to_s]
14
+ if output_dir.nil?
15
+ args.delete_at 3 # Remove argument if no output dir is wished for. This probably could be done better.
16
+ end
17
+ latexmk_successful = system('latexmk', *args) # latexmk instead of running 2.times
18
+ latex_cleanup output_dir if latexmk_successful == true && cleanup
19
+ latexmk_successful
20
+ end
21
+
22
+ # Cleans up LaTeX helper files in a specific directory
23
+ # @param working_directory a Pathname that points the directory that should get cleaned up
24
+ # @return false if error, nil if system command unknown
25
+ def latex_cleanup working_directory
26
+ # latexmk -c apparently cannot cleanup a specified subdirectory. So we have to change the working directory,
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
+ current_dir = Dir.getwd
29
+ Dir.chdir working_directory.to_s if working_directory
30
+ latexmk_successful = system 'latexmk -c'
31
+ Dir.chdir current_dir # should be the same as ../../.. # Dir.chdir '../../..'
32
+ latexmk_successful
33
+ end
34
+ end
35
+ end
36
+ end
@@ -1,3 +1,4 @@
1
+ require 'indoctrinatr/tools/content_for_tex_files'
1
2
  require 'indoctrinatr/tools/template_pack_configuration'
2
3
  require 'indoctrinatr/tools/directory_helpers'
3
4
  require 'indoctrinatr/tools/template_documentation_source_file'
@@ -5,12 +6,14 @@ require 'indoctrinatr/tools/default_values'
5
6
 
6
7
  module Indoctrinatr
7
8
  module Tools
8
- class TemplateDocumentationContent
9
+ class TemplateDocumentationContent < ContentForTexFiles
9
10
  include DirectoryHelpers
10
11
  include TemplatePackHelpers
11
12
 
12
13
  attr_accessor :template_pack_name, :list_of_files
13
14
 
15
+ # Overwrite the initialize method because the content is built up much more complex than for the other
16
+ # ContentForTexFile children.
14
17
  def initialize template_pack_name, configuration
15
18
  @configuration = configuration
16
19
  @template_pack_name = template_pack_name
@@ -18,33 +21,40 @@ module Indoctrinatr
18
21
  @attributes = configuration.attributes_as_hashes_in_array # we need: name, presentation, default_value, description
19
22
  @template_name = configuration.template_name
20
23
  @files = read_template_files_content
21
- @default_values_pdf_path = pdf_with_default_values_file_path
22
- # should have been generated automatically, error if something went wrong with it:
23
- fail IOError, "template with default values does not exist in current directory. Run indoctrinatr pdf #{template_pack_name}" unless File.exist? @default_values_pdf_path
24
- end
25
-
26
- def retrieve_binding
27
- binding
24
+ @default_values_pdf_path = default_values_example
25
+ @pdf_with_field_names_path = fieldname_values_example
28
26
  end
29
27
 
30
28
  private
31
29
 
32
30
  def read_template_files_content
33
31
  filenames = list_files_of_type template_pack_name
32
+ filenames.reject! { |f| f.include?(pack_documentation_examples_dir_path.relative_path_from(Pathname.new(Dir.pwd)).to_s) }
34
33
  filenames.inject [] do |files, filename|
35
34
  files.push TemplateDocumentationSourceFile.new filename
36
35
  end
37
36
  end
38
37
 
39
- def pdf_with_default_values_file_path
40
- # TODO: this would make more sense in one of the Helpers modules, but we don't want to create a new dependency there. Move this when file path shenanigans are generally revised.
41
- # get file path for template with default values:
42
- default_values = DefaultValues.new @configuration
43
- # if there is a change in where the pdf command (compiler class) saves it's output, this logic needs to be updated
44
- if default_values.customized_output_file_name == default_values.default_file_name
45
- Pathname.new(Dir.pwd).join default_values.customized_output_file_name
38
+ def default_values_example
39
+ default_values_compiler = TemplatePackDefaultValuesCompiler.new(template_pack_name)
40
+ unless default_values_compiler.pdf_exists?
41
+ TemplatePackDefaultValuesParser.new(template_pack_name).call
42
+ default_values_compiler.call
43
+ end
44
+ pdf_with_default_values_file_path @configuration
45
+ end
46
+
47
+ def fieldname_values_example
48
+ fieldnames_creator = TemplatePackFieldnamesCreator.new(template_pack_name)
49
+ # This gives user the option to customize the FieldNameValues Example that is appended in the documentation
50
+ return pdf_with_fieldname_values_file_path if fieldnames_creator.pdf_exists?
51
+
52
+ if fieldnames_creator.call
53
+ puts 'INFO: Example with field names has been automatically generated for the documentation' # More user information and for testing
54
+ pdf_with_fieldname_values_file_path
46
55
  else
47
- Pathname.new(Dir.pwd).join default_values.output_file_name
56
+ puts 'ERROR: Example with field names could not be created and is not included in documentation'
57
+ nil
48
58
  end
49
59
  end
50
60
  end
@@ -17,6 +17,10 @@ module Indoctrinatr
17
17
  documentation_files_path.join 'indoctrinatr-technical-documentation.sty'
18
18
  end
19
19
 
20
+ def source_image_tools_package_file_path
21
+ documentation_files_path.join 'dkd-image-tools.sty'
22
+ end
23
+
20
24
  def source_letterpaper_file_path
21
25
  documentation_files_path.join 'indoctrinatr_letterpaper.pdf'
22
26
  end
@@ -29,6 +33,10 @@ module Indoctrinatr
29
33
  documentation_compile_dir_path_name.join 'indoctrinatr-technical-documentation.sty'
30
34
  end
31
35
 
36
+ def image_tools_package_destination_path
37
+ documentation_compile_dir_path_name.join 'dkd-image-tools.sty'
38
+ end
39
+
32
40
  def letterpaper_file_destination_path
33
41
  documentation_compile_dir_path_name.join 'indoctrinatr_letterpaper.pdf'
34
42
  end
@@ -49,6 +57,11 @@ module Indoctrinatr
49
57
  documentation_compile_dir_path_name.join 'indoctrinatr-technical-documentation.log'
50
58
  end
51
59
 
60
+ # Accessor method to the attribute for classes that include this module
61
+ def documentation_temp_dir
62
+ documentation_compile_dir_path_name
63
+ end
64
+
52
65
  private
53
66
 
54
67
  def documentation_files_path
@@ -12,18 +12,18 @@ module Indoctrinatr
12
12
  private
13
13
 
14
14
  def set_programming_language
15
- case File.extname(@name)
16
- when '.tex'
17
- language = 'TeX'
18
- when '.sty'
19
- language = 'TeX'
20
- when '.erb' # .erb files are just supposed to be tex.erb files. TODO: more correct
21
- language = 'TeX'
22
- when '.rb'
23
- language = 'Ruby'
24
- else # probably YAML
25
- language = 'unspecified'
26
- end
15
+ language = case File.extname(@name)
16
+ when '.tex'
17
+ 'TeX'
18
+ when '.sty'
19
+ 'TeX'
20
+ when '.erb' # .erb files are just supposed to be tex.erb files. TODO: more correct
21
+ 'TeX'
22
+ when '.rb'
23
+ 'Ruby'
24
+ else # probably YAML
25
+ 'unspecified'
26
+ end
27
27
  language
28
28
  end
29
29
  end
@@ -1,6 +1,6 @@
1
1
  module Indoctrinatr
2
2
  module Tools
3
- class TemplatePackConfiguration
3
+ class TemplatePackConfiguration # wrapper class for config. See ConfigurationExtractor for details
4
4
  attr_accessor :template_asset_path, :default_file_name, :template_name, :textual_description, :output_file_name, :attributes_as_hashes_in_array
5
5
  end
6
6
  end
@@ -1,15 +1,18 @@
1
1
  require 'indoctrinatr/tools/configuration_extractor'
2
+ require 'indoctrinatr/tools/pdf_generator'
2
3
  require 'fileutils'
3
4
 
4
5
  module Indoctrinatr
5
6
  module Tools
6
7
  class TemplatePackDefaultValuesCompiler
7
8
  include TemplatePackHelpers
9
+ include PdfGenerator
8
10
 
9
11
  attr_accessor :template_pack_name
10
12
 
11
- def initialize template_pack_name
13
+ def initialize template_pack_name, keep_aux_files = false
12
14
  @template_pack_name = template_pack_name
15
+ @keep_aux_files = keep_aux_files
13
16
  end
14
17
 
15
18
  def call
@@ -18,15 +21,20 @@ module Indoctrinatr
18
21
  rename_if_necessary
19
22
  end
20
23
 
24
+ def pdf_exists?
25
+ check_for_folder
26
+ file_path = pdf_with_default_values_file_path ConfigurationExtractor.new(template_pack_name).call
27
+ File.exist? file_path
28
+ end
29
+
21
30
  private
22
31
 
23
32
  def compile_tex_file
24
- args = ['-shell-escape', '-interaction', 'batchmode', tex_with_default_values_file_path.to_s]
25
- 2.times { system('xelatex', *args) } # run two times for proper table-of-contents and page count handling. TODO: use latexmk
33
+ make_pdf tex_with_default_values_file_path, pack_documentation_examples_dir_path, !@keep_aux_files
26
34
  end
27
35
 
28
36
  def rename_if_necessary
29
- configuration = ConfigurationExtractor.new(template_pack_name).call
37
+ configuration = ConfigurationExtractor.new(template_pack_name).call # TODO: avoid repeated calling of the ConfigurationExtrator
30
38
  @default_values = DefaultValues.new configuration
31
39
  return if @default_values.customized_output_file_name == @default_values.default_file_name
32
40