-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
11 changed files
with
375 additions
and
588 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
'use strict' | ||
|
||
var fs = require('graceful-fs') | ||
var path = require('path') | ||
var Component = require('./compolib.Component') | ||
|
||
function CountComponents (opts) { | ||
this._opts = opts | ||
this._possibleExtensions = getAllTemplateExtensions.call(this) | ||
} | ||
|
||
CountComponents.prototype.init = function () { | ||
recursivelyWalkFiletree.call(this, this._opts.location.src) | ||
} | ||
|
||
function recursivelyWalkFiletree (dir) { | ||
fs.readdirSync(dir).filter(function (file) { | ||
if (file.charAt(0) === '.') { | ||
return // ignore hidden files | ||
} | ||
if (/^.*\.demo\.[^.\n]+$/.test(file)) { | ||
return // ignore *.demo.* files | ||
} | ||
if (isFolder(file)) { | ||
var filePath = path.join(dir, file) | ||
recursivelyWalkFiletree.call(this, filePath) | ||
} | ||
if (!isSupportedTemplateFile.call(this, file)) { | ||
return | ||
} | ||
|
||
var component = {} | ||
component.name = file.substr(0, file.indexOf('.')) | ||
component.fullPath = dir // for fetching file | ||
component.patternPath = dir.split(this._opts.location.src)[1] // folder | ||
|
||
// there could be a situation when e.g. .twig template initializes component | ||
// creation. When you see another template file (e.g. mustache) you | ||
// shouldn't initialize it again. | ||
if (componentExists.call(this, file, component.patternPath)) { | ||
return | ||
} | ||
|
||
// if component !exist - create it. | ||
var newComponent = new Component(this._opts, component, this._possibleExtensions) | ||
newComponent.assemble() | ||
}.bind(this)) | ||
} | ||
|
||
/** | ||
* Detect from filename if it's folder or a file. | ||
*/ | ||
function isFolder (file) { | ||
return path.extname(file) === '' | ||
} | ||
|
||
/** | ||
* Look up a component with the same name and url | ||
* @param title | ||
* @param folder | ||
* @returns {boolean} | ||
*/ | ||
function componentExists (title, folder) { | ||
for (var i = 0, l = this._opts.components.length; i < l; i++) { | ||
var component = this._opts.templateEngine[i] | ||
if (component.name === title && component.path === folder) { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
|
||
/** | ||
* Returns if file extension is among the ones passed in gulpfile.js config. | ||
* @param file | ||
* @returns {boolean} | ||
*/ | ||
function isSupportedTemplateFile (file) { | ||
var fileExtension = path.extname(file).toLowerCase() | ||
return this._possibleExtensions.indexOf(fileExtension) > -1 | ||
} | ||
|
||
module.exports = CountComponents |
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,39 @@ | ||
var fs = require('graceful-fs') | ||
var path = require('path') | ||
|
||
function GetDataFromJSON (opts) { | ||
this._opts = opts | ||
this._dataRegex = /["']data@(.*)["']/g | ||
this._jsonContnets = '' | ||
} | ||
|
||
GetDataFromJSON.prototype.fetchData = function (jsonPath) { | ||
if (!fs.existsSync(jsonPath)) { | ||
console.error(jsonPath + ' file does not exist!') | ||
return {} | ||
} | ||
|
||
this._jsonContents = fs.readFileSync(jsonPath, 'utf8') | ||
if (hasDataFileReference(this._jsonContents)) { | ||
var match = this._dataRegex.exec(this._jsonContents) | ||
replaceReferencesWithData(match) | ||
} | ||
return this._jsonContents | ||
} | ||
|
||
function hasDataFileReference (data) { | ||
return (data.indexOf('data@') !== -1) | ||
} | ||
|
||
function replaceReferencesWithData (match) { | ||
while (match != null) { | ||
var referencedFilename = match[1] | ||
var fileContents = this.fetchData(this._opts, | ||
path.join(this._opts.location.src, referencedFilename)) | ||
fileContents = fileContents || 'undefined' | ||
this._jsonContnets = this._jsonContnets.replace(referencedFilename, fileContents) | ||
match = this._dataRegex.exec(this._jsonContnets) | ||
} | ||
} | ||
|
||
exports.GetDataFromJSON = GetDataFromJSON |
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,22 @@ | ||
var helpers = require('./compolib.helpers') | ||
var Twig = require('twig') | ||
var twig = Twig.twig | ||
Twig.cache(false) | ||
|
||
function RenderPage (opts) { | ||
//this._opts = opts | ||
} | ||
|
||
RenderPage.prototype.render = function (config, data, destPath) { | ||
var dashboardHTML = renderHTML(config, data) | ||
helpers.writeFile(destPath, dashboardHTML) | ||
} | ||
|
||
function renderHTML (config, data) { | ||
var defaultConfig = { | ||
async: false | ||
} | ||
return twig(Object.assign(defaultConfig, config)).render(data) | ||
} | ||
|
||
exports.RenderPage = RenderPage |
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
Oops, something went wrong.