Scaffolding in place for build options

This commit is contained in:
Jeff Parsons 2016-02-10 12:24:27 -08:00
commit e4cee436cc
7 changed files with 99 additions and 13 deletions

1
_includes/build.html Normal file
View file

@ -0,0 +1 @@
<div id="{{ include.id }}"></div>

View file

@ -63,4 +63,8 @@ here and in markout.js. Examples include 'autopower' ('autoPower') and 'automou
{% endif %}
{% endif %}
<script type="text/javascript">{{ machine_embed }}('{{ machine.id }}','{{ machine_config }}','{{ machine_template }}','{{ machine_parms }}');</script>
{% if page.build %}
<script type="text/javascript" src="{{ site.baseurl }}/modules/pcbuild/lib/build.js"></script>
<script type="text/javascript">buildPC("{{ page.build }}");</script>
{% endif %}
{% endfor %}

View file

@ -4,11 +4,16 @@ title: Build Your Own PC
permalink: /devices/pc/machine/custom/
machines:
- type: pc
id: custom
name: Custom PC
id: custom-pc
uncompiled: true
autopower: false
build: build-pc
---
Build Your Own PC
---
{% include machine.html id="custom" %}
{% include build.html id="build-pc" %}
{% include machine.html id="custom-pc" %}

View file

