bookwatch 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (126) hide show
  1. checksums.yaml +7 -0
  2. data/bookwatch.gemspec +40 -0
  3. data/install_bin/bookwatch +5 -0
  4. data/lib/bookwatch/cli.rb +109 -0
  5. data/lib/bookwatch/code_example_reader.rb +95 -0
  6. data/lib/bookwatch/colorizer.rb +16 -0
  7. data/lib/bookwatch/commands/bind.rb +119 -0
  8. data/lib/bookwatch/commands/collection.rb +181 -0
  9. data/lib/bookwatch/commands/components/bind/directory_preparer.rb +33 -0
  10. data/lib/bookwatch/commands/components/bind/layout_preparer.rb +27 -0
  11. data/lib/bookwatch/commands/components/command_options.rb +45 -0
  12. data/lib/bookwatch/commands/components/imprint/directory_preparer.rb +24 -0
  13. data/lib/bookwatch/commands/generate.rb +92 -0
  14. data/lib/bookwatch/commands/imprint.rb +55 -0
  15. data/lib/bookwatch/commands/punch.rb +33 -0
  16. data/lib/bookwatch/commands/update_local_doc_repos.rb +42 -0
  17. data/lib/bookwatch/commands/watch.rb +100 -0
  18. data/lib/bookwatch/config/checkers/archive_menu_checker.rb +29 -0
  19. data/lib/bookwatch/config/checkers/ditamap_presence_checker.rb +27 -0
  20. data/lib/bookwatch/config/checkers/duplicate_section_name_checker.rb +33 -0
  21. data/lib/bookwatch/config/checkers/products_checker.rb +34 -0
  22. data/lib/bookwatch/config/checkers/repository_name_presence_checker.rb +34 -0
  23. data/lib/bookwatch/config/checkers/required_keys_checker.rb +18 -0
  24. data/lib/bookwatch/config/checkers/section_presence_checker.rb +15 -0
  25. data/lib/bookwatch/config/configuration.rb +119 -0
  26. data/lib/bookwatch/config/configuration_decorator.rb +54 -0
  27. data/lib/bookwatch/config/dita_config_generator.rb +61 -0
  28. data/lib/bookwatch/config/fetcher.rb +64 -0
  29. data/lib/bookwatch/config/imprint/configuration.rb +24 -0
  30. data/lib/bookwatch/config/product_config.rb +34 -0
  31. data/lib/bookwatch/config/section_config.rb +85 -0
  32. data/lib/bookwatch/config/validator.rb +33 -0
  33. data/lib/bookwatch/config/yaml_loader.rb +34 -0
  34. data/lib/bookwatch/css_link_checker.rb +67 -0
  35. data/lib/bookwatch/directory_helpers.rb +15 -0
  36. data/lib/bookwatch/dita_command_creator.rb +95 -0
  37. data/lib/bookwatch/dita_html_for_middleman_formatter.rb +45 -0
  38. data/lib/bookwatch/errors/programmer_mistake.rb +5 -0
  39. data/lib/bookwatch/html_document_manipulator.rb +21 -0
  40. data/lib/bookwatch/ingest/cloner_factory.rb +26 -0
  41. data/lib/bookwatch/ingest/destination_directory.rb +21 -0
  42. data/lib/bookwatch/ingest/git_accessor.rb +102 -0
  43. data/lib/bookwatch/ingest/git_cloner.rb +36 -0
  44. data/lib/bookwatch/ingest/local_filesystem_cloner.rb +66 -0
  45. data/lib/bookwatch/ingest/missing_working_copy.rb +27 -0
  46. data/lib/bookwatch/ingest/repo_identifier.rb +45 -0
  47. data/lib/bookwatch/ingest/section_repository.rb +49 -0
  48. data/lib/bookwatch/ingest/update_failure.rb +15 -0
  49. data/lib/bookwatch/ingest/update_success.rb +12 -0
  50. data/lib/bookwatch/ingest/working_copy.rb +36 -0
  51. data/lib/bookwatch/local_filesystem_accessor.rb +122 -0
  52. data/lib/bookwatch/middleman_runner.rb +48 -0
  53. data/lib/bookwatch/postprocessing/link_checker.rb +125 -0
  54. data/lib/bookwatch/postprocessing/redirection.rb +38 -0
  55. data/lib/bookwatch/preprocessing/dita_html_preprocessor.rb +91 -0
  56. data/lib/bookwatch/preprocessing/dita_pdf_preprocessor.rb +48 -0
  57. data/lib/bookwatch/preprocessing/link_to_site_gen_dir.rb +39 -0
  58. data/lib/bookwatch/preprocessing/preprocessor.rb +26 -0
  59. data/lib/bookwatch/server_director.rb +30 -0
  60. data/lib/bookwatch/sheller.rb +52 -0
  61. data/lib/bookwatch/streams/colorized_stream.rb +25 -0
  62. data/lib/bookwatch/streams/filter_stream.rb +22 -0
  63. data/lib/bookwatch/subnav/navigation_entries_from_html_toc.rb +59 -0
  64. data/lib/bookwatch/subnav/navigation_entries_from_markdown_root.rb +116 -0
  65. data/lib/bookwatch/subnav/pdf_config_creator.rb +50 -0
  66. data/lib/bookwatch/subnav/subnav_generator.rb +28 -0
  67. data/lib/bookwatch/subnav/subnav_generator_factory.rb +29 -0
  68. data/lib/bookwatch/subnav/template_creator.rb +71 -0
  69. data/lib/bookwatch/terminal.rb +19 -0
  70. data/lib/bookwatch/values/output_locations.rb +91 -0
  71. data/lib/bookwatch/values/product_info.rb +11 -0
  72. data/lib/bookwatch/values/section.rb +58 -0
  73. data/lib/bookwatch/values/subnav_template.rb +4 -0
  74. data/lib/bookwatch/values/user_message.rb +15 -0
  75. data/master_middleman/archive_drop_down_menu.rb +50 -0
  76. data/master_middleman/bookwatch_helpers.rb +259 -0
  77. data/master_middleman/compass_runner.rb +0 -0
  78. data/master_middleman/config.rb +34 -0
  79. data/master_middleman/quicklinks_renderer.rb +80 -0
  80. data/master_middleman/source/javascripts/all.js +2 -0
  81. data/master_middleman/source/javascripts/book.js +1 -0
  82. data/master_middleman/source/javascripts/bookwatch.js +103 -0
  83. data/master_middleman/source/layouts/_additional-scripts.erb +0 -0
  84. data/master_middleman/source/layouts/_book-footer.erb +0 -0
  85. data/master_middleman/source/layouts/_book-search.erb +0 -0
  86. data/master_middleman/source/layouts/_book-title.erb +3 -0
  87. data/master_middleman/source/layouts/_header.erb +34 -0
  88. data/master_middleman/source/layouts/_local-header.erb +0 -0
  89. data/master_middleman/source/layouts/_page-footer.erb +1 -0
  90. data/master_middleman/source/layouts/_title.erb +5 -0
  91. data/master_middleman/source/layouts/layout.erb +69 -0
  92. data/master_middleman/source/stylesheets/all.css.scss +3 -0
  93. data/master_middleman/source/stylesheets/base.scss +380 -0
  94. data/master_middleman/source/stylesheets/book-styles.css.scss +0 -0
  95. data/master_middleman/source/stylesheets/layout-styles.scss +0 -0
  96. data/master_middleman/source/stylesheets/partials/_book-base-values.scss +0 -0
  97. data/master_middleman/source/stylesheets/partials/_book-vars.scss +0 -0
  98. data/master_middleman/source/stylesheets/partials/_default.scss +300 -0
  99. data/master_middleman/source/stylesheets/partials/_footer.scss +64 -0
  100. data/master_middleman/source/stylesheets/partials/_header.scss +419 -0
  101. data/master_middleman/source/stylesheets/partials/_layout-vars.scss +0 -0
  102. data/master_middleman/source/stylesheets/partials/_mixins.scss +53 -0
  103. data/master_middleman/source/stylesheets/partials/_reset.scss +233 -0
  104. data/master_middleman/source/stylesheets/partials/_search.scss +78 -0
  105. data/master_middleman/source/stylesheets/partials/_sidenav.scss +191 -0
  106. data/master_middleman/source/stylesheets/partials/_syntax-highlight.scss +64 -0
  107. data/master_middleman/source/stylesheets/partials/_vars.scss +64 -0
  108. data/master_middleman/source/stylesheets/print.css.scss +58 -0
  109. data/master_middleman/source/subnavs/_default.erb +0 -0
  110. data/master_middleman/source/subnavs/_nav-links.erb +10 -0
  111. data/master_middleman/source/subnavs/_subnav_template.erb +8 -0
  112. data/master_middleman/subdirectory_aware_assets.rb +47 -0
  113. data/template_app/Gemfile +10 -0
  114. data/template_app/Gemfile.lock +43 -0
  115. data/template_app/config.ru +9 -0
  116. data/template_app/lib/rack_static_if_exists.rb +19 -0
  117. data/template_app/lib/search/handler.rb +47 -0
  118. data/template_app/lib/search/hit.rb +21 -0
  119. data/template_app/lib/search/query.rb +74 -0
  120. data/template_app/lib/search/renderer.rb +29 -0
  121. data/template_app/lib/server.rb +52 -0
  122. data/template_app/mail_sender.rb +69 -0
  123. data/template_app/rack_app.rb +110 -0
  124. data/template_app/search-results.html.erb +75 -0
  125. data/template_app/search.yml +22 -0
  126. metadata +491 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 686b95008877c126bfe9af603a9897343618f85e
