-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
Related: GH-26, GH-32 This project has external dependencies that no longer updated. Instead of forking and probably re-releasing it as separate packages it might be easier if we integrated it directly. This way, we don't have to manage separate project.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* Copyright 2017 trivago N.V. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS-IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import lineNumbers from './lineNumbers'; | ||
Check failure on line 16 in src/melody/melody-code-frame/index.js GitHub Actions / Test (18)
|
||
import { repeat } from 'lodash'; | ||
Check failure on line 17 in src/melody/melody-code-frame/index.js GitHub Actions / Test (18)
Check failure on line 17 in src/melody/melody-code-frame/index.js GitHub Actions / Test (18)
Check failure on line 17 in src/melody/melody-code-frame/index.js GitHub Actions / Test (20)
|
||
|
||
const NEWLINE = /\r\n|[\n\r\u2028\u2029]/; | ||
|
||
export default function({ rawLines, lineNumber, colNumber, length }) { | ||
Check failure on line 21 in src/melody/melody-code-frame/index.js GitHub Actions / Test (18)
|
||
const lines = rawLines.split(NEWLINE), | ||
Check failure on line 22 in src/melody/melody-code-frame/index.js GitHub Actions / Test (18)
|
||
start = Math.max(lineNumber - 3, 0), | ||
end = Math.min(lineNumber + 3, lines.length); | ||
|
||
return lineNumbers(lines.slice(start, end), { | ||
start: start + 1, | ||
before: ' ', | ||
Check failure on line 28 in src/melody/melody-code-frame/index.js GitHub Actions / Test (18)
|
||
after: ' | ', | ||
Check failure on line 29 in src/melody/melody-code-frame/index.js GitHub Actions / Test (18)
|
||
transform(params) { | ||
if (params.number !== lineNumber) { | ||
return; | ||
} | ||
|
||
if (typeof colNumber === 'number') { | ||
Check failure on line 35 in src/melody/melody-code-frame/index.js GitHub Actions / Test (18)
|
||
params.line += `\n${params.before}${repeat(' ', params.width)}${ | ||
Check failure on line 36 in src/melody/melody-code-frame/index.js GitHub Actions / Test (18)
|
||
params.after | ||
}${repeat(' ', colNumber)}${repeat('^', length)}`; | ||
Check failure on line 38 in src/melody/melody-code-frame/index.js GitHub Actions / Test (18)
|
||
} | ||
|
||
params.before = params.before.replace(/^./, '>'); | ||
}, | ||
}).join('\n'); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright 2014, 2015 Simon Lydell | ||
// X11 (“MIT”) Licensed. (See LICENSE.) | ||
/** | ||
* Copyright 2017 trivago N.V. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS-IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import { padStart } from 'lodash'; | ||
|
||
const get = options => (key, defaultValue) => | ||
key in options ? options[key] : defaultValue; | ||
|
||
function lineNumbers(lines, options) { | ||
const getOption = get(options); | ||
const transform = getOption('transform', Function.prototype); | ||
const padding = getOption('padding', ' '); | ||
const before = getOption('before', ' '); | ||
const after = getOption('after', ' | '); | ||
const start = getOption('start', 1); | ||
const end = start + lines.length - 1; | ||
const width = String(end).length; | ||
return lines.map(function(line, index) { | ||
const number = start + index; | ||
const params = { before, number, width, after, line }; | ||
transform(params); | ||
return ( | ||
params.before + | ||
padStart(params.number, width, padding) + | ||
params.after + | ||
params.line | ||
); | ||
}); | ||
} | ||
|
||
export default lineNumbers; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
/** | ||
* Copyright 2017 trivago N.V. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS-IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import { unaryOperators, binaryOperators, tests } from './operators'; | ||
import { AutoescapeParser } from './parser/autoescape'; | ||
import { BlockParser } from './parser/block'; | ||
import { DoParser } from './parser/do'; | ||
import { EmbedParser } from './parser/embed'; | ||
import { ExtendsParser } from './parser/extends'; | ||
import { FilterParser } from './parser/filter'; | ||
import { FlushParser } from './parser/flush'; | ||
import { ForParser } from './parser/for'; | ||
import { FromParser } from './parser/from'; | ||
import { IfParser } from './parser/if'; | ||
import { ImportParser } from './parser/import'; | ||
import { IncludeParser } from './parser/include'; | ||
import { MacroParser } from './parser/macro'; | ||
import { SetParser } from './parser/set'; | ||
import { SpacelessParser } from './parser/spaceless'; | ||
import { UseParser } from './parser/use'; | ||
import { MountParser } from './parser/mount'; | ||
|
||
import forVisitor from './visitors/for'; | ||
import testVisitor from './visitors/tests'; | ||
import filters from './visitors/filters'; | ||
import functions from './visitors/functions'; | ||
|
||
const filterMap = [ | ||
'attrs', | ||
'classes', | ||
'styles', | ||
'batch', | ||
'escape', | ||
'format', | ||
'merge', | ||
'nl2br', | ||
'number_format', | ||
'raw', | ||
'replace', | ||
'reverse', | ||
'round', | ||
'striptags', | ||
'title', | ||
'url_encode', | ||
'trim', | ||
].reduce((map, filterName) => { | ||
map[filterName] = 'melody-runtime'; | ||
return map; | ||
}, Object.create(null)); | ||
|
||
Object.assign(filterMap, filters); | ||
|
||
const functionMap = [ | ||
'attribute', | ||
'constant', | ||
'cycle', | ||
'date', | ||
'max', | ||
'min', | ||
'random', | ||
'range', | ||
'source', | ||
'template_from_string', | ||
].reduce((map, functionName) => { | ||
map[functionName] = 'melody-runtime'; | ||
return map; | ||
}, Object.create(null)); | ||
Object.assign(functionMap, functions); | ||
|
||
export const extension = { | ||
tags: [ | ||
AutoescapeParser, | ||
BlockParser, | ||
DoParser, | ||
EmbedParser, | ||
ExtendsParser, | ||
FilterParser, | ||
FlushParser, | ||
ForParser, | ||
FromParser, | ||
IfParser, | ||
ImportParser, | ||
IncludeParser, | ||
MacroParser, | ||
SetParser, | ||
SpacelessParser, | ||
UseParser, | ||
MountParser, | ||
], | ||
unaryOperators, | ||
binaryOperators, | ||
tests, | ||
visitors: [forVisitor, testVisitor], | ||
filterMap, | ||
functionMap, | ||
}; | ||
|
||
export { | ||
AutoescapeBlock, | ||
BlockStatement, | ||
BlockCallExpression, | ||
MountStatement, | ||
DoStatement, | ||
EmbedStatement, | ||
ExtendsStatement, | ||
FilterBlockStatement, | ||
FlushStatement, | ||
ForStatement, | ||
ImportDeclaration, | ||
FromStatement, | ||
IfStatement, | ||
IncludeStatement, | ||
MacroDeclarationStatement, | ||
VariableDeclarationStatement, | ||
SetStatement, | ||
SpacelessBlock, | ||
AliasExpression, | ||
UseStatement, | ||
UnaryNotExpression, | ||
UnaryNeqExpression, | ||
UnaryPosExpression, | ||
BinaryOrExpression, | ||
BinaryAndExpression, | ||
BitwiseOrExpression, | ||
BitwiseXorExpression, | ||
BitwiseAndExpression, | ||
BinaryEqualsExpression, | ||
BinaryNotEqualsExpression, | ||
BinaryLessThanExpression, | ||
BinaryGreaterThanExpression, | ||
BinaryLessThanOrEqualExpression, | ||
BinaryGreaterThanOrEqualExpression, | ||
BinaryNotInExpression, | ||
BinaryInExpression, | ||
BinaryMatchesExpression, | ||
BinaryStartsWithExpression, | ||
BinaryEndsWithExpression, | ||
BinaryRangeExpression, | ||
BinaryAddExpression, | ||
BinaryMulExpression, | ||
BinaryDivExpression, | ||
BinaryFloorDivExpression, | ||
BinaryModExpression, | ||
BinaryPowerExpression, | ||
BinaryNullCoalesceExpression, | ||
TestEvenExpression, | ||
TestOddExpression, | ||
TestDefinedExpression, | ||
TestSameAsExpression, | ||
TestNullExpression, | ||
TestDivisibleByExpression, | ||
TestConstantExpression, | ||
TestEmptyExpression, | ||
TestIterableExpression, | ||
} from './types'; |