@progress/kendo-common-tasks 8.0.7-dev.0 → 8.0.7-dev.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/README.md +2 -3
  2. package/index.js +5 -50
  3. package/package.json +13 -52
  4. package/docs-layout.hbs +0 -51
  5. package/docs-public/bootstrap.css +0 -6759
  6. package/docs-public/bootstrap.min.js +0 -7
  7. package/docs-public/codemirror/clike.min.js +0 -1
  8. package/docs-public/codemirror/codemirror.min.js +0 -5
  9. package/docs-public/codemirror/css.min.js +0 -1
  10. package/docs-public/codemirror/htmlmixed.min.js +0 -1
  11. package/docs-public/codemirror/javascript.min.js +0 -1
  12. package/docs-public/codemirror/jsx.min.js +0 -1
  13. package/docs-public/codemirror/php.min.js +0 -1
  14. package/docs-public/codemirror/runmode.min.js +0 -1
  15. package/docs-public/codemirror/xml.min.js +0 -1
  16. package/docs-public/docs.css +0 -208
  17. package/docs-public/docs.scss +0 -253
  18. package/docs-public/editor/angular/app/app.component.ts +0 -3
  19. package/docs-public/editor/angular/app/app.module.ts +0 -14
  20. package/docs-public/editor/angular/index.html +0 -32
  21. package/docs-public/editor/angular/main.ts +0 -15
  22. package/docs-public/editor/angular/polyfills.ts +0 -73
  23. package/docs-public/editor/angular/styles.css +0 -13
  24. package/docs-public/editor/builder/app/app.component.html +0 -1
  25. package/docs-public/editor/builder/app/app.component.ts +0 -17
  26. package/docs-public/editor/builder/app/app.css +0 -449
  27. package/docs-public/editor/builder/app/app.module.ts +0 -53
  28. package/docs-public/editor/builder/app/core/core.module.ts +0 -19
  29. package/docs-public/editor/builder/app/core/data/data-services.exports.ts +0 -71
  30. package/docs-public/editor/builder/app/core/data/data.service.ts +0 -183
  31. package/docs-public/editor/builder/app/core/data/odata-service-factory.ts +0 -23
  32. package/docs-public/editor/builder/app/core/data/odata.service.ts +0 -88
  33. package/docs-public/editor/builder/app/core/module.config.ts +0 -19
  34. package/docs-public/editor/builder/app/data/odata-provider/customer.config.ts +0 -17
  35. package/docs-public/editor/builder/app/data/odata-provider/customer.model.ts +0 -17
  36. package/docs-public/editor/builder/app/grid-demo.base.component.ts +0 -107
  37. package/docs-public/editor/builder/app/grid-demo.component.html +0 -37
  38. package/docs-public/editor/builder/app/grid-demo.component.ts +0 -1
  39. package/docs-public/editor/builder/app/shared/components/grid/grid.component.html +0 -5
  40. package/docs-public/editor/builder/app/shared/components/grid/grid.component.ts +0 -243
  41. package/docs-public/editor/builder/app/shared/services/grid-incell-editing.service.ts +0 -120
  42. package/docs-public/editor/builder/app/topSection.html +0 -12
  43. package/docs-public/editor/builder/app/topSection.ts +0 -25
  44. package/docs-public/editor/builder/assets/themes/metro.css +0 -18877
  45. package/docs-public/editor/builder/index.html +0 -14
  46. package/docs-public/editor/builder/main.ts +0 -14
  47. package/docs-public/editor/builder/polyfills.ts +0 -67
  48. package/docs-public/editor/builder/styles.css +0 -1
  49. package/docs-public/editor/builder/tsconfig.app.json +0 -13
  50. package/docs-public/editor/builder/typings.d.ts +0 -5
  51. package/docs-public/editor/react/app/main.jsx +0 -6
  52. package/docs-public/editor/react/index.html +0 -32
  53. package/docs-public/editor/vue/app/main.js +0 -5
  54. package/docs-public/editor/vue/index.html +0 -29
  55. package/docs-public/example-runner.js +0 -802
  56. package/docs-public/github.css +0 -99
  57. package/docs-public/snippets.js +0 -1722
  58. package/docs-public/tomorrow-night.css +0 -75
  59. package/docs-server.js +0 -152
  60. package/lint-slugs.js +0 -25
  61. package/markdown-serve/index.js +0 -10
  62. package/markdown-serve/parser.js +0 -234
  63. package/markdown-serve/resolver.js +0 -86
  64. package/markdown-serve/server.js +0 -370
  65. package/test/jest-setup.js +0 -2
  66. package/test/snippets.test.js +0 -373
