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
@return [Boolean] Determine whether or not to generate HTML output
@return [Boolean] Determine whether or not to clean the cookbook_files folder and recreate
@return [String] The directory that the inventory is stored in.
@return [String] The directory to store the web output.
@return [String] The web endpoint where Minimart
will be hosted.
Public Class Methods
@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
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
# 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
# File lib/minimart/commands/web.rb, line 84 def generate_html? can_generate_html end
# 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
# File lib/minimart/commands/web.rb, line 49 def make_web_directory FileUtils.mkdir_p web_directory end
# File lib/minimart/commands/web.rb, line 88 def print_success_message Configuration.output.puts_green('Minimart successfully built the static web files!') Configuration.output.puts_green("The static web files can be found in #{relative_web_path}") end
# File lib/minimart/commands/web.rb, line 93 def relative_web_path File.join('.', Pathname.new(web_directory).relative_path_from(Pathname.pwd)) end