@@ -45,13 +45,13 @@ export function splitLabelToCommands(label = "") {
4545 * @return {string }
4646 */
4747export function strip ( s ) {
48- // inspired from https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/string/strip.rb
49- if ( ( s === undefined ) || ( s === "" ) ) {
50- return s ;
51- }
52- const indents = s . split ( / \n / ) . map ( s => s . match ( / ^ [ \t ] * (? = \S ) / ) ) . filter ( m => m ) . map ( m => m [ 0 ] ) ;
53- const smallestIndent = indents . sort ( ( a , b ) => a . length - b . length ) [ 0 ] ;
54- return s . replace ( new RegExp ( `^${ smallestIndent } ` , "gm" ) , "" ) ;
48+ // inspired from https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/string/strip.rb
49+ if ( ( s === undefined ) || ( s === "" ) ) {
50+ return s ;
51+ }
52+ const indents = s . split ( / \n / ) . map ( s => s . match ( / ^ [ \t ] * (? = \S ) / ) ) . filter ( m => m ) . map ( m => m [ 0 ] ) ;
53+ const smallestIndent = indents . sort ( ( a , b ) => a . length - b . length ) [ 0 ] ;
54+ return s . replace ( new RegExp ( `^${ smallestIndent } ` , "gm" ) , "" ) ;
5555}
5656
5757/**
@@ -73,8 +73,8 @@ export function containIncludeCommand(commands = []) {
7373 * @param {string } label
7474 * @return {object }
7575 */
76- export function parseVariablesFromLabel ( kvMap , label ) {
77- const kv = Object . assign ( { } , kvMap ) ;
76+ export function parseVariablesFromLabel ( kvMap , label ) {
77+ const kv = Object . assign ( { } , kvMap ) ;
7878 const beginEx = "\^.*" ;
7979 const endEx = ".*\$" ;
8080 const sepEx = ",?" ;
@@ -90,18 +90,17 @@ export function parseVariablesFromLabel(kvMap,label) {
9090 valEx = "(([-\\w\\s]*,?)*)" ;
9191 }
9292 // Add value check here
93- switch ( typeof defaultKeyValueMap [ key ] ) {
94- case "string" :
95- valEx = quotesEx + valEx + quotesEx ;
96- break ;
97- case "boolean" :
93+ switch ( typeof defaultKeyValueMap [ key ] ) {
94+ case "string" :
95+ valEx = quotesEx + valEx + quotesEx ;
96+ break ;
97+ case "boolean" :
9898 // no quotes
99- valEx = quotesEx + "?(true|false)" + quotesEx + "?" ;
100- break ;
101- default :
102- logger . error ( "include-codeblock: parseVariablesFromLabel: key type `" +
103- typeof defaultKeyValueMap [ key ] + "` unknown (see options.js)" ) ;
104- break ;
99+ valEx = quotesEx + "?(true|false)" + quotesEx + "?" ;
100+ break ;
101+ default :
102+ logger . error ( "include-codeblock: parseVariablesFromLabel: key type `" + typeof defaultKeyValueMap [ key ] + "` unknown (see options.js)" ) ;
103+ break ;
105104 }
106105 // Val type cast to string.
107106 const regStr = beginEx + sepEx + spacesEx + keyEx +
@@ -123,18 +122,17 @@ export function parseVariablesFromLabel(kvMap,label) {
123122 * @param {string } content
124123 * @return {string }
125124 */
126- export function generateEmbedCode (
127- kvMap ,
128- { fileName, originalPath, content} ) {
125+ export function generateEmbedCode ( kvMap ,
126+ { fileName, originalPath, content} ) {
129127 const tContent = getTemplateContent ( kvMap ) ;
130- const kv = Object . assign ( { } , kvMap ) ;
128+ const kv = Object . assign ( { } , kvMap ) ;
131129 const count = hasTitle ( kv ) ? codeCounter ( ) : - 1 ;
132130 checkMapTypes ( kvMap , "generatedEmbedCode" ) ;
133- const contextMap = Object . assign ( { } , kvMap , {
134- "content" :content ,
135- "count" :count ,
136- "fileName" :fileName ,
137- "originalPath" :originalPath
131+ const contextMap = Object . assign ( { } , kvMap , {
132+ "content" : content ,
133+ "count" : count ,
134+ "fileName" : fileName ,
135+ "originalPath" : originalPath
138136 } ) ;
139137 // compile template
140138 const handlebars = Handlebars . compile ( tContent ) ;
@@ -148,8 +146,8 @@ export function generateEmbedCode(
148146 * @param {string } originalPath
149147 * @return {string }
150148 */
151- export function getContent ( filePath , originalPath ) {
152- return readFileFromPath ( filePath ) ;
149+ export function getContent ( filePath , originalPath ) {
150+ return readFileFromPath ( filePath ) ;
153151}
154152
155153/**
@@ -161,7 +159,7 @@ export function getContent(filePath,originalPath){
161159 * @return {string }
162160 */
163161export function embedCode ( kvMap ,
164- { filePath, originalPath, label} ) {
162+ { filePath, originalPath, label} ) {
165163 const code = getContent ( filePath , originalPath ) ;
166164 const fileName = path . basename ( filePath ) ;
167165 const kvmparsed = parseVariablesFromLabel ( kvMap , label ) ;
@@ -206,10 +204,10 @@ export function parse(content, baseDir, options = {}) {
206204 const replacedContent = embedCode (
207205 kvMap ,
208206 {
209- filePath : absolutePath ,
210- originalPath : originalPath ,
211- label
212- } ) ;
207+ filePath : absolutePath ,
208+ originalPath : originalPath ,
209+ label
210+ } ) ;
213211 results . push ( {
214212 target : all ,
215213 replaced : replacedContent
0 commit comments