jekyll-index-pages 0.4.0 → 0.4.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 +4 -4
- data/README.md +7 -2
- data/lib/jekyll-index-pages/tags/category-url.rb +36 -20
- data/lib/jekyll-index-pages/tags/tag-url.rb +36 -20
- data/lib/jekyll-index-pages/version.rb +1 -1
- data/spec/category-url_spec.rb +37 -5
- data/spec/tag-url_spec.rb +37 -5
- 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: 68ae1f6ad9f04cc3f99ec1d3ca767b7568c1c9b4
|
4
|
+
data.tar.gz: 56022368b8e991fe1442f9b55a2bdd70fbafca57
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 059ea292f70bbac59ad7793289eebabab3aedf032df1364790b9f51a38ccbe43a0d71ffb4bb06502c6565110a4243d71c856a90af676e463fff3a1f6bc66e8db
|
7
|
+
data.tar.gz: 8338182a3c61dfa12805e9fe07864974aadc67f2dc0a8e103ee5b0e249b548165ce3729eb08d543d53429ab84f3d39a6d0c07c02fc04a64896e76311eeeb7132
|
data/README.md
CHANGED
@@ -175,8 +175,13 @@ building some kind of navigation. For this particular use case, you can use `{%
|
|
175
175
|
category_url %}` and `{% tag_url %}` tags for getting the correct URL to a
|
176
176
|
given category or tag page.
|
177
177
|
|
178
|
-
`{% category_url %}` accepts a valid category name as an argument
|
179
|
-
|
178
|
+
`{% category_url %}` accepts a valid category name as an argument:
|
179
|
+
|
180
|
+
```liquid
|
181
|
+
<a href="{% category_url "Category name" %}">Category name</a>
|
182
|
+
```
|
183
|
+
|
184
|
+
Likewise, `{% tag_url %}` receives a valid tag name.
|
180
185
|
|
181
186
|
The following example demonstrates how to create a basic category navigation:
|
182
187
|
|
@@ -1,33 +1,49 @@
|
|
1
1
|
module JekyllIndexPages
|
2
2
|
class CategoryURL < Liquid::Tag
|
3
|
-
|
3
|
+
STRING_SYNTAX = %r{^\"[[:alnum:] ]+\"$}u
|
4
|
+
VARIABLE_SYNTAX = %r{^\(?[[:alnum:]\-\.\[\]]+\)?$}u
|
5
|
+
|
6
|
+
def initialize(tag, markup, tokens)
|
4
7
|
super
|
5
|
-
@
|
8
|
+
@markup = markup.strip
|
6
9
|
end
|
7
10
|
|
8
11
|
def render(context)
|
9
|
-
|
12
|
+
if @markup.match(STRING_SYNTAX)
|
13
|
+
@markup.gsub!("\"", "")
|
14
|
+
elsif @markup.match(VARIABLE_SYNTAX)
|
15
|
+
@markup = Liquid::Variable.new(@markup).render(context)
|
16
|
+
else
|
17
|
+
raise ArgumentError, <<-eos
|
18
|
+
Invalid syntax for category_url tag:
|
10
19
|
|
11
|
-
|
12
|
-
_, item = config.detect do |key, value|
|
13
|
-
key == "categories"
|
14
|
-
end
|
20
|
+
#{@markup}
|
15
21
|
|
16
|
-
|
17
|
-
category, _ = site.categories.detect do |key, value|
|
18
|
-
key == @text
|
19
|
-
end
|
22
|
+
Valid syntax:
|
20
23
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
else
|
29
|
-
""
|
24
|
+
{% category_url "Category name" %}
|
25
|
+
|
26
|
+
or
|
27
|
+
|
28
|
+
{% category_url name_in_variable %}
|
29
|
+
|
30
|
+
eos
|
30
31
|
end
|
32
|
+
|
33
|
+
site = context.registers[:site]
|
34
|
+
|
35
|
+
category, _ = site.categories.detect { |key, value| key == @markup }
|
36
|
+
return "" if !category
|
37
|
+
category_slug =
|
38
|
+
I18n.transliterate(
|
39
|
+
Jekyll::Utils.slugify(category),
|
40
|
+
:locale => I18n.locale
|
41
|
+
)
|
42
|
+
|
43
|
+
config = site.config["index_pages"] || {}
|
44
|
+
_, item = config.detect { |key, value| key == "categories" }
|
45
|
+
permalink = item ? item["permalink"] : "/:label/"
|
46
|
+
permalink.sub(":label", category_slug)
|
31
47
|
end
|
32
48
|
end
|
33
49
|
end
|
@@ -1,33 +1,49 @@
|
|
1
1
|
module JekyllIndexPages
|
2
2
|
class TagURL < Liquid::Tag
|
3
|
-
|
3
|
+
STRING_SYNTAX = %r{^\"[[:alnum:]\-]+\"$}u
|
4
|
+
VARIABLE_SYNTAX = %r{^\(?[[:alnum:]\-\.\[\]]+\)?$}u
|
5
|
+
|
6
|
+
def initialize(tag, markup, tokens)
|
4
7
|
super
|
5
|
-
@
|
8
|
+
@markup = markup.strip
|
6
9
|
end
|
7
10
|
|
8
11
|
def render(context)
|
9
|
-
|
12
|
+
if @markup.match(STRING_SYNTAX)
|
13
|
+
@markup.gsub!("\"", "")
|
14
|
+
elsif @markup.match(VARIABLE_SYNTAX)
|
15
|
+
@markup = Liquid::Variable.new(@markup).render(context)
|
16
|
+
else
|
17
|
+
raise ArgumentError, <<-eos
|
18
|
+
Invalid syntax for tag_url tag:
|
10
19
|
|
11
|
-
|
12
|
-
_, item = config.detect do |key, value|
|
13
|
-
key == "tags"
|
14
|
-
end
|
20
|
+
#{@markup}
|
15
21
|
|
16
|
-
|
17
|
-
tag, _ = site.tags.detect do |key, value|
|
18
|
-
key == @text
|
19
|
-
end
|
22
|
+
Valid syntax:
|
20
23
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
else
|
29
|
-
""
|
24
|
+
{% tag_url "Tag name" %}
|
25
|
+
|
26
|
+
or
|
27
|
+
|
28
|
+
{% tag_url name_in_variable %}
|
29
|
+
|
30
|
+
eos
|
30
31
|
end
|
32
|
+
|
33
|
+
site = context.registers[:site]
|
34
|
+
|
35
|
+
tag, _ = site.tags.detect { |key, value| key == @markup }
|
36
|
+
return "" if !tag
|
37
|
+
tag_slug =
|
38
|
+
I18n.transliterate(
|
39
|
+
Jekyll::Utils.slugify(tag),
|
40
|
+
:locale => I18n.locale
|
41
|
+
)
|
42
|
+
|
43
|
+
config = site.config["index_pages"] || {}
|
44
|
+
_, item = config.detect { |key, value| key == "tags" }
|
45
|
+
permalink = item ? item["permalink"] : "/:label/"
|
46
|
+
permalink.sub(":label", tag_slug)
|
31
47
|
end
|
32
48
|
end
|
33
49
|
end
|
data/spec/category-url_spec.rb
CHANGED
@@ -24,20 +24,20 @@ describe JekyllIndexPages::CategoryURL do
|
|
24
24
|
let(:template) { Liquid::Template.parse("{% category_url %}") }
|
25
25
|
|
26
26
|
describe "CategoryURL.render" do
|
27
|
-
it "
|
28
|
-
expect
|
27
|
+
it "raises ArgumentError" do
|
28
|
+
expect { template.render!(payload, info) }.to raise_error(ArgumentError)
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
33
|
context "When a valid category name is provided" do
|
34
34
|
let(:template) do
|
35
|
-
Liquid::Template.parse("{% category_url Ciencia ficción %}")
|
35
|
+
Liquid::Template.parse("{% category_url \"Ciencia ficción\" %}")
|
36
36
|
end
|
37
37
|
|
38
38
|
describe "CategoryURL.render" do
|
39
39
|
it "returns a valid category page URL" do
|
40
|
-
expect(template.render(payload, info)).to eq("/ciencia-ficcion/")
|
40
|
+
expect(template.render!(payload, info)).to eq("/ciencia-ficcion/")
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
@@ -54,7 +54,39 @@ describe JekyllIndexPages::CategoryURL do
|
|
54
54
|
|
55
55
|
describe "CategoryURL.render" do
|
56
56
|
it "returns a valid category page URL" do
|
57
|
-
expect(template.render(payload, info)).to eq("/custom/ciencia-ficcion/")
|
57
|
+
expect(template.render!(payload, info)).to eq("/custom/ciencia-ficcion/")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context "When a valid category name is provided as a variable" do
|
64
|
+
let(:template) do
|
65
|
+
Liquid::Template.parse <<-eos
|
66
|
+
{% for category in site.categories %}{% if forloop.last %}{% category_url category[0] %}{% endif %}{% endfor %}
|
67
|
+
eos
|
68
|
+
end
|
69
|
+
|
70
|
+
describe "CategoryURL.render" do
|
71
|
+
it "returns a valid category page URL" do
|
72
|
+
expect(template.render!(payload, info)).to start_with("/ciencia-ficcion/")
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context "and a custom category permalink is provided" do
|
77
|
+
let(:overrides) do
|
78
|
+
{
|
79
|
+
"index_pages" => {
|
80
|
+
"categories" => {
|
81
|
+
"permalink" => "/custom/:label/"
|
82
|
+
}
|
83
|
+
}
|
84
|
+
}
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "CategoryURL.render" do
|
88
|
+
it "returns a valid category page URL" do
|
89
|
+
expect(template.render!(payload, info)).to start_with("/custom/ciencia-ficcion/")
|
58
90
|
end
|
59
91
|
end
|
60
92
|
end
|
data/spec/tag-url_spec.rb
CHANGED
@@ -24,20 +24,20 @@ describe JekyllIndexPages::TagURL do
|
|
24
24
|
let(:template) { Liquid::Template.parse("{% tag_url %}") }
|
25
25
|
|
26
26
|
describe "TagURL.render" do
|
27
|
-
it "
|
28
|
-
expect
|
27
|
+
it "raises ArgumentError" do
|
28
|
+
expect { template.render!(payload, info) }.to raise_error(ArgumentError)
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
33
|
context "When a valid tag name is provided" do
|
34
34
|
let(:template) do
|
35
|
-
Liquid::Template.parse("{% tag_url ciencia-ficción %}")
|
35
|
+
Liquid::Template.parse("{% tag_url \"ciencia-ficción\" %}")
|
36
36
|
end
|
37
37
|
|
38
38
|
describe "TagURL.render" do
|
39
39
|
it "returns a valid tag page URL" do
|
40
|
-
expect(template.render(payload, info)).to eq("/ciencia-ficcion/")
|
40
|
+
expect(template.render!(payload, info)).to eq("/ciencia-ficcion/")
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
@@ -54,7 +54,39 @@ describe JekyllIndexPages::TagURL do
|
|
54
54
|
|
55
55
|
describe "TagURL.render" do
|
56
56
|
it "returns a valid tag page URL" do
|
57
|
-
expect(template.render(payload, info)).to eq("/custom/ciencia-ficcion/")
|
57
|
+
expect(template.render!(payload, info)).to eq("/custom/ciencia-ficcion/")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context "When a valid tag name is provided as a variable" do
|
64
|
+
let(:template) do
|
65
|
+
Liquid::Template.parse <<-eos
|
66
|
+
{% for tag in site.tags %}{% if forloop.last %}{% tag_url tag[0] %}{% endif %}{% endfor %}
|
67
|
+
eos
|
68
|
+
end
|
69
|
+
|
70
|
+
describe "TagURL.render" do
|
71
|
+
it "returns a valid tag page URL" do
|
72
|
+
expect(template.render!(payload, info)).to start_with("/ciencia-ficcion/")
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context "and a custom tag permalink is provided" do
|
77
|
+
let(:overrides) do
|
78
|
+
{
|
79
|
+
"index_pages" => {
|
80
|
+
"tags" => {
|
81
|
+
"permalink" => "/custom/:label/"
|
82
|
+
}
|
83
|
+
}
|
84
|
+
}
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "TagURL.render" do
|
88
|
+
it "returns a valid tag page URL" do
|
89
|
+
expect(template.render!(payload, info)).to start_with("/custom/ciencia-ficcion/")
|
58
90
|
end
|
59
91
|
end
|
60
92
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-index-pages
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jose Miguel Venegas Mendoza
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-04-
|
11
|
+
date: 2017-04-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: i18n
|