From 11ab09c30bf5182917d721ffb0dbc1b271fa000a Mon Sep 17 00:00:00 2001 From: Jay Traband Date: Tue, 15 Sep 2015 12:26:37 -0700 Subject: [PATCH] Fix for styling bug + additional styleguide examples --- public/_includes/_util-fns.jade | 4 ++- .../_includes/styleguide/_code-examples.jade | 32 ++++++++++++++++--- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/public/_includes/_util-fns.jade b/public/_includes/_util-fns.jade index 2f5f11d128..9496480ff3 100644 --- a/public/_includes/_util-fns.jade +++ b/public/_includes/_util-fns.jade @@ -98,7 +98,9 @@ mixin makeJson(path, fileName, title, jsonConfig, stylePatterns) - } while (matches != null && rx.global ); - for (var match in repls) { - var repl = repls[match]; -- var rx2 = new RegExp(match, repl.isGlobal ? "g" : ""); +- // var escapedMatch = match.replace(/\\/g,'\\').replace(/\(/g,'\(').replace(/\)/g, '\)').replace(/\./,'\.'); +- // var rx2 = new RegExp(escapedMatch, repl.isGlobal ? "g" : ""); +- var rx2 = match; - str = str.replace(rx2, repl.repl); - }; - return str; diff --git a/public/docs/_includes/styleguide/_code-examples.jade b/public/docs/_includes/styleguide/_code-examples.jade index 2e8ecf778a..2df6cf32e7 100644 --- a/public/docs/_includes/styleguide/_code-examples.jade +++ b/public/docs/_includes/styleguide/_code-examples.jade @@ -199,13 +199,13 @@ include ../../../_includes/_util-fns A more complicated example might be: code-example(format="linenums" language="js"). - - var stylePattern = { pnk: /script (src=.*&quot)/g, otl: /(my-app)/ }; + - var stylePattern = { pnk: /script (src=.*")/g, otl: /(\S*my-app.*$)/m }; +makeExample('styleguide', 'js/index.html', 'index.html', stylePattern ) :markdown Which applies multiple styles and uses an intermediate javascript object as opposed to a literal. - - var stylePattern = { pnk: /script (src=.*")/g, otl: /(my-app)/ }; + - var stylePattern = { pnk: /script (src=.*")/g, otl: /(\S*my-app.*$)/m }; +makeExample('styleguide', 'js/index.html', 'index.html', stylePattern ) :markdown @@ -214,10 +214,10 @@ include ../../../_includes/_util-fns object is passed in then it is assumed to apply to all of the tabs. code-example(format="linenums" language="js"). - -var stylePatterns = [{ pnk: /script (src=.*")/g }, {pnk: /(result)/ }]; + -var stylePatterns = [{ pnk: /script (src=.*")/g }, {pnk: /(result)/ }]; +makeTabs('styleguide', 'js/index.html, js/spec.js', 'index.html,unit test', stylePatterns) - -var stylePatterns = [{ pnk: /script (src=.*")/g }, {pnk: /(result)/ }]; + -var stylePatterns = [{ pnk: /script (src=.*")/g }, {pnk: /(result)/ }]; +makeTabs('styleguide', 'js/index.html, js/spec.js', 'index.html,unit test', stylePatterns) .l-sub-section @@ -257,6 +257,23 @@ include ../../../_includes/_util-fns +makeJson('styleguide', 'package.json', "Selected parts of the package.json file", {paths: 'version, scripts.tsc, scripts.start '} ) + :markdown + Styling selected portions of the json is also supported. + + code-example(format="linenums" language="js"). + +makeJson('styleguide', 'package.json', "package.json dependencies", {paths: 'dependencies'}, { pnk: [/(\S*traceur.*)/, /(\Sangular2.*)/, /(\Ssystem.*)/ ]}) + + +makeJson('styleguide', 'package.json', "package.json dependencies", {paths: 'dependencies'}, { pnk: [/(\S*traceur.*)/, /(\Sangular2.*)/, /(\Ssystem.*)/ ]}) + + :markdown + As well as styling across multiple lines. + + code-example(format="linenums" language="js"). + +makeJson('styleguide', 'package.json', "Foo", {paths: 'name, version, dependencies '}, styles ) + + - var styles = { pnk: /(^.*dependencies[\s\S]* \})/gm }; + +makeJson('styleguide', 'package.json', "Foo", {paths: 'name, version, dependencies '}, styles ) + .l-sub-section :markdown ### Inline code and code examples provided directly i.e. not from an example file. @@ -362,3 +379,10 @@ include ../../../_includes/_util-fns +makeExample('styleguide', 'js/app-class-w-annotations.js')(format="linenums:15") + :markdown + Or to supress line numbering completely you can use + + code-example(). + +makeExample('styleguide', 'js/app-class-w-annotations.js')(format=".") + + +makeExample('styleguide', 'js/app-class-w-annotations.js')(format=".") \ No newline at end of file