Skip to content

Commit

Permalink
Purloined dist build process from jQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
cykod committed Sep 30, 2011
1 parent 239d661 commit 9e5a0c5
Show file tree
Hide file tree
Showing 6 changed files with 282 additions and 71 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1 +1,2 @@
dist
build/*.json
95 changes: 29 additions & 66 deletions Makefile
Expand Up @@ -9,88 +9,55 @@ JS_ENGINE ?= `which node nodejs`
COMPILER = ${JS_ENGINE} ${BUILD_DIR}/uglify.js --unsafe
POST_COMPILER = ${JS_ENGINE} ${BUILD_DIR}/post-compile.js

BASE_FILES = ${SRC_DIR}/jquery.js\
${SRC_DIR}/callbacks.js\
${SRC_DIR}/deferred.js\
${SRC_DIR}/support.js\
${SRC_DIR}/data.js\
${SRC_DIR}/queue.js\
${SRC_DIR}/attributes.js\
${SRC_DIR}/event.js\
${SRC_DIR}/selector.js\
${SRC_DIR}/traversing.js\
${SRC_DIR}/manipulation.js\
${SRC_DIR}/css.js\
${SRC_DIR}/ajax.js\
${SRC_DIR}/ajax/jsonp.js\
${SRC_DIR}/ajax/script.js\
${SRC_DIR}/ajax/xhr.js\
${SRC_DIR}/effects.js\
${SRC_DIR}/offset.js\
${SRC_DIR}/dimensions.js
BASE_FILES = ${SRC_DIR}/jquery.tmpl.min.js\
${SRC_DIR}/deck.js/core/deck.core.js\
${SRC_DIR}/codemirror/lib/codemirror.js\
${SRC_DIR}/codemirror/mode/xml/xml.js\
${SRC_DIR}/codemirror/mode/css/css.js\
${SRC_DIR}/codemirror/mode/javascript/javascript.js\
${SRC_DIR}/codemirror/mode/htmlmixed/htmlmixed.js\
${SRC_DIR}/deck.js/extensions/status/deck.status.js\
${SRC_DIR}/deck.js/extensions/navigation/deck.navigation.js\
${SRC_DIR}/deck.coder.js\
${SRC_DIR}/deck.js/extensions/hash/deck.hash.js\
${SRC_DIR}/deck.js/extensions/menu/deck.menu.js

MODULES = ${SRC_DIR}/intro.js\
${BASE_FILES}\
${SRC_DIR}/outro.js
${BASE_FILES}

JQ = ${DIST_DIR}/jquery.js
JQ_MIN = ${DIST_DIR}/jquery.min.js
CODERDECK= ${DIST_DIR}/coderdeck.js
CODERDECK_MIN = ${DIST_DIR}/coderdeck.min.js

SIZZLE_DIR = ${SRC_DIR}/sizzle

JQ_VER = $(shell cat version.txt)
VER = sed "s/@VERSION/${JQ_VER}/"
CODERDECK_VER = $(shell cat version.txt)
VER = sed "s/@VERSION/${CODERDECK_VER}/"

DATE=$(shell git log -1 --pretty=format:%ad)

all: update_submodules core

core: jquery min lint size
@@echo "jQuery build complete."
core: coderdeck min
@@echo "Coderdeck build complete."

${DIST_DIR}:
@@mkdir -p ${DIST_DIR}

jquery: ${JQ}
coderdeck: ${CODERDECK}

${JQ}: ${MODULES} | ${DIST_DIR}
@@echo "Building" ${JQ}
${CODERDECK}: ${MODULES} | ${DIST_DIR}
@@echo "Building" ${CODERDECK}

@@cat ${MODULES} | \
sed 's/.function..jQuery...{//' | \
sed 's/}...jQuery..;//' | \
sed 's/@DATE/'"${DATE}"'/' | \
${VER} > ${JQ};

${SRC_DIR}/selector.js: ${SIZZLE_DIR}/sizzle.js
@@echo "Building selector code from Sizzle"
@@sed '/EXPOSE/r src/sizzle-jquery.js' ${SIZZLE_DIR}/sizzle.js | grep -v window.Sizzle > ${SRC_DIR}/selector.js
${VER} > ${CODERDECK};

lint: jquery
@@if test ! -z ${JS_ENGINE}; then \
echo "Checking jQuery against JSLint..."; \
${JS_ENGINE} build/jslint-check.js; \
else \
echo "You must have NodeJS installed in order to test jQuery against JSLint."; \
fi
min: coderdeck ${CODERDECK_MIN}

size: jquery min
${CODERDECK_MIN}: ${CODERDECK}
@@if test ! -z ${JS_ENGINE}; then \
gzip -c ${JQ_MIN} > ${JQ_MIN}.gz; \
wc -c ${JQ} ${JQ_MIN} ${JQ_MIN}.gz | ${JS_ENGINE} ${BUILD_DIR}/sizer.js; \
rm ${JQ_MIN}.gz; \
else \
echo "You must have NodeJS installed in order to size jQuery."; \
fi

min: jquery ${JQ_MIN}

${JQ_MIN}: ${JQ}
@@if test ! -z ${JS_ENGINE}; then \
echo "Minifying jQuery" ${JQ_MIN}; \
${COMPILER} ${JQ} > ${JQ_MIN}.tmp; \
${POST_COMPILER} ${JQ_MIN}.tmp > ${JQ_MIN}; \
rm -f ${JQ_MIN}.tmp; \
echo "Minifying CoderDeck" ${CODERDECK_MIN}; \
${COMPILER} ${CODERDECK} > ${CODERDECK_MIN}.tmp; \
${POST_COMPILER} ${CODERDECK_MIN}.tmp > ${CODERDECK_MIN}; \
rm -f ${CODERDECK_MIN}.tmp; \
else \
echo "You must have NodeJS installed in order to minify jQuery."; \
fi
Expand All @@ -99,12 +66,8 @@ clean:
@@echo "Removing Distribution directory:" ${DIST_DIR}
@@rm -rf ${DIST_DIR}

@@echo "Removing built copy of Sizzle"
@@rm -f src/selector.js

distclean: clean
@@echo "Removing submodules"
@@rm -rf test/qunit src/sizzle

# change pointers for submodules and update them to what is specified in jQuery
# --merge doesn't work when doing an initial clone, thus test if we have non-existing
Expand Down
2 changes: 1 addition & 1 deletion build/post-compile.js
Expand Up @@ -5,7 +5,7 @@ var print = require( "sys" ).print,
src = fs.readFileSync( process.argv[2], "utf8" ),
version = fs.readFileSync( "version.txt", "utf8" ),
// License Template
license = "/*! CoderDeck @VERSION http://coderdeck.com/ | http://coderdeck.com/license */";
license = fs.readFileSync("src/intro.js","utf8");


