View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 0003468 | Composr | core | public | 2017-12-27 03:08 | 2018-01-28 23:48 |
| Reporter | Chris Graham | Assigned To | Chris Graham | ||
| Severity | Feature-request | ||||
| Status | closed | Resolution | won't fix | ||
| Product Version | |||||
| Fixed in Version | |||||
| Summary | 0003468: Automatic Tempcode indentation | ||||
| Description | During Tempcode compilation, insert indentation symbols for indenting a certain number of tabs, around Tempcode parameters that are on a new line and indented with tabs. It would work out the number of tabs from the indentation level of a parameter. This feature would be on by default, but disabled in performance options. The idea is it makes it easier for people to work out how the HTML works. I'm finding it a bit frustrating working with third-party code that suffers divitus, and don't necessarily want to use the element inspector. | ||||
| Tags | No tags attached. | ||||
| Time estimation (hours) | 2 | ||||
| Sponsorship open | |||||
|
|
Update testSetup health check to make sure this is off for live sites. |
|
|
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 .= ')'; + 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 { |
| Date Modified | Username | Field | Change |
|---|---|---|---|
| 2017-12-27 03:08 | Chris Graham | New Issue | |
| 2018-01-22 02:55 | Chris Graham | Note Added: 0005396 | |
| 2018-01-28 23:48 | Chris Graham | Note Added: 0005413 | |
| 2018-01-28 23:48 | Chris Graham | Status | non-assigned => closed |
| 2018-01-28 23:48 | Chris Graham | Assigned To | => Chris Graham |
| 2018-01-28 23:48 | Chris Graham | Resolution | open => won't fix |