lib/phlex/rails/layout.rb in phlex-rails-0.6.1 vs lib/phlex/rails/layout.rb in phlex-rails-0.7.0

- old
+ new

@@ -10,7 +10,52 @@ include Helpers::ActionCableMetaTag include Helpers::AutoDiscoveryLinkTag include Helpers::JavaScriptIncludeTag include Helpers::JavaScriptImportMapTags include Helpers::JavaScriptImportModuleTag + + module Interface + def render(view, _locals, &block) + component = new + + component.call(view_context: view) do |yielded| + case yielded + when Symbol + output = view.view_flow.get(yielded) + else + output = yield + end + + case output + when ActiveSupport::SafeBuffer + component.unsafe_raw output + end + + nil + end + end + + def identifier + name + end + + def virtual_path + return @virtual_path if defined? @virtual_path + + @virtual_path = name&.dup.tap do |n| + n.gsub!("::", ".") + n.gsub!(/([a-z])([A-Z])/, '\1_\2') + n.downcase! + end + end + end + + def self.included(klass) + unless klass < Phlex::HTML + raise Phlex::ArgumentError, + "👋 #{name} should only be included into Phlex::HTML classes." + end + + klass.extend(Interface) + end end end