Skip to content

Commit

Permalink
Add Opal::BuilderProcessors::RubyERBProcessor
Browse files Browse the repository at this point in the history
  • Loading branch information
hmdne committed Nov 17, 2022
1 parent c8fb0a1 commit eb978b2
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lib/opal/builder_processors.rb
Expand Up @@ -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

Expand All @@ -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

Expand Down

0 comments on commit eb978b2

Please sign in to comment.