-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2cf6812
commit 3f5a685
Showing
6 changed files
with
208 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import DefineMap from 'can-define/map/map' | ||
import { pageProps, fieldProps, buttonProps } from './propsLists' | ||
|
||
const getRegEx = (varName, useExplicitSearch) => { | ||
const lowerCaseVarName = varName.toLowerCase() | ||
|
||
const parens = `\\(${lowerCaseVarName}\\)` | ||
const percent = `\\%${lowerCaseVarName}\\%` | ||
const brackets = `\\[${lowerCaseVarName}\\]` | ||
const noTrailingQuotes = `${lowerCaseVarName}(?!")` | ||
const implicitPrep = `(?<!")${lowerCaseVarName}` | ||
|
||
const implicitRegEx = new RegExp(`${implicitPrep}&${noTrailingQuotes}|${parens}|${percent}|${brackets}|${lowerCaseVarName}`, 'gi') | ||
const greedyRegEx = new RegExp(`${noTrailingQuotes}|${parens}|${percent}|${brackets}|${lowerCaseVarName}`, 'gi') | ||
|
||
return useExplicitSearch ? implicitRegEx : greedyRegEx | ||
} | ||
|
||
const getMatches = (page, regEx) => { // pages or fields or buttons | ||
const foundMatches = { page: [], fields: [], buttons: [] } | ||
// check top level page properties | ||
for (const entry of pageProps) { | ||
const prop = entry.key | ||
const testValue = page[prop] | ||
|
||
const matches = testValue.match(regEx) | ||
|
||
if (matches && matches.length) { | ||
foundMatches.page.push(entry.display) | ||
} | ||
} | ||
|
||
for (const field of page.fields) { | ||
for (const entry of fieldProps) { | ||
const prop = entry.key | ||
const testValue = field[prop] | ||
|
||
const matches = testValue.match(regEx) | ||
|
||
if (matches && matches.length) { | ||
foundMatches.fields.push(entry.display) | ||
} | ||
} | ||
} | ||
|
||
for (const button of page.buttons) { | ||
for (const entry of buttonProps) { | ||
const prop = entry.key | ||
const testValue = button[prop] | ||
|
||
const matches = testValue.match(regEx) | ||
|
||
if (matches && matches.length) { | ||
foundMatches.buttons.push(entry.display) | ||
} | ||
} | ||
} | ||
|
||
return foundMatches | ||
} | ||
|
||
export const findVarUsage = (varName, pages, useExplicitSearch) => { | ||
const regEx = getRegEx(varName, useExplicitSearch) | ||
const matches = new DefineMap({}) | ||
|
||
for (const page of pages) { | ||
matches[page.name] = getMatches(page, regEx) | ||
} | ||
|
||
console.log('final matches', matches) | ||
return matches | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
export const pageProps = [ | ||
{ key: 'name', type: 'macro', display: 'Page Name' }, | ||
{ key: 'text', type: 'macro', display: 'Question Text' }, | ||
{ key: 'repeatVar', type: 'string', display: 'Counting Variable' }, | ||
{ key: 'outerLoopVar', type: 'string', display: 'Outer Loop Variable' }, | ||
{ key: 'learn', type: 'macro', display: 'LearnMore Prompt' }, | ||
{ key: 'help', type: 'macro', display: 'LearnMore Response' }, | ||
{ key: 'helpReader', type: 'macro', display: 'Video Transcript' }, | ||
{ key: 'codeBefore', type: 'logic', display: 'Before Logic' }, | ||
{ key: 'codeAfter', type: 'logic', display: 'After Logic' } | ||
] | ||
|
||
export const fieldProps = [ | ||
{ key: 'label', type: 'macro', display: 'Field Label' }, | ||
{ key: 'name', type: 'string', display: 'Field Variable' }, | ||
{ key: 'value', type: 'macro', display: 'Field Default Value' }, | ||
{ key: 'invalidPrompt', type: 'macro', display: 'Field Custom Invalid Prompt' }, | ||
{ key: 'sample', type: 'macro', display: 'Field Sample Value' } | ||
] | ||
|
||
export const buttonProps = [ | ||
{ key: 'label', type: 'macro', display: 'Button Label' }, | ||
{ key: 'name', type: 'string', display: 'Button Variable Name' }, | ||
{ key: 'value', type: 'macro', display: 'Button Default Value' }, | ||
{ key: 'repeatVar', type: 'string', display: 'Button Counting Variable' }, | ||
{ key: 'url', type: 'macro', display: 'Button URL' } | ||
] |
Oops, something went wrong.