Class: Bookbinder::Commands::Bind

Inherits:
Object
  • Object
show all
Includes:
Naming
Defined in:
lib/bookbinder/commands/bind.rb

Instance Method Summary collapse

Methods included from Naming

#command_type, #flag?

Constructor Details

#initialize(base_streams, output_locations: nil, config_fetcher: nil, config_decorator: nil, file_system_accessor: nil, middleman_runner: nil, sitemap_writer: nil, preprocessor: nil, cloner_factory: nil, section_repository: nil, directory_preparer: nil) ⇒ Bind

Returns a new instance of Bind.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/bookbinder/commands/bind.rb', line 11

def initialize(base_streams,
               output_locations: nil,
               config_fetcher: nil,
               config_decorator: nil,
               file_system_accessor: nil,
               middleman_runner: nil,
               sitemap_writer: nil,
               preprocessor: nil,
               cloner_factory: nil,
               section_repository: nil,
               directory_preparer: nil)

  @base_streams = base_streams
  @output_locations = output_locations
  @config_fetcher = config_fetcher
  @config_decorator = config_decorator
  @file_system_accessor = file_system_accessor
  @middleman_runner = middleman_runner
  @sitemap_writer = sitemap_writer
  @preprocessor = preprocessor
  @cloner_factory = cloner_factory
  @section_repository = section_repository
  @directory_preparer = directory_preparer
end

Instance Method Details

#command_for?(test_command_name) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/bookbinder/commands/bind.rb', line 41

def command_for?(test_command_name)
  %w(bind publish).include?(test_command_name)
end

#deprecated_command_for?(command_name) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/bookbinder/commands/bind.rb', line 45

def deprecated_command_for?(command_name)
  %w(publish).include?(command_name)
end

#run(cli_arguments) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/bookbinder/commands/bind.rb', line 49

def run(cli_arguments)
  bind_options        = Components::CommandOptions.new(cli_arguments, base_streams).tap(&:validate!)
  bind_config         = config_fetcher.fetch_config
  cloner              = cloner_factory.produce(bind_options.local_repo_dir)

  directory_preparer.prepare_directories(
    bind_config,
    File.expand_path('../../../../', __FILE__),
    output_locations,
    cloner,
    ref_override: bind_options.ref_override
  )
  sections = section_repository.fetch(
    configured_sections: bind_config.sections,
    destination_dir: output_locations.cloned_preprocessing_dir,
    ref_override: bind_options.ref_override,
    cloner: cloner,
    streams: base_streams
  )
  preprocessor.preprocess(
    sections,
    output_locations,
    options: bind_options.options,
    output_streams: bind_options.streams,
    config: bind_config
  )
  if file_system_accessor.file_exist?('redirects.rb')
    file_system_accessor.copy('redirects.rb', output_locations.final_app_dir)
  end
  generation_result = middleman_runner.run(
    ["build", bind_options.verbosity].compact.join(" "),
    streams: bind_options.streams,
    output_locations: output_locations,
    config: config_decorator.generate(bind_config, sections),
    local_repo_dir: bind_options.local_repo_dir,
    subnavs: subnavs(sections)
  )
  if generation_result.success?
    file_system_accessor.copy(output_locations.build_dir, output_locations.public_dir)
    result = sitemap_writer.write(
      bind_config.public_host,
      bind_options.streams,
      bind_config.broken_link_exclusions
    )

    bind_options.streams[:success].puts "Bookbinder bound your book into #{output_locations.final_app_dir}"

    result.has_broken_links? ? 1 : 0
  else
    bind_options.streams[:err].puts "Your bind failed. Rerun with --verbose to troubleshoot."
    1
  end
end

#usageObject



36
37
38
39
# File 'lib/bookbinder/commands/bind.rb', line 36

def usage
  ["bind <local|remote> [--verbose] [--dita-flags=\\\"<dita-option>=<value>\\\"]",
   "Bind the sections specified in config.yml from <local> or <remote> into the final_app directory"]
end