Skip to content

Commit

Permalink
Add {{raw}} helper + less strict spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
nolimits4web committed Oct 24, 2017
1 parent 3b33a9b commit 063d7f4
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const Template7Utils = {
},
helperToSlices(string) {
const { quoteDoubleRexExp, quoteSingleRexExp } = Template7Utils;
const helperParts = string.replace(/[{}#}]/g, '').split(' ');
const helperParts = string.replace(/[{}#}]/g, '').trim().split(' ');
const slices = [];
let shiftIndex;
let i;
Expand Down Expand Up @@ -83,7 +83,7 @@ const Template7Utils = {
if (!string) return [];
const stringBlocks = string.split(/({{[^{^}]*}})/);
for (i = 0; i < stringBlocks.length; i += 1) {
const block = stringBlocks[i];
let block = stringBlocks[i];
if (block === '') continue;
if (block.indexOf('{{') < 0) {
blocks.push({
Expand All @@ -94,6 +94,9 @@ const Template7Utils = {
if (block.indexOf('{/') >= 0) {
continue;
}
block = block
.replace(/{{([#/])*([ ])*/, '{{$1')
.replace(/([ ])*}}/, '}}');
if (block.indexOf('{#') < 0 && block.indexOf(' ') < 0 && block.indexOf('else') < 0) {
// Simple variable
blocks.push({
Expand Down Expand Up @@ -157,14 +160,21 @@ const Template7Utils = {
}
if (foundClosed) {
if (shiftIndex) i = shiftIndex;
blocks.push({
type: 'helper',
helperName,
contextName: helperContext,
content: helperContent,
inverseContent: elseContent,
hash: helperHash,
});
if (helperName === 'raw') {
blocks.push({
type: 'plain',
content: helperContent,
});
} else {
blocks.push({
type: 'helper',
helperName,
contextName: helperContext,
content: helperContent,
inverseContent: elseContent,
hash: helperHash,
});
}
}
} else if (block.indexOf(' ') > 0) {
if (isPartial) {
Expand Down

0 comments on commit 063d7f4

Please sign in to comment.