4
+ data.tar.gz: eba03326cca45031e7bb2b238efc7a23fdc3135d
5
+ SHA512:
6
+ metadata.gz: abfdc87b7c3ee117b69b51e8800f9140a7574f91677e7459306725af103cd6c9e5fed1517e8b02218ed3d98419cfaef6ae320630621c5d80701500e2895107e2
7
+ data.tar.gz: 9b6c38bee013251cfb7fdb52bb340fef1c4f592f55899b8624507f835749f90b8ebe346145df7c97cef6f572939b952b2366d8dd621e2de052916f3014d34f18
@@ -0,0 +1,40 @@
1
+ require 'base64'
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'bookwatch'
5
+ s.version = '1.0.0'
6
+ s.summary = 'Bookbinder with everything disabled except the watch function'
7
+ s.description = 'A command line utility to be run in Book repositories to stitch together their constituent Markdown repos into a temporary static-HTML-serving application'
8
+ s.authors = ['Mike Grafton', 'Lucas Marks', 'Gavin Morgan', 'Nikhil Gajwani', 'Dan Wendorf', 'Brenda Chan', 'Matthew Boedicker', 'Andrew Bruce', 'Frank Kotsianas', 'Elena Sharma', 'Christa Hartsock', 'Michael Trestman', 'Alpha Chen', 'Sarah McAlear', 'Gregg Van Hove']
9
+ s.email = Base64.decode64('Z21vcmdhbkBnb3Bpdm90YWwuY29t') # Gavin's
10
+ s.files = Dir['lib/**/*'] + Dir['template_app/**/*'] + Dir['master_middleman/**/*'] + Dir['install_bin/bookwatch'] + Dir['bookwatch.gemspec']
11
+ s.homepage = 'https://github.com/pivotal-cf/bookbinder'
12
+ s.license = 'MIT'
13
+ s.bindir = 'install_bin'
14
+ s.executable = 'bookwatch'
15
+
16
+ s.required_ruby_version = '>= 2.0.0'
17
+ s.add_runtime_dependency 'fog-aws', ['~> 0.7.1']
18
+ s.add_runtime_dependency 'ansi', ['~> 1.4']
19
+ s.add_runtime_dependency 'middleman', ['~> 3.4.0']
20
+ s.add_runtime_dependency 'middleman-livereload', ['~> 3.4.3']
21
+ s.add_runtime_dependency 'middleman-syntax', ['~> 2.0']
22
+ s.add_runtime_dependency 'rouge', '!= 1.9.1'
23
+ s.add_runtime_dependency 'redcarpet', ['~> 3.2.3']
24
+ s.add_runtime_dependency 'css_parser'
25
+ s.add_runtime_dependency 'puma'
26
+ s.add_runtime_dependency 'rack-rewrite'
27
+ s.add_runtime_dependency 'therubyracer'
28
+ s.add_runtime_dependency 'git', '~> 1.2.8'
29
+ s.add_runtime_dependency 'nokogiri', ['1.6.7.2']
30
+ s.add_runtime_dependency 'thor'
31
+ s.add_runtime_dependency 'elasticsearch'
32
+ s.add_runtime_dependency 'font-awesome-sass'
33
+
34
+ s.add_development_dependency 'license_finder'
35
+ s.add_development_dependency 'pry-byebug'
36
+ s.add_development_dependency 'rake'
37
+ s.add_development_dependency 'rspec'
38
+ s.add_development_dependency 'sendgrid-ruby', '< 3.0'
39
+ s.add_development_dependency 'jasmine'
40
+ end
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/bookwatch/cli'
4
+
5
+ Bookwatch::CLI.start
@@ -0,0 +1,109 @@
1
+ require 'thor'
2
+
3
+ require_relative 'ingest/git_accessor'
4
+ require_relative 'streams/colorized_stream'
5
+ require_relative 'colorizer'
6
+ require_relative 'commands/collection'
7
+
8
+ module Bookwatch
9
+ class CLI < Thor
10
+ def self.exit_on_failure?
11
+ true
12
+ end
13
+
14
+ map '--version' => :version
15
+ map '--help' => :help
16
+
17
+ desc '--version', 'Print the version of bookwatch'
18
+ def version
19
+ gemspec = File.expand_path('../../../bookwatch.gemspec', __FILE__)
20
+ say "bookwatch #{Gem::Specification::load(gemspec).version}"
21
+ end
22
+
23
+ desc '--help', 'Print this message'
24
+ def help(command=nil)
25
+ super
26
+ end
27
+
28
+ =begin
29
+ desc 'generate <book_name>', 'DISABLED: Generate a skeleton book that can be bound with "bookwatch bind"'
30
+ def generate(book_name)
31
+ code = legacy_commands.generate(book_name)
32
+ raise Thor::Error, '' if code != 0
33
+ end
34
+
35
+ desc 'bind <local|remote> [options]', 'DISABLED: Bind the sections specified in config.yml from <local> or <remote> into the final_app directory'
36
+ option :verbose, type: :boolean
37
+ option 'dita-flags', desc: '--dita-flags=\"<dita-option>=<value>\"'
38
+ option :require_valid_subnav_links, type: :boolean, desc: 'Check that subnav link targets exist, always true for remote'
39
+ def bind(source)
40
+ code = legacy_commands.bind(source, options[:verbose], options['dita-flags'], options[:require_valid_subnav_links])
41
+ raise Thor::Error, '' if code != 0
42
+ end
43
+
44
+ desc 'punch <git tag>', 'DISABLED: Apply the specified <git tag> to your book, sections, and layout repo'
45
+ def punch(git_tag)
46
+ code = legacy_commands.punch(git_tag)
47
+ raise Thor::Error, '' if code != 0
48
+ end
49
+
50
+ desc 'update_local_doc_repos', 'DISABLED: Run `git pull` on all sections that exist at the same directory level as your book directory'
51
+ def update_local_doc_repos
52
+ code = legacy_commands.update_local_doc_repos
53
+ raise Thor::Error, '' if code != 0
54
+ end
55
+ =end
56
+
57
+ desc 'watch [repo1 [repo2]]', 'Bind and serve a local book, watching for changes'
58
+ long_desc <<-LONG_DESC
59
+ Bind and serve a local book, watching for changes
60
+
61
+ Optionally, you can provide a subset of the repositories in the book to be watched.
62
+ This will exclude any repositories not specified from being available in the bound book, even if they exist on your file system.
63
+ LONG_DESC
64
+ def watch(*repos)
65
+ code = legacy_commands.watch(repos)
66
+ raise Thor::Error, '' if code != 0
67
+ end
68
+
69
+ =begin
70
+ desc 'imprint <local|remote> [options]', 'DISABLED: Generate a PDF for a given book'
71
+ option :verbose, type: :boolean
72
+ option 'dita-flags', desc: '--dita-flags=\"<dita-option>=<value>\"'
73
+ def imprint(source)
74
+ code = legacy_commands.imprint(source, options[:verbose], options['dita-flags'])
75
+ raise Thor::Error, '' if code != 0
76
+ end
77
+
78
+ def method_missing(command, *args)
79
+ puts "Unknown command '#{command}'"
80
+ puts ""
81
+ help
82
+ end
83
+
84
+ private
85
+
86
+ attr_reader :legacy_commands
87
+
88
+ def initialize(*)
89
+ super
90
+
91
+ @legacy_commands = Bookwatch::Commands::Collection.new(colorized_streams, git)
92
+ end
93
+
94
+ def git
95
+ @git ||= Ingest::GitAccessor.new
96
+ end
97
+
98
+ def colorized_streams
99
+ @streams ||= {
100
+ err: Streams::ColorizedStream.new(Colorizer::Colors.red, $stderr),
101
+ out: $stdout,
102
+ success: Streams::ColorizedStream.new(Colorizer::Colors.green, $stdout),
103
+ warn: Streams::ColorizedStream.new(Colorizer::Colors.yellow, $stdout),
104
+ }
105
+ end
106
+ =end
107
+
108
+ end
109
+ end
@@ -0,0 +1,95 @@
1
+ module Bookwatch
2
+ class CodeExampleReader
3
+ class InvalidSnippet < StandardError
4
+ def initialize(repo, marker)
5
+ super "Error with marker #{marker} in #{repo}."
6
+ end
7
+ end
8
+
9
+ def initialize(streams, fs)
10
+ @out = streams[:out]
11
+ @fs = fs
12
+ end
13
+
14
+ def get_snippet_and_language_at(marker, working_copy)
15
+ if working_copy.available?
16
+ process_snippet(marker, working_copy)
17
+ else
18
+ out.puts(" skipping (not found) #{working_copy.full_name}")
19
+ ''
20
+ end
21
+ end
22
+
23
+ class Snippet
24
+ def initialize(text, language_pattern)
25
+ @text = text
26
+ @language_pattern = language_pattern
27
+ end
28
+
29
+ def valid?
30
+ ! text.empty?
31
+ end
32
+
33
+ def language
34
+ language_match = lines[0].match(language_pattern)
35
+ Array(language_match)[1]
36
+ end
37
+
38
+ def content
39
+ lines[1..-2].join("\n").strip
40
+ end
41
+
42
+ private
43
+
44
+ attr_reader :text, :language_pattern
45
+
46
+ def lines
47
+ text.split("\n")
48
+ end
49
+ end
50
+
51
+ private
52
+
53
+ attr_reader :out, :fs
54
+
55
+ def process_snippet(marker, working_copy)
56
+ snippet = Snippet.new(
57
+ find_text(working_copy.path, pattern_for(marker)),
58
+ language_pattern_for(marker)
59
+ )
60
+ if snippet.valid?
61
+ [snippet.content, snippet.language]
62
+ else
63
+ raise InvalidSnippet.new(working_copy.full_name, marker)
64
+ end
65
+ end
66
+
67
+ def find_text(start_path, pattern)
68
+ fs.find_files_recursively(start_path).
69
+ lazy.
70
+ select {|path| fs.file_exist?(path) }.
71
+ map {|path| fs.read(path) }.
72
+ map {|contents|
73
+ begin
74
+ contents.scan(pattern)
75
+ rescue ArgumentError => e
76
+ cannot_scan
77
+ end
78
+ }.
79
+ map(&:first).
80
+ detect ->{""} {|text| text}
81
+ end
82
+
83
+ def pattern_for(marker)
84
+ /code_snippet #{Regexp.escape(marker)} start.*code_snippet #{Regexp.escape(marker)} end/m
85
+ end
86
+
87
+ def language_pattern_for(marker)
88
+ /code_snippet #{Regexp.escape(marker)} start (\w+)/
89
+ end
90
+
91
+ def cannot_scan
92
+ []
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,16 @@
1
+ require 'ansi/code'
2
+ require 'ostruct'
3
+
4
+ module Bookwatch
5
+ class Colorizer
6
+ Colors = OpenStruct.new(
7
+ green: ->(msg) { ANSI.green {msg} },
8
+ red: ->(msg) { ANSI.red {msg} },
9
+ yellow: ->(msg) { ANSI.yellow {msg} },
10
+ )
11
+
12
+ def colorize(string, color)
13
+ color.call string.to_s
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,119 @@
1
+ require 'middleman-syntax'
2
+
3
+ require_relative 'components/command_options'
4
+
5
+ module Bookwatch
6
+ module Commands
7
+ class Bind
8
+ def initialize(base_streams,
9
+ output_locations: nil,
10
+ config_fetcher: nil,
11
+ config_decorator: nil,
12
+ file_system_accessor: nil,
13
+ middleman_runner: nil,
14
+ link_checker: nil,
15
+ preprocessor: nil,
16
+ cloner_factory: nil,
17
+ section_repository: nil,
18
+ directory_preparer: nil)
19
+
20
+ @base_streams = base_streams
21
+ @output_locations = output_locations
22
+ @config_fetcher = config_fetcher
23
+ @config_decorator = config_decorator
24
+ @file_system_accessor = file_system_accessor
25
+ @middleman_runner = middleman_runner
26
+ @link_checker = link_checker
27
+ @preprocessor = preprocessor
28
+ @cloner_factory = cloner_factory
29
+ @section_repository = section_repository
30
+ @directory_preparer = directory_preparer
31
+ end
32
+
33
+ def run(bind_type, verbose = false, dita_flags = nil, require_valid_subnav_links = false)
34
+ bind_options = Components::CommandOptions.new([bind_type], base_streams, verbose)
35
+ bind_config = config_fetcher.fetch_config
36
+ cloner = cloner_factory.produce(bind_options.local_repo_dir)
37
+
38
+ require_valid_subnav_links = true unless bind_type == 'local'
39
+
40
+ directory_preparer.prepare_directories(
41
+ bind_config,
42
+ File.expand_path('../../../../', __FILE__),
43
+ output_locations,
44
+ cloner,
45
+ ref_override: bind_options.ref_override
46
+ )
47
+
48
+ sections = section_repository.fetch(
49
+ configured_sections: bind_config.sections,
50
+ destination_dir: output_locations.cloned_preprocessing_dir,
51
+ ref_override: bind_options.ref_override,
52
+ cloner: cloner,
53
+ streams: base_streams
54
+ )
55
+ preprocessor.preprocess(
56
+ sections,
57
+ output_locations,
58
+ options: { dita_flags: dita_flags, require_valid_subnav_links: require_valid_subnav_links },
59
+ output_streams: bind_options.streams,
60
+ config: bind_config
61
+ )
62
+ if file_system_accessor.file_exist?('redirects.rb')
63
+ file_system_accessor.copy('redirects.rb', output_locations.final_app_dir)
64
+ end
65
+
66
+ generation_result = middleman_runner.run(
67
+ 'build --verbose',
68
+ streams: bind_options.streams,
69
+ output_locations: output_locations,
70
+ config: config_decorator.generate(bind_config, sections),
71
+ local_repo_dir: bind_options.local_repo_dir,
72
+ subnavs: subnavs(sections),
73
+ product_info: product_infos(sections)
74
+ )
75
+ if generation_result.success?
76
+ file_system_accessor.copy(output_locations.build_dir, output_locations.public_dir)
77
+
78
+ link_checker.check!(bind_config.broken_link_exclusions)
79
+
80
+ bind_options.streams[:success].puts "Bookwatch bound your book into #{output_locations.final_app_dir}"
81
+
82
+ link_checker.has_errors? ? 1 : 0
83
+ else
84
+ bind_options.streams[:err].puts "Your bind failed. Rerun with --verbose to troubleshoot."
85
+ 1
86
+ end
87
+ end
88
+
89
+ private
90
+
91
+ attr_reader(
92
+ :base_streams,
93
+ :cloner_factory,
94
+ :config_decorator,
95
+ :config_fetcher,
96
+ :directory_preparer,
97
+ :file_system_accessor,
98
+ :final_app_directory,
99
+ :output_locations,
100
+ :preprocessor,
101
+ :section_repository,
102
+ :link_checker,
103
+ :middleman_runner,
104
+ )
105
+
106
+ def subnavs(sections)
107
+ sections.map(&:subnav).reduce({}, :merge)
108
+ end
109
+
110
+ def product_infos(sections)
111
+ temp = Hash.new
112
+ sections.each do |section|
113
+ temp[section.namespace] = section.product_info
114
+ end
115
+ temp
116
+ end
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,181 @@
1
+ Dir.glob(File.expand_path('../../commands/*.rb', __FILE__)).each do |command_file|
2
+ require command_file unless command_file =~ /collection\.rb\z/
3
+ end
4
+
5
+ require_relative '../commands/components/bind/directory_preparer'
6
+ require_relative '../commands/components/imprint/directory_preparer'
7
+ require_relative '../config/configuration_decorator'
8
+ require_relative '../config/fetcher'
9
+ require_relative '../config/validator'
10
+ require_relative '../config/yaml_loader'
11
+ require_relative '../config/configuration'
12
+ require_relative '../config/imprint/configuration'
13
+ require_relative '../dita_command_creator'
14
+ require_relative '../dita_html_for_middleman_formatter'
15
+ require_relative '../html_document_manipulator'
16
+ require_relative '../ingest/cloner_factory'
17
+ require_relative '../ingest/section_repository'
18
+ require_relative '../local_filesystem_accessor'
19
+ require_relative '../middleman_runner'
20
+ require_relative '../postprocessing/link_checker'
21
+ require_relative '../preprocessing/dita_html_preprocessor'
22
+ require_relative '../preprocessing/dita_pdf_preprocessor'
23
+ require_relative '../preprocessing/link_to_site_gen_dir'
24
+ require_relative '../preprocessing/preprocessor'
25
+ require_relative '../subnav/subnav_generator_factory'
26
+ require_relative '../sheller'
27
+ require_relative '../values/output_locations'
28
+
29
+ module Bookwatch
30
+ module Commands
31
+ class Collection
32
+ include Enumerable
33
+
34
+ def initialize(streams, version_control_system)
35
+ @streams = streams
36
+ @version_control_system = version_control_system
37
+ end
38
+
39
+ def generate(*args)
40
+ Commands::Generate.new(
41
+ local_filesystem_accessor,
42
+ sheller,
43
+ Dir.pwd,
44
+ streams
45
+ ).run(*args)
46
+ end
47
+
48
+ def punch(*args)
49
+ Commands::Punch.new(
50
+ streams,
51
+ configuration_fetcher(Config::Configuration),
52
+ version_control_system
53
+ ).run(*args)
54
+ end
55
+
56
+ def update_local_doc_repos
57
+ Commands::UpdateLocalDocRepos.new(
58
+ streams,
59
+ configuration_fetcher(Config::Configuration),
60
+ version_control_system
61
+ ).run
62
+ end
63
+
64
+ def bind(*args)
65
+ @bind ||= Commands::Bind.new(
66
+ streams,
67
+ middleman_runner: runner,
68
+ output_locations: output_locations,
69
+ config_fetcher: configuration_fetcher(Config::Configuration),
70
+ config_decorator: Config::ConfigurationDecorator.new(loader: config_loader, config_filename: 'bookwatch.yml'),
71
+ file_system_accessor: local_filesystem_accessor,
72
+ link_checker: Postprocessing::LinkChecker.new(local_filesystem_accessor, final_app_directory, streams),
73
+ preprocessor: Preprocessing::Preprocessor.new(
74
+ Preprocessing::DitaHTMLPreprocessor.new(
75
+ local_filesystem_accessor,
76
+ subnav_generator_factory,
77
+ DitaHtmlForMiddlemanFormatter.new(local_filesystem_accessor, html_document_manipulator),
78
+ dita_command_creator,
79
+ sheller
80
+ ),
81
+ Preprocessing::LinkToSiteGenDir.new(local_filesystem_accessor, subnav_generator_factory)
82
+ ),
83
+ cloner_factory: Ingest::ClonerFactory.new(streams, local_filesystem_accessor, version_control_system),
84
+ section_repository: Ingest::SectionRepository.new,
85
+ directory_preparer: directory_preparer
86
+ ).run(*args)
87
+ end
88
+
89
+ def watch(repos=[])
90
+ @watch ||= Commands::Watch.new(
91
+ streams,
92
+ middleman_runner: runner,
93
+ output_locations: output_locations,
94
+ config_fetcher: configuration_fetcher(Config::Configuration),
95
+ config_decorator: Config::ConfigurationDecorator.new(loader: config_loader, config_filename: 'bookwatch.yml'),
96
+ file_system_accessor: local_filesystem_accessor,
97
+ preprocessor: Preprocessing::Preprocessor.new(Preprocessing::LinkToSiteGenDir.new(local_filesystem_accessor, subnav_generator_factory)),
98
+ cloner: local_file_system_cloner,
99
+ section_repository: Ingest::SectionRepository.new,
100
+ directory_preparer: directory_preparer,
101
+ repo_restrictions: repos
102
+ ).run
103
+ end
104
+
105
+ def imprint(*args)
106
+ Bookwatch::Commands::Imprint.new(
107
+ streams,
108
+ output_locations: output_locations,
109
+ config_fetcher: configuration_fetcher(Config::Imprint::Configuration),
110
+ preprocessor: Preprocessing::Preprocessor.new(Preprocessing::DitaPDFPreprocessor.new(local_filesystem_accessor, dita_command_creator, sheller)),
111
+ cloner_factory: Ingest::ClonerFactory.new(streams, local_filesystem_accessor, version_control_system),
112
+ section_repository: Ingest::SectionRepository.new,
113
+ directory_preparer: Commands::Components::Imprint::DirectoryPreparer.new(local_filesystem_accessor)
114
+ ).run(*args)
115
+ end
116
+
117
+ private
118
+
119
+ attr_reader :streams, :version_control_system
120
+
121
+ def dita_command_creator
122
+ DitaCommandCreator.new(ENV['PATH_TO_DITA_OT_LIBRARY'])
123
+ end
124
+
125
+ def configuration_fetcher(config_class)
126
+ Bookwatch::Config::Fetcher.new(
127
+ Bookwatch::Config::Validator.new(local_filesystem_accessor),
128
+ config_loader,
129
+ config_class
130
+ ).tap do |fetcher|
131
+ fetcher.set_config_file_path './config.yml'
132
+ fetcher.set_config_dir_path './config/'
133
+ end
134
+ end
135
+
136
+ def config_loader
137
+ @config_loader ||= Config::YAMLLoader.new
138
+ end
139
+
140
+ def subnav_generator_factory
141
+ Subnav::SubnavGeneratorFactory.new(local_filesystem_accessor, output_locations)
142
+ end
143
+
144
+ def directory_preparer
145
+ Commands::Components::Bind::DirectoryPreparer.new(local_filesystem_accessor)
146
+ end
147
+
148
+ def output_locations
149
+ OutputLocations.new(final_app_dir: final_app_directory, context_dir: File.absolute_path('.'))
150
+ end
151
+
152
+ def final_app_directory
153
+ @final_app_directory ||= File.absolute_path('final_app')
154
+ end
155
+
156
+ def html_document_manipulator
157
+ @html_document_manipulator ||= HtmlDocumentManipulator.new
158
+ end
159
+
160
+ def local_filesystem_accessor
161
+ @local_filesystem_accessor ||= LocalFilesystemAccessor.new
162
+ end
163
+
164
+ def sheller
165
+ @sheller ||= Sheller.new
166
+ end
167
+
168
+ def sitemap_port
169
+ 41722
170
+ end
171
+
172
+ def runner
173
+ MiddlemanRunner.new(local_filesystem_accessor, sheller)
174
+ end
175
+
176
+ def local_file_system_cloner
177
+ Ingest::LocalFilesystemCloner.new(streams, local_filesystem_accessor, File.expand_path('..'))
178
+ end
179
+ end
180
+ end
181
+ end