module GuidesStyleMbland

Constants

GIT_COMMANDS
TEMPLATE_FILES
VERSION

Public Class Methods

clear_template_files_and_create_new_repository( basedir, outstream = $stdout) click to toggle source
# File lib/guides_style_mbland/repository.rb, line 23
def self.clear_template_files_and_create_new_repository(
  basedir, outstream = $stdout)
  remove_template_files basedir, outstream
  delete_create_repo_command_from_go_script basedir, outstream
  create_new_git_repository basedir, outstream
end
delete_create_repo_command_from_go_script(basedir, outstream) click to toggle source
# File lib/guides_style_mbland/repository.rb, line 39
def self.delete_create_repo_command_from_go_script(basedir, outstream)
  Dir.chdir basedir do
    outstream.puts 'Removing `:create_repo` command from the `./go` script.'
    go_script = File.join basedir, 'go'
    content = File.read go_script
    match = /\ndef_command\(\n  :create_repo,.*?end\n/m.match content
    content = "#{match.pre_match}#{match.post_match}" unless match.nil?
    File.write go_script, content
  end
end
exec_cmd_capture_output(command, outstream) click to toggle source
# File lib/guides_style_mbland/repository.rb, line 69
def self.exec_cmd_capture_output(command, outstream)
  opts = { out: outstream, err: outstream }
  exit $CHILD_STATUS.exitstatus unless system command, opts
end
remove_template_files(basedir, outstream) click to toggle source
# File lib/guides_style_mbland/repository.rb, line 30
def self.remove_template_files(basedir, outstream)
  Dir.chdir basedir do
    outstream.puts 'Clearing Guides Template files.'
    files = TEMPLATE_FILES.map { |f| File.join basedir, f }
      .select { |f| File.exist? f }
    File.delete(*files)
  end
end
update_navigation_configuration(basedir) click to toggle source

Automatically updates the ‘navigation:` field in _config.yml.

Does this by parsing the front matter from files in ‘pages/`. Preserves the existing order of items in `navigation:`, but new items may need to be reordered manually.

# File lib/guides_style_mbland/navigation.rb, line 123
def self.update_navigation_configuration(basedir)
  config_path = File.join basedir, '_config.yml'
  config_data = SafeYAML.load_file config_path, safe: true
  return unless config_data
  nav_data = config_data['navigation'] || []
  NavigationMenu.update_navigation_data(nav_data, basedir, config_data)
  NavigationMenuWriter.write_navigation_data_to_config_file(
    config_path, nav_data)
end
update_theme() click to toggle source
# File lib/guides_style_mbland/update.rb, line 2
def self.update_theme
  exec({ 'RUBYOPT' => nil }, 'bundle',
    *%w(update --source guides_style_mbland))
end

Private Class Methods

create_new_git_repository(basedir, outstream) click to toggle source
# File lib/guides_style_mbland/repository.rb, line 56
def self.create_new_git_repository(basedir, outstream)
  Dir.chdir basedir do
    outstream.puts 'Removing old git repository.'
    FileUtils.rm_rf '.git'
    GIT_COMMANDS.each do |description, command|
      outstream.puts description
      exec_cmd_capture_output command, outstream
    end
    outstream.puts "All done! Run \'git commit\' to create your first commit."
  end
end