Skip to content

Commit

Permalink
Prefer content for page component content
Browse files Browse the repository at this point in the history
Rather than `html_content`.
  • Loading branch information
kohler committed Oct 25, 2024
1 parent e8affb1 commit 7c61b97
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
4 changes: 2 additions & 2 deletions devel/manual/fmt.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ nonnegative integer. The languages defined so far are:

The `Ftext` class can convert between some formats.

(Note that open-source HotCRP ships without Markdown support.)
(Open-source HotCRP ships without Markdown support.)


## Ftext
Expand Down Expand Up @@ -297,7 +297,7 @@ HotCRP understands the following format specifications.
| Format specification | Result |
|:--------------------------|:-----------------------------------------------------|
| `:url` | The string argument is urlencoded. |
| `:html` | The string argument is HTML-encoded; i.e., `&<>"'` are replaced by HTML entities. |
| `:html` | The string argument is HTML-encoded: `&<>"'` are replaced by HTML entities. |
| `:ftext` | When possible, the string argument is incorporated as an ftext, rather than having its format translated or stripped. |
| `:humanize_url` | If the argument string is a simple url, such as `https://hotcrp.com/privacy`, it is replaced by a shorter version, such as `hotcrp.com/privacy`. |
| `:.2f`, etc. | The numeric argument is rendered using a printf-style specification. |
Expand Down
31 changes: 20 additions & 11 deletions devel/manual/pages.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,26 +59,34 @@ and terminates request processing. A `request_function` may also throw a value
of type `Redirection` to force HotCRP to redirect the user’s browser to
another URI.

## Rendering the result
## Printing the result

Assuming the `request_function`s do not throw a redirection, HotCRP next
re-scans the component list and prints the corresponding components.

To print a component, HotCRP checks for:
Many HotCRP pages do not have separate `request_function`s, instead handling
all request parsing as part of the first `print_function` for a page.

1. A `print_function` property. If present, this calls the corresponding PHP
callback, using the same syntax and arguments as `request_function`, above.
To print a component, HotCRP:

2. Otherwise, an `html_content` property. If present, this is copied to the output.
1. First, HotCRP prints the component itself, by looking for a
`print_function` or `content` property.

3. In either case, if the component has a `print_members` property, HotCRP
next prints the members of the group with the component’s name.
* If `print_function` is present, HotCRP calls the corresponding PHP
callback to print the component. The `print_function` property uses the
same syntax as `request_function`, and the callback takes the same
arguments.

A `print_function` may cancel further rendering by returning explicit `false`,
or by throwing a `Redirection` or `PageCompletion` exception.
A `print_function` may cancel further rendering by returning explicit
`false`, or by throwing a `Redirection` or `PageCompletion` exception.

Many HotCRP pages do not have separate `request_function`s, instead handling
all request parsing as part of the first `print_function` for a page.
* Otherwise, if `content` is present, HotCRP prints that content. This
property is an [ftext string][ftext].

* Otherwise, HotCRP prints nothing for the component itself.

2. Second, if the component has a `print_members` property, HotCRP recursively
prints the members of the group with the component’s name.

## Shorthand

Expand Down Expand Up @@ -108,3 +116,4 @@ components support conditions relating to the current request.


[components]: ./components.md
[ftext]: ./fmt.md
4 changes: 3 additions & 1 deletion src/componentset.php
Original file line number Diff line number Diff line change
Expand Up @@ -518,8 +518,10 @@ private function _print_body($gj, $print_members) {
$result = null;
if (isset($gj->print_function)) {
$result = $this->call_function($gj, $gj->print_function, $gj);
} else if (isset($gj->content)) {
echo Ftext::as(5, $gj->content, 0);
} else if (isset($gj->html_content)) {
echo $gj->html_content;
echo $gj->html_content; /* XXX backward compat */
}
if (isset($gj->print_members)) {
$print_members = $gj->print_members;
Expand Down

0 comments on commit 7c61b97

Please sign in to comment.