Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

repo sync #1594

Merged
merged 13 commits into from
Nov 24, 2020
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ When creating a group, you must choose a policy that defines which repositories
{% warning %}

**Warning**

{% indented_data_reference site.data.reusables.github-actions.self-hosted-runner-security spaces=3 %}

For more information, see "[About self-hosted runners](/actions/hosting-your-own-runners/about-self-hosted-runners#self-hosted-runner-security-with-public-repositories)."

{% endwarning %}
Expand Down Expand Up @@ -78,7 +80,9 @@ When creating a group, you must choose a policy that defines which organizations
{% warning %}

**Warning**

{% indented_data_reference site.data.reusables.github-actions.self-hosted-runner-security spaces=3 %}

For more information, see "[About self-hosted runners](/actions/hosting-your-own-runners/about-self-hosted-runners#self-hosted-runner-security-with-public-repositories)."

{% endwarning %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
{% warning %}

**Warning**

{% indented_data_reference site.data.reusables.github-actions.self-hosted-runner-security spaces=3 %}

For more information, see "[About self-hosted runners](/actions/hosting-your-own-runners/about-self-hosted-runners#self-hosted-runner-security-with-public-repositories)."

{% endwarning %}
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module.exports = {
testPathIgnorePatterns: [
'node_modules/',
'vendor/',
'tests/helpers.js',
'tests/helpers/',
...isBrowser ? [] : ['tests/browser/browser.js']
],
testMatch: [
Expand Down
28 changes: 14 additions & 14 deletions lib/liquid-tags/indented-data-reference.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
const Liquid = require('liquid')
const liquid = new Liquid.Engine()
const LiquidTag = require('./liquid-tag')
const assert = require('assert')

// This class supports a tag that expects two parameters, a data reference and `spaces=NUMBER`:
Expand All @@ -12,17 +10,14 @@ const assert = require('assert')
// reference is used inside a block element (like a list or nested list) without
// affecting the formatting when the reference is used elsewhere via {{ site.data.foo.bar }}.

module.exports = class IndentedDataReference extends LiquidTag {
constructor (template, tagName, dataReferenceAndNumberOfSpaces) {
super(template, tagName, dataReferenceAndNumberOfSpaces.trim())
}

async parseTemplate (context) {
const template = await this.getTemplate()

module.exports = class IndentedDataReference extends Liquid.Tag {
async render (context) {
// obfuscate first legit space, remove all other spaces, then restore legit space
// this way we can support spaces=NUMBER as well as spaces = NUMBER
const input = this.param.replace(/\s/, 'REALSPACE').replace(/\s/g, '').replace('REALSPACE', ' ')
const input = this.markup.trim()
.replace(/\s/, 'REALSPACE')
.replace(/\s/g, '')
.replace('REALSPACE', ' ')

const [dataReference, spaces] = input.split(' ')

Expand All @@ -31,11 +26,16 @@ module.exports = class IndentedDataReference extends LiquidTag {

assert(parseInt(numSpaces) || numSpaces === '0', '"spaces=NUMBER" must include a number')

const renderedReference = await require('../render-content')(`{{ ${dataReference} }}`, context.environments[0])
// Get the referenced value from the context
const value = await context.get(dataReference)

// 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"
if (!value) return

// add spaces to each line
const renderedReferenceWithIndent = renderedReference.replace(/^/mg, ' '.repeat(numSpaces))
const renderedReferenceWithIndent = value.replace(/^/mg, ' '.repeat(numSpaces))

return liquid.parseAndRender(template, { renderedReferenceWithIndent })
return this.template.engine.parseAndRender(renderedReferenceWithIndent, context)
}
}
1 change: 1 addition & 0 deletions script/check-deps.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const path = require('path')
const main = async () => {
const data = await dependencyCheck({
entries: [
path.posix.join(__dirname, '..', '*.js'),
path.posix.join(__dirname, '..', '*', '*.js'),
path.posix.join('!', __dirname, '..', 'javascripts', '*.js'),
path.posix.join(__dirname, '..', 'script', 'graphql', '*.js')
Expand Down
2 changes: 1 addition & 1 deletion tests/content/featured-links.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { getDOM, getJSON } = require('../helpers')
const { getDOM, getJSON } = require('../helpers/supertest')
const enterpriseServerReleases = require('../../lib/enterprise-server-releases')
const japaneseCharacters = require('japanese-characters')
const nonEnterpriseDefaultVersion = require('../../lib/non-enterprise-default-version')
Expand Down
2 changes: 1 addition & 1 deletion tests/content/site-tree.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const revalidator = require('revalidator')
const schema = require('../../lib/site-tree-schema')
const latestEnterpriseRelease = require('../../lib/enterprise-server-releases').latest
const { getJSON } = require('../helpers')
const { getJSON } = require('../helpers/supertest')
const flat = require('flat')
const japaneseCharacters = require('japanese-characters')
const nonEnterpriseDefaultVersion = require('../../lib/non-enterprise-default-version')
Expand Down
2 changes: 1 addition & 1 deletion tests/content/webhooks.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { difference } = require('lodash')
const { getJSON } = require('../helpers')
const { getJSON } = require('../helpers/supertest')
const { latest } = require('../../lib/enterprise-server-releases')
const allVersions = Object.values(require('../../lib/all-versions'))
const payloadVersions = allVersions.map(v => v.miscVersionName)
Expand Down
2 changes: 1 addition & 1 deletion tests/helpers.js → tests/helpers/supertest.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

const cheerio = require('cheerio')
const supertest = require('supertest')
const app = require('../server')
const app = require('../../server')

const helpers = {}

Expand Down
2 changes: 1 addition & 1 deletion tests/meta/orphan-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const path = require('path')
describe('check for orphan tests', () => {
test('all tests are in sub-directories', () => {
// A known list of exceptions that can live outside of directories
const EXCEPTIONS = ['README.md', 'helpers.js']
const EXCEPTIONS = ['README.md']
const pathToTests = path.join(process.cwd(), 'tests')

// Get a list of files/directories in `/tests`
Expand Down
2 changes: 1 addition & 1 deletion tests/rendering/breadcrumbs.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { getDOM, getJSON } = require('../helpers')
const { getDOM, getJSON } = require('../helpers/supertest')
const nonEnterpriseDefaultVersion = require('../../lib/non-enterprise-default-version')

describe('breadcrumbs', () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/rendering/curated-homepage-links.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { getDOM } = require('../helpers')
const { getDOM } = require('../helpers/supertest')

describe('curated homepage links', () => {
jest.setTimeout(5 * 60 * 1000)
Expand Down
2 changes: 1 addition & 1 deletion tests/rendering/footer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { getDOM } = require('../helpers')
const { getDOM } = require('../helpers/supertest')
const enterpriseServerReleases = require('../../lib/enterprise-server-releases')
const nonEnterpriseDefaultVersion = require('../../lib/non-enterprise-default-version')

Expand Down
2 changes: 1 addition & 1 deletion tests/rendering/head.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { getDOM } = require('../helpers')
const { getDOM } = require('../helpers/supertest')
const languages = require('../../lib/languages')

describe('<head>', () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/rendering/header.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { getDOM } = require('../helpers')
const { getDOM } = require('../helpers/supertest')
const { oldestSupported, latest } = require('../../lib/enterprise-server-releases')
const nonEnterpriseDefaultVersion = require('../../lib/non-enterprise-default-version')

Expand Down
2 changes: 1 addition & 1 deletion tests/rendering/page-titles.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const enterpriseServerReleases = require('../../lib/enterprise-server-releases')
const { getDOM } = require('../helpers')
const { getDOM } = require('../helpers/supertest')

describe('page titles', () => {
jest.setTimeout(300 * 1000)
Expand Down
2 changes: 1 addition & 1 deletion tests/rendering/rest.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const fs = require('fs')
const path = require('path')
const { difference, isPlainObject } = require('lodash')
const { getJSON } = require('../helpers')
const { getJSON } = require('../helpers/supertest')
const enterpriseServerReleases = require('../../lib/enterprise-server-releases')
// list of REST markdown files that do not correspond to REST API resources
// TODO could we get this list dynamically, say via page frontmatter?
Expand Down
2 changes: 1 addition & 1 deletion tests/rendering/robots-txt.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const languages = require('../../lib/languages')
const robotsParser = require('robots-parser')
const robotsMiddleware = require('../../middleware/robots')
const { get } = require('../helpers')
const { get } = require('../helpers/supertest')
const MockExpressResponse = require('mock-express-response')
const products = require('../../lib/all-products')
const enterpriseServerReleases = require('../../lib/enterprise-server-releases')
Expand Down
2 changes: 1 addition & 1 deletion tests/rendering/server.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const lodash = require('lodash')
const enterpriseServerReleases = require('../../lib/enterprise-server-releases')
const { get, getDOM, head } = require('../helpers')
const { get, getDOM, head } = require('../helpers/supertest')
const path = require('path')
const nonEnterpriseDefaultVersion = require('../../lib/non-enterprise-default-version')

Expand Down
2 changes: 1 addition & 1 deletion tests/rendering/sidebar.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { getDOM } = require('../helpers')
const { getDOM } = require('../helpers/supertest')
const nonEnterpriseDefaultVersion = require('../../lib/non-enterprise-default-version')

describe('sidebar', () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/routing/deprecated-enterprise-versions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const app = require('../../server')
const enterpriseServerReleases = require('../../lib/enterprise-server-releases')
const { get, getDOM } = require('../helpers')
const { get, getDOM } = require('../helpers/supertest')
const supertest = require('supertest')

describe('enterprise deprecation', () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/routing/developer-site-redirects.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { eachOfLimit } = require('async')
const enterpriseServerReleases = require('../../lib/enterprise-server-releases')
const { get } = require('../helpers')
const { get } = require('../helpers/supertest')
const { getEnterpriseVersionNumber } = require('../../lib/patterns')
const nonEnterpriseDefaultVersion = require('../../lib/non-enterprise-default-version')
const restRedirectFixtures = require('../fixtures/rest-redirects')
Expand Down
2 changes: 1 addition & 1 deletion tests/routing/enterprise-release-notes.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { get } = require('../helpers')
const { get } = require('../helpers/supertest')

describe('enterprise release notes', () => {
jest.setTimeout(60 * 1000)
Expand Down
2 changes: 1 addition & 1 deletion tests/routing/language-code-redirects.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { get } = require('../helpers')
const { get } = require('../helpers/supertest')

describe('language code redirects', () => {
jest.setTimeout(5 * 60 * 1000)
Expand Down
2 changes: 1 addition & 1 deletion tests/routing/redirects.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const app = require('../../server')
const enterpriseServerReleases = require('../../lib/enterprise-server-releases')
const nonEnterpriseDefaultVersion = require('../../lib/non-enterprise-default-version')
const Page = require('../../lib/page')
const { get } = require('../helpers')
const { get } = require('../helpers/supertest')

describe('redirects', () => {
jest.setTimeout(5 * 60 * 1000)
Expand Down
2 changes: 1 addition & 1 deletion tests/routing/top-developer-site-path-redirects.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { head } = require('../helpers')
const { head } = require('../helpers/supertest')

describe('developer.github.com redirects', () => {
jest.setTimeout(30 * 60 * 1000)
Expand Down
20 changes: 8 additions & 12 deletions tests/unit/liquid-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,36 +85,32 @@ describe('liquid helper tags', () => {

test('without any number of spaces specified', async () => {
const template = '{% indented_data_reference site.data.reusables.example %}'
const expected = ` <p>a rose by any other name
would smell as sweet</p>
`
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 expected = `<p>a rose by any other name
would smell as sweet</p>
`
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 expected = `<p>a rose by any other name
would smell as sweet</p>
`
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 expected = ` <p>a rose by any other name
would smell as sweet</p>
`
const expected = ` a rose by any other name
would smell as sweet`
const output = await liquid.parseAndRender(template, context)
expect(output).toBe(expected)
})
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/products.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const revalidator = require('revalidator')
const products = require('../../lib/all-products')
const schema = require('../../lib/products-schema')
const { getDOM, getJSON } = require('../helpers')
const { getDOM, getJSON } = require('../helpers/supertest')
const nonEnterpriseDefaultVersion = require('../../lib/non-enterprise-default-version')

describe('products module', () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const revalidator = require('revalidator')
const allVersions = require('../../lib/all-versions')
const { latest } = require('../../lib/enterprise-server-releases')
const schema = require('../../lib/versions-schema')
const { getJSON } = require('../helpers')
const { getJSON } = require('../helpers/supertest')
const nonEnterpriseDefaultVersion = require('../../lib/non-enterprise-default-version')

describe('versions module', () => {
Expand Down