Class: Frails::Component::Renderer
- Inherits:
-
ActionView::PartialRenderer
- Object
- ActionView::PartialRenderer
- Frails::Component::Renderer
- Includes:
- RendererConcerns
- Defined in:
- lib/frails/component/renderer.rb
Instance Method Summary collapse
-
#find_template(path, locals) ⇒ Object
Overwritten to make sure we don’t lookup partials.
-
#render(context, options, &block) ⇒ Object
rubocop:disable Metrics/AbcSize.
Instance Method Details
#find_template(path, locals) ⇒ Object
Overwritten to make sure we don’t lookup partials. Even though this inherits from the PartialRenderer, component templates do not have the underscore prefix that partials have.
Additionally, this will ensure that ONLY the app/components directory is used as the only view path to search within when looking up the component template.
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/frails/component/renderer.rb', line 11 def find_template(path, locals) path_count = @lookup_context.view_paths.size @lookup_context.view_paths.unshift Frails.components_path old_paths = @lookup_context.view_paths.pop(path_count) prefixes = path.include?('/') ? [] : @lookup_context.prefixes result = @lookup_context.find_template(path, prefixes, false, locals, @details) @lookup_context.view_paths.unshift(*old_paths) @lookup_context.view_paths.pop result end |
#render(context, options, &block) ⇒ Object
rubocop:disable Metrics/AbcSize
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/frails/component/renderer.rb', line 26 def render(context, , &block) @view = context @component = .delete(:component) klass = presenter_class @presenter = klass.new(@view, @component, ) @children = block_given? ? @view.capture(&block) : nil [:partial] = @presenter result = @presenter.run_callbacks :render do if @presenter.respond_to?(:render) @presenter.render(&block) else [:locals] = @presenter.locals [:locals][:children] = @children super context, , block end end apply_styles((result.respond_to?(:body) ? result.body : result) || nil) end |