lib/opal/builder_processors.rb in opal-1.6.0.alpha1 vs lib/opal/builder_processors.rb in opal-1.6.0.rc1
- old
+ new
@@ -112,10 +112,16 @@
def self.match?(other)
super || File.extname(other.to_s) == ''
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
def initialize(*args)
super
@@ -131,9 +137,27 @@
def prepare(source, path)
::Opal::ERB::Compiler.new(source, path).prepared_source
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
def source
result = ::ERB.new(@source.to_s).result