// Previously done in sed but reimplemented here due to portability issues
Expand Down
216 changes: 216 additions & 0 deletions sample-dist.html
@@ -0,0 +1,216 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>CoderDeck Sample</title>
<meta name="viewport" content="width=1024">

<!-- Replace path with correct path to deck.core.css. -->
<link rel="stylesheet" href="css/deck.core.css" type="text/css">
<link rel="stylesheet" href="css/deck.navigation.css">
<link rel="stylesheet" href="css/deck.status.css">
<link rel="stylesheet" href="css/deck.hash.css">
<link rel="stylesheet" href="css/deck.menu.css">
<link rel="stylesheet" href="css/deck.coder.css">


<link rel="stylesheet" href="src/codemirror/lib/codemirror.css">
<link rel="stylesheet" href="src/codemirror/theme/default.css">
<!-- Replace path with correct path to Modernizr file. -->


<link rel="stylesheet" id='style-theme-link' href="css/coderdeck.css" type="text/css" >

<script src='src/jquery.min.js'></script>
<script src="src/modernizr.js"></script>
</head>
<body class="deck-container">

<script type='text/coderdeck' id='coderdeck-default'>
<html>
<head>
<script src='src/jquery.min.js'>SCRIPTEND
</head>
<body>
CODE
</body>
</html>
</script>


<script type='text/coderdeck' id='coderdeck-style-example'>
<html>
<title>test</title>
<style>
CODE
</style>
<body>
<h1>I'm a H1 heading</h1>
<h2>I'm a H2 heading</h2>
<p>Pargraph of text &lt;p&gt; here</p>
<div class='stuff'>I'm a div &lt;div&gt; with class "stuff"</div>
<div id='my-div'>I'm a &lt;div&gt; with id "my-div"</div>
</body>
</html>
</script>

<article class='slide'>
<h1>CoderDeck sample</h1>
</article>

<!-- Apply a class of "coder-editor" to a textarea to make it show up as runnable code -->
<article class='slide slide-list'>
<h2>Basic Code Editor</h2>
<p>Basic split code editor is created by adding a class of "coder-editor" to a textarea.
Press run, then modify some code and press "run" again</p>

<textarea class='coder-editor'>
<header>
<h1>My Site!</h1>
<nav><ul>
<li><a href='#'>Link 1</a></li>
<li><a href='#'>Link 2</a></li>
</ul></nav>
</header>

<section id='content'>
<article class='blog-post'>
<h1>Blog Post 1</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ac elit at nisl sagittis consequat sed eget tellus. Aliquam gravida, nunc sit amet viverra dictum, nibh justo semper massa</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ac elit at nisl sagittis consequat sed eget tellus. Aliquam gravida, nunc sit amet viverra dictum, nibh justo semper massa</p>
</article>
</section>
<footer>
<a href='#'>Link 1</a> | <a href='#'>Link 2</a>
</footer>
</textarea>
</article>

