Sha256: b23baed635097202042f5f1d615d15f1159ef3948dd0fe2da4e25e6592544cec
Contents?: true
Size: 1.19 KB
Versions: 6
Compression:
Stored size: 1.19 KB
Contents
require "action_view" module Rbexy module Rails class ComponentTemplateResolver < ActionView::FileSystemResolver # Rails 6 requires us to override `_find_all` in order to hook def _find_all(name, prefix, partial, details, key, locals) find_templates(name, prefix, partial, details, locals) end # Rails 5 only requires `find_templates` (which tbh is the proper way # to implement subclasses of ActionView::Resolver) def find_templates(name, prefix, partial, details, locals = []) return [] unless name.is_a? Rbexy::Component::TemplatePath templates_path = File.join(@path, prefix, name) extensions = details[:handlers].join(",") Dir["#{templates_path}.*{#{extensions}}"].map do |template_path| source = File.binread(template_path) handler = ActionView::Template.handler_for_extension(File.extname(template_path)[1..-1]) virtual_path = ["rbexy_component", prefix, name].join("/") ActionView::Template.new( source, template_path, handler, locals: [], virtual_path: virtual_path ) end end end end end
Version data entries
6 entries across 6 versions & 1 rubygems