Class: SorbetView::Compiler::TemplateCompiler
- Inherits:
-
Object
- Object
- SorbetView::Compiler::TemplateCompiler
- Extended by:
- T::Sig
- Defined in:
- lib/sorbet_view/compiler/template_compiler.rb
Instance Method Summary collapse
- #compile(template_path, source) ⇒ Object
- #compile_file(template_path) ⇒ Object
-
#initialize(adapter: Adapters::ErbAdapter.new, config: Configuration.load) ⇒ TemplateCompiler
constructor
A new instance of TemplateCompiler.
- #invalidate_ivar_cache! ⇒ Object
Constructor Details
#initialize(adapter: Adapters::ErbAdapter.new, config: Configuration.load) ⇒ TemplateCompiler
Returns a new instance of TemplateCompiler.
10 11 12 13 14 |
# File 'lib/sorbet_view/compiler/template_compiler.rb', line 10 def initialize(adapter: Adapters::ErbAdapter.new, config: Configuration.load) @adapter = adapter @generator = T.let(RubyGenerator.new, RubyGenerator) @config = config end |
Instance Method Details
#compile(template_path, source) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/sorbet_view/compiler/template_compiler.rb', line 22 def compile(template_path, source) Perf.measure('compiler.compile') do segments = @adapter.extract_segments(source) context = TemplateContext.resolve(template_path, @config) @generator.generate(segments: segments, context: context, config: @config) end rescue => e # On parse failure, generate a minimal file so Sorbet doesn't complain about missing files context = TemplateContext.resolve(template_path, @config) CompileResult.new( ruby_source: "# typed: ignore\n# sorbet_view: failed to parse #{template_path}: #{e.}\n", source_map: SourceMap::SourceMap.empty(template_path, context.ruby_path), locals: nil, locals_sig: nil ) end |
#compile_file(template_path) ⇒ Object
40 41 42 43 |
# File 'lib/sorbet_view/compiler/template_compiler.rb', line 40 def compile_file(template_path) source = File.read(template_path) compile(template_path, source) end |
#invalidate_ivar_cache! ⇒ Object
17 18 19 |
# File 'lib/sorbet_view/compiler/template_compiler.rb', line 17 def invalidate_ivar_cache! @generator.invalidate_ivar_cache! end |