Module: Matestack::Ui::Core::Helper
- Defined in:
- lib/matestack/ui/core/helper.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #render(*args) ⇒ Object
- #render_component(layout, page, component_key, options) ⇒ Object
- #render_layout(layout, page, options, root_layout) ⇒ Object
- #render_page(page, options, root_layout) ⇒ Object
- #setup_context ⇒ Object
Class Method Details
.included(base) ⇒ Object
6 7 8 |
# File 'lib/matestack/ui/core/helper.rb', line 6 def self.included(base) base.extend ClassMethods end |
Instance Method Details
#render(*args) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/matestack/ui/core/helper.rb', line 21 def render(*args) setup_context if args.first.is_a?(Class) && args.first.ancestors.include?(Base) raise 'expected a hash as second argument' unless args.second.is_a?(Hash) || args.second.nil? begin controller_layout = self.class.send(:_layout) rescue controller_layout = nil end = args.second || {} layout = .delete(:matestack_layout) || self.class.matestack_layout page = args.first if controller_layout == false root_layout = layout ? layout.layout : false else # when using the turbo-rails gem, controller_layout is a Proc # https://github.com/hotwired/turbo-rails/blob/v1.0.1/app/controllers/turbo/frames/frame_request.rb#L16 # and not nil or a string indicating which layout to be used like before if controller_layout.nil? || controller_layout.is_a?(Proc) root_layout = "application" else root_layout = controller_layout end end if layout && params[:only_page].nil? && params[:component_key].nil? && params[:component_class].nil? render_layout layout, page, , root_layout else if params[:component_key] && params[:component_class].nil? render_component layout, page, params[:component_key], elsif params[:component_class] if params[:component_key] render_component nil, params[:component_class].constantize, params[:component_key], JSON.parse(params[:public_options] || '{}') else render html: params[:component_class].constantize.(public_options: JSON.parse(params[:public_options] || '{}')) end else if params[:only_page] render_page page, , false else render_page page, , root_layout end end end else super end end |
#render_component(layout, page, component_key, options) ⇒ Object
81 82 83 84 |
# File 'lib/matestack/ui/core/helper.rb', line 81 def render_component(layout, page, component_key, ) layout ? layout.new() { page.new() } : page.new() # create page structure in order to later access registered async components render html: Matestack::Ui::Core::Context.async_components[component_key].render_content.html_safe, layout: false end |
#render_layout(layout, page, options, root_layout) ⇒ Object
73 74 75 |
# File 'lib/matestack/ui/core/helper.rb', line 73 def render_layout(layout, page, , root_layout) render html: layout.new() { page.new() }.render_content.html_safe, layout: root_layout end |
#render_page(page, options, root_layout) ⇒ Object
77 78 79 |
# File 'lib/matestack/ui/core/helper.rb', line 77 def render_page(page, , root_layout) render html: page.new().render_content.html_safe, layout: root_layout end |