bookbindery 4.0.0 → 4.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4186b0031cc1db33f20038d884a71624f845d175
4
- data.tar.gz: 439d522cdaba03d005039b45e44b9b3917dab82d
3
+ metadata.gz: 9f6a8e4eb39aa0fd160b3172ba64ea6b9235cf00
4
+ data.tar.gz: 336570ec41b4e7ba131acab5565a9c210e122227
5
5
  SHA512:
6
- metadata.gz: 384fc6c0bf881e81cc2fd34040af92eae6b83150cbdd14b441d72d84355d2a8ce4dcb0044a892de797eec4f20b3660739fbb99529a0a7b0d57a8295fa827a0a6
7
- data.tar.gz: 3310d764be0a0d8063e9142ccff2c55046f4378b255a8e5fe63ceb8919a5eb5ddbf10cf8d24584810f5b78678365654a931a2fc66df3f11b9649f54255fbacaf
6
+ metadata.gz: e6b3d8dbd2a9b312574024ff56ed8669de906b7290b1de9a5de3e2bb1ea372fc2b6d11bdf7f7f8239153dac485135e4c8993ed814ca3ef6ebe5d62e1ae815848
7
+ data.tar.gz: a6bcdfcc72d5a57a090a88bc60cddcd74d2f0bb5715b34db798310104181843c25feb50089aaf5d2e7b6f06169226c02dfb2e36a40f80ae0aced02a663c622bf
@@ -3,7 +3,6 @@ require_relative 'command_runner'
3
3
  require_relative 'command_validator'
4
4
  require_relative 'commands/collection'
5
5
  require_relative 'config/cf_credentials'
6
- require_relative 'config/configuration'
7
6
  require_relative 'terminal'
8
7
 
9
8
  module Bookbinder
@@ -16,7 +15,11 @@ module Bookbinder
16
15
  command_name, *command_arguments = args
17
16
 
18
17
  logger = DeprecatedLogger.new
19
- commands = Commands::Collection.new(logger, version_control_system)
18
+ commands = Commands::Collection.new(
19
+ logger,
20
+ {out: $stdout, err: $stderr},
21
+ version_control_system
22
+ )
20
23
 
21
24
  command_validator = CommandValidator.new(commands, commands.help.usage_message)
22
25
  command_runner = CommandRunner.new(logger, commands)
@@ -120,7 +120,6 @@ module Bookbinder
120
120
  subnavs)
121
121
  file_system_accessor.copy output_locations.build_dir, output_locations.public_dir
122
122
 
