Skip to content
This repository was archived by the owner on Jul 12, 2018. It is now read-only.

Commit 003da41

Browse files
author
Mike Bland
committed
Use go_script gem; update guides_style_18f, nav
In addition to the gem updates, the sidebar item now reads "Making repo descriptions short and clear" to match the title on that page. The nav bar highlight doesn't work unless the titles match.
1 parent d08c607 commit 003da41

File tree

4 files changed

+46
-135
lines changed

4 files changed

+46
-135
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ source 'https://rubygems.org'
22

33
gem 'jekyll'
44
gem 'rouge'
5+
gem 'go_script'
56

67
group :jekyll_plugins do
78
gem 'guides_style_18f'

Gemfile.lock

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ GEM
1414
execjs (2.5.2)
1515
fast-stemmer (1.0.2)
1616
ffi (1.9.9)
17-
guides_style_18f (0.0.0)
17+
go_script (0.1.4)
18+
bundler (~> 1.10)
19+
safe_yaml (~> 1.0)
20+
guides_style_18f (0.1.1)
1821
jekyll (~> 2.5)
1922
rouge (~> 1.9)
2023
sass (~> 3.4)
@@ -72,6 +75,7 @@ PLATFORMS
7275
ruby
7376

7477
DEPENDENCIES
78+
go_script
7579
guides_style_18f
7680
jekyll
7781
rouge

_config.yml

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
baseurl: /open-source-guide
21
markdown: redcarpet
32
name: 18F Open Source Style Guide
43
exclude:
5-
- go
6-
- copy-template
4+
- CONTRIBUTING.md
75
- Gemfile
86
- Gemfile.lock
9-
- README.md
107
- LICENSE.md
8+
- README.md
9+
- go
1110

1211
permalink: pretty
1312
highlighter: rouge
1413

14+
sass:
15+
style: :compressed
16+
1517
# Author/Organization info to be displayed in the templates
1618
author:
1719
name: 18F
@@ -30,7 +32,7 @@ navigation:
3032
- text: Naming your project
3133
url: naming-your-project/
3234
internal: true
33-
- text: Writing the repo description
35+
- text: Making repo descriptions short and clear
3436
url: writing-the-repo-description/
3537
internal: true
3638
- text: Making READMEs readable
@@ -51,15 +53,6 @@ repos:
5153
description: Main repository
5254
url: https://github.com/18F/open-source-guide
5355

54-
# Style Variables
55-
brand_color: "#1188ff"
56-
57-
google_analytics_ua: UA-48605964-19
58-
59-
# To use the shared 18F Guides styles when deploying to pages.18f.gov,
60-
# uncomment the following; comment it out during local development:
61-
asset_root: /guides-template
62-
6356
back_link:
6457
url: "https://pages.18f.gov/guides/"
6558
text: Read more 18F Guides

go

Lines changed: 33 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -1,141 +1,54 @@
11
#! /usr/bin/env ruby
2-
#
3-
# 18F Guides Jekyll template
4-
#
5-
# Written in 2015 by Mike Bland (michael.bland@gsa.gov)
6-
# on behalf of the 18F team, part of the US General Services Administration:
7-
# https://18f.gsa.gov/
8-
#
9-
# To the extent possible under law, the author(s) have dedicated all copyright
10-
# and related and neighboring rights to this software to the public domain
11-
# worldwide. This software is distributed without any warranty.
12-
#
13-
# You should have received a copy of the CC0 Public Domain Dedication along
14-
# with this software. If not, see
15-
# <https://creativecommons.org/publicdomain/zero/1.0/>.
16-
#
17-
# @author Mike Bland (michael.bland@gsa.gov)
18-
#
19-
# ----
20-
#
21-
# ./go script: unified development environment interface
22-
#
23-
# Inspired by:
24-
# http://www.thoughtworks.com/insights/blog/praise-go-script-part-i
25-
# http://www.thoughtworks.com/insights/blog/praise-go-script-part-ii
26-
#
27-
# Author: Mike Bland (michael.bland@gsa.gov)
28-
# Date: 2015-04-15
292

30-
MIN_VERSION = "2.1.5"
3+
require 'English'
314

32-
unless RUBY_VERSION >= MIN_VERSION
33-
puts <<EOF
5+
Dir.chdir File.dirname(__FILE__)
346

