jekyll-conrefifier 0.0.1 → 0.1.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/lib/jekyll-conrefifier.rb +22 -0
- data/lib/version.rb +1 -1
- data/spec/conrefifier_spec.rb +9 -1
- data/spec/fixtures/_data/categories.yml +3 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 326edf243db654eb22ef5f0cd49e5c6bcc756bb8
|
4
|
+
data.tar.gz: 099db511d1e1e3214cf9f88f86766cf77db5e57e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 44652e364eb5b19833c525612e9adc352fb8ffb53ab99bd2f7d6817377ee7cff2d6cbee674267ab3266c779fe9818e16b861d4fbd55d34bf14c3f1856a87f8a2
|
7
|
+
data.tar.gz: 4b318e9be13d3ecc9694a9f164a6e979b5dc8d2d4e747d0b08ae8e1814fcf4d3d07b6c22fc386696f4a5bd29ca67af93cb7f50fcfecb23adc8a4d2fc067ffb05
|
data/lib/jekyll-conrefifier.rb
CHANGED
@@ -1,3 +1,16 @@
|
|
1
|
+
class Hash
|
2
|
+
def insert_before(key, kvpair)
|
3
|
+
arr = to_a
|
4
|
+
pos = arr.index(arr.assoc(key))
|
5
|
+
if pos
|
6
|
+
arr.insert(pos, kvpair)
|
7
|
+
else
|
8
|
+
arr << kvpair
|
9
|
+
end
|
10
|
+
replace Hash[arr]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
1
14
|
module Jekyll
|
2
15
|
class Document
|
3
16
|
alias_method :old_read, :read
|
@@ -23,10 +36,15 @@ module Jekyll
|
|
23
36
|
# - '{{ site.data.conrefs.product_name[site.audience] }} Glossary'
|
24
37
|
# renders as "GitHub Glossary" for dotcom, but "GitHub Enterprise Glossary" for Enterprise
|
25
38
|
def read
|
39
|
+
keys_to_modify = {}
|
26
40
|
old_read
|
27
41
|
data.each_pair do |data_file, data_set|
|
28
42
|
if data_set.is_a? Hash
|
29
43
|
data_set.each_pair do |key, values|
|
44
|
+
if key =~ /\{\{.+?\}\}/
|
45
|
+
new_key = Liquid::Template.parse(key).render({ "site" => { "data" => data }.merge(config) })
|
46
|
+
keys_to_modify[key] = new_key
|
47
|
+
end
|
30
48
|
if values.is_a? Array
|
31
49
|
values.each_with_index do |value, i|
|
32
50
|
if value =~ /\{\{.+?\}\}/
|
@@ -36,6 +54,10 @@ module Jekyll
|
|
36
54
|
end
|
37
55
|
end
|
38
56
|
end
|
57
|
+
keys_to_modify.each_pair do |old_key, new_key|
|
58
|
+
data[data_file].insert_before(old_key, [new_key, data[data_file][old_key]])
|
59
|
+
data[data_file].delete(old_key)
|
60
|
+
end
|
39
61
|
end
|
40
62
|
end
|
41
63
|
end
|
data/lib/version.rb
CHANGED
data/spec/conrefifier_spec.rb
CHANGED
@@ -9,10 +9,18 @@ describe("Conrefifier") do
|
|
9
9
|
expect(@dest.join("articles", "welcome-to-github", "index.html")).to exist
|
10
10
|
end
|
11
11
|
|
12
|
-
it "writes the proper content after fetching info from a data file" do
|
12
|
+
it "writes the proper content for values after fetching info from a data file" do
|
13
13
|
index_file = @dest.join("index.html")
|
14
14
|
expect(index_file).to exist
|
15
15
|
index_contents = File.read(index_file)
|
16
16
|
expect(index_contents).to include("GitHub Glossary")
|
17
17
|
end
|
18
|
+
|
19
|
+
|
20
|
+
it "writes the proper content for keys after fetching info from a data file" do
|
21
|
+
index_file = @dest.join("index.html")
|
22
|
+
expect(index_file).to exist
|
23
|
+
index_contents = File.read(index_file)
|
24
|
+
expect(index_contents).to include("<a href=\"/categories/amazing\">Amazing</a>")
|
25
|
+
end
|
18
26
|
end
|
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.0
|
4
|
+
version: 0.1.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: 2014-11-
|
11
|
+
date: 2014-11-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|