jekyll-everypolitician 0.2.0 → 0.3.0
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 +4 -4
- data/.travis.yml +3 -0
- data/CHANGELOG.md +15 -2
- data/README.md +27 -2
- data/bin/console +4 -5
- data/jekyll-everypolitician.gemspec +1 -0
- data/lib/jekyll/everypolitician/version.rb +1 -1
- data/lib/jekyll/everypolitician.rb +41 -13
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9387daa16bfcd547db3dcf3c7b7927d72af361ac
|
4
|
+
data.tar.gz: 7530ef6cd4232c9ed4f07bc723d6ccd142e67938
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de2310fa3695a3ab4b8a89e9a95018914cab6315d6b0ff06246fea9300196a5225a4a7e202a2b85c0f2a75ff82ae80373050af98ee5fce00560b0a948e0d99bf
|
7
|
+
data.tar.gz: 6bfd4923784f3ea99103a0213cd6bcb819ebc890231d1367607d44af761c7ad7a63ca2dbb4f64ec1dd19ce5a6609273809fe52361b975398924b105108456fee
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -2,9 +2,16 @@
|
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
This project adheres to [Semantic Versioning](http://semver.org/).
|
4
4
|
|
5
|
-
## 0.
|
5
|
+
## [0.3.0] - 2015-12-02
|
6
6
|
|
7
|
-
|
7
|
+
### Changed
|
8
|
+
|
9
|
+
- `everypolitician_url` in `_config.yml` has been renamed to `everypolitician` and is now a hash. See the [Usage section in the README](https://github.com/everypolitician/jekyll-everypolitician/blob/2d9d9d562e99608b33038f712305c179e0196c8e/README.md#usage) for more details on how to use this. This means you can specify multiple sources for your data [#2](https://github.com/everypolitician/jekyll-everypolitician/issues/2)
|
10
|
+
- `persons` collection is now called `people` [#3](https://github.com/everypolitician/jekyll-everypolitician/issues/3)
|
11
|
+
|
12
|
+
### Fixed
|
13
|
+
|
14
|
+
- We no longer raise an error if the config is missing.
|
8
15
|
|
9
16
|
## [0.2.0] - 2015-12-02
|
10
17
|
|
@@ -12,4 +19,10 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
12
19
|
|
13
20
|
- You can now set `everypolitician_url` in `_config.yml` to an everypolitician popolo url
|
14
21
|
|
22
|
+
## 0.1.0 - 2015-12-02
|
23
|
+
|
24
|
+
- Initial release
|
25
|
+
|
26
|
+
|
15
27
|
[0.2.0]: https://github.com/everypolitician/jekyll-everypolitician/compare/v0.1.0...v0.2.0
|
28
|
+
[0.3.0]: https://github.com/everypolitician/jekyll-everypolitician/compare/v0.2.0...v0.3.0
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Jekyll::Everypolitician
|
1
|
+
# Jekyll::Everypolitician [](https://travis-ci.org/everypolitician/jekyll-everypolitician)
|
2
2
|
|
3
3
|
Use [EveryPolitician](http://everypolitician.org) data in your Jekyll generated site.
|
4
4
|
|
@@ -29,7 +29,32 @@ gems:
|
|
29
29
|
|
30
30
|
## Usage
|
31
31
|
|
32
|
-
|
32
|
+
You need to configure Jekyll so it knows which data to use. In your `_config.yml` add the following to tell jekyll-everypolitician where to get the data from:
|
33
|
+
|
34
|
+
```yaml
|
35
|
+
everypolitician:
|
36
|
+
sources:
|
37
|
+
- https://github.com/everypolitician/everypolitician-data/raw/master/data/Australia/Representatives/ep-popolo-v1.0.json
|
38
|
+
```
|
39
|
+
|
40
|
+
This tells it to use the data for the Australian Representatives, and specifies which version of the data to use, in this case `master`.
|
41
|
+
|
42
|
+
When sources is an array, as in the example above, the collections that are created are `people`, `organizations`, `areas` and `events`.
|
43
|
+
|
44
|
+
Sometimes you'll want more than one source, for example you might want the upper house as well. For this case you can specify sources as a hash:
|
45
|
+
|
46
|
+
```yaml
|
47
|
+
everypolitician:
|
48
|
+
sources:
|
49
|
+
assembly: https://github.com/everypolitician/everypolitician-data/raw/master/data/Australia/Representatives/ep-popolo-v1.0.json
|
50
|
+
senate: https://github.com/everypolitician/everypolitician-data/raw/master/data/Australia/Senate/ep-popolo-v1.0.json
|
51
|
+
```
|
52
|
+
|
53
|
+
When `sources` is a hash like this the collections that are created are prefixed with the key of the hash, e.g. `assembly_people`, `senate_people`, `assembly_areas` etc.
|
54
|
+
|
55
|
+
### Layouts
|
56
|
+
|
57
|
+
This plugin will try and use layouts that are named after the generated collections. So in the examples above if you'd specified `sources` as an array then it would try to use `_layouts/people.html` as the layout for the `people` collection. Similarly if you specify `sources` as a hash then it would try to use something like `_layouts/assembly_people.html` for the `assembly_people` collection.
|
33
58
|
|
34
59
|
## Development
|
35
60
|
|
data/bin/console
CHANGED
@@ -6,9 +6,8 @@ require 'jekyll/everypolitician'
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
# Pry.start
|
9
|
+
SITE = Jekyll::Site.new(Jekyll.configuration)
|
10
|
+
SITE.config['everypolitician_url'] = 'test/fixtures/vatican-ep-popolo-v1.0.json'
|
12
11
|
|
13
|
-
require '
|
14
|
-
|
12
|
+
require 'pry'
|
13
|
+
Pry.start
|
@@ -10,44 +10,72 @@ require 'active_support/core_ext/string'
|
|
10
10
|
module Jekyll
|
11
11
|
module Everypolitician
|
12
12
|
class Generator < Jekyll::Generator
|
13
|
+
COLLECTION_MAPPING = {
|
14
|
+
'persons' => 'people'
|
15
|
+
}
|
16
|
+
|
13
17
|
def generate(site)
|
14
|
-
|
18
|
+
return unless site.config.key?('everypolitician')
|
19
|
+
sources = site.config['everypolitician']['sources']
|
20
|
+
if sources.is_a?(Array)
|
21
|
+
generate_collections(site, sources.first)
|
22
|
+
elsif sources.is_a?(Hash)
|
23
|
+
sources.each do |prefix, source|
|
24
|
+
generate_collections(site, source, prefix)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def generate_collections(site, source, prefix = nil)
|
30
|
+
popolo = JSON.parse(open(source).read)
|
15
31
|
memberships = popolo['memberships']
|
16
|
-
popolo.keys.each do |
|
17
|
-
next unless popolo[
|
32
|
+
popolo.keys.each do |type|
|
33
|
+
next unless popolo[type].is_a?(Array)
|
34
|
+
collection_name = collection_name_for(type, prefix)
|
18
35
|
collection = Collection.new(site, collection_name)
|
19
|
-
popolo[
|
36
|
+
popolo[type].each do |item|
|
20
37
|
next unless item['id']
|
21
38
|
path = File.join(site.source, "_#{collection_name}", "#{item['id'].parameterize}.md")
|
22
39
|
doc = Document.new(path, collection: collection, site: site)
|
23
40
|
doc.merge_data!(item)
|
24
41
|
doc.merge_data!(
|
25
42
|
'title' => item['name'],
|
26
|
-
'
|
27
|
-
'memberships' => memberships_for(item, collection_name, memberships)
|
43
|
+
'memberships' => memberships_for(item, type, memberships)
|
28
44
|
)
|
45
|
+
if site.layouts.key?(collection_name)
|
46
|
+
doc.merge_data!('layout' => collection_name)
|
47
|
+
end
|
29
48
|
collection.docs << doc
|
30
49
|
end
|
31
50
|
site.collections[collection_name] = collection
|
32
51
|
end
|
33
52
|
|
34
53
|
memberships.each do |membership|
|
35
|
-
membership['person'] = site.collections['persons'].docs.find { |p| p.data['id'] == membership['person_id'] }
|
36
|
-
membership['area'] = site.collections['areas'].docs.find { |a| a.data['id'] == membership['area_id'] }
|
37
|
-
membership['legislative_period'] = site.collections['events'].docs.find { |e| e.data['id'] == membership['legislative_period_id'] }
|
38
|
-
membership['organization'] = site.collections['organizations'].docs.find { |o| o.data['id'] == membership['organization_id'] }
|
39
|
-
membership['party'] = site.collections['organizations'].docs.find { |o| o.data['id'] == membership['on_behalf_of_id'] }
|
54
|
+
membership['person'] = site.collections[collection_name_for('persons', prefix)].docs.find { |p| p.data['id'] == membership['person_id'] }
|
55
|
+
membership['area'] = site.collections[collection_name_for('areas', prefix)].docs.find { |a| a.data['id'] == membership['area_id'] }
|
56
|
+
membership['legislative_period'] = site.collections[collection_name_for('events', prefix)].docs.find { |e| e.data['id'] == membership['legislative_period_id'] }
|
57
|
+
membership['organization'] = site.collections[collection_name_for('organizations', prefix)].docs.find { |o| o.data['id'] == membership['organization_id'] }
|
58
|
+
membership['party'] = site.collections[collection_name_for('organizations', prefix)].docs.find { |o| o.data['id'] == membership['on_behalf_of_id'] }
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def collection_name_for(type, prefix = nil)
|
63
|
+
name = COLLECTION_MAPPING[type] || type
|
64
|
+
if prefix
|
65
|
+
[prefix, name].join('_')
|
66
|
+
else
|
67
|
+
name
|
40
68
|
end
|
41
69
|
end
|
42
70
|
|
43
|
-
def memberships_for(item,
|
71
|
+
def memberships_for(item, type, memberships)
|
44
72
|
map = {
|
45
73
|
'areas' => 'area_id',
|
46
74
|
'persons' => 'person_id',
|
47
75
|
'events' => 'legislative_period_id',
|
48
76
|
'organizations' => 'on_behalf_of_id'
|
49
77
|
}
|
50
|
-
memberships.find_all { |m| m[map[
|
78
|
+
memberships.find_all { |m| m[map[type]] == item['id'] }
|
51
79
|
end
|
52
80
|
end
|
53
81
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-everypolitician
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Mytton
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry
|
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'
|
83
97
|
description:
|
84
98
|
email:
|
85
99
|
- chrismytton@gmail.com
|