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,
lib/guides_style_18f/breadcrumbs.rb,
lib/guides_style_18f/generated_nodes.rb,
lib/guides_style_18f/generated_pages.rb,
lib/guides_style_18f/namespace_flattener.rb

Defined Under Namespace

Modules: FrontMatter, NavigationMenu Classes: AssetRootTag, Assets, Breadcrumbs, GeneratedNodes, GeneratedPage, GeneratedPages, Generator, IncludeTag, Layouts, NamespaceFlattener, NavigationMenuWriter, PopLastUrlComponent, Sass, ShouldExpandNavTag

Constant Summary collapse

VERSION =
'1.0.6'
TEMPLATE_FILES =
%w(
  _pages/add-a-new-page/make-a-child-page.md
  _pages/add-a-new-page.md
  _pages/add-images.md
  _pages/advanced-features.md
  _pages/github-setup.md
  _pages/images.png
  _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
)
GIT_COMMANDS =
{
  'Creating a new git repository.' => 'git init',
  '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



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

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



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

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



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

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.



122
123
124
125
126
127
128
129
130
# File 'lib/guides_style_18f/navigation.rb', line 122

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_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