Skip to content

Commit 9f2dfcd

Browse files
committed
Update sgml.md
1 parent b0cd2b4 commit 9f2dfcd

File tree

1 file changed

+49
-3
lines changed

1 file changed

+49
-3
lines changed

reference/sgml.md

+49-3
Original file line numberDiff line numberDiff line change
@@ -28,38 +28,84 @@ end
2828

2929
### `#after_template`
3030

31+
A hook that is called after the template is rendered. Can be overridden to add custom behavior.
32+
3133
### `#around_template`
3234

35+
A hook that wraps the template rendering. Can be overridden to add custom behavior before and after rendering. You should always call `super` in your implementation.
36+
37+
```ruby
38+
def around_template
39+
puts "Before rendering"
40+
super
41+
puts "After rendering"
42+
end
43+
```
44+
3345
### `#await`
3446

47+
Waits for an asynchronous task to complete. If the task isn’t completed, it flushes. Supports `Concurrent::IVar` and `Async::Task`.
48+
3549
### `#before_template`
3650

51+
A hook that is called before the template is rendered. Can be overridden to add custom behavior.
52+
3753
### `#call`
3854

55+
Renders the view and returns the buffer. The default buffer is a mutable String.
56+
3957
### `#capture`
4058

41-
### `#comment`
59+
Captures the block and returns the output as a string. In Rails, this is an `ActionView::SafeBuffer`.
4260

4361
### `#comment`
4462

63+
Outputs an HTML comment. You can wrap other content and the content will still be rendered.
64+
4565
### `#context`
4666

67+
Returns the current render context data.
68+
4769
### `#flush`
4870

71+
Flushes the buffer if not capturing.
72+
4973
### `#format_object`
5074

75+
Formats an object for output. Can be overridden to handle different object types.
76+
5177
### `#plain`
5278

79+
Outputs text content. The text will be HTML-escaped.
80+
5381
### `#render?`
5482

83+
Determines if the component should render. By default, it returns `true`. Override this method to conditionally render the component.
84+
5585
### `#render`
5686

87+
Renders another component, block, string, or enumerable of the above.
88+
5789
### `#tag`
5890

59-
### `#unsafe_raw`
91+
This is like `public_send`, but it only sends if the method is an HTML tag. It will not send to the `script` tag. If you need to do that, use `#unsafe_tag`.
92+
93+
### `#unsafe_raw(content = nil)`
94+
95+
Outputs the given string without any HTML safety. Should be used with caution.
6096

61-
### `#unsafe_tag`
97+
### `#unsafe_tag(name, ...)`
98+
99+
Similar to `#tag`, but allows rendering of potentially unsafe tags like `<script>`.
62100

63101
### `#vanish`
64102

103+
Similar to `#capture`, but the output is discarded.
104+
65105
### `#whitespace`
106+
107+
Outputs a whitespace character. Useful for getting inline elements to wrap. You can optionall pass a block to wrap the content with a whitespace character on before and after.
108+
109+
### `#view_template`
110+
111+
The main template method that should be overridden in subclasses to define the component’s structure.

0 commit comments

Comments
 (0)