Module: GuidesStyle18F

Defined in:
lib/guides_style_18f/update.rb,
lib/guides_style_18f/sass.rb,
lib/guides_style_18f/tags.rb,
lib/guides_style_18f/assets.rb,
lib/guides_style_18f/layouts.rb,
lib/guides_style_18f/version.rb,
lib/guides_style_18f/includes.rb,
lib/guides_style_18f/generator.rb,
lib/guides_style_18f/navigation.rb,
lib/guides_style_18f/repository.rb

Overview

Author:

Defined Under Namespace

Modules: FrontMatter Classes: AssetRootTag, Assets, Generator, IncludeTag, Layouts, PopLastUrlComponent, Sass, ShouldExpandNavTag

Constant Summary collapse

VERSION =
'0.1.13'
TEMPLATE_FILES =
%w(
  _pages/add-a-new-page/make-a-child-page.md
  _pages/add-a-new-page.md
  _pages/add-images.md
  _pages/github-setup.md
  _pages/post-your-guide.md
  _pages/update-the-config-file/understanding-baseurl.md
  _pages/update-the-config-file.md
  images/18f-pages.png
  images/description.png
  images/gh-add-guide.png
  images/gh-branches-link.png
  images/gh-default-branch.png
  images/gh-settings-button.png
  images/gh-webhook.png
  images/images.png
)
GIT_COMMANDS =
{
  'Creating a new git repository.' => 'git init',
  'Creating 18f-pages branch.' => 'git checkout -b 18f-pages',
  'Adding files for initial commit.' => 'git add .',
}

Class Method Summary collapse

Class Method Details

.clear_template_files_and_create_new_repository(basedir, outstream = $stdout) ⇒ Object



25
26
27
28
29
30
# File 'lib/guides_style_18f/repository.rb', line 25

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) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/guides_style_18f/repository.rb', line 41

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) ⇒ Object



71
72
73
74
# File 'lib/guides_style_18f/repository.rb', line 71

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) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/guides_style_18f/repository.rb', line 32

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) ⇒ Object

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.



117
118
119
120
121
122
123
124
# File 'lib/guides_style_18f/navigation.rb', line 117

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'] || []
  update_navigation_data(nav_data, basedir)
  write_navigation_data_to_config_file(config_path, nav_data)
end

.update_themeObject



4
5
6
# File 'lib/guides_style_18f/update.rb', line 4

def self.update_theme
  exec({ 'RUBYOPT' => nil }, 'bundle', *%w(update --source guides_style_18f))
end