guides_style_18f 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ea930944731dbf4c720382a295ad2f8d1298db6f
4
- data.tar.gz: 5f462e287ce9fee7fc67bbd2ec146b991bdc56db
3
+ metadata.gz: cd5d447399f636ae03c629d890ffcb51ff356411
4
+ data.tar.gz: 631d01dd0ade29050945220ba2a7754205e4af62
5
5
  SHA512:
6
- metadata.gz: 308c09132a3f41e8fb39cc4b897753c3fc4cee371f13dce3ea4c44ed0152fc7e1df605ff7d3c91ce8623d0c905e599ca482a5125fcec2fa1883415b1d1916e2c
7
- data.tar.gz: 9164d3b7762a6c7c7f0ace8e095ccc55f5824776a6c95e68b5e86cc1cac46fabc6a0888b9192c65222d10a8d60e93789bd3c017ef940912072190f81211885da
6
+ metadata.gz: fe1e5f02a9eed69c042d4c7ec71a17757aadd476e186f42540f0f6216b165a0986afbe20f8ccac897b2d35ce10ed6a1020b859df41fd4b5d484341bd673765c2
7
+ data.tar.gz: 85baa1f257bdcc03fd4d2b126ae5e4d4ac11c667ed73a919d3bafe44a7087cd74faa374188852ea2ab861b9f49592ec2178bcd255042018c110ce9397f5de31b
@@ -3,6 +3,49 @@
3
3
  require 'safe_yaml'
4
4
 
5
5
  module GuidesStyle18F
6
+ module FrontMatter
7
+ def self.load(basedir)
8
+ Dir[File.join basedir, 'pages', '**', '*.md'].map do |f|
9
+ [f[basedir.size + 1..-1], SafeYAML.load_file(f, safe: true)]
10
+ end.to_h
11
+ end
12
+
13
+ def self.validate_with_message_upon_error(front_matter)
14
+ files_with_errors = validate front_matter
15
+ return if files_with_errors.empty?
16
+ message = ['The following files have errors in their front matter:']
17
+ files_with_errors.each do |file, errors|
18
+ message << " #{file}:"
19
+ message.concat errors.map { |error| " #{error}" }
20
+ end
21
+ message.join "\n" unless message.size == 1
22
+ end
23
+
24
+ def self.validate(front_matter)
25
+ front_matter.map do |file, data|
26
+ next [file, ['no front matter defined']] unless data.instance_of? Hash
27
+ errors = missing_property_errors(data) + permalink_errors(data)
28
+ [file, errors] unless errors.empty?
29
+ end.compact.to_h
30
+ end
31
+
32
+ def self.missing_property_errors(data)
33
+ properties = %w(title permalink)
34
+ properties.map { |p| "no `#{p}:` property" unless data[p] }.compact
35
+ end
36
+ private_class_method :missing_property_errors
37
+
38
+ def self.permalink_errors(data)
39
+ pl = data['permalink']
40
+ return [] if pl.nil?
41
+ errors = []
42
+ errors << "`permalink:` does not begin with '/'" unless pl.start_with? '/'
43
+ errors << "`permalink:` does not end with '/'" unless pl.end_with? '/'
44
+ errors
45
+ end
46
+ private_class_method :permalink_errors
47
+ end
48
+
6
49
  # Automatically updates the `navigation:` field in _config.yml.
7
50
  #
8
51
  # Does this by parsing the front matter from files in `pages/`. Preserves the
@@ -27,10 +70,10 @@ module GuidesStyle18F
27
70
  private_class_method :update_navigation_data
28
71
 
29
72
  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|
73
+ front_matter = FrontMatter.load basedir
74
+ errors = FrontMatter.validate_with_message_upon_error front_matter
75
+ abort errors + "\n_config.yml not updated" if errors
76
+ pages_data = front_matter.values.group_by do |fm|
34
77
  fm['parent'].nil? ? 'parents' : 'children'
35
78
  end
36
79
  %w(parents children).each { |category| pages_data[category] ||= [] }
@@ -1,5 +1,5 @@
1
1
  # @author Mike Bland (michael.bland@gsa.gov)
2
2
 
3
3
  module GuidesStyle18F
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.1'
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.1.0
4
+ version: 0.1.1
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-28 00:00:00.000000000 Z
11
+ date: 2015-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll