Module: RSX::Helpers
- Defined in:
- lib/rsx/helpers.rb
Overview
Mixed into ActionView so components can be rendered from ERB, Haml, Slim or anywhere else a view helper is available.
<%= rsx UserProfile, user: @user %>
<%= rsx "Card", title: "Hello" do %>
<p>Body rendered by ERB, passed to the component as children.</p>
<% end %>
Instance Method Summary collapse
- #rsx(target, **props, &block) ⇒ Object (also: #render_rsx)
-
#rsx_file(path, **props) ⇒ Object
Renders a .rsx file directly by path, relative to the configured paths.
Instance Method Details
#rsx(target, **props, &block) ⇒ Object Also known as: render_rsx
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/rsx/helpers.rb', line 12 def rsx(target, **props, &block) children = if block captured = capture(&block) RSX::Children.new { RSX.raw(captured) } end component = target.is_a?(String) || target.is_a?(Symbol) ? RSX.lookup_component(target) : target RSX.safe(RSX.render_component(component, props.empty? ? nil : props, children, self)) end |
#rsx_file(path, **props) ⇒ Object
Renders a .rsx file directly by path, relative to the configured paths.
25 26 27 |
# File 'lib/rsx/helpers.rb', line 25 def rsx_file(path, **props) RSX.render_file(path, context: self, **props) end |