@@ -1,75 +0,0 @@
1
- /* Tomorrow Night Theme */
2
- /* http://jmblog.github.com/color-themes-for-google-code-highlightjs */
3
- /* Original theme - https://github.com/chriskempson/tomorrow-theme */
4
- /* http://jmblog.github.com/color-themes-for-google-code-highlightjs */
5
-
6
- /* Tomorrow Comment */
7
- .hljs-comment,
8
- .hljs-quote {
9
- color: #969896;
10
- }
11
-
12
- /* Tomorrow Red */
13
- .hljs-variable,
14
- .hljs-template-variable,
15
- .hljs-tag,
16
- .hljs-name,
17
- .hljs-selector-id,
18
- .hljs-selector-class,
19
- .hljs-regexp,
20
- .hljs-deletion {
21
- color: #cc6666;
22
- }
23
-
24
- /* Tomorrow Orange */
25
- .hljs-number,
26
- .hljs-built_in,
27
- .hljs-builtin-name,
28
- .hljs-literal,
29
- .hljs-type,
30
- .hljs-params,
31
- .hljs-meta,
32
- .hljs-link {
33
- color: #de935f;
34
- }
35
-
36
- /* Tomorrow Yellow */
37
- .hljs-attribute {
38
- color: #f0c674;
39
- }
40
-
41
- /* Tomorrow Green */
42
- .hljs-string,
43
- .hljs-symbol,
44
- .hljs-bullet,
45
- .hljs-addition {
46
- color: #b5bd68;
47
- }
48
-
49
- /* Tomorrow Blue */
50
- .hljs-title,
51
- .hljs-section {
52
- color: #81a2be;
53
- }
54
-
55
- /* Tomorrow Purple */
56
- .hljs-keyword,
57
- .hljs-selector-tag {
58
- color: #b294bb;
59
- }
60
-
61
- .hljs {
62
- display: block;
63
- overflow-x: auto;
64
- background: #1d1f21;
65
- color: #c5c8c6;
66
- padding: 0.5em;
67
- }
68
-
69
- .hljs-emphasis {
70
- font-style: italic;
71
- }
72
-
73
- .hljs-strong {
74
- font-weight: bold;
75
- }
package/docs-server.js DELETED
@@ -1,152 +0,0 @@
1
- const path = require('path');
2
- const fs = require('fs');
3
-
4
- const express = require('express');
5
- const mds = require('./markdown-serve');
6
- const BrowserSync = require('browser-sync');
7
- const serveIndex = require('serve-index');
8
- const rewrite = require('express-urlrewrite');
9
- const argv = require('yargs').argv;
10
-
11
- module.exports = (libraryName, onServerStart, done) => {
12
- const app = express();
13
- const platformMatch = new RegExp(/kendo.*(react|angular|vue|builder)/g).exec(libraryName);
14
- const platform = argv.platform || (platformMatch && platformMatch[1]) || 'angular';
15
- const staticContentOptions = {
16
- setHeaders: (response) => {
17
- response.set('Access-Control-Allow-Origin', 'http://run.plnkr.co');
18
- }
19
- };
20
-
21
- app.use(rewrite(/(.+)\.md$/, '/$1'));
22
-
23
- app.set('views', __dirname);
24
- app.set('view engine', 'hbs');
25
-
26
- app.use('/internals', express.static(path.join(__dirname, 'docs-public')));
27
- app.use('/internals', express.static(path.join(__dirname, '.compiled')));
28
- app.use('/cdn', express.static('dist/cdn/'));
29
- app.use('/npm', express.static('node_modules', staticContentOptions));
30
- app.use('/npm', express.static('../../node_modules', staticContentOptions));
31
- app.use(`/npm/@progress/${libraryName}`, express.static('.', staticContentOptions));
32
- app.use('/', serveIndex('docs', { 'icons': true }));
33
- app.use('/', express.static('docs/'));
34
-
35
- const constant = (x) => () => x;
36
- const meta = (_, options = "") => {
37
- const opts = options.split(' ').reduce((hash, tuple) => {
38
- const [ key, value ] = tuple.split(':');
39
- if (key) {
40
- hash[key] = value;
41
- }
42
- return hash;
43
- }, {});
44
-
45
- const attr = Object.keys(opts).map(
46
- (key) => `data-${key}='${opts[key]}'`
47
- );
48
-
49
- if (Object.prototype.hasOwnProperty.call(opts, 'height')) {
50
- attr.push(`style='height: ${Number(opts['height']) + 50}px'`);
51
- }
52
-
53
- return `<div ${attr.join(' ')}>`;
54
- };
55
- const encode = { '&': '&amp;', '<': '&lt;', '>': '&gt;' };
56
- const escapeHtml = (str) => str.replace(/[&<>]/g, (char) => encode[char]);
57
- const exists = (file) => {
58
- try {
59
- fs.accessSync(file, fs.F_OK);
60
- return true;
61
- } catch (e) {
62
- return false;
63
- }
64
- };
65
- const variant = (_, options) => {
66
- const opts = options.split(' ').reduce((hash, tuple) => {
67
- const [ key, value ] = tuple.split(':');
68
- if (key) {
69
- hash[key] = value;
70
- }
71
- return hash;
72
- }, {});
73
-
74
- return String(``
75
- + `<div>`
76
- + `<h4> Vartiant: ${opts.title}</h4>`);
77
-
78
- };
79
- const embedFile = (_, options) => {
80
- const params = options.split(' ');
81
- const filepath = path.join("docs", "examples", params[0]);
82
-
83
- if (!exists(filepath)) {
84
- console.warn(`Demo file ${filepath} not found.`); // eslint-disable-line no-console
85
- return "";
86
- }
87
-
88
- const basename = path.basename(filepath);
89
- const language = path.extname(basename).replace('.','');
90
- const hidden = params.some(p => p === "hidden");
91
- const preview = params.some(p => p === "preview");
92
- const content = escapeHtml(fs.readFileSync(filepath, 'utf-8'));
93
- return `
94
- <pre data-file='${basename}' ${hidden ? "data-hidden='true'" : "" }>
95
- <code class='language-${language}-multiple${preview ? "-preview" : "" }'>${content}</code>
96
- </pre>`;
97
- };
98
- const platformContent = (_, platformCapture, contentCapture) =>
99
- (platformCapture === platform ? contentCapture : '');
100
-
101
- const processPlugins = (content, plugins) => {
102
- let result = content;
103
- plugins.forEach((plugin) => {
104
- const pluginRe = new RegExp(`{%\\s*${plugin.name}\\s*([^%]+)?\\s*%}`, 'g');
105
- result = result.replace(plugin.regExp || pluginRe, plugin.process);
106
- });
107
- return result;
108
- };
109
-
110
- app.use(mds.middleware({
111
- rootDirectory: 'docs',
112
- view: 'docs-layout',
113
- preParse: function(markdownFile) {
114
- let content = markdownFile.parseContent();
115
-
116
- content = processPlugins(content, [
117
- {
118
- name: "platform_content",
119
- regExp: new RegExp('{%\\s*platform_content\\s*([^%]+?)\\s*%}((.|\\n)*?){%\\s*endplatform_content\\s*%}', 'g'),
120
- process: platformContent
121
- },
122
- { name: "variant", process: variant },
123
- { name: "endvariant", process: constant("</div>") },
124
- { name: "embed_file", process: embedFile },
125
- { name: "meta", process: meta },
126
- { name: "endmeta", process: constant("</div>") }
127
- ]);
128
-
129
- return {
130
- scriptSrc: `js/${libraryName}.js`,
131
- styleSrc: `css/${libraryName}.css`,
132
- content: content,
133
- platform: platform,
134
- blueprint: 'stackblitz'
135
- };
136
- }
137
- }));
138
-
139
- app.listen(3000, () => {
140
- const browserSync = BrowserSync.create();
141
-
142
- browserSync.init({
143
- open: false,
144
- port: 8080,
145
- proxy: "localhost:3000"
146
- });
147
-
148
- onServerStart(browserSync);
149
- });
150
-
151
- process.on('exit', done);
152
- };
package/lint-slugs.js DELETED
@@ -1,25 +0,0 @@
1
- const contains = require('gulp-contains');
2
- const PluginError = require('plugin-error');
3
-
4
- module.exports = (gulp, packageName) => {
5
- const reportError = message => (string, file, cb) => {
6
- const filename = /[/\\](docs.*)$/.exec(file.path)[1];
7
- const error = `
8
- ${message.replace(/FILE/, filename)}
9
- I can't tell you exactly where due to technical limitations, sorry.
10
- Validation provided by ${packageName}.`;
11
- cb(new PluginError('gulp-contains', error));
12
- };
13
-
14
- gulp.task('lint-slugs', () =>
15
- gulp.src('docs/**/*.{md,hbs}')
16
- .pipe(contains({
17
- search: /{%\s*(?!(asset_path|variant|endvariant|embed_file|endmeta|meta|slug|platform_content|endplatform_content)\b)\w+/,
18
- onFound: reportError("Unknown Liquid tags found in 'FILE'.")
19
- }))
20
- .pipe(contains({
21
- search: /{%\s*slug\s+(?!([a-zA-Z0-9_-])+\s*%})/,
22
- onFound: reportError("Slugs with invalid characters found in 'FILE'.")
23
- }))
24
- );
25
- };
@@ -1,10 +0,0 @@
1
- /**
2
- * @author Nguyen Ly <lyphtec@gmail.com>
3
- * @copyright Nguyen Ly 2014
4
- * @license MIT License
5
- *
6
- * @fileOverview This is the base module definition
7
- * @module markdown-serve
8
- */
9
-
10
- module.exports = require('./server');
@@ -1,234 +0,0 @@
1
- /**
2
- * @author Nguyen Ly <lyphtec@gmail.com>
3
- * @copyright Nguyen Ly 2014
4
- * @license MIT License
5
- *
6
- * @fileOverview Handles Markdown file parsing, extracting out the YAML front-matter and parsing the content converting to HTML
7
- * @module markdown-serve/parser
8
- * @requires fs
9
- * @requires js-yaml
10
- * @requires marked
11
- * @requires highlight.js
12
- * @requires lodash
13
- * @requires crypto
14
- * @requires path
15
- * @requires mkdirp
16
- * @exports markdown-serve/parser
17
- */
18
-
19
- var fs = require('fs'),
20
- yaml = require('js-yaml'),
21
- marked = require('marked'),
22
- hl = require('highlight.js'),
23
- _ = require('lodash'),
24
- path = require('path'),
25
- mkdirp = require('mkdirp'),
26
- crypto = require('crypto');
27
-
28
- exports = module.exports = {
29
- /**
30
- * {@link MarkdownFile}
31
- * @this {MarkdownFile}
32
- */
33
- MarkdownFile : MarkdownFile,
34
-
35
- /**
36
- * [parse()]{@link module:markdown-serve/parser.parse} callback
37
- * @callback module:markdown-serve/parser~parseCallback
38
- * @alias parseCallback
39
- * @param {?Object} err Errors if any
40
- * @param {MarkdownFile} result
41
- */
42
-
43
- /**
44
- * Attempts to load a MarkdownFile
45
- * @function
46
- * @param {string} file Full path to file to load
47
- * @param {?Object=} markedOptions Optional options to pass to "marked" module for Markdown processing
48
- * @param {parseCallback} callback [parseCallback]{@link module:markdown-serve/parser~parseCallback}
49
- * @returns {MarkdownFile}
50
- */
51
- parse : function(file, markedOptions, callback) {
52
- var noOpts = false;
53
-
54
- // make 2nd arg optional
55
- if (arguments.length === 2 && _.isFunction(arguments[1])) {
56
- callback = arguments[1];
57
- noOpts = true;
58
- }
59
-
60
- fs.readFile(file, 'utf8', function(err, data) {
61
- if (err) {
62
- return callback(err);
63
- }
64
-
65
- var result = new MarkdownFile(file);
66
- result.checksum = checksum(data);
67
- result.stats = getStats(file);
68
- result.created = result.stats.ctime;
69
- result.modified = result.stats.mtime;
70
- result.size = result.stats.size;
71
-
72
- var content = data.replace(/^-{3}/, '').split('---'); // split on normalised (trimmed) "---" lines
73
-
74
- if (content.length === 1) {
75
- result.rawContent = content[0];
76
- } else {
77
- // if we cannot parse the YAML, we assume file has no front matter
78
- var meta = parseYml(content[0]);
79
-
80
- // does data have YAML front matter? : as "---" is a valid Markdown tag (ie. it's a <hr />)
81
- if (meta) {
82
- result.meta = meta;
83
-
84
- content.shift(); // strip out YAML front matter
85
- }
86
-
87
- result.rawContent = content.join('---').replace(/^\n*/, '');
88
- }
89
-
90
- result._markedOptions = noOpts ? null : markedOptions;
91
-
92
- return callback(null, result);
93
- });
94
- }
95
- };
96
-
97
- /**
98
- * Represents a Markdown file.
99
- *
100
- * This object cannot be instantiated directly, but is returned as a result of [MarkdownServer.get()]{@link MarkdownServer#get} or [MarkdownServer.save()]{@link MarkdownServer#save}. It
101
- * is also made available as the `markdownFile` view model object passed to view when used as a simple middleware.
102
- *
103
- * Members with name starting with an underscore (_) are designed to be used internally.
104
- *
105
- * In typical usage, the parsed Markdown content (HTML) is available as an additional step (call to [MarkdownFile.parseContent()]{@link MarkdownFile#parseContent}),
106
- * rather than as a string property on the object. The reasoning behind this is for performance reasons, sometimes you do not need to get
107
- * at the HTML content straight away and need to apply some custom logic to specify front-matter variables ([MarkdownFile.meta]{@link MarkdownFile#meta})
108
- * first, eg. implementing a "draft publishing" feature.
109
- *
110
- * However, in some situations (eg. when using the [hbs]{@link https://github.com/donpark/hbs} view engine - the view doesn't support calling methods on the view model
111
- * object passed to it. In this case, when used as a middleware, you can set the `preParse` option to true and the parsed HTML content will
112
- * be available as the [MarkdownFile.parseContent()]{@link MarkdownFile#parsedContent} string property.
113
- *
114
- * @class
115
- * @alias MarkdownFile
116
- * @param {string} file Full path to file on the physical file system. File does not have to exist, as [MarkdownFile.saveChanges()]{@link MarkdownFile#saveChanges} can be called to create the file
117
- * @property {string} _file Gets the full path to file on the physical file system. Designed to be used internally & is set from the file parameter value when instantiated. NOTE: This property is deleted and not available when used in simple middleware scenario as exposing it could potentially be a security risk.
118
- * @property {?Object} meta Gets or sets the Javascript option that is serialized/de-serialized to/from the YAML front-matter in the file header. If set, the property will be serialized to YAML when [MarkdownFile.saveChanges()]{@link MarkdownFile#saveChanges} is called.
119
- * @property {string} rawContent Gets or sets the raw Markdown text content of file
120
- * @property {?Object} _markedOptions Gets the options that is passed to the [marked]{@link https://github.com/chjj/marked} module used for Markdown processing. This is a reference to [MarkdownServer.markedOptions]{@link MarkdownServer#markedOptions}.
121
- * @property {Object=} stats Gets the Node fs.Stats object containing properties of file
122
- * @property {Date=} created Gets the date file was created
123
- * @property {Date=} modified Gets the date file was last modified
124
- * @property {number=} size Gets the size in bytes of file
125
- * @property {string=} checksum Gets the SHA1 checksum of file contents (can be used as an ETag)
126
- * @property {string=} parsedContent Gets the result from [MarkdownFile.parseContent()]{@link MarkdownFile#parseContent}. This property is only made available when used
127
- * in the simple middleware scenario and when the `preParse` option is set to true. It is also set when no `view` option is specified.
128
- */
129
- function MarkdownFile(file) {
130
- if (!file) throw new Error('file is required');
131
-
132
- this._file = file;
133
- this.meta = null;
134
- this.rawContent = null;
135
- this._markedOptions = null;
136
- }
137
-
138
- /**
139
- * [MarkdownFile.parseContent()]{@link MarkdownFile#parseContent} callback
140
- * @callback MarkdownFile~parseContentCallback
141
- * @alias parseContentCallback
142
- * @param {?Object} err Errors if any
143
- * @param {string} result Converted HTML string
144
- */
145
-
146
- /**
147
- * Parses [MarkdownFile.rawContent]{@link MarkdownFile#rawContent} & returns HTML
148
- * @param {parseContentCallback} callback [parseContentCallback]{@link MarkdownFile~parseContentCallback}
149
- * @returns {string} Converted HTML string
150
- */
151
- MarkdownFile.prototype.parseContent = function(callback) {
152
- if (!this.rawContent) return callback(new Error('No rawContent to parse'));
153
-
154
- return parseMarkdown(this.rawContent, this._markedOptions, callback);
155
- };
156
-
157
- /**
158
- * [MarkdownFile.saveChanges()]{@link MarkdownFile#saveChanges} method callback
159
- * @callback MarkdownFile~saveChangesCallback
160
- * @alias saveChangesCallback
161
- * @param {?Object} err Errors if any
162
- * @param {boolean} result Success indicator
163
- */
164
-
165
- /**
166
- * Writes changes back to file on disk, overwriting existing file if it exists
167
- * @param {saveChangesCallback} callback [saveChangesCallback]{@link MarkdownFile~saveChangesCallback}
168
- * @returns {boolean} Success indicator
169
- */
170
- MarkdownFile.prototype.saveChanges = function(callback) {
171
- // create containing folder if it doesn't exist
172
- var dir = path.dirname(this._file);
173
- if (!fs.existsSync(dir))
174
- mkdirp.sync(dir);
175
-
176
- var s = '';
177
-
178
- if (this.meta) {
179
- s = yaml.safeDump(this.meta);
180
- s += '---\n\n';
181
- }
182
-
183
- s += this.rawContent;
184
-
185
- fs.writeFile(this._file, s, function(err) {
186
- if (err) return callback(err);
187
-
188
- return callback(null, true);
189
- });
190
- };
191
-
192
-
193
- //
194
- // Privates
195
- //
196
-
197
- function getStats(file) {
198
- return fs.statSync(file);
199
- }
200
-
201
- function parseYml(data) {
202
- if (!data) return null;
203
-
204
- try {
205
- return yaml.safeLoad(data);
206
- } catch (e) {
207
- // Log this somewhere?
208
- // console.log(e);
209
- }
210
-
211
- return null;
212
- }
213
-
214
- function parseMarkdown(source, options, callback) {
215
- if (options) {
216
- marked.setOptions(options);
217
- } else {
218
- // this seems to be the default - but we are setting it here explicitly
219
- marked.setOptions({
220
- highlight: function(code) {
221
- return hl.highlightAuto(code).value;
222
- }
223
- });
224
- }
225
-
226
- return marked(source, callback);
227
- }
228
-
229
- function checksum(str, algorithm, encoding) {
230
- return crypto
231
- .createHash(algorithm || 'sha1')
232
- .update(str, 'utf8')
233
- .digest(encoding || 'hex');
234
- }
@@ -1,86 +0,0 @@
1
- /**
2
- * @author Nguyen Ly <lyphtec@gmail.com>
3
- * @copyright Nguyen Ly 2014
4
- * @license MIT License
5
- *
6
- * @fileOverview Markdown file resolver
7
- * @module markdown-serve/resolver
8
- * @requires path
9
- * @requires fs
10
- * @exports markdown-serve/resolver
11
- */
12
-
13
- var path = require('path'),
14
- fs = require('fs');
15
-
16
- /**
17
- * File resolver utility
18
- * @function
19
- * @param {string} urlPath Relative URL path to file to try to resolve. Must start with a / and do not include the file extension
20
- * @param {string} rootDir Full path to root folder on file system that contains files to resolve
21
- * @param {resolverOptions=} options Optional [options]{@link MarkdownServer~resolverOptions} to specify default page name and file extension
22
- * @param {string} [options.defaultPageName=index] Name of default document
23
- * @param {string} [options.fileExtension=md] File extension of Markdown files
24
- * @returns {string} Full path to Markdown file if it exists, otherwise null
25
- */
26
- exports = module.exports = function(urlPath, rootDir, options) {
27
- if (!urlPath || urlPath[0] != '/') return null;
28
-
29
- rootDir = path.resolve(rootDir);
30
-
31
- var ext = (options && options.fileExtension) ? options.fileExtension : 'md';
32
- if (ext.indexOf('.') !== 0)
33
- ext = '.' + ext; // default is ".md"
34
-
35
- var defPageName = (options && options.defaultPageName) ? options.defaultPageName : 'index';
36
-
37
- // root
38
- if (urlPath === '/') {
39
- var indx = path.resolve(rootDir, defPageName + ext);
40
- return exists(indx) ? indx : null;
41
- }
42
-
43
- urlPath = decodeURIComponent(urlPath).substring(1); // strip out leading '/' and normalize URI
44
-
45
- // append index to trailing slashes
46
- if (urlPath.match(/\/$/))
47
- urlPath += defPageName;
48
-
49
- // /name
50
- var file = path.resolve(rootDir, urlPath + ext);
51
- if (exists(file)) return file;
52
-
53
- // /with-dash
54
- file = path.resolve(rootDir, urlPath.replace(/-/g, ' ') + ext);
55
- if (exists(file)) return file;
56
-
57
- // check existence of each segment -- taking into account dashes -- and build up final path
58
- var segs = urlPath.split('/');
59
- var u = rootDir;
60
- for (var i = 0; i < segs.length; i++) {
61
- var s = segs[i];
62
-
63
- if (i === segs.length - 1)
64
- s += '.md';
65
-
66
- var p = path.resolve(u, s);
67
- if (exists(p)) {
68
- u = p;
69
- } else {
70
- p = path.resolve(u, s.replace(/-/g, ' '));
71
- if (exists(p))
72
- u = p;
73
- else
74
- return null;
75
- }
76
- }
77
- // make sure last segment is included in final result
78
- if (u.match(/\.md$/) && exists(u)) return u;
79
-
80
-
81
- return null;
82
- };
83
-
84
- function exists(file) {
85
- return fs.existsSync(file);
86
- }