@ -1451,7 +1451,7 @@ HTMLOut.prototype.getMachineXML = function(sToken, sIndent, aParms, sXMLFile, sS
var m = new MarkOut(s, sIndent, obj.req, null, obj.fDebug);
s = m.convertMD(" ").trim();
obj.processMachines(m.getMachines(), function doneProcessXMLMachines() {
obj.processMachines(m.getMachines(), m.getBuildOptions(), function doneProcessXMLMachines() {
obj.getMarkdownFile(obj.sFile, sToken, sIndent, aParms, s, true);
});
return;
@ -1749,7 +1749,7 @@ HTMLOut.prototype.getMarkdownFile = function(sFile, sToken, sIndent, aParms, sPr
* any duplicates from that array, and then call processMachines() at some later point, after
* all tokens have been replaced.
*/
obj.processMachines(m.getMachines(), function doneProcessMachines() {
obj.processMachines(m.getMachines(), m.getBuildOptions(), function doneProcessMachines() {
if (sToken) {
obj.aTokens[sToken] = sPrevious? (sPrevious + sIndent + s) : s;
obj.replaceTokens();
@ -1809,7 +1809,7 @@ HTMLOut.prototype.getRandomString = function(sIndent)
};
/**
* processMachines(aMachines, done)
* processMachines(aMachines, buildOptions, done)
*
* At a minimum, each machine object should contain the following properties:
*
@ -1819,9 +1819,10 @@ HTMLOut.prototype.getRandomString = function(sIndent)
*
* @this {HTMLOut}
* @param {Array} aMachines is an array of objects containing information about each machine on the current page
* @param {Object} buildOptions
* @param {function()} done
*/
HTMLOut.prototype.processMachines = function(aMachines, done)
HTMLOut.prototype.processMachines = function(aMachines, buildOptions, done)
{
for (var iMachine = 0; iMachine < aMachines.length; iMachine++) {
@ -1905,6 +1906,12 @@ HTMLOut.prototype.processMachines = function(aMachines, done)
}
}
this.addFilesToHTML(asFiles, sScriptEmbed);
if (buildOptions.id) {
asFiles = [];
asFiles.push("/modules/pcbuild/lib/build.js");
sScriptEmbed = '<script type="text/javascript">buildPC("' + buildOptions.id + '")</script>';
this.addFilesToHTML(asFiles, sScriptEmbed);
}
}
}
}
@ -1912,7 +1919,7 @@ HTMLOut.prototype.processMachines = function(aMachines, done)
};
/**
* addFilesToHTML(asFiles)
* addFilesToHTML(asFiles, sScriptEmbed)
*
* @this {HTMLOut}
* @param {Array.<string>} asFiles is a list of CSS and/or JS files to include in the HTML

View file

@ -116,6 +116,7 @@ function MarkOut(sMD, sIndent, req, aParms, fDebug, fMachineXML, fAutoHeading)
this.sHTML = null;
this.aIDs = []; // this keeps track of auto-generated ID attributes for page elements, to insure uniqueness
this.aMachines = []; // this keeps track of embedded machines on the page
this.buildOptions = {}; // this keeps track of any build options specified on the page
this.aMachineDefs = {}; // this keeps track of any machine definitions at the top of the file (as part of any Jekyll "Front Matter")
}
@ -265,6 +266,17 @@ MarkOut.prototype.getMachines = function()
return this.aMachines;
};
/**
* getBuildOptions()
*
* @this {MarkOut}
* @return {Object} containing build options, if any
*/
MarkOut.prototype.getBuildOptions = function()
{
return this.buildOptions;
};
/**
* generateID(sText)
*
@ -409,6 +421,7 @@ MarkOut.prototype.convertMD = function(sIndent)
/*
* Extract machine definitions, if any, from the Front Matter.
*/
var aSubMatch;
var aMachineDefs = aMatch[1].match(/\nmachines:([\s\S]*?)\n([^\s]|$)/);
if (aMachineDefs) {
var asMachines = aMachineDefs[1].split(/\n[ \t]+-\s*/);
@ -485,9 +498,14 @@ MarkOut.prototype.convertMD = function(sIndent)
* heading with the same value.
*/
if (this.fAutoHeading) {
aMatch = aMatch[1].match(/title:\s*(.*?)\s*?\n/);
if (aMatch) sMD = aMatch[1] + "\n---\n\n" + sMD;
aSubMatch = aMatch[1].match(/title:\s*(.*?)\s*?\n/);
if (aSubMatch) sMD = aSubMatch[1] + "\n---\n\n" + sMD;
}
/*
* If a "build" ID element existed in the Front Matter, capture it.
*/
aSubMatch = aMatch[1].match(/build:\s*(\S*)/);
if (aSubMatch) this.buildOptions.id = aSubMatch[1];
}
}
@ -1094,11 +1112,12 @@ MarkOut.prototype.convertMDMachineLinks = function(sBlock)
* Before we start looking for Markdown-style machine links, see if there are any Liquid-style machines,
* (in case this Markdown file is part of a Jekyll installation) and convert them to Markdown-style links.
*/
var reIncludes = /\{%\s*include machine\.html\s+id="(.*?)"\s*%}/g;
var reIncludes = /\{%\s*include\s+machine\.html\s+id=(["'])(.*?)\1\s*%}/g;
while ((aMatch = reIncludes.exec(sBlock))) {
sReplacement = "";
sMachineID = aMatch[1];
sMachineID = aMatch[2];
if (!this.fMachineXML && this.aMachineDefs[sMachineID]) {
var machine = this.aMachineDefs[sMachineID];
sMachine = machine['type'] || "pc";
@ -1108,12 +1127,15 @@ MarkOut.prototype.convertMDMachineLinks = function(sBlock)
sMachineXSLFile = machine['template'] || "";
sMachineVersion = (machine['uncompiled'] && machine['uncompiled'] == "true"? "uncompiled" : "");
sMachineParms = machine['parms'] || "";
sReplacement = "[Embedded PC](" + sMachineXMLFile + ' "' + sMachine + 'js!' + sMachineID + '!' + sMachineXSLFile + '!!' + sMachineOptions + '!' + sMachineParms + '")';
sReplacement = machine['name'] || "Embedded PC";
sReplacement = "[" + sReplacement + "](" + sMachineXMLFile + ' "' + sMachine + 'js!' + sMachineID + '!' + sMachineXSLFile + '!!' + sMachineOptions + '!' + sMachineParms + '")';
}
sBlock = sBlock.replace(aMatch[0], sReplacement);
reIncludes.lastIndex = 0; // reset lastIndex, since we just modified the string that reIncludes is iterating over
}
sBlock = sBlock.replace(/\{%\s*include\s+build\.html\s+id=(["'])(.*?)\1\s*%}/g, '<div id=$1$2$1></div>');
/*
* Start looking for Markdown-style machine links now...
*/

View file

@ -0,0 +1,47 @@
/**
* @fileoverview PCjs Build Options
* @author <a href="mailto:Jeff@pcjs.org">Jeff Parsons</a>
* @version 1.0
* Created 2016-Feb-10
*
* Copyright © 2012-2016 Jeff Parsons <Jeff@pcjs.org>
*
* This file is part of the JavaScript Machines Project (aka JSMachines) at <http://jsmachines.net/>
* and <http://pcjs.org/>.
*
* JSMachines is free software: you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation, either version 3
* of the License, or (at your option) any later version.
*
* JSMachines is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with JSMachines.
* If not, see <http://www.gnu.org/licenses/gpl.html>.
*
* You are required to include the above copyright notice in every source code file of every
* copy or modified version of this work, and to display that copyright notice on every screen
* that loads or runs any version of this software (see Computer.COPYRIGHT).
*
* Some JSMachines files also attempt to load external resource files, such as character-image files,
* ROM files, and disk image files. Those external resource files are not considered part of the
* JSMachines Project for purposes of the GNU General Public License, and the author does not claim
* any copyright as to their contents.
*/
"use strict";
/*
* This file provides all the UI options for building a functional PCjs PC.
*/
/**
* buildPC(idElement)
*
* @param {string} idElement (the ID of the DIV where build UI options should be presented)
*/
function buildPC(idElement)
{
alert("build.js loaded: " + idElement);
}

View file

@ -1251,7 +1251,7 @@ FDC.prototype.loadSelectedDrive = function(sDisketteName, sDiskettePath, file)
}
return;
}
this.notice("Nothing to load");
this.notice("Unable to load the selected drive");
};
/**