commit 871e2105b884cc604124b128527cd5bb396a4a46
parent 010c2f54bc0bb3accf86fea6c4b559de8f5cce64
Author: Felicitus <felicitus@felicitus.org>
Date: Wed, 27 Jun 2012 21:22:04 +0200
Added support for individual debug files in the frontend, instead of having a large JS file which is hard to debug.
Diffstat:
5 files changed, 53 insertions(+), 9 deletions(-)
diff --git a/config.php.template b/config.php.template
@@ -107,11 +107,18 @@ Configuration::setOption("partkeepr.frontend.autologin.username", null);
Configuration::setOption("partkeepr.frontend.autologin.password", null);
/**
- * Specifies if frontend debugging should be turned on
+ * Specifies if frontend debugging should be turned on. This will create a non-minified, single JS file
+ * out of all source files
*/
Configuration::setOption("partkeepr.frontend.debug", false);
/**
+ * Specifies if the frontend should load each single JS file individually, in contrast to merging all JS files
+ * into partkeepr-debug.js.
+ */
+Configuration::setOption("partkeepr.frontend.debug_all", false);
+
+/**
* Specifies if cronjobs should be checked. Disable this on Windows unless we have an automatic cronjob runner
* emulation implemented.
*/
diff --git a/src/frontend/index.php b/src/frontend/index.php
@@ -86,7 +86,13 @@ if (Configuration::getOption("partkeepr.frontend.autologin.enabled", false) ===
/* Load and render the template */
$template = $twig->loadTemplate("index.tpl");
-echo $template->render(array(
- "debug" => Configuration::getOption("partkeepr.frontend.debug", false),
- "parameters" => $aParameters
- ));-
\ No newline at end of file
+$renderParams = array();
+$renderParams["debug_all"] = Configuration::getOption("partkeepr.frontend.debug_all", false);
+$renderParams["debug"] = Configuration::getOption("partkeepr.frontend.debug", false);
+$renderParams["parameters"] = $aParameters;
+
+if ($renderParams["debug_all"]) {
+ $renderParams["scripts"] = unserialize(file_get_contents(PartKeepr::getRootDirectory() . "/partkeepr.jsfiles"));
+}
+
+echo $template->render($renderParams);
diff --git a/src/frontend/templates/index.tpl b/src/frontend/templates/index.tpl
@@ -19,9 +19,17 @@
<!-- Include the ExtJS JavaScript Library -->
<script type="text/javascript" src="extjs/bootstrap.js"></script>
{% if debug %}
+ {% if debug_all %}
+ <script type="text/javascript" src="extjs/ext-all-debug.js"></script>
+ {% for i in scripts %}
+ <script type="text/javascript" src="{{ i }}"></script>
+ {% endfor %}
+ <script type="text/javascript" src="js/Ext.ux/Ext.ux.formatter-all-debug.js"></script>
+ {% else %}
<script type="text/javascript" src="extjs/ext-all-debug.js"></script>
<script type="text/javascript" src="js/partkeepr-debug.js"></script>
<script type="text/javascript" src="js/Ext.ux/Ext.ux.formatter-all-debug.js"></script>
+ {% endif %}
{% else %}
<script type="text/javascript" src="extjs/ext-all.js"></script>
<script type="text/javascript" src="js/partkeepr.js"></script>
diff --git a/util/classes/ExtJSFile.php b/util/classes/ExtJSFile.php
@@ -146,8 +146,20 @@ class ExtJSFile {
return implode(",\n", $aData);
}
+ public function getArray () {
+ $aData = array($this->filename);
+
+ foreach ($this->childs as $child) {
+ $aData = array_merge($aData, $child->getArray());
+ }
+
+ return $aData;
+ }
+
/**
* Returns the JSB Entry for the class
+ *
+ * @return String A single JSB entry with PATH and NAME.
*/
private function getJSBEntry () {
$template = '{"path": "[PATH]","name": "[NAME]"}';
diff --git a/util/gen-jsb3-file.php b/util/gen-jsb3-file.php
@@ -13,6 +13,10 @@
// Check if the path argument was given. If not, bail out.
if ($_SERVER["argc"] !== 3) {
echo "Usage: gen-jsb3-filelist.php <path> <extjspath>\n\n";
+ echo "This script generates two files:\n";
+ echo "- partkeepr.jsb3 (Used with jsb to build minimized JS builds)\n";
+ echo "- partkeepr.jsfiles (Used by the frontend when you set partkeepr.frontend.debug_all)\n";
+
exit(-1);
}
@@ -93,16 +97,24 @@ foreach ($records as $key => $record) {
}
}
-
}
$aData = array();
+$aData2 = array();
foreach ($rootList as $item) {
$aData[] = $item->getJSB();
+ $aData2 = array_merge($aData2, $item->getArray());
}
$template = file_get_contents(__DIR__."/../partkeepr.jsb3.template");
$template = str_replace("{{FILES}}", implode(",\n", $aData), $template);
-file_put_contents(__DIR__."/../partkeepr.jsb3", $template);-
\ No newline at end of file
+foreach ($aData2 as $key => $p) {
+ $p = str_replace($path, "", $p);
+ $p = str_replace("/examples/ux", "/js/Ext.ux", $p);
+ $aData2[$key]= str_replace($extjspath, "", $p);
+}
+
+file_put_contents(__DIR__."/../partkeepr.jsb3", $template);
+file_put_contents(__DIR__."/../partkeepr.jsfiles", serialize($aData2));+
\ No newline at end of file