35-
*** ABORTING: Unsupported Ruby version ***
36-
37-
Ruby version #{MIN_VERSION} or greater is required to work with the Hub, but
38-
this Ruby is version #{RUBY_VERSION}. Consider using a version manager such as
39-
rbenv (https://github.com/sstephenson/rbenv) or rvm (https://rvm.io/)
40-
to install a Ruby version specifically for Hub development.
41-
42-
EOF
43-
exit 1
7+
def try_command_and_restart(command)
8+
exit $CHILD_STATUS.exitstatus unless system command
9+
exec RbConfig.ruby, *[$PROGRAM_NAME].concat(ARGV)
4410
end
4511

46-
def exec_cmd(cmd)
47-
exit $?.exitstatus unless system(cmd)
12+
begin
13+
require 'bundler/setup' if File.exist? 'Gemfile'
14+
rescue LoadError
15+
try_command_and_restart 'gem install bundler'
16+
rescue SystemExit
17+
try_command_and_restart 'bundle install'
4818
end
4919

50-
def init
51-
begin
52-
require 'bundler'
53-
rescue LoadError
54-
puts "Installing Bundler gem..."
55-
exec_cmd 'gem install bundler'
56-
puts "Bundler installed; installing gems"
57-
end
58-
exec_cmd 'bundle install'
20+
begin
21+
require 'go_script'
22+
rescue LoadError
23+
try_command_and_restart 'gem install go_script' unless File.exist? 'Gemfile'
24+
abort "Please add \"gem 'go_script'\" to your Gemfile"
5925
end
6026

61-
def update_gems
62-
exec_cmd 'bundle update'
63-
exec_cmd 'git add Gemfile.lock'
64-
end
27+
require 'guides_style_18f'
6528

66-
JEKYLL_BUILD_CMD = "exec jekyll build --trace"
67-
JEKYLL_SERVE_CMD = "exec jekyll serve --trace"
29+
extend GoScript
30+
check_ruby_version '2.1.5'
6831

69-
def serve
70-
exec "bundle #{JEKYLL_SERVE_CMD}"
71-
end
32+
command_group :dev, 'Development commands'
7233

73-
def build
74-
exec_cmd "bundle #{JEKYLL_BUILD_CMD}"
34+
def_command :update_nav, 'Update the \'navigation:\' data in _config.yml' do
35+
GuidesStyle18F.update_navigation_configuration Dir.pwd
7536
end
7637

77-
# Groups a set of commands by common function.
78-
class CommandGroup
79-
attr_accessor :description, :commands
80-
private_class_method :new
81-
@@groups = Array.new
82-
83-
# @param description [String] short description of the group
84-
# @param commands [Hash<Symbol,String>] mapping from command function name
85-
# to a brief description; each key must be the name of a function in this
86-
# script
87-
def initialize(description, commands)
88-
@description = description
89-
@commands = commands
90-
end
91-
92-
def to_s
93-
padding = @commands.keys.max_by {|i| i.size}.size + 2
94-
["\n#{@description}"].concat(
95-
@commands.map {|name, desc| " %-#{padding}s#{desc}" % name}).join("\n")
96-
end
97-
98-
def self.add_group(description, commands)
99-
@@groups << new(description, commands)
100-
end
101-
102-
def self.groups
103-
@@groups
104-
end
105-
106-
def self.check_command_exists(command_symbol)
107-
all_commands = @@groups.map {|i| i.commands.keys}.flatten
108-
unless all_commands.member? command_symbol
109-
puts "Unknown option or command: #{command_symbol}"
110-
usage(exitstatus: 1)
111-
end
112-
end
38+
def_command :update_theme, 'Update the guides_style_18f gem' do
39+
exec_cmd 'bundle update --source guides_style_18f'
11340
end
11441

115-
CommandGroup.add_group(
116-
'Development commands',
117-
{
118-
:init => 'Set up the dev environment',
119-
:update_gems => 'Execute Bundler to update gem set',
120-
:serve => 'Serves the site at localhost:4000',
121-
:build => 'Builds the site',
122-
})
123-
124-
def usage(exitstatus: 0)
125-
puts <<EOF
126-
Usage: #{$0} [options] [command]
42+
def_command :update_gems, 'Update Ruby gems' do |gems|
43+
update_gems gems
44+
end
12745

128-
options:
129-
-h,--help Show this help
130-
EOF
131-
CommandGroup.groups.each {|s| puts s}
132-
exit exitstatus
46+
def_command :serve, 'Serve the site at localhost:4000' do
47+
serve_jekyll
13348
end
13449

135-
usage(exitstatus: 1) unless ARGV.size == 1
136-
command = ARGV.shift
137-
usage if ['-h', '--help'].include? command
50+
def_command :build, 'Build the site' do
51+
build_jekyll
52+
end
13853

139-
command = command.to_sym
140-
CommandGroup.check_command_exists command
141-
send command
54+
execute_command ARGV

0 commit comments

Comments
 (0)