|
28 | 28 |
|
29 | 29 | ### `#after_template`
|
30 | 30 |
|
| 31 | +A hook that is called after the template is rendered. Can be overridden to add custom behavior. |
| 32 | + |
31 | 33 | ### `#around_template`
|
32 | 34 |
|
| 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 | + |
33 | 45 | ### `#await`
|
34 | 46 |
|
| 47 | +Waits for an asynchronous task to complete. If the task isn’t completed, it flushes. Supports `Concurrent::IVar` and `Async::Task`. |
| 48 | + |
35 | 49 | ### `#before_template`
|
36 | 50 |
|
| 51 | +A hook that is called before the template is rendered. Can be overridden to add custom behavior. |
| 52 | + |
37 | 53 | ### `#call`
|
38 | 54 |
|
| 55 | +Renders the view and returns the buffer. The default buffer is a mutable String. |
| 56 | + |
39 | 57 | ### `#capture`
|
40 | 58 |
|
41 |
| -### `#comment` |
| 59 | +Captures the block and returns the output as a string. In Rails, this is an `ActionView::SafeBuffer`. |
42 | 60 |
|
43 | 61 | ### `#comment`
|
44 | 62 |
|
| 63 | +Outputs an HTML comment. You can wrap other content and the content will still be rendered. |
| 64 | + |
45 | 65 | ### `#context`
|
46 | 66 |
|
| 67 | +Returns the current render context data. |
| 68 | + |
47 | 69 | ### `#flush`
|
48 | 70 |
|
| 71 | +Flushes the buffer if not capturing. |
| 72 | + |
49 | 73 | ### `#format_object`
|
50 | 74 |
|
| 75 | +Formats an object for output. Can be overridden to handle different object types. |
| 76 | + |
51 | 77 | ### `#plain`
|
52 | 78 |
|
| 79 | +Outputs text content. The text will be HTML-escaped. |
| 80 | + |
53 | 81 | ### `#render?`
|
54 | 82 |
|
| 83 | +Determines if the component should render. By default, it returns `true`. Override this method to conditionally render the component. |
| 84 | + |
55 | 85 | ### `#render`
|
56 | 86 |
|
| 87 | +Renders another component, block, string, or enumerable of the above. |
| 88 | + |
57 | 89 | ### `#tag`
|
58 | 90 |
|
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. |
60 | 96 |
|
61 |
| -### `#unsafe_tag` |
| 97 | +### `#unsafe_tag(name, ...)` |
| 98 | + |
| 99 | +Similar to `#tag`, but allows rendering of potentially unsafe tags like `<script>`. |
62 | 100 |
|
63 | 101 | ### `#vanish`
|
64 | 102 |
|
| 103 | +Similar to `#capture`, but the output is discarded. |
| 104 | + |
65 | 105 | ### `#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