Class: Sakusei::ErbProcessor
- Inherits:
-
Object
- Object
- Sakusei::ErbProcessor
- Defined in:
- lib/sakusei/erb_processor.rb
Overview
Processes ERB templates in markdown content
Defined Under Namespace
Classes: ErbContext
Instance Method Summary collapse
-
#initialize(content, base_dir, source_file: nil) ⇒ ErbProcessor
constructor
A new instance of ErbProcessor.
- #process ⇒ Object
Constructor Details
#initialize(content, base_dir, source_file: nil) ⇒ ErbProcessor
Returns a new instance of ErbProcessor.
9 10 11 12 13 |
# File 'lib/sakusei/erb_processor.rb', line 9 def initialize(content, base_dir, source_file: nil) @content = content @base_dir = base_dir @source_file = source_file end |
Instance Method Details
#process ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/sakusei/erb_processor.rb', line 15 def process # Create a context object with helper methods context = ErbContext.new(@base_dir, source_file: @source_file) # Process the ERB — setting filename makes require_relative resolve # relative to the source document, not the working directory. erb = ERB.new(@content, trim_mode: '-') erb.filename = @source_file if @source_file erb.result(context.template_binding) rescue StandardError => e raise Error, "ERB processing error: #{e.}" end |