indoctrinatr-tools 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. checksums.yaml +7 -0
  2. data/.arcconfig +9 -0
  3. data/.coveralls.yml +1 -0
  4. data/.gitignore +54 -0
  5. data/.rubocop.yml +10 -0
  6. data/.rvmrc +5 -0
  7. data/.travis.yml +19 -0
  8. data/Gemfile +4 -0
  9. data/LICENSE +21 -0
  10. data/README.md +74 -0
  11. data/Rakefile +32 -0
  12. data/assets/images/dkd_logo.png +0 -0
  13. data/assets/images/logo.png +0 -0
  14. data/bin/indoctrinatr +146 -0
  15. data/cucumber.yml +1 -0
  16. data/features/autocompletion_support.feature +9 -0
  17. data/features/demo.feature +17 -0
  18. data/features/documentation.feature +11 -0
  19. data/features/pack.feature +11 -0
  20. data/features/parse.feature +6 -0
  21. data/features/pdf.feature +10 -0
  22. data/features/scaffold.feature +23 -0
  23. data/features/step_definitions/common.rb +3 -0
  24. data/features/step_definitions/indoctrinatr_cli.rb +11 -0
  25. data/features/support/env.rb +1 -0
  26. data/features/version.feature +5 -0
  27. data/features/workflow.feature +8 -0
  28. data/indoctrinatr-tools.gemspec +39 -0
  29. data/lib/indoctrinatr/templates/configuration.yaml +17 -0
  30. data/lib/indoctrinatr/templates/documentation/indoctrinatr-technical-documentation-content.tex.erb +36 -0
  31. data/lib/indoctrinatr/templates/documentation/indoctrinatr-technical-documentation.sty +195 -0
  32. data/lib/indoctrinatr/templates/documentation/indoctrinatr-technical-documentation.tex.erb +89 -0
  33. data/lib/indoctrinatr/templates/documentation/indoctrinatr_letterpaper.pdf +0 -0
  34. data/lib/indoctrinatr/templates/template.tex.erb +8 -0
  35. data/lib/indoctrinatr/tools.rb +9 -0
  36. data/lib/indoctrinatr/tools/configuration_extractor.rb +27 -0
  37. data/lib/indoctrinatr/tools/default_values.rb +54 -0
  38. data/lib/indoctrinatr/tools/directory_helpers.rb +18 -0
  39. data/lib/indoctrinatr/tools/template_documentation_content.rb +52 -0
  40. data/lib/indoctrinatr/tools/template_documentation_helpers.rb +59 -0
  41. data/lib/indoctrinatr/tools/template_documentation_source_file.rb +31 -0
  42. data/lib/indoctrinatr/tools/template_pack_configuration.rb +7 -0
  43. data/lib/indoctrinatr/tools/template_pack_default_values_compiler.rb +38 -0
  44. data/lib/indoctrinatr/tools/template_pack_default_values_parser.rb +51 -0
  45. data/lib/indoctrinatr/tools/template_pack_demo.rb +23 -0
  46. data/lib/indoctrinatr/tools/template_pack_documentation.rb +111 -0
  47. data/lib/indoctrinatr/tools/template_pack_helpers.rb +38 -0
  48. data/lib/indoctrinatr/tools/template_pack_packer.rb +49 -0
  49. data/lib/indoctrinatr/tools/template_pack_scaffold.rb +57 -0
  50. data/lib/indoctrinatr/tools/version.rb +5 -0
  51. data/lib/redcloth_latex_formatter_patch/patch.rb +35 -0
  52. data/spec/indoctrinatr/templates/configuration_file_spec.rb +9 -0
  53. data/spec/indoctrinatr/templates/tex_file_spec.rb +9 -0
  54. data/spec/indoctrinatr/tools/textile_support_spec.rb +18 -0
  55. data/spec/indoctrinatr/tools/version_spec.rb +8 -0
  56. data/spec/redcloth_latex_formatter_patch/patch_spec.rb +30 -0
  57. data/spec/spec_helper.rb +2 -0
  58. metadata +304 -0
