Module: Ruact::ViewHelper
- Defined in:
- lib/ruact/view_helper.rb
Overview
ActionView helper module included in ActionView::Base via Railtie. Provides the ruact_component method that ERB templates call after the preprocessor transforms PascalCase tags into <%= ruact_component(…) %>.
Thread-safe: ActionView creates a fresh view context per request, so the render context (set by Ruact::Controller#ruact_render on the controller as @ruact_render_context and copied to the view by Rails’s view_assigns plumbing — see Story 7.9 / Bug 7.8-B) is per-request — no shared state.
Instance Method Summary collapse
-
#__ruact_component__(name, props = {}) ⇒ Object
Registers
namewithpropsin the per-render RenderContext (set by Ruact::Controller#ruact_render on the controller as @ruact_render_context; Rails copies it to the view via_assigns_for_view_contextbecause the name does not matchDEFAULT_PROTECTED_INSTANCE_VARIABLES‘s /A@_/ filter) and returns an HTML comment placeholder that HtmlConverter later replaces with a ReactElement node.
Instance Method Details
#__ruact_component__(name, props = {}) ⇒ Object
Registers name with props in the per-render RenderContext (set by Ruact::Controller#ruact_render on the controller as @ruact_render_context; Rails copies it to the view via _assigns_for_view_context because the name does not match DEFAULT_PROTECTED_INSTANCE_VARIABLES‘s /A@_/ filter) and returns an HTML comment placeholder that HtmlConverter later replaces with a ReactElement node.
The returned string MUST be html_safe so ActionView does not escape the angle brackets — if it were escaped, HtmlConverter would not find the placeholder in the HTML output.
23 24 25 26 27 28 29 |
# File 'lib/ruact/view_helper.rb', line 23 def __ruact_component__(name, props = {}) ctx = @ruact_render_context raise Ruact::Error, "ruact: __ruact_component__ called outside a ruact_render flow" if ctx.nil? token = ctx.register(name, props) "<!-- #{token} -->".html_safe end |