class Bunto::Commands::Build

Public Class Methods

build(site, options) click to toggle source

Build your Bunto site.

site - the Bunto::Site instance to build options - A Hash of options passed to the command

Returns nothing.

# File lib/bunto/commands/build.rb, line 53
def build(site, options)
  t = Time.now
  source      = options["source"]
  destination = options["destination"]
  incremental = options["incremental"]
  Bunto.logger.info "Source:", source
  Bunto.logger.info "Destination:", destination
  Bunto.logger.info "Incremental build:",
    (incremental ? "enabled" : "disabled. Enable with --incremental")
  Bunto.logger.info "Generating..."
  process_site(site)
  Bunto.logger.info "", "done in #{(Time.now - t).round(3)} seconds."
end
init_with_program(prog) click to toggle source

Create the Mercenary command for the Bunto CLI for this Command

# File lib/bunto/commands/build.rb, line 6
def init_with_program(prog)
  prog.command(:build) do |c|
    c.syntax      "build [options]"
    c.description "Build your site"
    c.alias :b

    add_build_options(c)

    c.action do |_, options|
      options["serving"] = false
      Bunto::Commands::Build.process(options)
    end
  end
end
process(options) click to toggle source

Build your bunto site Continuously watch if `watch` is set to true in the config.

# File lib/bunto/commands/build.rb, line 23
def process(options)
  # Adjust verbosity quickly
  Bunto.logger.adjust_verbosity(options)

  options = configuration_from_options(options)
  site = Bunto::Site.new(options)

  if options.fetch("skip_initial_build", false)
    Bunto.logger.warn "Build Warning:", "Skipping the initial build." \
                " This may result in an out-of-date site."
  else
    build(site, options)
  end

  if options.fetch("detach", false)
    Bunto.logger.info "Auto-regeneration:",
      "disabled when running server detached."
  elsif options.fetch("watch", false)
    watch(site, options)
  else
    Bunto.logger.info "Auto-regeneration:", "disabled. Use --watch to enable."
  end
end
watch(site, options) click to toggle source

Private: Watch for file changes and rebuild the site.

site - A Bunto::Site instance options - A Hash of options passed to the command

Returns nothing.

# File lib/bunto/commands/build.rb, line 73
def watch(site, options)
  # Warn Windows users that they might need to upgrade.
  if Utils::Platforms.bash_on_windows?
    Bunto.logger.warn "",
      "Auto-regeneration may not work on some Windows versions."
    Bunto.logger.warn "",
      "Please see: https://github.com/Microsoft/BashOnWindows/issues/216"
    Bunto.logger.warn "",
      "If it does not work, please upgrade Bash on Windows or "\
        "run Bunto with --no-watch."
  end

  External.require_with_graceful_fail "bunto-watch"
  watch_method = Bunto::Watcher.method(:watch)
  if watch_method.parameters.size == 1
    watch_method.call(
      options
    )
  else
    watch_method.call(
      options, site
    )
  end
end