Module: Compony::ViewHelpers
- Included in:
- ControllerMixin
- Defined in:
- lib/compony/view_helpers.rb
Overview
Methods in this module are available in content blocks and Rails views. Rule of thumb: this holds methods that require a view context and results are rendered immediately.
Instance Method Summary collapse
-
#compony_actions ⇒ Object
Use this in your application layout to render all actions of the current root component.
-
#compony_button ⇒ Object
Given a component and a family/model, this instanciates and renders a button component.
-
#compony_link(comp_name_or_cst, model_or_family_name_or_cst, *link_args, label_opts: {}, **link_kwargs) ⇒ Object
Renders a link to a component given a comp and model or family.
Instance Method Details
#compony_actions ⇒ Object
Use this in your application layout to render all actions of the current root component.
8 9 10 11 |
# File 'lib/compony/view_helpers.rb', line 8 def compony_actions return nil unless Compony.root_comp Compony.root_comp.render_actions(self, wrapper_class: 'root-actions', action_class: 'root-action') end |
#compony_button ⇒ Object
Given a component and a family/model, this instanciates and renders a button component.
32 33 34 |
# File 'lib/compony/view_helpers.rb', line 32 def (...) Compony.(...).render(helpers.controller) end |
#compony_link(comp_name_or_cst, model_or_family_name_or_cst, *link_args, label_opts: {}, **link_kwargs) ⇒ Object
Renders a link to a component given a comp and model or family. If authentication is configured and the current user has insufficient permissions to access the target object, the link is not displayed.
22 23 24 25 26 27 |
# File 'lib/compony/view_helpers.rb', line 22 def compony_link(comp_name_or_cst, model_or_family_name_or_cst, *link_args, label_opts: {}, **link_kwargs) model = model_or_family_name_or_cst.respond_to?(:model_name) ? model_or_family_name_or_cst : nil comp = Compony.comp_class_for!(comp_name_or_cst, model_or_family_name_or_cst).new(data: model) return unless comp.standalone_access_permitted_for?(self) return helpers.link_to(comp.label(model, **label_opts), Compony.path(comp.comp_name, comp.family_name, model), *link_args, **link_kwargs) end |