From eb978b27d01beb451340a35f26c0fcab414cef26 Mon Sep 17 00:00:00 2001 From: hmdne <54514036+hmdne@users.noreply.github.com> Date: Tue, 15 Nov 2022 08:41:12 +0100 Subject: [PATCH] Add Opal::BuilderProcessors::RubyERBProcessor --- lib/opal/builder_processors.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lib/opal/builder_processors.rb b/lib/opal/builder_processors.rb index 22b2ca8f41..35194e6254 100644 --- a/lib/opal/builder_processors.rb +++ b/lib/opal/builder_processors.rb @@ -114,6 +114,12 @@ def self.match?(other) end end + # This handler is for files named ".opalerb", which ought to + # first get compiled to Ruby code using ERB, then with Opal. + # Unlike below processors, OpalERBProcessor can be used to + # compile templates, which will in turn output HTML. Take + # a look at docs/templates.md to understand this subsystem + # better. class OpalERBProcessor < RubyProcessor handles :opalerb @@ -133,6 +139,24 @@ def prepare(source, path) end end + # This handler is for files named ".rb.erb", which ought to + # first get preprocessed via ERB, then via Opal. + class RubyERBProcessor < RubyProcessor + handles :"rb.erb" + + def compiled + @compiled ||= begin + @source = ::ERB.new(@source.to_s).result + + compiler = compiler_for(@source, file: @filename) + compiler.compile + compiler + end + end + end + + # This handler is for files named ".js.erb", which ought to + # first get preprocessed via ERB, then served verbatim as JS. class ERBProcessor < Processor handles :erb