class Minimart::Commands::Web

Web is the main entrance point for building the web interface for Minimart. This class will generate the index file to be used by Berkshelf, archived cookbooks, and HTML used to browse the available inventory.

Attributes

can_generate_html[R]

@return [Boolean] Determine whether or not to generate HTML output

clean_cookbooks[R]

@return [Boolean] Determine whether or not to clean the cookbook_files folder and recreate

cookbooks[R]
inventory_directory[R]

@return [String] The directory that the inventory is stored in.

web_directory[R]

@return [String] The directory to store the web output.

web_endpoint[R]

@return [String] The web endpoint where Minimart will be hosted.

Public Class Methods

new(opts = {}) click to toggle source

@param [Hash] opts @option opts [String] :inventory_directory The directory that the inventory is stored in. @option opts [String] :web_directory The directory to store the web output. @option opts [String] :host The web endpoint where Minimart will be hosted. @option opts [Boolean] :can_generate_html Determine whether or not to generate HTML output @option opts [Boolean] :clean_cookbooks Determine whether or not to clean the cookbook_files folder and recreate

# File lib/minimart/commands/web.rb, line 29
def initialize(opts = {})
  @inventory_directory = File.expand_path(opts[:inventory_directory])
  @web_directory       = File.expand_path(opts[:web_directory])
  @web_endpoint        = opts[:host]
  @can_generate_html   = opts.fetch(:html, true)
  @clean_cookbooks     = opts.fetch(:clean_cookbooks, true)
end

Public Instance Methods

execute!() click to toggle source

Generate the web output.

# File lib/minimart/commands/web.rb, line 38
def execute!
  make_web_directory
  generate_universe
  generate_html
  print_success_message
end

Private Instance Methods

generate_html() click to toggle source
# File lib/minimart/commands/web.rb, line 66
def generate_html
  return unless generate_html?

  Configuration.output.puts "Generating Minimart HTML."

  generator = Minimart::Web::HtmlGenerator.new(
    web_directory: web_directory,
    cookbooks:     cookbooks,
    clean_cookbooks: clean_cookbooks
  )

  generator.generate
end
generate_html?() click to toggle source
# File lib/minimart/commands/web.rb, line 84
def generate_html?
  can_generate_html
end
generate_universe() click to toggle source
# File lib/minimart/commands/web.rb, line 53
def generate_universe
  Configuration.output.puts "Building the cookbook index."

  generator = Minimart::Web::UniverseGenerator.new(
    web_directory: web_directory,
    endpoint:      web_endpoint,
    cookbooks:     cookbooks,
    clean_cookbooks: clean_cookbooks
  )

  generator.generate
end
make_web_directory() click to toggle source
# File lib/minimart/commands/web.rb, line 49
def make_web_directory
  FileUtils.mkdir_p web_directory
end
print_success_message() click to toggle source
relative_web_path() click to toggle source
# File lib/minimart/commands/web.rb, line 93
def relative_web_path
  File.join('.', Pathname.new(web_directory).relative_path_from(Pathname.pwd))
end