Class: CustomERB::Compiler::TrimScanner
Overview
Constant Summary
collapse
- TrimSplitRegexp =
/(<@@)|(@@>)|(<@=)|(<@#)|(<@)|(@>\n)|(@>)|(\n)/
- ExplicitTrimRegexp =
/(^[ \t]*<@-)|(-@>\n?\z)|(<@-)|(-@>)|(<@@)|(@@>)|(<@=)|(<@#)|(<@)|(@>)|(\n)/
- CustomERB_STAG =
%w(<@= <@# <@)
Constants inherited
from Scanner
Scanner::SplitRegexp
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Scanner
default_scanner=, make_scanner, regist_scanner
Constructor Details
#initialize(src, trim_mode, percent) ⇒ TrimScanner
Returns a new instance of TrimScanner.
303
304
305
306
307
308
309
310
311
312
313
314
315
316
|
# File 'lib/ontomde-core/customERB.rb', line 303
def initialize(src, trim_mode, percent)
super
@trim_mode = trim_mode
@percent = percent
if @trim_mode == '>'
@scan_line = self.method(:trim_line1)
elsif @trim_mode == '<>'
@scan_line = self.method(:trim_line2)
elsif @trim_mode == '-'
@scan_line = self.method(:explicit_trim_line)
else
@scan_line = self.method(:scan_line)
end
end
|
Instance Attribute Details
Returns the value of attribute stag.
317
318
319
|
# File 'lib/ontomde-core/customERB.rb', line 317
def stag
@stag
end
|
Instance Method Details
#explicit_trim_line(line) ⇒ Object
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
|
# File 'lib/ontomde-core/customERB.rb', line 384
def explicit_trim_line(line)
line.split(ExplicitTrimRegexp).each do |token|
next if token.empty?
if @stag.nil? && /[ \t]*<@-/ =~ token
yield('<@')
elsif @stag && /-@>\n/ =~ token
yield('@>')
yield(:cr)
elsif @stag && token == '-@>'
yield('@>')
else
yield(token)
end
end
end
|
#is_erb_stag?(s) ⇒ Boolean
401
402
403
|
# File 'lib/ontomde-core/customERB.rb', line 401
def is_erb_stag?(s)
CustomERB_STAG.member?(s)
end
|
#percent_line(line, &block) ⇒ Object
333
334
335
336
337
338
339
340
341
342
343
344
|
# File 'lib/ontomde-core/customERB.rb', line 333
def percent_line(line, &block)
if @stag || line[0] != ?@
return @scan_line.call(line, &block)
end
line[0] = ''
if line[0] == ?@
@scan_line.call(line, &block)
else
yield(PercentLine.new(line.chomp))
end
end
|
#scan(&block) ⇒ Object
319
320
321
322
323
324
325
326
327
328
329
330
331
|
# File 'lib/ontomde-core/customERB.rb', line 319
def scan(&block)
@stag = nil
if @percent
@src.each do |line|
percent_line(line, &block)
end
else
@src.each do |line|
@scan_line.call(line, &block)
end
end
nil
end
|
#scan_line(line) ⇒ Object
346
347
348
349
350
351
|
# File 'lib/ontomde-core/customERB.rb', line 346
def scan_line(line)
line.split(SplitRegexp).each do |token|
next if token.empty?
yield(token)
end
end
|
#trim_line1(line) ⇒ Object
353
354
355
356
357
358
359
360
361
362
363
|
# File 'lib/ontomde-core/customERB.rb', line 353
def trim_line1(line)
line.split(TrimSplitRegexp).each do |token|
next if token.empty?
if token == "@>\n"
yield('@>')
yield(:cr)
break
end
yield(token)
end
end
|
#trim_line2(line) ⇒ Object
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
|
# File 'lib/ontomde-core/customERB.rb', line 365
def trim_line2(line)
head = nil
line.split(TrimSplitRegexp).each do |token|
next if token.empty?
head = token unless head
if token == "@>\n"
yield('@>')
if is_erb_stag?(head)
yield(:cr)
else
yield("\n")
end
break
end
yield(token)
end
end
|