guides_style_18f 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 33166601f73e4e3de2c486510d864ba4a0287ddc
4
- data.tar.gz: 59c1b03d44b1bc245abec3fcd3e2cdd6e185db95
3
+ metadata.gz: ea930944731dbf4c720382a295ad2f8d1298db6f
4
+ data.tar.gz: 5f462e287ce9fee7fc67bbd2ec146b991bdc56db
5
5
  SHA512:
6
- metadata.gz: 5b2b60050dc12ada4d745a798b9a5f46d888513598f6bcc92062e6a3fa5dab617ca88e3fa254477fef21041aba1690ff0521cc77861272d68d2ce2ddb0971e53
7
- data.tar.gz: e09a3773e817951991a3f5e64c73c0a4bddd962f1f93b59addd076168148c3ac46574bf0895ca59455800eedba43b657b4f7b7f50023312913b288e0f87b8569
6
+ metadata.gz: 308c09132a3f41e8fb39cc4b897753c3fc4cee371f13dce3ea4c44ed0152fc7e1df605ff7d3c91ce8623d0c905e599ca482a5125fcec2fa1883415b1d1916e2c
7
+ data.tar.gz: 9164d3b7762a6c7c7f0ace8e095ccc55f5824776a6c95e68b5e86cc1cac46fabc6a0888b9192c65222d10a8d60e93789bd3c017ef940912072190f81211885da
@@ -4,5 +4,7 @@ require 'guides_style_18f/assets'
4
4
  require 'guides_style_18f/generator'
5
5
  require 'guides_style_18f/includes'
6
6
  require 'guides_style_18f/layouts'
7
+ require 'guides_style_18f/navigation'
8
+ require 'guides_style_18f/repository'
7
9
  require 'guides_style_18f/sass'
8
10
  require 'guides_style_18f/version'
@@ -1,6 +1,6 @@
1
1
  # @author Mike Bland (michael.bland@gsa.gov)
2
2
 
3
- require 'jekyll/generator'
3
+ require 'jekyll'
4
4
 
5
5
  module GuidesStyle18F
6
6
  class Generator < ::Jekyll::Generator
