Skip to content
This repository was archived by the owner on Mar 14, 2022. It is now read-only.

Commit

Permalink
Merge pull request #136 from Financial-Times/demo-dependencies
Browse files Browse the repository at this point in the history
Demo dependencies
  • Loading branch information
triblondon committed Nov 26, 2014
2 parents a246908 + 77f5044 commit d9c38ce
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions lib/tasks/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ function buildHtml(gulp, demoConfig, staticSource) {
}
data.oDemoTitle = files.getModuleName() + ': ' + demoConfig.name + ' demo';
if (demoConfig.sass) {
data.oDemoStyle = '<link rel="stylesheet" href="' + getStylesheetHref(demoConfig.sass, staticSource) + '" />';
data.oDemoStyle = getStylesheetTags(demoConfig.sass, demoConfig.dependencies, staticSource);
}
if (demoConfig.js) {
data.oDemoScript = '<script src="' + getScriptSrc(demoConfig.js, staticSource) + '"></script>';
data.oDemoScript = getScriptTags(demoConfig.js, demoConfig.dependencies, staticSource);
}
data.oDemoBodyClasses = demoConfig.bodyClasses;
data.oDemoTpl = fs.readFileSync(src, {encoding: 'utf8'});
Expand All @@ -125,20 +125,30 @@ function buildHtml(gulp, demoConfig, staticSource) {
});
}

function getStylesheetHref(sassPath, staticSource) {
function getStylesheetTags(sassPath, dependencies, staticSource) {
var stylesheets = '';
if (staticSource === 'local') {
return path.basename(sassPath).replace('.scss', '.css');
if (dependencies) {
stylesheets += '<link rel="stylesheet" href="//build.origami.ft.com/bundles/css?modules=' + dependencies.toString() + '" />\n\t';
}
stylesheets += '<link rel="stylesheet" href="' + path.basename(sassPath).replace('.scss', '.css') + '" />';
} else {
return '/bundles/css?modules=' + files.getModuleName() + ((sassPath !== "main.scss") ? ':/' + sassPath : '');
stylesheets += '<link rel="stylesheet" href="/bundles/css?modules=' + files.getModuleName() + ((sassPath !== "main.scss") ? ':/' + sassPath : '') + (dependencies ? ',' + dependencies.toString() : '') + '" />';
}
return stylesheets;
}

function getScriptSrc(scriptPath, staticSource) {
function getScriptTags(scriptPath, dependencies, staticSource) {
var scripts = '';
if (staticSource === 'local') {
return path.basename(scriptPath);
if (dependencies) {
scripts += '<script src="//build.origami.ft.com/bundles/js?modules=' + dependencies.toString() + '"></script>\n\t';
}
scripts += '<script src="' + path.basename(scriptPath) + '"></script>';
} else {
return '/bundles/js?modules=' + files.getModuleName() + ((scriptPath !== "main.js") ? ':/' + scriptPath : '');
scripts += '<script src="/bundles/js?modules=' + files.getModuleName() + ((scriptPath !== "main.js") ? ':/' + scriptPath : '') + (dependencies ? ',' + dependencies.toString() : '') + '"></script>';
}
return scripts;
}

function convertToNewFormat(demosConfig) {
Expand Down

0 comments on commit d9c38ce

Please sign in to comment.