jekyll-conrefifier 0.1.2 → 0.2.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/README.md +58 -0
- data/lib/jekyll-conrefifier.rb +56 -1
- data/lib/version.rb +1 -1
- data/spec/conrefifier_spec.rb +24 -0
- data/spec/fixtures/_config.yml +12 -0
- data/spec/fixtures/_data/categories.yml +1 -1
- data/spec/fixtures/_data/enterprise_filtered_categories.yml +25 -0
- data/spec/fixtures/_data/filtered_categories.yml +25 -0
- data/spec/fixtures/enterprise_filtered_index.html +26 -0
- data/spec/fixtures/filtered_index.html +26 -0
- metadata +6 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a3be384c388b690824874267ef348482dda86d27
|
|
4
|
+
data.tar.gz: 157ee1105193aac294cbbd2b9c84e6113951de4c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 262e12f3d372e557388b9a0d156392c7d2f9a856daaef6984cb8ddd144ace9bcd8dd585d67ae9bf527240fbd7c44bd9485e9f8c5130ba820ba63514033acb0a2
|
|
7
|
+
data.tar.gz: 51ab2c709f54d4915a8e6c9b69da097c57b3ee06c9a035312ae0c96fdab38b32ebcf29c432a7ac9d419d1977ecd3099f667a2c7ee7c7e432f7ced32867f70593
|
data/README.md
CHANGED
|
@@ -56,3 +56,61 @@ Bootcamp:
|
|
|
56
56
|
```
|
|
57
57
|
|
|
58
58
|
The value renders out to "GitHub Glossary", just like above.
|
|
59
|
+
|
|
60
|
+
## Liquid filtering within data files
|
|
61
|
+
|
|
62
|
+
You can add filters within data files, to show or hide content depending on certain variable criteria.
|
|
63
|
+
|
|
64
|
+
For example, given a data file that looks like this:
|
|
65
|
+
|
|
66
|
+
``` yaml
|
|
67
|
+
Listing:
|
|
68
|
+
{% if page.version == '2.0' %}
|
|
69
|
+
- Article v2.0
|
|
70
|
+
{% endif %}
|
|
71
|
+
{% if page.version != '2.0' %}
|
|
72
|
+
- Article v2.1
|
|
73
|
+
{% endif %}
|
|
74
|
+
|
|
75
|
+
{% unless page.version == '2.0' %}
|
|
76
|
+
Ignored:
|
|
77
|
+
- Item1
|
|
78
|
+
- Item 2
|
|
79
|
+
{% endunless %}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
If `page.version` is equal to `'2.0'`, only `Listing: - Artivle v2.0` will render.
|
|
83
|
+
|
|
84
|
+
To support such a syntax, you'll need to add a new entry in your `config.yml` that defines your variables, like this:
|
|
85
|
+
|
|
86
|
+
``` yaml
|
|
87
|
+
|
|
88
|
+
data_file_variables:
|
|
89
|
+
-
|
|
90
|
+
scope:
|
|
91
|
+
path: ""
|
|
92
|
+
values:
|
|
93
|
+
version: "2.0"
|
|
94
|
+
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
`data_file_variables` is an array of hashes. The `scope` key defines which data files are affected by the variables; the data file must match the path define in `path`. Regular expression syntaxes are supported in `path`, and a blank `path` refers to every data file. The `values` key specifies every key you want to support in your data file.
|
|
98
|
+
|
|
99
|
+
Here's a more complex example:
|
|
100
|
+
|
|
101
|
+
``` yaml
|
|
102
|
+
data_file_variables:
|
|
103
|
+
-
|
|
104
|
+
scope:
|
|
105
|
+
path: ""
|
|
106
|
+
values:
|
|
107
|
+
version: "2.0"
|
|
108
|
+
-
|
|
109
|
+
scope:
|
|
110
|
+
path: "ent\\w+_"
|
|
111
|
+
values:
|
|
112
|
+
version: "2.1"
|
|
113
|
+
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
In this case, every data file has a `page.version` of `2.0`. However, only data files prefixed with `ent`, containing one or more word characters (`\w+`), and followed by an underscore (`_`), have a value of `2.1`.
|
data/lib/jekyll-conrefifier.rb
CHANGED
|
@@ -22,7 +22,7 @@ module Jekyll
|
|
|
22
22
|
old_read(opts)
|
|
23
23
|
@data.each_pair do |key, value|
|
|
24
24
|
if value =~ /\{\{.+?\}\}/
|
|
25
|
-
value = Liquid::Template.parse(value).render({
|
|
25
|
+
value = Liquid::Template.parse(value).render({ 'site' => { 'data' => @site.data }.merge(@site.config) })
|
|
26
26
|
@data[key] = Jekyll::Renderer.new(@site, self).convert(value)
|
|
27
27
|
@data[key] = @data[key].sub(/^<p>/, '').sub(/<\/p>$/, '').strip
|
|
28
28
|
end
|
|
@@ -32,6 +32,61 @@ module Jekyll
|
|
|
32
32
|
|
|
33
33
|
class Site
|
|
34
34
|
alias_method :old_read, :read
|
|
35
|
+
alias_method :old_read_data_to, :read_data_to
|
|
36
|
+
|
|
37
|
+
def in_source_dir(*paths)
|
|
38
|
+
paths.reduce(source) do |base, path|
|
|
39
|
+
Jekyll.sanitized_path(base, path)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# allows us to filter data file content out on conditionals, eg. `{% if page.version == ... %}`
|
|
44
|
+
def read_data_to(dir, data)
|
|
45
|
+
return unless File.directory?(dir) && (!safe || !File.symlink?(dir))
|
|
46
|
+
|
|
47
|
+
entries = Dir.chdir(dir) do
|
|
48
|
+
Dir['*.{yaml,yml,json,csv}'] + Dir['*'].select { |fn| File.directory?(fn) }
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
entries.each do |entry|
|
|
52
|
+
path = in_source_dir(dir, entry)
|
|
53
|
+
next if File.symlink?(path) && safe
|
|
54
|
+
|
|
55
|
+
key = sanitize_filename(File.basename(entry, '.*'))
|
|
56
|
+
if File.directory?(path)
|
|
57
|
+
read_data_to(path, data[key] = {})
|
|
58
|
+
else
|
|
59
|
+
case File.extname(path).downcase
|
|
60
|
+
when '.csv'
|
|
61
|
+
data[key] = CSV.read(path, :headers => true).map(&:to_hash)
|
|
62
|
+
else
|
|
63
|
+
contents = File.read(path)
|
|
64
|
+
if (matches = contents.scan /(\{% (?:if|unless).+? %\}.*?\{% end(?:if|unless) %\})/m)
|
|
65
|
+
unless matches.empty?
|
|
66
|
+
filename = File.basename(path)
|
|
67
|
+
contents = apply_vars_to_datafile(contents, filename, matches, config['data_file_variables'])
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
data[key] = SafeYAML.load(contents)
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def apply_vars_to_datafile(contents, filename, matches, data_file_variables)
|
|
77
|
+
return contents if data_file_variables.nil?
|
|
78
|
+
data_vars = {}
|
|
79
|
+
scopes = data_file_variables.select { |v| v['scope']['path'].empty? || Regexp.new(v['scope']['path']) =~ filename }
|
|
80
|
+
scopes.each do |scope|
|
|
81
|
+
data_vars = data_vars.merge(scope['values'])
|
|
82
|
+
end
|
|
83
|
+
temp_config = self.config.merge({ 'page' => data_vars })
|
|
84
|
+
matches.each do |match|
|
|
85
|
+
contents = contents.sub(match.first, Liquid::Template.parse(match.first).render(temp_config))
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
contents
|
|
89
|
+
end
|
|
35
90
|
|
|
36
91
|
# allow us to use any variable within Jekyll data files; for example:
|
|
37
92
|
# - '{{ site.data.conrefs.product_name[site.audience] }} Glossary'
|
data/lib/version.rb
CHANGED
data/spec/conrefifier_spec.rb
CHANGED
|
@@ -29,4 +29,28 @@ describe("Conrefifier") do
|
|
|
29
29
|
index_contents = File.read(index_file)
|
|
30
30
|
expect(index_contents).to include("<strong>wow!</strong>")
|
|
31
31
|
end
|
|
32
|
+
|
|
33
|
+
it 'filters simple items' do
|
|
34
|
+
filtered_index_file = @dest.join("filtered_index.html")
|
|
35
|
+
expect(filtered_index_file).to exist
|
|
36
|
+
filtered_index_contents = File.read(filtered_index_file)
|
|
37
|
+
expect(filtered_index_contents).to include("GitHub Glossary")
|
|
38
|
+
expect(filtered_index_contents).to include("Fork A Repo")
|
|
39
|
+
expect(filtered_index_contents).to include("Article v2.0")
|
|
40
|
+
expect(filtered_index_contents).to include("Still show")
|
|
41
|
+
expect(filtered_index_contents).to_not include("Article v2.1")
|
|
42
|
+
expect(filtered_index_contents).to_not include("Ignored")
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it 'filters items when a prefix is provided' do
|
|
46
|
+
enterprise_filtered_index = @dest.join("enterprise_filtered_index.html")
|
|
47
|
+
expect(enterprise_filtered_index).to exist
|
|
48
|
+
filtered_index_contents = File.read(enterprise_filtered_index)
|
|
49
|
+
expect(filtered_index_contents).to include("GitHub Glossary")
|
|
50
|
+
expect(filtered_index_contents).to include("Fork A Repo")
|
|
51
|
+
expect(filtered_index_contents).to include("Article v2.1")
|
|
52
|
+
expect(filtered_index_contents).to include("Still show")
|
|
53
|
+
expect(filtered_index_contents).to_not include("Article v2.0")
|
|
54
|
+
expect(filtered_index_contents).to_not include("Ignored")
|
|
55
|
+
end
|
|
32
56
|
end
|
data/spec/fixtures/_config.yml
CHANGED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
Bootcamp:
|
|
2
|
+
- Set Up Git
|
|
3
|
+
- Create A Repo
|
|
4
|
+
- Fork A Repo
|
|
5
|
+
- Be Social
|
|
6
|
+
- '{{ site.data.conrefs.product_name[site.audience] }} Glossary'
|
|
7
|
+
- Good Resources for Learning Git and GitHub
|
|
8
|
+
|
|
9
|
+
Listing:
|
|
10
|
+
{% if page.version == '2.0' %}
|
|
11
|
+
- Article v2.0
|
|
12
|
+
{% endif %}
|
|
13
|
+
{% if page.version != '2.0' %}
|
|
14
|
+
- Article v2.1
|
|
15
|
+
{% endif %}
|
|
16
|
+
- Wow
|
|
17
|
+
{% if page.version == '2.0' or page.version == '2.1' %}
|
|
18
|
+
- Still show
|
|
19
|
+
{% endif %}
|
|
20
|
+
|
|
21
|
+
{% unless page.version == '2.1' %}
|
|
22
|
+
Ignored:
|
|
23
|
+
- Item1
|
|
24
|
+
- Item 2
|
|
25
|
+
{% endunless %}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
Bootcamp:
|
|
2
|
+
- Set Up Git
|
|
3
|
+
- Create A Repo
|
|
4
|
+
- Fork A Repo
|
|
5
|
+
- Be Social
|
|
6
|
+
- '{{ site.data.conrefs.product_name[site.audience] }} Glossary'
|
|
7
|
+
- Good Resources for Learning Git and GitHub
|
|
8
|
+
|
|
9
|
+
Listing:
|
|
10
|
+
{% if page.version == '2.0' %}
|
|
11
|
+
- Article v2.0
|
|
12
|
+
{% endif %}
|
|
13
|
+
{% if page.version != '2.0' %}
|
|
14
|
+
- Article v2.1
|
|
15
|
+
{% endif %}
|
|
16
|
+
- Wow
|
|
17
|
+
{% if page.version == '2.0' or page.version == '2.1' %}
|
|
18
|
+
- Still show
|
|
19
|
+
{% endif %}
|
|
20
|
+
|
|
21
|
+
{% unless page.version == '2.0' %}
|
|
22
|
+
Ignored:
|
|
23
|
+
- Item1
|
|
24
|
+
- Item 2
|
|
25
|
+
{% endunless %}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
---
|
|
2
|
+
---
|
|
3
|
+
<ul id="categories">
|
|
4
|
+
{% for category_hash in site.data.enterprise_filtered_categories %}
|
|
5
|
+
{% assign category_title = category_hash[0] %}
|
|
6
|
+
{% assign category_articles = category_hash[1] %}
|
|
7
|
+
|
|
8
|
+
<li class="category">
|
|
9
|
+
|
|
10
|
+
<h5>
|
|
11
|
+
<span class="handle"></span>
|
|
12
|
+
<a href="{{ site.baseurl }}/categories/{{ category_title | slugify }}">{{ category_title }}</a>
|
|
13
|
+
</h5>
|
|
14
|
+
|
|
15
|
+
<ul class="chevron list">
|
|
16
|
+
{% for title in category_articles %}
|
|
17
|
+
<li class="article">
|
|
18
|
+
<a href="{{ site.baseurl }}/articles/{{ title | slugify }}" class="km-article-link">{{ title }}</a>
|
|
19
|
+
</li>
|
|
20
|
+
{% endfor %}
|
|
21
|
+
</ul>
|
|
22
|
+
|
|
23
|
+
</li>
|
|
24
|
+
|
|
25
|
+
{% endfor %}
|
|
26
|
+
</ul>
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
---
|
|
2
|
+
---
|
|
3
|
+
<ul id="categories">
|
|
4
|
+
{% for category_hash in site.data.filtered_categories %}
|
|
5
|
+
{% assign category_title = category_hash[0] %}
|
|
6
|
+
{% assign category_articles = category_hash[1] %}
|
|
7
|
+
|
|
8
|
+
<li class="category">
|
|
9
|
+
|
|
10
|
+
<h5>
|
|
11
|
+
<span class="handle"></span>
|
|
12
|
+
<a href="{{ site.baseurl }}/categories/{{ category_title | slugify }}">{{ category_title }}</a>
|
|
13
|
+
</h5>
|
|
14
|
+
|
|
15
|
+
<ul class="chevron list">
|
|
16
|
+
{% for title in category_articles %}
|
|
17
|
+
<li class="article">
|
|
18
|
+
<a href="{{ site.baseurl }}/articles/{{ title | slugify }}" class="km-article-link">{{ title }}</a>
|
|
19
|
+
</li>
|
|
20
|
+
{% endfor %}
|
|
21
|
+
</ul>
|
|
22
|
+
|
|
23
|
+
</li>
|
|
24
|
+
|
|
25
|
+
{% endfor %}
|
|
26
|
+
</ul>
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: jekyll-conrefifier
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Garen J. Torikian
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2015-
|
|
11
|
+
date: 2015-02-02 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: jekyll
|
|
@@ -77,7 +77,11 @@ files:
|
|
|
77
77
|
- spec/fixtures/_config.yml
|
|
78
78
|
- spec/fixtures/_data/categories.yml
|
|
79
79
|
- spec/fixtures/_data/conrefs.yml
|
|
80
|
+
- spec/fixtures/_data/enterprise_filtered_categories.yml
|
|
81
|
+
- spec/fixtures/_data/filtered_categories.yml
|
|
80
82
|
- spec/fixtures/_layouts/article.html
|
|
83
|
+
- spec/fixtures/enterprise_filtered_index.html
|
|
84
|
+
- spec/fixtures/filtered_index.html
|
|
81
85
|
- spec/fixtures/index.html
|
|
82
86
|
- spec/spec_helper.rb
|
|
83
87
|
homepage: ''
|