Skip to content

Commit f00d067

Browse files
authored
repo sync
2 parents d18940b + b3cb3f9 commit f00d067

File tree

3 files changed

+53
-8
lines changed

3 files changed

+53
-8
lines changed

content/github/getting-started-with-github/github-glossary.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ versions:
1010
---
1111

1212
{% for term in site.data.glossaries.external %}
13-
### {{term.term}}
14-
{{term.description}}
13+
### {% data glossaries.external[forloop.index0].term %}
14+
{% data glossaries.external[forloop.index0].description %}
1515
---
1616
{% endfor %}
1717

lib/liquid-tags/data.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const Liquid = require('liquid')
22

3-
const Syntax = /([a-z0-9/\\_.-]+)/i
3+
const Syntax = /([a-z0-9/\\_.\-[\]]+)/i
44
const SyntaxHelp = "Syntax Error in 'data' - Valid syntax: data [path]"
55

66
module.exports = class Data extends Liquid.Tag {

tests/unit/liquid-helpers.js

+50-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const { liquid } = require('../../lib/render-content')
22
const { loadPageMap } = require('../../lib/pages')
33
const entities = new (require('html-entities').XmlEntities)()
4-
const { set } = require('lodash')
54
const nonEnterpriseDefaultVersion = require('../../lib/non-enterprise-default-version')
65

76
describe('liquid helper tags', () => {
@@ -15,11 +14,16 @@ describe('liquid helper tags', () => {
1514
context.currentVersion = nonEnterpriseDefaultVersion
1615
context.pages = pageMap
1716
context.redirects = []
18-
context.site = {}
17+
context.site = {
18+
data: {
19+
reusables: {
20+
example: 'a rose by any other name\nwould smell as sweet'
21+
}
22+
}
23+
}
1924
context.page = {
2025
relativePath: 'desktop/index.md'
2126
}
22-
set(context.site, 'data.reusables.example', 'a rose by any other name\nwould smell as sweet')
2327
done()
2428
})
2529

@@ -83,8 +87,6 @@ describe('liquid helper tags', () => {
8387
})
8488

8589
describe('indented_data_reference tag', () => {
86-
set(context.site, 'data.reusables.example', 'a rose by any other name\nwould smell as sweet')
87-
8890
test('without any number of spaces specified', async () => {
8991
const template = '{% indented_data_reference site.data.reusables.example %}'
9092
const expected = ` a rose by any other name
@@ -117,4 +119,47 @@ would smell as sweet`
117119
expect(output).toBe(expected)
118120
})
119121
})
122+
123+
describe('data tag', () => {
124+
test(
125+
'handles bracketed array access within for-in loop',
126+
async () => {
127+
const template = `
128+
{% for term in site.data.glossaries.external %}
129+
### {% data glossaries.external[forloop.index0].term %}
130+
{% data glossaries.external[forloop.index0].description %}
131+
---
132+
{% endfor %}`
133+
134+
const localContext = { ...context }
135+
localContext.site = {
136+
data: {
137+
variables: {
138+
fire_emoji: ':fire:'
139+
},
140+
glossaries: {
141+
external: [
142+
{ term: 'lit', description: 'Awesome things. {% data variables.fire_emoji %}' },
143+
{ term: 'Zhu Li', description: '_"Zhu Li, do the thing!"_ :point_up:' }
144+
]
145+
}
146+
}
147+
}
148+
149+
const expected = `
150+
151+
### lit
152+
Awesome things. :fire:
153+
---
154+
155+
### Zhu Li
156+
_"Zhu Li, do the thing!"_ :point_up:
157+
---
158+
`
159+
160+
const output = await liquid.parseAndRender(template, localContext)
161+
expect(output).toBe(expected)
162+
}
163+
)
164+
})
120165
})

0 commit comments

Comments
 (0)