123
- raise "Your public host must be a single String." unless host_for_sitemap.is_a?(String)
124
123
  result = sitemap_writer.write(
125
124
  host_for_sitemap,
126
125
  streams,
@@ -28,8 +28,9 @@ module Bookbinder
28
28
  class Collection
29
29
  include Enumerable
30
30
 
31
- def initialize(logger, version_control_system)
31
+ def initialize(logger, base_streams, version_control_system)
32
32
  @logger = logger
33
+ @base_streams = base_streams
33
34
  @version_control_system = version_control_system
34
35
  end
35
36
 
@@ -46,7 +47,7 @@ module Bookbinder
46
47
 
47
48
  private
48
49
 
49
- attr_reader :logger, :version_control_system
50
+ attr_reader :logger, :base_streams, :version_control_system
50
51
 
51
52
  def list
52
53
  standard_commands + flags
@@ -58,6 +59,12 @@ module Bookbinder
58
59
 
59
60
  def standard_commands
60
61
  @standard_commands ||= [
62
+ Commands::Generate.new(
63
+ local_file_system_accessor,
64
+ Sheller.new,
65
+ Dir.pwd,
66
+ colored_streams
67
+ ),
61
68
  build_and_push_tarball,
62
69
  bind,
63
70
  Commands::PushFromLocal.new(logger, configuration_fetcher, 'acceptance'),
@@ -68,8 +75,7 @@ module Bookbinder
68
75
  Commands::UpdateLocalDocRepos.new(
69
76
  colored_streams,
70
77
  configuration_fetcher,
71
- version_control_system,
72
- local_file_system_accessor
78
+ version_control_system
73
79
  ),
74
80
  ]
75
81
  end
@@ -118,9 +124,9 @@ module Bookbinder
118
124
  end
119
125
 
120
126
  def colored_streams
121
- { out: $stdout,
122
- success: Streams::ColorizedStream.new(Colorizer::Colors.green, $stdout),
123
- err: Streams::ColorizedStream.new(Colorizer::Colors.red, $stderr) }
127
+ { out: base_streams[:out],
128
+ success: Streams::ColorizedStream.new(Colorizer::Colors.green, base_streams[:out]),
129
+ err: Streams::ColorizedStream.new(Colorizer::Colors.red, base_streams[:err]) }
124
130
  end
125
131
 
126
132
  def configuration_fetcher
@@ -0,0 +1,94 @@
1
+ module Bookbinder
2
+ module Commands
3
+ class Generate
4
+ include Commands::Naming
5
+
6
+ def initialize(fs, sheller, context_dir, streams)
7
+ @fs = fs
8
+ @sheller = sheller
9
+ @context_dir = context_dir
10
+ @streams = streams
11
+ end
12
+
13
+ def command_for?(name)
14
+ name == 'generate'
15
+ end
16
+
17
+ def usage
18
+ ["generate <book-name>",
19
+ "Generate a skeleton book that can be bound with 'bookbinder bind'"]
20
+ end
21
+
22
+ def run((name))
23
+ path = context_dir.join(name)
24
+ streams[:out].puts "Generating book at #{path}…"
25
+ if fs.file_exist?(path)
26
+ streams[:err].puts "Cannot generate book: directory already exists"
27
+ 1
28
+ elsif install(path).success?
29
+ streams[:success].puts "Successfully generated book at #{path}"
30
+ 0
31
+ else
32
+ 1
33
+ end
34
+ end
35
+
36
+ private
37
+
38
+ attr_reader :fs, :sheller, :streams
39
+
40
+ def install(path)
41
+ make_middleman_dir(path)
42
+ init_gemfile(path)
43
+ init_config(path)
44
+ init_index(path)
45
+ bundle_install(path)
46
+ end
47
+
48
+ def make_middleman_dir(path)
49
+ fs.make_directory(path.join('master_middleman/build'))
50
+ end
51
+
52
+ def init_gemfile(path)
53
+ fs.write(
54
+ text: <<-GEMFILE,
55
+ source "https://rubygems.org"
56
+
57
+ gem "bookbindery"
58
+ GEMFILE
59
+ to: path.join('Gemfile')
60
+ )
61
+ end
62
+
63
+ def init_config(path)
64
+ fs.write(
65
+ text: YAML.dump(
66
+ 'book_repo' => '',
67
+ 'public_host' => '',
68
+ ),
69
+ to: path.join('config.yml')
70
+ )
71
+ end
72
+
73
+ def init_index(path)
74
+ fs.write(
75
+ text: '# Empty book',
76
+ to: path.join('master_middleman/source/index.md.erb')
77
+ )
78
+ end
79
+
80
+ def bundle_install(path)
81
+ Bundler.with_clean_env do
82
+ sheller.run_command(
83
+ "bundle install --binstubs --gemfile=#{path.join('Gemfile')}",
84
+ out: streams[:out], err: streams[:err]
85
+ )
86
+ end
87
+ end
88
+
89
+ def context_dir
90
+ Pathname(@context_dir)
91
+ end
92
+ end
93
+ end
94
+ end
@@ -7,11 +7,10 @@ module Bookbinder
7
7
  class UpdateLocalDocRepos
8
8
  include Commands::Naming
9
9
 
10
- def initialize(streams, configuration_fetcher, version_control_system, filesystem)
10
+ def initialize(streams, configuration_fetcher, version_control_system)
11
11
  @streams = streams
12
12
  @configuration_fetcher = configuration_fetcher
13
13
  @version_control_system = version_control_system
14
- @filesystem = filesystem
15
14
  end
16
15
 
17
16
  def usage
@@ -33,8 +32,7 @@ module Bookbinder
33
32
 
34
33
  attr_reader(:streams,
35
34
  :configuration_fetcher,
36
- :version_control_system,
37
- :filesystem)
35
+ :version_control_system)
38
36
 
39
37
  def report(result)
40
38
  messages = { true => "updated", false => "skipping (#{result.reason})" }
@@ -7,17 +7,8 @@ module Bookbinder
7
7
  MissingRequiredKeyError = Class.new(RuntimeError)
8
8
 
9
9
  def check(config)
10
- missing_keys = []
11
-
12
- Config::Configuration::CONFIG_REQUIRED_KEYS.each do |required_key|
13
- begin
14
- config.public_send(required_key)
15
- rescue KeyError
16
- missing_keys.push(required_key)
17
- end
18
- end
19
-
20
- if missing_keys.length > 0
10
+ missing_keys = Config::Configuration::CONFIG_REQUIRED_KEYS.reject { |key| config.has_option?(key) }
11
+ if missing_keys.any?
21
12
  MissingRequiredKeyError.new("Your config.yml is missing required key(s). Required keys are #{missing_keys.join(", ")}.")
22
13
  end
23
14
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bookbindery
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 4.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Grafton
@@ -15,7 +15,7 @@ authors:
15
15
  autorequire:
16
16
  bindir: install_bin
17
17
  cert_chain: []
18
- date: 2015-06-24 00:00:00.000000000 Z
18
+ date: 2015-07-01 00:00:00.000000000 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: fog-aws
@@ -279,6 +279,7 @@ files:
279
279
  - lib/bookbinder/commands/build_and_push_tarball.rb
280
280
  - lib/bookbinder/commands/chain.rb
281
281
  - lib/bookbinder/commands/collection.rb
282
+ - lib/bookbinder/commands/generate.rb
282
283
  - lib/bookbinder/commands/help.rb
283
284
  - lib/bookbinder/commands/naming.rb
284
285
  - lib/bookbinder/commands/push_from_local.rb