Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Opal::BuilderProcessors::RubyERBProcessor #2470

Merged
merged 1 commit into from Nov 17, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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