We apologize for the instability of composr.app and appreciate your patience. We are working on the statistics addon and trying to find an optimal way to store and render data. Unfortunately, we have yet to find a solution that can handle the traffic (and therefore, tens of millions of statistical records) of composr.app. We're working hard on one.
I experimented with this, and it doesn't work well for at least 2 reasons:
- Lots of unneeded line breaks still persist
- Not all parameters are put on their own line in code, and don't want to enforce them to be
Here's the diff I made during my testing...
diff --git a/docs/pages/comcode_custom/EN/codebook_3.txt b/docs/pages/comcode_custom/EN/codebook_3.txt
index b06609582..e4bac46ca 100644
--- a/docs/pages/comcode_custom/EN/codebook_3.txt
+++ b/docs/pages/comcode_custom/EN/codebook_3.txt
@@ -658,7 +658,7 @@ We have the following which are either unlikely to be useful, or potentially uns
'keep' parameters are placed inside URLs in order to give Composr some extra information when loading a page. Their URL-presence is automatically relayed/preserved in all Composr links within the page. To enable a 'keep' parameter, simply append [tt]&<name>=1[/tt] to the URL (replace '1' if appropriate, but usually we do use '1' to enable). If there are no parameters in the URL and URL Schemes are not enabled, use a '?' instead of a '&'.
The 'keep' parameters available are:
- - [tt]keep_cache[/tt] -- set to '1' to temporarily enable caching or '0' to temporarily disable. You can also use [tt]cache[/tt] so it works on a per-page basis, with the exception of this not affecting the template and language caching.
+ - [tt]keep_cache[/tt] -- set to '1' to temporarily enable caching or '0' to temporarily disable and also work harder to indent HTML nicely. You can also use [tt]cache[/tt] so it works on a per-page basis, with the exception of this not affecting the template and language caching.
- [tt]keep_no_dev_mode[/tt] -- set to '1' to disable development mode (which only runs if you're working out of a subversion repository anyway)
- [tt]keep_hide_dev_mode_message[/tt] -- set to '1' if you don't want the "Dev-mode is on" message to show if dev-mode is on (maybe you're taking screenshots?)
- [tt]keep_no_ext_check[/tt] -- set to '1' to force the webstandards checker to not check dependency files
diff --git a/sources/tempcode.php b/sources/tempcode.php
index ef8ceb2e3..bc3c559da 100644
--- a/sources/tempcode.php
+++ b/sources/tempcode.php
@@ -2138,6 +2138,24 @@ function tempcode_include($filepath)
return $ret;
}
+/**
+ * Indent to a particular level. Assumes first line is already indented.
+ *
+ * @param string $code Code
+ * @param integer $level Level
+ * @return string Result
+ *
+ * @ignore
+ */
+function tempcode_indent($code, $level)
+{
+ if ($level == 0) {
+ return $code;
+ }
+
+ return preg_replace('#\n#', "\n" . str_repeat("\t", $level), $code);
+}
+
/**
* Evaluate some PHP, with ability to better debug.
* In a way this can also quash problems, so only use when debugging. The "@" before eval turns off attach_message.
diff --git a/sources/tempcode_compiler.php b/sources/tempcode_compiler.php
index 32a6732dc..211e9e7e5 100755
--- a/sources/tempcode_compiler.php
+++ b/sources/tempcode_compiler.php
@@ -470,6 +470,23 @@ function compile_template($data, $template_name, $theme, $lang, $tolerate_errors
}
$temp .= ')';
- Lots of unneeded line breaks still persist
- Not all parameters are put on their own line in code, and don't want to enforce them to be
Here's the diff I made during my testing...
diff --git a/docs/pages/comcode_custom/EN/codebook_3.txt b/docs/pages/comcode_custom/EN/codebook_3.txt
index b06609582..e4bac46ca 100644
--- a/docs/pages/comcode_custom/EN/codebook_3.txt
+++ b/docs/pages/comcode_custom/EN/codebook_3.txt
@@ -658,7 +658,7 @@ We have the following which are either unlikely to be useful, or potentially uns
'keep' parameters are placed inside URLs in order to give Composr some extra information when loading a page. Their URL-presence is automatically relayed/preserved in all Composr links within the page. To enable a 'keep' parameter, simply append [tt]&<name>=1[/tt] to the URL (replace '1' if appropriate, but usually we do use '1' to enable). If there are no parameters in the URL and URL Schemes are not enabled, use a '?' instead of a '&'.
The 'keep' parameters available are:
- - [tt]keep_cache[/tt] -- set to '1' to temporarily enable caching or '0' to temporarily disable. You can also use [tt]cache[/tt] so it works on a per-page basis, with the exception of this not affecting the template and language caching.
+ - [tt]keep_cache[/tt] -- set to '1' to temporarily enable caching or '0' to temporarily disable and also work harder to indent HTML nicely. You can also use [tt]cache[/tt] so it works on a per-page basis, with the exception of this not affecting the template and language caching.
- [tt]keep_no_dev_mode[/tt] -- set to '1' to disable development mode (which only runs if you're working out of a subversion repository anyway)
- [tt]keep_hide_dev_mode_message[/tt] -- set to '1' if you don't want the "Dev-mode is on" message to show if dev-mode is on (maybe you're taking screenshots?)
- [tt]keep_no_ext_check[/tt] -- set to '1' to force the webstandards checker to not check dependency files
diff --git a/sources/tempcode.php b/sources/tempcode.php
index ef8ceb2e3..bc3c559da 100644
--- a/sources/tempcode.php
+++ b/sources/tempcode.php
@@ -2138,6 +2138,24 @@ function tempcode_include($filepath)
return $ret;
}
+/**
+ * Indent to a particular level. Assumes first line is already indented.
+ *
+ * @param string $code Code
+ * @param integer $level Level
+ * @return string Result
+ *
+ * @ignore
+ */
+function tempcode_indent($code, $level)
+{
+ if ($level == 0) {
+ return $code;
+ }
+
+ return preg_replace('#\n#', "\n" . str_repeat("\t", $level), $code);
+}
+
/**
* Evaluate some PHP, with ability to better debug.
* In a way this can also quash problems, so only use when debugging. The "@" before eval turns off attach_message.
diff --git a/sources/tempcode_compiler.php b/sources/tempcode_compiler.php
index 32a6732dc..211e9e7e5 100755
--- a/sources/tempcode_compiler.php
+++ b/sources/tempcode_compiler.php
@@ -470,6 +470,23 @@ function compile_template($data, $template_name, $theme, $lang, $tolerate_errors
}
$temp .= ')';
+ if (get_param_integer('keep_cache', 0) == 0) {
+ $indent_level = 0;
+ if ($i > 0) {
+ $previous_bits = implode('', array_slice($bits, 0, $i - 4));
+ $last_line_end = strrpos($previous_bits, "\n");
+ if ($last_line_end !== false) {
+ $last_line = substr($previous_bits, $last_line_end + 1);
+ if (trim($last_line, "\t") == '') {
+ $indent_level = strlen($last_line);
+ }
+ }
+ }
+ if ($indent_level != 0) {
+ $temp = 'tempcode_indent(' . $temp . ', ' . strval($indent_level) . ')';
+ }
+ }
+
if ($escaped === array()) {
$current_level_data[] = $temp;
} else {