<!-- Apply a class of "coder-editor-full" along with "coder-editor" to a textarea to make it show up as runnable code -->
<article class='slide slide-list'>
<h2>Full Page Code Editor</h2>
<p>Basic full page code editor is created by adding a class of "coder-editor-full" along with "coder-editor" to a textarea.
Press run, then press "back", then modify some code and press "run" again</p>

<textarea class='coder-editor coder-editor-full'>
<header>
<h1>My Site!</h1>
<nav><ul>
<li><a href='#'>Link 1</a></li>
<li><a href='#'>Link 2</a></li>
</ul></nav>
</header>

<section id='content'>
<article class='blog-post'>
<h1>Blog Post 1</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ac elit at nisl sagittis consequat sed eget tellus. Aliquam gravida, nunc sit amet viverra dictum, nibh justo semper massa</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ac elit at nisl sagittis consequat sed eget tellus. Aliquam gravida, nunc sit amet viverra dictum, nibh justo semper massa</p>
</article>
</section>
<footer>
<a href='#'>Link 1</a> | <a href='#'>Link 2</a>
</footer>
</textarea>
</article>


<!-- add a "data-coder-template" to use a different template (see the template definitions at the top)
add a "data-language" to use a different CodeMirror2 mode other than htmlmixed. Options include "html", "javascript", "css", "xml" and any other mode supported by CodeMirror2
-->
<article class='slide slide-list'>
<h2>Custom template and custom language</h2>
<p>Basic full page code editor is created by adding a class of "coder-editor-full" along with "coder-editor" to a textarea.
Press run, then press "back", then modify some code and press "run" again</p>

<textarea class='coder-editor' data-coder-template="coderdeck-style-example" data-language="css">
h1 { color:blue; }
h2 { color:red;}
p { color:pink;}
.stuff { color:purple;}
#my-div { color:teal;}
</textarea>
</article>



<!-- add a "data-coder-instant" to do on-the-fly updating-->
<article class='slide slide-list'>
<h2>Instant Update Sample</h2>
<p>Try modifying any of the HTML on the left, the right side should updated periodically as you type. This is done by adding a class of "coder-editor-instant" to the textarea</p>

<textarea class='coder-editor coder-editor-instant' data-coder-template="coderdeck-style-example" data-language="css">
h1 { color:blue; }
h2 { color:red;}
p { color:pink;}
.stuff { color:purple;}
#my-div { color:teal;}
</textarea>
</article>


<!-- Javascript works normally as well, libraries and external css (including jquery) can be included in template -->
<article class='slide slide-list'>
<h2>Javascript/jQuery Example</h2>
<p> Javascript works normally as well, libraries and external css (including jquery) can be included in the coderdeck template.</p>
<textarea class='coder-editor'>
<script>
$(function() {
$(".box").animate({
'top':"50%",
'left':"50%" });
});
</script>
<style>
.box {
top:0px; left:0px;
width:50px; height:50px;
position:absolute;
background-color:red;
}
</style>
<div class='box'></div>
</textarea>
</article>



<article class='slide slide-list'>
<h2>Local Storage</h2>
<p> If you want your changes to a slide to survive between page reloads you can define a data-save attribute which will save it to the attributes value in localstorage. Make a code change, hit run/save and reload this slide.</p>
<p> You can also use the same 'data-save' attribute on mulitiple slides to keep the same code moving forwad</p>
<textarea class='coder-editor' data-save='dummy'>
<h1>This is some dummy content..</h1>
</textarea>
</article>


<article class='slide slide-list'>
<h2>Solutions</h2>
<p>If you want to add a solution to an exercise, you can add a coderdeck-solution script tag in the slide </p>
<textarea class='coder-editor'>

<script>
// Display an alert message
// if a confirm dialog returns true
</script>
</textarea>

<script type='coder-solution'>
SCRIPT
if(confirm("Do you want an alert?")) {
alert("Yay!");
}
SCRIPTEND
</script>
</article>

<script src='dist/coderdeck.min.js'></script>

<script>
$(function() {
$.deck('.slide');
});
</script>
</body>
</html>
6 changes: 2 additions & 4 deletions src/deck.coder.js
@@ -1,13 +1,11 @@
/*!
*Copyright (c) 2011 Cykod LLC
Copyright (c) 2011 Cykod LLC
Dual licensed under the MIT license and the GPL license
*/


/*
This module adds a code editor that shows up in individual slides
*/


Expand Down Expand Up @@ -138,7 +136,6 @@ This module adds a code editor that shows up in individual slides

var editor = $element.data("editor");
var height = $(currentSlide).height() - $container.position().top - 80;
alert(height);
$(editor.getScrollerElement()).height(height);
$destination.height(height);
}
Expand Down Expand Up @@ -201,6 +198,7 @@ This module adds a code editor that shows up in individual slides
generateCodeSlide($container,current);
}
resizeEditors(current,$container);
});
});

})(jQuery,'deck',this);

0 comments on commit 9e5a0c5

Please sign in to comment.