-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide js-fiddle merge task to generate simple demo page #11
- Loading branch information
1 parent
cba69e8
commit a1dc519
Showing
10 changed files
with
888 additions
and
48 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
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,85 @@ | ||
/* | ||
* This module provides a function to join jsfiddle examples into single fancy html output. | ||
* The examples must have the following layout: | ||
* example_name | ||
* |- demo.html | ||
* |- demo.js | ||
* \- demo.css | ||
* | ||
*/ | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const dot = require('dot'); | ||
|
||
/* | ||
* Generate html output for given example. | ||
* Calls callback(contents) when the contents of the output html file is generated. | ||
* | ||
* If exampleName is '*' then one big file with all examples is generated. | ||
* | ||
*/ | ||
const parse = (exampleName, examplesPath, callback, onlyBody=false, conf=null) => { | ||
const exampleDir = path.resolve(__dirname, examplesPath, exampleName); | ||
|
||
const globalExampleTemplateFile = fs.readFileSync(path.resolve(__dirname, examplesPath, 'index.html')); | ||
const singleExampleTemplateFile = fs.readFileSync(path.resolve(__dirname, examplesPath, 'example.html')); | ||
|
||
const globalExampleTemplate = dot.template(globalExampleTemplateFile); | ||
const singleExampleTemplate = dot.template(singleExampleTemplateFile); | ||
|
||
|
||
// Make one big html out of all examples | ||
if(exampleName == '*') { | ||
|
||
const examples = fs.readdirSync(path.resolve(__dirname, examplesPath)).filter((folder) => { | ||
return fs.lstatSync(path.resolve(__dirname, examplesPath, folder)).isDirectory(); | ||
}); | ||
|
||
let joinArray = []; | ||
|
||
const examplesJoined = () => { | ||
callback(globalExampleTemplate({ | ||
examples: joinArray, | ||
config: conf | ||
})); | ||
}; | ||
|
||
const exampleJoinCallback = (i) => { | ||
if(i >= examples.length) { | ||
examplesJoined(); | ||
return; | ||
} | ||
parse(examples[i], examplesPath, (result) => { | ||
joinArray.push(result); | ||
exampleJoinCallback(i+1); | ||
}, true, conf); | ||
}; | ||
|
||
exampleJoinCallback(0); | ||
|
||
} else { | ||
|
||
fs.readFile(path.resolve(exampleDir, 'demo.css'), (err, data) => { | ||
if (err) throw err; | ||
const cssContents = data.toString(); | ||
|
||
fs.readFile(path.resolve(exampleDir, 'demo.js'), (err, data) => { | ||
if (err) throw err; | ||
const jsContents = data.toString(); | ||
|
||
fs.readFile(path.resolve(exampleDir, 'demo.html'), (err, data) => { | ||
if (err) throw err; | ||
const htmlContents = data.toString(); | ||
callback(singleExampleTemplate({ | ||
cssContents, | ||
jsContents, | ||
title: htmlContents.replace(/Demo/ig, ''), | ||
config: conf | ||
})); | ||
}); | ||
}); | ||
}); | ||
} | ||
}; | ||
|
||
module.exports = parse; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<div class="exampleContent"> | ||
<span class="htmlExampleContents"> | ||
{{=it.title}} | ||
</span> | ||
<style> | ||
{{=it.cssContents}} | ||
</style> | ||
<script> | ||
{{=it.jsContents}} | ||
</script> | ||
</div> |
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,84 @@ | ||
<!doctype html> | ||
|
||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
|
||
<title>Examples</title> | ||
<meta name="description" content="jquery-usos examples demo"> | ||
<meta name="author" content="Piotr Styczyński"> | ||
|
||
<script src="../src/vendor/jquery-1.9.1.js"></script> | ||
<script src="../src/vendor/jquery-migrate-1.1.0.js"></script> | ||
<script src="../src/vendor/jquery-ui-1.10.1.custom.js"></script> | ||
<script src="../lib/jquery-usos.min.js"></script> | ||
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js" integrity="sha384-alpBpkh1PFOepccYVYDB4do5UnbKysX5WZXm3XxPqe5iKTfUKjNkCk9SaVuEZflJ" crossorigin="anonymous"></script> | ||
|
||
|
||
<link rel="stylesheet" href="../jquery-ui-theme/jquery-ui-1.10.1.custom.css"> | ||
<link rel="stylesheet" href="../jquery-ui-theme/tooltipster.css"> | ||
<link rel="stylesheet" href="../lib/jquery-usos.css"> | ||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous"> | ||
|
||
</head> | ||
|
||
<body> | ||
|
||
<style> | ||
h1 { | ||
font-size: 200%; | ||
width: 100%; | ||
background-color: #416067; | ||
height: 43px; | ||
color: white; | ||
padding-top: 2px; | ||
margin-left: -40px; | ||
margin-bottom: 20px; | ||
padding-left: 30px; | ||
} | ||
.exampleContent { | ||
margin-top: 66px; | ||
margin-bottom: -38px; | ||
} | ||
.htmlExampleContents { | ||
margin-left: 90px; | ||
display: block; | ||
} | ||
p { | ||
margin-top: 5px; | ||
margin-bottom: 5px; | ||
} | ||
.header { | ||
width: 100%; | ||
background-color: black; | ||
position: fixed; | ||
top: 0px; | ||
} | ||
.header > img { | ||
box-shadow: 0px 0px 141px #161616; | ||
color: black; | ||
border-radius: 184px; | ||
height: 50px; | ||
} | ||
.header > span { | ||
color: white; | ||
margin-left: 15px; | ||
font-weight: 600; | ||
z-index: 9999999 !important; | ||
} | ||
</style> | ||
|
||
<div class="header"> | ||
<img src="https://avatars1.githubusercontent.com/u/2855566?s=200&v=4" /> | ||
<span> | ||
JQuery-USOS version {{=it.config.version}} | ||
</span> | ||
</div> | ||
|
||
{{~it.examples :value:index}} | ||
<div>{{=value}}</div> | ||
{{~}} | ||
|
||
</body> | ||
|
||
</html> |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.