Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/liquid-tags/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Note that link tags will only render links that are available in the current pag
| `{% homepage_link_with_intro /href %}` | The linked page's title and intro, with homepage-specific styling.
| `{% link_in_list /href %}` | The linked page's title in a list item.
| `{% topic_link_in_list /href %}` | The linked map topic's title in a list item (used in category TOCs).
| `{% indented_data_reference site.data.foo.bar spaces=NUMBER %}` | The data reference with the specified number of spaces prepended to each line.
| `{% indented_data_reference foo.bar spaces=NUMBER %}` | A data reference with the specified number of spaces prepended to each line. Defaults to 2 spaces if no spaces included. For example: `{% indented_data_reference reusables.enterprise_management_console.enable-disable-security-features %}`

## Creating tags

Expand Down
2 changes: 1 addition & 1 deletion lib/liquid-tags/indented-data-reference.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module.exports = {
assert(parseInt(numSpaces) || numSpaces === '0', '"spaces=NUMBER" must include a number')

// Get the referenced value from the context
const value = await this.liquid.evalValue(dataReference, context)
const value = await this.liquid.evalValue(`site.data.${dataReference}`, context)

// If nothing is found in the context, exit with nothing; this may
// feel weird and that we should throw an error, but this is "The Liquid Way TM"
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/liquid-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,31 +107,31 @@ describe('liquid helper tags', () => {

describe('indented_data_reference tag', () => {
test('without any number of spaces specified', async () => {
const template = '{% indented_data_reference site.data.reusables.example %}'
const template = '{% indented_data_reference reusables.example %}'
const expected = ` a rose by any other name
would smell as sweet`
const output = await liquid.parseAndRender(template, context)
expect(output).toBe(expected)
})

test('with 0 spaces specified', async () => {
const template = '{% indented_data_reference site.data.reusables.example spaces=0 %}'
const template = '{% indented_data_reference reusables.example spaces=0 %}'
const expected = `a rose by any other name
would smell as sweet`
const output = await liquid.parseAndRender(template, context)
expect(output).toBe(expected)
})

test('with 0 spaces specified and whitespace around equals sign', async () => {
const template = '{% indented_data_reference site.data.reusables.example spaces = 0 %}'
const template = '{% indented_data_reference reusables.example spaces = 0 %}'
const expected = `a rose by any other name
would smell as sweet`
const output = await liquid.parseAndRender(template, context)
expect(output).toBe(expected)
})

test('with 5 spaces specified', async () => {
const template = '{% indented_data_reference site.data.reusables.example spaces=5 %}'
const template = '{% indented_data_reference reusables.example spaces=5 %}'
const expected = ` a rose by any other name
would smell as sweet`
const output = await liquid.parseAndRender(template, context)
Expand Down