|
| 1 | +/* |
| 2 | + * mustache utilities for patternlab-node - v0.10.1 - 2015 |
| 3 | + * |
| 4 | + * Geoffrey Pursell, Brian Muenzenmeyer, and the web community. |
| 5 | + * Licensed under the MIT license. |
| 6 | + * |
| 7 | + * Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice. |
| 8 | + * |
| 9 | + */ |
| 10 | + |
| 11 | +(function () { |
| 12 | + 'use strict'; |
| 13 | + |
| 14 | + // the term "alphanumeric" includes underscores. |
| 15 | + |
| 16 | + // look for an opening mustache include tag, followed by >=0 whitespaces |
| 17 | + var partialsStr = '{{>\\s*'; |
| 18 | + // begin 1st exterior group, a mandatory group |
| 19 | + // look for >0 of an interior group comprising |
| 20 | + // >0 digits, followed by a hyphen, followed by >0 alphanumerics |
| 21 | + partialsStr += '((\\d+-[\\w-]+\\/)+'; |
| 22 | + // then an interior group comprising |
| 23 | + // >0 digits, followed by a hyphen, followed by >0 alphanumerics, |
| 24 | + // followed by an optional group of a period followed by >0 alphanumerics |
| 25 | + partialsStr += '(\\d+-[\\w-]+(\\.\\w+)?)'; |
| 26 | + // if the previous two interior groups are not found, look for any number of |
| 27 | + // alphanumerics or hyphens |
| 28 | + partialsStr += '|[\\w\\-]+)'; |
| 29 | + // end 1st exterior group |
| 30 | + // begin 2nd exterior group, an optional group |
| 31 | + // look for a colon, followed by >0 alphanumerics or hyphens, |
| 32 | + // followed by >=0 interior groups |
| 33 | + // comprising a pipe, followed by >0 alphanumerics or hyphens |
| 34 | + partialsStr += '(\\:[\\w\\-]+(\\|[\\w\\-]+)*)?'; |
| 35 | + // end 2nd exterior group |
| 36 | + // begin 3rd exterior group, an optional group |
| 37 | + // look for an opening parenthesis, followed by >=0 whitespaces, followed by |
| 38 | + // >0 alphanumerics, followed by >=0 whitespaces, followed by a colon, |
| 39 | + // followed by >=0 whitespaces |
| 40 | + partialsStr += '(\\(\\s*\\w+\\s*\\:\\s*'; |
| 41 | + // followed by an interior group |
| 42 | + // comprising a single quote, followed by an interior group comprising |
| 43 | + // >=0 characters that are not single quotes or backslashes |
| 44 | + // or >=0 character pairs comprising a backlash, followed by any character. |
| 45 | + // look for a single quote to terminate this pattern |
| 46 | + partialsStr += '(\'([^\'\\\\]|\\\\.)*\''; |
| 47 | + // if the pattern wrapped in single quotes is not found, look for one wrapped |
| 48 | + // in double quotes |
| 49 | + // look for a double quote, followed by an interior group comprising |
| 50 | + // >=0 characters that are not double quotes or backslashes |
| 51 | + // or >=0 character pairs comprising a backlash, followed by any character. |
| 52 | + // look for a double quote to terminate this pattern |
| 53 | + partialsStr += '|"([^"\\\\]|\\\\.)*")'; |
| 54 | + // look for a closing parenthesis |
| 55 | + partialsStr += '\\))?'; |
| 56 | + // end 3rd exterior group |
| 57 | + // look for >=0 whitespaces, followed by closing mustache tag |
| 58 | + partialsStr += '\\s*}}'; |
| 59 | + var partialsRE = new RegExp(partialsStr, 'g'); |
| 60 | + |
| 61 | + // look for an opening mustache include tag, followed by >=0 whitespaces |
| 62 | + var partialsWithStyleModifiersStr = '{{>\\s*'; |
| 63 | + // one or more characters comprising any combination of alphanumerics, |
| 64 | + // hyphens, periods, slashses, and tildes |
| 65 | + partialsWithStyleModifiersStr += '([\\w\\-\\.\\/~]+)'; |
| 66 | + // the previous group cannot be followed by an opening parenthesis |
| 67 | + partialsWithStyleModifiersStr += '(?!\\()'; |
| 68 | + // a colon followed by one or more characters comprising any combination |
| 69 | + // of alphanumerics, hyphens, and pipes |
| 70 | + partialsWithStyleModifiersStr += '(\\:[\\w\\-\\|]+)'; |
| 71 | + // an optional group of characters starting with >=0 whitespaces, followed by |
| 72 | + // an opening parenthesis, followed by any number of characters that are not |
| 73 | + // closing parentheses, followed by a closing parenthesis |
| 74 | + partialsWithStyleModifiersStr += '(\\s*\\([^\\)]*\\))?'; |
| 75 | + // look for >=0 whitespaces, followed by closing mustache tag |
| 76 | + partialsWithStyleModifiersStr += '\\s*}}'; |
| 77 | + var partialsWithStyleModifiersRE = new RegExp(partialsWithStyleModifiersStr, 'g'); |
| 78 | + |
| 79 | + // look for an opening mustache include tag, followed by >=0 whitespaces |
| 80 | + var partialsWithPatternParametersStr = '{{>\\s*'; |
| 81 | + // one or more characters comprising any combination of alphanumerics, |
| 82 | + // hyphens, periods, slashses, and tildes |
| 83 | + partialsWithPatternParametersStr += '([\\w\\-\\.\\/~]+)'; |
| 84 | + // an optional group comprising a colon followed by one or more characters |
| 85 | + // comprising any combination of alphanumerics, |
| 86 | + // hyphens, and pipes |
| 87 | + partialsWithPatternParametersStr += '(\\:[\\w\\-\\|]+)?'; |
| 88 | + // a group of characters starting with >=0 whitespaces, followed by an opening |
| 89 | + // parenthesis, followed by any number of characters that are not closing |
| 90 | + // parentheses, followed by a closing parenthesis |
| 91 | + partialsWithPatternParametersStr += '(\\s*\\([^\\)]*\\))'; |
| 92 | + // look for >=0 whitespaces, followed by closing mustache tag |
| 93 | + partialsWithPatternParametersStr += '\\s*}}'; |
| 94 | + var partialsWithPatternParametersRE = new RegExp(partialsWithPatternParametersStr, 'g'); |
| 95 | + |
| 96 | + // look for an opening mustache loop tag, followed by >=0 whitespaces |
| 97 | + var listItemsStr = '{{#\\s*'; |
| 98 | + // look for the string 'listItems.' or 'listitems.' |
| 99 | + listItemsStr += '(list(I|i)tems\\.)'; |
| 100 | + // look for a number 1 - 20, spelled out |
| 101 | + listItemsStr += '(one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve|thirteen|fourteen|fifteen|sixteen|seventeen|eighteen|nineteen|twenty)'; |
| 102 | + // look for >=0 whitespaces, followed by closing mustache tag |
| 103 | + listItemsStr += '\\s*}}'; |
| 104 | + var listItemsRE = new RegExp(listItemsStr, 'g'); |
| 105 | + |
| 106 | + // look for an opening mustache loop tag, followed by >=0 whitespaces |
| 107 | + var partialKeyStr = '{{>\\s*'; |
| 108 | + // one or more characters comprising any combination of alphanumerics, |
| 109 | + // hyphens, periods, slashses, and tildes |
| 110 | + partialKeyStr += '([\\w\\-\\.\\/~]+)'; |
| 111 | + // an optional group of characters starting with a colon, followed by >0 |
| 112 | + // alphanumerics, hyphens, or pipes |
| 113 | + partialKeyStr += '(\\:[\\w\\-|]+)?'; |
| 114 | + // an optional group of characters starting with a colon, followed by >0 |
| 115 | + // alphanumerics or hyphens |
| 116 | + partialKeyStr += '(\\:[\\w\\-]+)?'; |
| 117 | + // an optional group of characters starting with >=0 whitespaces, followed by |
| 118 | + // an opening parenthesis, followed by any number of characters that are not |
| 119 | + // closing parentheses, followed by a closing parenthesis |
| 120 | + partialKeyStr += '(\\s*\\([^\\)]*\\))?'; |
| 121 | + // look for >=0 whitespaces, followed by closing mustache tag |
| 122 | + partialKeyStr += '\\s*}}'; |
| 123 | + var partialKeyRE = new RegExp(partialKeyStr, 'g'); |
| 124 | + |
| 125 | + var utilMustache = { |
| 126 | + partialsRE: partialsRE, |
| 127 | + partialsWithStyleModifiersRE: partialsWithStyleModifiersRE, |
| 128 | + partialsWithPatternParametersRE: partialsWithPatternParametersRE, |
| 129 | + listItemsRE: listItemsRE, |
| 130 | + partialKeyRE: partialKeyRE |
| 131 | + }; |
| 132 | + |
| 133 | + module.exports = utilMustache; |
| 134 | +})(); |
0 commit comments