@@ -0,0 +1,8 @@
1
+ % This is the official Indoctrinatr "Hello World Template".
2
+ \documentclass{article}
3
+
4
+ \begin{document}
5
+ \section{Hello <%= variable1 -%>}
6
+
7
+ The <%= variable1 -%> is <%= variable2 -%>!
8
+ \end{document}
@@ -0,0 +1,9 @@
1
+ require 'indoctrinatr/tools/version'
2
+ require 'redcloth_latex_formatter_patch/patch'
3
+
4
+ begin
5
+ require 'pry'
6
+ rescue LoadError => e
7
+ puts e.message
8
+ # I think we can live without pry
9
+ end
@@ -0,0 +1,27 @@
1
+ require 'indoctrinatr/tools/template_pack_configuration'
2
+
3
+ module Indoctrinatr
4
+ module Tools
5
+ class ConfigurationExtractor
6
+ include TemplatePackHelpers
7
+
8
+ attr_reader :template_pack_name
9
+
10
+ def initialize template_pack_name
11
+ @template_pack_name = template_pack_name
12
+ end
13
+
14
+ def call # rubocop:disable Metrics/AbcSize
15
+ config_file = YAML.load_file config_file_path
16
+ configuration = TemplatePackConfiguration.new
17
+ configuration.template_asset_path = assets_path.to_s
18
+ configuration.default_file_name = "#{template_pack_name}_with_default_values.pdf"
19
+ configuration.output_file_name = config_file.fetch('output_file_name', "#{template_pack_name}_with_default_values.pdf")
20
+ configuration.template_name = config_file.fetch 'template_name'
21
+ configuration.textual_description = config_file.fetch 'textual_description'
22
+ configuration.attributes_as_hashes_in_array = config_file.fetch 'fields', []
23
+ configuration
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,54 @@
1
+ require 'redcloth'
2
+
3
+ module Indoctrinatr
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
+
27
+ def output_file_name
28
+ @_output_file_name
29
+ end
30
+
31
+ def default_file_name
32
+ @_default_file_name
33
+ end
34
+
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
+
40
+ @_configuration.attributes_as_hashes_in_array.each do |attribute_hash|
41
+ instance_variable_set("@_#{attribute_hash['name']}", attribute_hash['default_value'])
42
+
43
+ define_singleton_method "raw_#{attribute_hash['name']}".to_sym do
44
+ instance_variable_get("@_#{attribute_hash['name']}")
45
+ end
46
+
47
+ define_singleton_method attribute_hash['name'].to_sym do
48
+ instance_variable_get("@_#{attribute_hash['name']}").to_latex
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,18 @@
1
+ module Indoctrinatr
2
+ module Tools
3
+ module DirectoryHelpers
4
+ def print_dirtree_style directory = '.'
5
+ Dir.glob("#{directory}/**/*").inject [] do |entries, entry| # list entries recursively
6
+ nesting = entry.count(File::SEPARATOR) + 1 # nesting starts with 2, because for \dirtree 1 is root
7
+ name = entry.split(File::SEPARATOR).last
8
+ entries.push ".#{nesting} #{name}. " # formatting for \dirtree: .<level><space><text-node>.<space>
9
+ end
10
+ end
11
+
12
+ def list_files_of_type directory = '.', types = %w(erb rb yaml sty tex) # default file types for template docs
13
+ # found and modified from http://stackoverflow.com/a/3504307/1796645
14
+ Dir.glob("#{directory}/**/*.{#{types.join(',')}}") # recursively list files of type in types array
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,52 @@
1
+ require 'indoctrinatr/tools/template_pack_configuration'
2
+ require 'indoctrinatr/tools/directory_helpers'
3
+ require 'indoctrinatr/tools/template_documentation_source_file'
4
+ require 'indoctrinatr/tools/default_values'
5
+
6
+ module Indoctrinatr
7
+ module Tools
8
+ class TemplateDocumentationContent
9
+ include DirectoryHelpers
10
+ include TemplatePackHelpers
11
+
12
+ attr_accessor :template_pack_name, :list_of_files
13
+
14
+ def initialize template_pack_name, configuration
15
+ @configuration = configuration
16
+ @template_pack_name = template_pack_name
17
+ @list_of_files = print_dirtree_style @template_pack_name
18
+ @attributes = configuration.attributes_as_hashes_in_array # we need: name, presentation, default_value, description
19
+ @template_name = configuration.template_name
20
+ @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
28
+ end
29
+
30
+ private
31
+
32
+ def read_template_files_content
33
+ filenames = list_files_of_type template_pack_name
34
+ filenames.inject [] do |files, filename|
35
+ files.push TemplateDocumentationSourceFile.new filename
36
+ end
37
+ end
38
+
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
46
+ else
47
+ Pathname.new(Dir.pwd).join default_values.output_file_name
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,59 @@
1
+ require 'tmpdir'
2
+
3
+ module Indoctrinatr
4
+ module Tools
5
+ module TemplateDocumentationHelpers
6
+ attr_accessor :documentation_compile_dir_path_name
7
+
8
+ def make_documentation_compile_dir_path_name
9
+ @documentation_compile_dir_path_name = Pathname.new Dir.mktmpdir 'indoctrinatr_tools_tmp'
10
+ end
11
+
12
+ def content_tex_file_path
13
+ documentation_files_path.join 'indoctrinatr-technical-documentation-content.tex.erb'
14
+ end
15
+
16
+ def source_latex_package_file_path
17
+ documentation_files_path.join 'indoctrinatr-technical-documentation.sty'
18
+ end
19
+
20
+ def source_letterpaper_file_path
21
+ documentation_files_path.join 'indoctrinatr_letterpaper.pdf'
22
+ end
23
+
24
+ def source_main_tex_file_path
25
+ documentation_files_path.join 'indoctrinatr-technical-documentation.tex.erb'
26
+ end
27
+
28
+ def latex_package_destination_path
29
+ documentation_compile_dir_path_name.join 'indoctrinatr-technical-documentation.sty'
30
+ end
31
+
32
+ def letterpaper_file_destination_path
33
+ documentation_compile_dir_path_name.join 'indoctrinatr_letterpaper.pdf'
34
+ end
35
+
36
+ def content_tex_file_destination_path
37
+ documentation_compile_dir_path_name.join 'indoctrinatr-technical-documentation-content.tex'
38
+ end
39
+
40
+ def main_tex_file_destination_path
41
+ documentation_compile_dir_path_name.join 'indoctrinatr-technical-documentation.tex'
42
+ end
43
+
44
+ def documentation_file_path
45
+ documentation_compile_dir_path_name.join 'indoctrinatr-technical-documentation.pdf'
46
+ end
47
+
48
+ def latex_log_file
49
+ documentation_compile_dir_path_name.join 'indoctrinatr-technical-documentation.log'
50
+ end
51
+
52
+ private
53
+
54
+ def documentation_files_path
55
+ Pathname.new(File.expand_path(File.dirname(__FILE__))).join('..', 'templates', 'documentation')
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,31 @@
1
+ module Indoctrinatr
2
+ module Tools
3
+ class TemplateDocumentationSourceFile
4
+ attr_reader :name, :content, :language
5
+
6
+ def initialize filename
7
+ @name = filename
8
+ @content = File.read filename
9
+ @language = set_programming_language
10
+ end
11
+
12
+ private
13
+
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
27
+ language
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,7 @@
1
+ module Indoctrinatr
2
+ module Tools
3
+ class TemplatePackConfiguration
4
+ attr_accessor :template_asset_path, :default_file_name, :template_name, :textual_description, :output_file_name, :attributes_as_hashes_in_array
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,38 @@
1
+ require 'indoctrinatr/tools/configuration_extractor'
2
+ require 'fileutils'
3
+
4
+ module Indoctrinatr
5
+ module Tools
6
+ class TemplatePackDefaultValuesCompiler
7
+ include TemplatePackHelpers
8
+
9
+ attr_accessor :template_pack_name
10
+
11
+ def initialize template_pack_name
12
+ @template_pack_name = template_pack_name
13
+ end
14
+
15
+ def call
16
+ check_for_folder
17
+ compile_tex_file
18
+ rename_if_necessary
19
+ end
20
+
21
+ private
22
+
23
+ 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
26
+ end
27
+
28
+ def rename_if_necessary
29
+ configuration = ConfigurationExtractor.new(template_pack_name).call
30
+ @default_values = DefaultValues.new configuration
31
+ return if @default_values.customized_output_file_name == @default_values.default_file_name
32
+
33
+ FileUtils.rm @default_values.customized_output_file_name if File.exist? @default_values.customized_output_file_name
34
+ FileUtils.mv(@default_values.default_file_name, @default_values.customized_output_file_name)
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,51 @@
1
+ require 'indoctrinatr/tools/template_pack_helpers'
2
+ require 'indoctrinatr/tools/default_values'
3
+ require 'indoctrinatr/tools/configuration_extractor'
4
+ require 'erubis'
5
+ require 'to_latex'
6
+
7
+ module Indoctrinatr
8
+ module Tools
9
+ class TemplatePackDefaultValuesParser
10
+ include TemplatePackHelpers
11
+
12
+ attr_accessor :template_pack_name, :configuration, :default_values, :tex_file_content, :parsed_tex_file_content
13
+
14
+ def initialize template_pack_name
15
+ @template_pack_name = template_pack_name
16
+ end
17
+
18
+ def call
19
+ check_for_folder
20
+ read_config_file
21
+ read_tex_file
22
+ parse_tex_file
23
+ write_tex_file
24
+ show_success
25
+ end
26
+
27
+ private
28
+
29
+ def read_config_file
30
+ @configuration = ConfigurationExtractor.new(template_pack_name).call
31
+ @default_values = DefaultValues.new @configuration
32
+ end
33
+
34
+ def read_tex_file
35
+ @tex_file_content = File.read tex_file_path
36
+ end
37
+
38
+ def parse_tex_file
39
+ @parsed_tex_file_content = Erubis::Eruby.new(@tex_file_content).result(default_values.retrieve_binding)
40
+ end
41
+
42
+ def write_tex_file
43
+ File.write tex_with_default_values_file_path, parsed_tex_file_content
44
+ end
45
+
46
+ def show_success
47
+ puts "The template pack '#{template_pack_name}' has been successfully parsed with default values."
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,23 @@
1
+ require 'indoctrinatr/tools/template_pack_helpers'
2
+
3
+ module Indoctrinatr
4
+ module Tools
5
+ class TemplatePackDemo
6
+ include TemplatePackHelpers
7
+
8
+ attr_accessor :template_pack_name
9
+
10
+ def initialize template_pack_name
11
+ @template_pack_name = template_pack_name
12
+ end
13
+
14
+ def call
15
+ TemplatePackScaffold.new(template_pack_name).call
16
+ TemplatePackDefaultValuesParser.new(template_pack_name).call
17
+ TemplatePackDefaultValuesCompiler.new(template_pack_name).call
18
+ TemplatePackDocumentation.new(template_pack_name).call
19
+ TemplatePackPacker.new(template_pack_name).call
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,111 @@
1
+ require 'indoctrinatr/tools/template_documentation_content'
2
+ require 'indoctrinatr/tools/template_pack_helpers'
3
+ require 'indoctrinatr/tools/template_documentation_helpers'
4
+ require 'indoctrinatr/tools/configuration_extractor'
5
+ require 'erubis'
6
+ require 'to_latex'
7
+ require 'fileutils'
8
+
9
+ module Indoctrinatr
10
+ module Tools
11
+ class TemplatePackDocumentation
12
+ include TemplatePackHelpers
13
+ include TemplateDocumentationHelpers
14
+
15
+ attr_accessor :template_pack_name
16
+
17
+ def initialize template_pack_name
18
+ @template_pack_name = template_pack_name
19
+ end
20
+
21
+ def call
22
+ fill_documentation_content
23
+ read_content_tex_file
24
+ read_main_tex_file
25
+ parse_content_tex_file
26
+ parse_main_tex_file
27
+ create_temp_compile_dir
28
+ write_content_tex_file
29
+ write_main_tex_file
30
+ copy_source_files
31
+ if compile_documentation_to_pdf
32
+ copy_doc_file_to_template_pack
33
+ delete_temp_dir
34
+ show_success
35
+ else
36
+ handle_latex_error
37
+ end
38
+ end
39
+
40
+ private
41
+
42
+ def fill_documentation_content
43
+ configuration = ConfigurationExtractor.new(template_pack_name).call
44
+ begin
45
+ @documentation_content = TemplateDocumentationContent.new template_pack_name, configuration
46
+ rescue IOError => ex
47
+ abort ex.message
48
+ end
49
+ end
50
+
51
+ def read_content_tex_file
52
+ @content_tex_file_content = File.read content_tex_file_path
53
+ end
54
+
55
+ def read_main_tex_file
56
+ @main_tex_file_content = File.read source_main_tex_file_path
57
+ end
58
+
59
+ def parse_content_tex_file
60
+ @parsed_content_tex_file_content = Erubis::Eruby.new(@content_tex_file_content).result(@documentation_content.retrieve_binding)
61
+ end
62
+
63
+ def parse_main_tex_file
64
+ @parsed_main_tex_file_content = Erubis::Eruby.new(@main_tex_file_content).result(@documentation_content.retrieve_binding)
65
+ end
66
+
67
+ def create_temp_compile_dir
68
+ make_documentation_compile_dir_path_name
69
+ end
70
+
71
+ def write_content_tex_file
72
+ File.write content_tex_file_destination_path, @parsed_content_tex_file_content
73
+ end
74
+
75
+ def write_main_tex_file
76
+ File.write main_tex_file_destination_path, @parsed_main_tex_file_content
77
+ end
78
+
79
+ def copy_source_files
80
+ FileUtils.copy_file source_latex_package_file_path, latex_package_destination_path
81
+ FileUtils.copy_file source_letterpaper_file_path, letterpaper_file_destination_path
82
+ end
83
+
84
+ def compile_documentation_to_pdf
85
+ args = ['-xelatex',
86
+ '-shell-escape',
87
+ '-interaction=batchmode', # more silent output
88
+ "-output-directory=#{documentation_compile_dir_path_name}", main_tex_file_destination_path.to_s] # without this xelatex tries to use the current working directory
89
+ latexmk_successful = system('latexmk', *args) # latexmk instead of running 2.times
90
+ latexmk_successful # false if error, nil if system command unknown
91
+ end
92
+
93
+ def copy_doc_file_to_template_pack
94
+ FileUtils.copy_file documentation_file_path, pack_technical_documentation_file_path
95
+ end
96
+
97
+ def delete_temp_dir
98
+ FileUtils.remove_entry_secure documentation_compile_dir_path_name
99
+ end
100
+
101
+ def handle_latex_error
102
+ puts "possible LaTeX compilation failure! see #{latex_log_file_destination} for details. " # idea: process $CHILD_STATUS
103
+ FileUtils.copy_file latex_log_file, latex_log_file_destination
104
+ end
105
+
106
+ def show_success
107
+ puts "A documentation for '#{template_pack_name}' has been successfully generated."
108
+ end
109
+ end
110
+ end
111
+ end