@@ -0,0 +1,121 @@
1
+ # @author Mike Bland (michael.bland@gsa.gov)
2
+
3
+ require 'safe_yaml'
4
+
5
+ module GuidesStyle18F
6
+ # Automatically updates the `navigation:` field in _config.yml.
7
+ #
8
+ # Does this by parsing the front matter from files in `pages/`. Preserves the
9
+ # existing order of items in `navigation:`, but new items may need to be
10
+ # reordered manually.
11
+ def self.update_navigation_configuration(basedir)
12
+ config_path = File.join basedir, '_config.yml'
13
+ config_data = SafeYAML.load_file config_path, safe: true
14
+ return unless config_data
15
+ nav_data = config_data['navigation'] || []
16
+ nav_data = update_navigation_data nav_data, basedir
17
+ write_navigation_data_to_config_file config_path, nav_data
18
+ end
19
+
20
+ def self.update_navigation_data(nav_data, basedir)
21
+ pages_data = pages_front_matter basedir
22
+ children = pages_data['children'].map { |child| child['title'].downcase }
23
+ nav_data.reject! { |nav| children.include? nav['text'].downcase }
24
+ update_parent_nav_data nav_data, pages_data['parents']
25
+ add_children_to_parents nav_data, pages_data['children']
26
+ end
27
+ private_class_method :update_navigation_data
28
+
29
+ def self.pages_front_matter(basedir)
30
+ front_matter = Dir[File.join basedir, 'pages', '**', '*.md'].map do |f|
31
+ SafeYAML.load_file f, safe: true
32
+ end
33
+ pages_data = front_matter.group_by do |fm|
34
+ fm['parent'].nil? ? 'parents' : 'children'
35
+ end
36
+ %w(parents children).each { |category| pages_data[category] ||= [] }
37
+ pages_data
38
+ end
39
+ private_class_method :pages_front_matter
40
+
41
+ def self.update_parent_nav_data(nav_data, parents)
42
+ nav_by_title = nav_data_by_title nav_data
43
+ parents.each do |page|
44
+ page_nav = page_nav page
45
+ title = page_nav['text'].downcase
46
+ if nav_by_title.member? title
47
+ nav_by_title[title].merge! page_nav
48
+ else
49
+ nav_data << page_nav
50
+ end
51
+ end
52
+ end
53
+ private_class_method :update_parent_nav_data
54
+
55
+ def self.nav_data_by_title(nav_data)
56
+ nav_data.map { |nav| [nav['text'].downcase, nav] }.to_h
57
+ end
58
+ private_class_method :nav_data_by_title
59
+
60
+ def self.page_nav(front_matter)
61
+ { 'text' => front_matter['title'],
62
+ 'url' => "#{front_matter['permalink'].split('/').last}/",
63
+ 'internal' => true,
64
+ }
65
+ end
66
+ private_class_method :page_nav
67
+
68
+ def self.add_children_to_parents(nav_data, children)
69
+ parents_by_title = nav_data_by_title nav_data
70
+ children.each { |child| add_child_to_parent child, parents_by_title }
71
+ nav_data
72
+ end
73
+ private_class_method :add_children_to_parents
74
+
75
+ def self.add_child_to_parent(child, parents_by_title)
76
+ child_nav_data = page_nav child
77
+ title = child_nav_data['text'].downcase
78
+ parent = parent child, parents_by_title
79
+ children = parent['children'] ||= []
80
+ children_by_title = children.map { |c| [c['text'].downcase, c] }.to_h
81
+
82
+ if children_by_title.member? title
83
+ children_by_title[title].merge! child_nav_data
84
+ else
85
+ children << child_nav_data
86
+ end
87
+ end
88
+ private_class_method :add_child_to_parent
89
+
90
+ def self.parent(child, parents_by_title)
91
+ parent = parents_by_title[child['parent'].downcase]
92
+ return parent unless parent.nil?
93
+ fail StandardError, 'Parent page not present in existing ' \
94
+ "config: \"#{child['parent']}\" needed by: \"#{child['title']}\""
95
+ end
96
+ private_class_method :parent
97
+
98
+ def self.write_navigation_data_to_config_file(config_path, nav_data)
99
+ lines = []
100
+ in_navigation = false
101
+ open(config_path).each_line do |line|
102
+ in_navigation = process_line line, lines, nav_data, in_navigation
103
+ end
104
+ File.write config_path, lines.join
105
+ end
106
+ private_class_method :write_navigation_data_to_config_file
107
+
108
+ def self.process_line(line, lines, nav_data, in_navigation = false)
109
+ if !in_navigation && line.start_with?('navigation:')
110
+ lines << line << nav_data.to_yaml["---\n".size..-1]
111
+ in_navigation = true
112
+ elsif in_navigation
113
+ in_navigation = line.start_with?(' ') || line.start_with?('-')
114
+ lines << line unless in_navigation
115
+ else
116
+ lines << line
117
+ end
118
+ in_navigation
119
+ end
120
+ private_class_method :process_line
121
+ end
@@ -0,0 +1,74 @@
1
+ # @author Mike Bland (michael.bland@gsa.gov)
2
+
3
+ require 'English'
4
+ require 'fileutils'
5
+
6
+ module GuidesStyle18F
7
+ TEMPLATE_FILES = %w(
8
+ pages/child-page.md
9
+ pages/config.md
10
+ pages/github.md
11
+ pages/images.md
12
+ pages/new-page.md
13
+ pages/posting.md
14
+ images/18f-pages.png
15
+ images/description.png
16
+ images/gh-add-guide.png
17
+ images/gh-branches-link.png
18
+ images/gh-default-branch.png
19
+ images/gh-settings-button.png
20
+ images/gh-webhook.png
21
+ images/images.png
22
+ )
23
+
24
+ def self.clear_template_files_and_create_new_repository(
25
+ basedir, outstream = $stdout)
26
+ remove_template_files basedir, outstream
27
+ delete_create_repo_command_from_go_script basedir, outstream
28
+ create_new_git_repository basedir, outstream
29
+ end
30
+
31
+ def self.remove_template_files(basedir, outstream)
32
+ Dir.chdir basedir do
33
+ outstream.puts 'Clearing Guides Template files.'
34
+ files = TEMPLATE_FILES.map { |f| File.join basedir, f }
35
+ .select { |f| File.exist? f }
36
+ File.delete(*files)
37
+ end
38
+ end
39
+
40
+ def self.delete_create_repo_command_from_go_script(basedir, outstream)
41
+ Dir.chdir basedir do
42
+ outstream.puts 'Removing `:create_repo` command from the `./go` script.'
43
+ go_script = File.join basedir, 'go'
44
+ content = File.read go_script
45
+ match = /\ndef_command\(\n :create_repo,.*?end\n/m.match content
46
+ content = "#{match.pre_match}#{match.post_match}" unless match.nil?
47
+ File.write go_script, content
48
+ end
49
+ end
50
+
51
+ GIT_COMMANDS = {
52
+ 'Creating a new git repository.' => 'git init',
53
+ 'Creating 18f-pages branch.' => 'git checkout -b 18f-pages',
54
+ 'Adding files for initial commit.' => 'git add .',
55
+ }
56
+
57
+ def self.create_new_git_repository(basedir, outstream)
58
+ Dir.chdir basedir do
59
+ outstream.puts 'Removing old git repository.'
60
+ FileUtils.rm_rf '.git'
61
+ GIT_COMMANDS.each do |description, command|
62
+ outstream.puts description
63
+ exec_cmd_capture_output command, outstream
64
+ end
65
+ outstream.puts "All done! Run \'git commit\' to create your first commit."
66
+ end
67
+ end
68
+ private_class_method :create_new_git_repository
69
+
70
+ def self.exec_cmd_capture_output(command, outstream)
71
+ opts = { out: outstream, err: outstream }
72
+ exit $CHILD_STATUS.exitstatus unless system command, opts
73
+ end
74
+ end
@@ -168,10 +168,7 @@ Navigation
168
168
 
169
169
  .sidebar-nav a {
170
170
  display: block;
171
- padding-bottom: 10px;
172
- padding-right: 10px;
173
- padding-left: 14px;
174
- padding-top: 10px;
171
+ padding: 10px;
175
172
  -webkit-transition: .4s;
176
173
  transition: .4s;
177
174
  width: 80%;
@@ -203,6 +200,7 @@ Navigation
203
200
  list-style: none;
204
201
  border-bottom: 1px solid #babbbd;
205
202
  font-size: 1.125em;
203
+ padding-left: 4px;
206
204
  overflow: hidden;
207
205
  }
208
206
 
@@ -1,5 +1,5 @@
1
1
  # @author Mike Bland (michael.bland@gsa.gov)
2
2
 
3
3
  module GuidesStyle18F
4
- VERSION = '0.0.1'
4
+ VERSION = '0.1.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: guides_style_18f
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Bland
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-22 00:00:00.000000000 Z
11
+ date: 2015-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -66,6 +66,48 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: codeclimate-test-reporter
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: coveralls
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
69
111
  - !ruby/object:Gem::Dependency
70
112
  name: bundler
71
113
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +122,20 @@ dependencies:
80
122
  - - ">="
81
123
  - !ruby/object:Gem::Version
82
124
  version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
83
139
  description: Provides consistent style elements for documents based on the 18F Guides
84
140
  Template (https://pages.18f.gov/guides-template/). The 18F Guides theme is based
85
141
  on DOCter (https://github.com/cfpb/docter/) from CFPB (http://cfpb.github.io/).
@@ -117,6 +173,8 @@ files:
117
173
  - lib/guides_style_18f/includes/sidebar.html
118
174
  - lib/guides_style_18f/layouts.rb
119
175
  - lib/guides_style_18f/layouts/default.html
176
+ - lib/guides_style_18f/navigation.rb
177
+ - lib/guides_style_18f/repository.rb
120
178
  - lib/guides_style_18f/sass.rb
121
179
  - lib/guides_style_18f/sass/_guides_style_18f_custom.scss
122
180
  - lib/guides_style_18f/sass/_guides_style_18f_main.scss