Class: I18nliner::PreProcessors::ErbPreProcessor
- Inherits:
-
Object
- Object
- I18nliner::PreProcessors::ErbPreProcessor
- Defined in:
- lib/i18nliner/pre_processors/erb_pre_processor.rb
Defined Under Namespace
Classes: Context, Helper, TBlock
Constant Summary collapse
- ERB_EXPRESSION =
need to evaluate all expressions and statements, so we can correctly match the start/end of the ‘t` block expression (including nested ones)
/<%=\s*(?<content>.*?)\s*%>/
- ERB_BLOCK_EXPRESSION =
/ \A <%= .*? (\sdo|\{) (\s*\|[^\|]+\|)? \s* %> \z /xm
- ERB_T_BLOCK_EXPRESSION =
/ \A <%= \s* t \s*? (\(\)\s*)? (\sdo|\{) \s* %> \z /xm
- ERB_STATEMENT =
/\A<%[^=]/
- ERB_END_STATEMENT =
/ \A <% \s* (end|\}) (\W|%>\z) /xm
- ERB_TOKENIZER =
/(<%.*?%>)/m
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(source) ⇒ ErbPreProcessor
constructor
A new instance of ErbPreProcessor.
- #result ⇒ Object
Constructor Details
#initialize(source) ⇒ ErbPreProcessor
Returns a new instance of ErbPreProcessor.
316 317 318 |
# File 'lib/i18nliner/pre_processors/erb_pre_processor.rb', line 316 def initialize(source) @source = source end |
Class Method Details
.process(source) ⇒ Object
312 313 314 |
# File 'lib/i18nliner/pre_processors/erb_pre_processor.rb', line 312 def self.process(source) new(source).result end |
Instance Method Details
#result ⇒ Object
320 321 322 323 324 325 326 327 328 329 330 331 |
# File 'lib/i18nliner/pre_processors/erb_pre_processor.rb', line 320 def result # the basic idea: # 1. whenever we find a t block expr, go till we find the end # 2. if we find another t block expr before the end, goto step 1 # 3. capture any inline expressions along the way # 4. if we find *any* other statement or block expr, abort, # since it's a no-go # TODO get line numbers for errors ctx = @source.split(ERB_TOKENIZER).inject(Context.new, :<<) raise MalformedErbError.new('possibly unterminated block expression') if ctx.parent ctx.result end |