Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/ExeBy/exe_root.../opt/alt/ruby22/lib64/ruby/2.2.0
File: erb.rb
# -*- coding: us-ascii -*-
[0] Fix | Delete
# = ERB -- Ruby Templating
[1] Fix | Delete
#
[2] Fix | Delete
# Author:: Masatoshi SEKI
[3] Fix | Delete
# Documentation:: James Edward Gray II, Gavin Sinclair, and Simon Chiang
[4] Fix | Delete
#
[5] Fix | Delete
# See ERB for primary documentation and ERB::Util for a couple of utility
[6] Fix | Delete
# routines.
[7] Fix | Delete
#
[8] Fix | Delete
# Copyright (c) 1999-2000,2002,2003 Masatoshi SEKI
[9] Fix | Delete
#
[10] Fix | Delete
# You can redistribute it and/or modify it under the same terms as Ruby.
[11] Fix | Delete
[12] Fix | Delete
require "cgi/util"
[13] Fix | Delete
[14] Fix | Delete
#
[15] Fix | Delete
# = ERB -- Ruby Templating
[16] Fix | Delete
#
[17] Fix | Delete
# == Introduction
[18] Fix | Delete
#
[19] Fix | Delete
# ERB provides an easy to use but powerful templating system for Ruby. Using
[20] Fix | Delete
# ERB, actual Ruby code can be added to any plain text document for the
[21] Fix | Delete
# purposes of generating document information details and/or flow control.
[22] Fix | Delete
#
[23] Fix | Delete
# A very simple example is this:
[24] Fix | Delete
#
[25] Fix | Delete
# require 'erb'
[26] Fix | Delete
#
[27] Fix | Delete
# x = 42
[28] Fix | Delete
# template = ERB.new <<-EOF
[29] Fix | Delete
# The value of x is: <%= x %>
[30] Fix | Delete
# EOF
[31] Fix | Delete
# puts template.result(binding)
[32] Fix | Delete
#
[33] Fix | Delete
# <em>Prints:</em> The value of x is: 42
[34] Fix | Delete
#
[35] Fix | Delete
# More complex examples are given below.
[36] Fix | Delete
#
[37] Fix | Delete
#
[38] Fix | Delete
# == Recognized Tags
[39] Fix | Delete
#
[40] Fix | Delete
# ERB recognizes certain tags in the provided template and converts them based
[41] Fix | Delete
# on the rules below:
[42] Fix | Delete
#
[43] Fix | Delete
# <% Ruby code -- inline with output %>
[44] Fix | Delete
# <%= Ruby expression -- replace with result %>
[45] Fix | Delete
# <%# comment -- ignored -- useful in testing %>
[46] Fix | Delete
# % a line of Ruby code -- treated as <% line %> (optional -- see ERB.new)
[47] Fix | Delete
# %% replaced with % if first thing on a line and % processing is used
[48] Fix | Delete
# <%% or %%> -- replace with <% or %> respectively
[49] Fix | Delete
#
[50] Fix | Delete
# All other text is passed through ERB filtering unchanged.
[51] Fix | Delete
#
[52] Fix | Delete
#
[53] Fix | Delete
# == Options
[54] Fix | Delete
#
[55] Fix | Delete
# There are several settings you can change when you use ERB:
[56] Fix | Delete
# * the nature of the tags that are recognized;
[57] Fix | Delete
# * the value of <tt>$SAFE</tt> under which the template is run;
[58] Fix | Delete
# * the binding used to resolve local variables in the template.
[59] Fix | Delete
#
[60] Fix | Delete
# See the ERB.new and ERB#result methods for more detail.
[61] Fix | Delete
#
[62] Fix | Delete
# == Character encodings
[63] Fix | Delete
#
[64] Fix | Delete
# ERB (or Ruby code generated by ERB) returns a string in the same
[65] Fix | Delete
# character encoding as the input string. When the input string has
[66] Fix | Delete
# a magic comment, however, it returns a string in the encoding specified
[67] Fix | Delete
# by the magic comment.
[68] Fix | Delete
#
[69] Fix | Delete
# # -*- coding: utf-8 -*-
[70] Fix | Delete
# require 'erb'
[71] Fix | Delete
#
[72] Fix | Delete
# template = ERB.new <<EOF
[73] Fix | Delete
# <%#-*- coding: Big5 -*-%>
[74] Fix | Delete
# \_\_ENCODING\_\_ is <%= \_\_ENCODING\_\_ %>.
[75] Fix | Delete
# EOF
[76] Fix | Delete
# puts template.result
[77] Fix | Delete
#
[78] Fix | Delete
# <em>Prints:</em> \_\_ENCODING\_\_ is Big5.
[79] Fix | Delete
#
[80] Fix | Delete
#
[81] Fix | Delete
# == Examples
[82] Fix | Delete
#
[83] Fix | Delete
# === Plain Text
[84] Fix | Delete
#
[85] Fix | Delete
# ERB is useful for any generic templating situation. Note that in this example, we use the
[86] Fix | Delete
# convenient "% at start of line" tag, and we quote the template literally with
[87] Fix | Delete
# <tt>%q{...}</tt> to avoid trouble with the backslash.
[88] Fix | Delete
#
[89] Fix | Delete
# require "erb"
[90] Fix | Delete
#
[91] Fix | Delete
# # Create template.
[92] Fix | Delete
# template = %q{
[93] Fix | Delete
# From: James Edward Gray II <james@grayproductions.net>
[94] Fix | Delete
# To: <%= to %>
[95] Fix | Delete
# Subject: Addressing Needs
[96] Fix | Delete
#
[97] Fix | Delete
# <%= to[/\w+/] %>:
[98] Fix | Delete
#
[99] Fix | Delete
# Just wanted to send a quick note assuring that your needs are being
[100] Fix | Delete
# addressed.
[101] Fix | Delete
#
[102] Fix | Delete
# I want you to know that my team will keep working on the issues,
[103] Fix | Delete
# especially:
[104] Fix | Delete
#
[105] Fix | Delete
# <%# ignore numerous minor requests -- focus on priorities %>
[106] Fix | Delete
# % priorities.each do |priority|
[107] Fix | Delete
# * <%= priority %>
[108] Fix | Delete
# % end
[109] Fix | Delete
#
[110] Fix | Delete
# Thanks for your patience.
[111] Fix | Delete
#
[112] Fix | Delete
# James Edward Gray II
[113] Fix | Delete
# }.gsub(/^ /, '')
[114] Fix | Delete
#
[115] Fix | Delete
# message = ERB.new(template, 0, "%<>")
[116] Fix | Delete
#
[117] Fix | Delete
# # Set up template data.
[118] Fix | Delete
# to = "Community Spokesman <spokesman@ruby_community.org>"
[119] Fix | Delete
# priorities = [ "Run Ruby Quiz",
[120] Fix | Delete
# "Document Modules",
[121] Fix | Delete
# "Answer Questions on Ruby Talk" ]
[122] Fix | Delete
#
[123] Fix | Delete
# # Produce result.
[124] Fix | Delete
# email = message.result
[125] Fix | Delete
# puts email
[126] Fix | Delete
#
[127] Fix | Delete
# <i>Generates:</i>
[128] Fix | Delete
#
[129] Fix | Delete
# From: James Edward Gray II <james@grayproductions.net>
[130] Fix | Delete
# To: Community Spokesman <spokesman@ruby_community.org>
[131] Fix | Delete
# Subject: Addressing Needs
[132] Fix | Delete
#
[133] Fix | Delete
# Community:
[134] Fix | Delete
#
[135] Fix | Delete
# Just wanted to send a quick note assuring that your needs are being addressed.
[136] Fix | Delete
#
[137] Fix | Delete
# I want you to know that my team will keep working on the issues, especially:
[138] Fix | Delete
#
[139] Fix | Delete
# * Run Ruby Quiz
[140] Fix | Delete
# * Document Modules
[141] Fix | Delete
# * Answer Questions on Ruby Talk
[142] Fix | Delete
#
[143] Fix | Delete
# Thanks for your patience.
[144] Fix | Delete
#
[145] Fix | Delete
# James Edward Gray II
[146] Fix | Delete
#
[147] Fix | Delete
# === Ruby in HTML
[148] Fix | Delete
#
[149] Fix | Delete
# ERB is often used in <tt>.rhtml</tt> files (HTML with embedded Ruby). Notice the need in
[150] Fix | Delete
# this example to provide a special binding when the template is run, so that the instance
[151] Fix | Delete
# variables in the Product object can be resolved.
[152] Fix | Delete
#
[153] Fix | Delete
# require "erb"
[154] Fix | Delete
#
[155] Fix | Delete
# # Build template data class.
[156] Fix | Delete
# class Product
[157] Fix | Delete
# def initialize( code, name, desc, cost )
[158] Fix | Delete
# @code = code
[159] Fix | Delete
# @name = name
[160] Fix | Delete
# @desc = desc
[161] Fix | Delete
# @cost = cost
[162] Fix | Delete
#
[163] Fix | Delete
# @features = [ ]
[164] Fix | Delete
# end
[165] Fix | Delete
#
[166] Fix | Delete
# def add_feature( feature )
[167] Fix | Delete
# @features << feature
[168] Fix | Delete
# end
[169] Fix | Delete
#
[170] Fix | Delete
# # Support templating of member data.
[171] Fix | Delete
# def get_binding
[172] Fix | Delete
# binding
[173] Fix | Delete
# end
[174] Fix | Delete
#
[175] Fix | Delete
# # ...
[176] Fix | Delete
# end
[177] Fix | Delete
#
[178] Fix | Delete
# # Create template.
[179] Fix | Delete
# template = %{
[180] Fix | Delete
# <html>
[181] Fix | Delete
# <head><title>Ruby Toys -- <%= @name %></title></head>
[182] Fix | Delete
# <body>
[183] Fix | Delete
#
[184] Fix | Delete
# <h1><%= @name %> (<%= @code %>)</h1>
[185] Fix | Delete
# <p><%= @desc %></p>
[186] Fix | Delete
#
[187] Fix | Delete
# <ul>
[188] Fix | Delete
# <% @features.each do |f| %>
[189] Fix | Delete
# <li><b><%= f %></b></li>
[190] Fix | Delete
# <% end %>
[191] Fix | Delete
# </ul>
[192] Fix | Delete
#
[193] Fix | Delete
# <p>
[194] Fix | Delete
# <% if @cost < 10 %>
[195] Fix | Delete
# <b>Only <%= @cost %>!!!</b>
[196] Fix | Delete
# <% else %>
[197] Fix | Delete
# Call for a price, today!
[198] Fix | Delete
# <% end %>
[199] Fix | Delete
# </p>
[200] Fix | Delete
#
[201] Fix | Delete
# </body>
[202] Fix | Delete
# </html>
[203] Fix | Delete
# }.gsub(/^ /, '')
[204] Fix | Delete
#
[205] Fix | Delete
# rhtml = ERB.new(template)
[206] Fix | Delete
#
[207] Fix | Delete
# # Set up template data.
[208] Fix | Delete
# toy = Product.new( "TZ-1002",
[209] Fix | Delete
# "Rubysapien",
[210] Fix | Delete
# "Geek's Best Friend! Responds to Ruby commands...",
[211] Fix | Delete
# 999.95 )
[212] Fix | Delete
# toy.add_feature("Listens for verbal commands in the Ruby language!")
[213] Fix | Delete
# toy.add_feature("Ignores Perl, Java, and all C variants.")
[214] Fix | Delete
# toy.add_feature("Karate-Chop Action!!!")
[215] Fix | Delete
# toy.add_feature("Matz signature on left leg.")
[216] Fix | Delete
# toy.add_feature("Gem studded eyes... Rubies, of course!")
[217] Fix | Delete
#
[218] Fix | Delete
# # Produce result.
[219] Fix | Delete
# rhtml.run(toy.get_binding)
[220] Fix | Delete
#
[221] Fix | Delete
# <i>Generates (some blank lines removed):</i>
[222] Fix | Delete
#
[223] Fix | Delete
# <html>
[224] Fix | Delete
# <head><title>Ruby Toys -- Rubysapien</title></head>
[225] Fix | Delete
# <body>
[226] Fix | Delete
#
[227] Fix | Delete
# <h1>Rubysapien (TZ-1002)</h1>
[228] Fix | Delete
# <p>Geek's Best Friend! Responds to Ruby commands...</p>
[229] Fix | Delete
#
[230] Fix | Delete
# <ul>
[231] Fix | Delete
# <li><b>Listens for verbal commands in the Ruby language!</b></li>
[232] Fix | Delete
# <li><b>Ignores Perl, Java, and all C variants.</b></li>
[233] Fix | Delete
# <li><b>Karate-Chop Action!!!</b></li>
[234] Fix | Delete
# <li><b>Matz signature on left leg.</b></li>
[235] Fix | Delete
# <li><b>Gem studded eyes... Rubies, of course!</b></li>
[236] Fix | Delete
# </ul>
[237] Fix | Delete
#
[238] Fix | Delete
# <p>
[239] Fix | Delete
# Call for a price, today!
[240] Fix | Delete
# </p>
[241] Fix | Delete
#
[242] Fix | Delete
# </body>
[243] Fix | Delete
# </html>
[244] Fix | Delete
#
[245] Fix | Delete
#
[246] Fix | Delete
# == Notes
[247] Fix | Delete
#
[248] Fix | Delete
# There are a variety of templating solutions available in various Ruby projects:
[249] Fix | Delete
# * ERB's big brother, eRuby, works the same but is written in C for speed;
[250] Fix | Delete
# * Amrita (smart at producing HTML/XML);
[251] Fix | Delete
# * cs/Template (written in C for speed);
[252] Fix | Delete
# * RDoc, distributed with Ruby, uses its own template engine, which can be reused elsewhere;
[253] Fix | Delete
# * and others; search {RubyGems.org}[https://rubygems.org/] or
[254] Fix | Delete
# {The Ruby Toolbox}[https://www.ruby-toolbox.com/].
[255] Fix | Delete
#
[256] Fix | Delete
# Rails, the web application framework, uses ERB to create views.
[257] Fix | Delete
#
[258] Fix | Delete
class ERB
[259] Fix | Delete
Revision = '$Date:: 2014-12-12 19:48:57 +0900#$' # :nodoc: #'
[260] Fix | Delete
[261] Fix | Delete
# Returns revision information for the erb.rb module.
[262] Fix | Delete
def self.version
[263] Fix | Delete
"erb.rb [2.1.0 #{ERB::Revision.split[1]}]"
[264] Fix | Delete
end
[265] Fix | Delete
end
[266] Fix | Delete
[267] Fix | Delete
#--
[268] Fix | Delete
# ERB::Compiler
[269] Fix | Delete
class ERB
[270] Fix | Delete
# = ERB::Compiler
[271] Fix | Delete
#
[272] Fix | Delete
# Compiles ERB templates into Ruby code; the compiled code produces the
[273] Fix | Delete
# template result when evaluated. ERB::Compiler provides hooks to define how
[274] Fix | Delete
# generated output is handled.
[275] Fix | Delete
#
[276] Fix | Delete
# Internally ERB does something like this to generate the code returned by
[277] Fix | Delete
# ERB#src:
[278] Fix | Delete
#
[279] Fix | Delete
# compiler = ERB::Compiler.new('<>')
[280] Fix | Delete
# compiler.pre_cmd = ["_erbout=''"]
[281] Fix | Delete
# compiler.put_cmd = "_erbout.concat"
[282] Fix | Delete
# compiler.insert_cmd = "_erbout.concat"
[283] Fix | Delete
# compiler.post_cmd = ["_erbout"]
[284] Fix | Delete
#
[285] Fix | Delete
# code, enc = compiler.compile("Got <%= obj %>!\n")
[286] Fix | Delete
# puts code
[287] Fix | Delete
#
[288] Fix | Delete
# <i>Generates</i>:
[289] Fix | Delete
#
[290] Fix | Delete
# #coding:UTF-8
[291] Fix | Delete
# _erbout=''; _erbout.concat "Got "; _erbout.concat(( obj ).to_s); _erbout.concat "!\n"; _erbout
[292] Fix | Delete
#
[293] Fix | Delete
# By default the output is sent to the print method. For example:
[294] Fix | Delete
#
[295] Fix | Delete
# compiler = ERB::Compiler.new('<>')
[296] Fix | Delete
# code, enc = compiler.compile("Got <%= obj %>!\n")
[297] Fix | Delete
# puts code
[298] Fix | Delete
#
[299] Fix | Delete
# <i>Generates</i>:
[300] Fix | Delete
#
[301] Fix | Delete
# #coding:UTF-8
[302] Fix | Delete
# print "Got "; print(( obj ).to_s); print "!\n"
[303] Fix | Delete
#
[304] Fix | Delete
# == Evaluation
[305] Fix | Delete
#
[306] Fix | Delete
# The compiled code can be used in any context where the names in the code
[307] Fix | Delete
# correctly resolve. Using the last example, each of these print 'Got It!'
[308] Fix | Delete
#
[309] Fix | Delete
# Evaluate using a variable:
[310] Fix | Delete
#
[311] Fix | Delete
# obj = 'It'
[312] Fix | Delete
# eval code
[313] Fix | Delete
#
[314] Fix | Delete
# Evaluate using an input:
[315] Fix | Delete
#
[316] Fix | Delete
# mod = Module.new
[317] Fix | Delete
# mod.module_eval %{
[318] Fix | Delete
# def get(obj)
[319] Fix | Delete
# #{code}
[320] Fix | Delete
# end
[321] Fix | Delete
# }
[322] Fix | Delete
# extend mod
[323] Fix | Delete
# get('It')
[324] Fix | Delete
#
[325] Fix | Delete
# Evaluate using an accessor:
[326] Fix | Delete
#
[327] Fix | Delete
# klass = Class.new Object
[328] Fix | Delete
# klass.class_eval %{
[329] Fix | Delete
# attr_accessor :obj
[330] Fix | Delete
# def initialize(obj)
[331] Fix | Delete
# @obj = obj
[332] Fix | Delete
# end
[333] Fix | Delete
# def get_it
[334] Fix | Delete
# #{code}
[335] Fix | Delete
# end
[336] Fix | Delete
# }
[337] Fix | Delete
# klass.new('It').get_it
[338] Fix | Delete
#
[339] Fix | Delete
# Good! See also ERB#def_method, ERB#def_module, and ERB#def_class.
[340] Fix | Delete
class Compiler # :nodoc:
[341] Fix | Delete
class PercentLine # :nodoc:
[342] Fix | Delete
def initialize(str)
[343] Fix | Delete
@value = str
[344] Fix | Delete
end
[345] Fix | Delete
attr_reader :value
[346] Fix | Delete
alias :to_s :value
[347] Fix | Delete
[348] Fix | Delete
def empty?
[349] Fix | Delete
@value.empty?
[350] Fix | Delete
end
[351] Fix | Delete
end
[352] Fix | Delete
[353] Fix | Delete
class Scanner # :nodoc:
[354] Fix | Delete
@scanner_map = {}
[355] Fix | Delete
def self.regist_scanner(klass, trim_mode, percent)
[356] Fix | Delete
@scanner_map[[trim_mode, percent]] = klass
[357] Fix | Delete
end
[358] Fix | Delete
[359] Fix | Delete
def self.default_scanner=(klass)
[360] Fix | Delete
@default_scanner = klass
[361] Fix | Delete
end
[362] Fix | Delete
[363] Fix | Delete
def self.make_scanner(src, trim_mode, percent)
[364] Fix | Delete
klass = @scanner_map.fetch([trim_mode, percent], @default_scanner)
[365] Fix | Delete
klass.new(src, trim_mode, percent)
[366] Fix | Delete
end
[367] Fix | Delete
[368] Fix | Delete
def initialize(src, trim_mode, percent)
[369] Fix | Delete
@src = src
[370] Fix | Delete
@stag = nil
[371] Fix | Delete
end
[372] Fix | Delete
attr_accessor :stag
[373] Fix | Delete
[374] Fix | Delete
def scan; end
[375] Fix | Delete
end
[376] Fix | Delete
[377] Fix | Delete
class TrimScanner < Scanner # :nodoc:
[378] Fix | Delete
def initialize(src, trim_mode, percent)
[379] Fix | Delete
super
[380] Fix | Delete
@trim_mode = trim_mode
[381] Fix | Delete
@percent = percent
[382] Fix | Delete
if @trim_mode == '>'
[383] Fix | Delete
@scan_line = self.method(:trim_line1)
[384] Fix | Delete
elsif @trim_mode == '<>'
[385] Fix | Delete
@scan_line = self.method(:trim_line2)
[386] Fix | Delete
elsif @trim_mode == '-'
[387] Fix | Delete
@scan_line = self.method(:explicit_trim_line)
[388] Fix | Delete
else
[389] Fix | Delete
@scan_line = self.method(:scan_line)
[390] Fix | Delete
end
[391] Fix | Delete
end
[392] Fix | Delete
attr_accessor :stag
[393] Fix | Delete
[394] Fix | Delete
def scan(&block)
[395] Fix | Delete
@stag = nil
[396] Fix | Delete
if @percent
[397] Fix | Delete
@src.each_line do |line|
[398] Fix | Delete
percent_line(line, &block)
[399] Fix | Delete
end
[400] Fix | Delete
else
[401] Fix | Delete
@scan_line.call(@src, &block)
[402] Fix | Delete
end
[403] Fix | Delete
nil
[404] Fix | Delete
end
[405] Fix | Delete
[406] Fix | Delete
def percent_line(line, &block)
[407] Fix | Delete
if @stag || line[0] != ?%
[408] Fix | Delete
return @scan_line.call(line, &block)
[409] Fix | Delete
end
[410] Fix | Delete
[411] Fix | Delete
line[0] = ''
[412] Fix | Delete
if line[0] == ?%
[413] Fix | Delete
@scan_line.call(line, &block)
[414] Fix | Delete
else
[415] Fix | Delete
yield(PercentLine.new(line.chomp))
[416] Fix | Delete
end
[417] Fix | Delete
end
[418] Fix | Delete
[419] Fix | Delete
def scan_line(line)
[420] Fix | Delete
line.scan(/(.*?)(<%%|%%>|<%=|<%#|<%|%>|\n|\z)/m) do |tokens|
[421] Fix | Delete
tokens.each do |token|
[422] Fix | Delete
next if token.empty?
[423] Fix | Delete
yield(token)
[424] Fix | Delete
end
[425] Fix | Delete
end
[426] Fix | Delete
end
[427] Fix | Delete
[428] Fix | Delete
def trim_line1(line)
[429] Fix | Delete
line.scan(/(.*?)(<%%|%%>|<%=|<%#|<%|%>\n|%>|\n|\z)/m) do |tokens|
[430] Fix | Delete
tokens.each do |token|
[431] Fix | Delete
next if token.empty?
[432] Fix | Delete
if token == "%>\n"
[433] Fix | Delete
yield('%>')
[434] Fix | Delete
yield(:cr)
[435] Fix | Delete
else
[436] Fix | Delete
yield(token)
[437] Fix | Delete
end
[438] Fix | Delete
end
[439] Fix | Delete
end
[440] Fix | Delete
end
[441] Fix | Delete
[442] Fix | Delete
def trim_line2(line)
[443] Fix | Delete
head = nil
[444] Fix | Delete
line.scan(/(.*?)(<%%|%%>|<%=|<%#|<%|%>\n|%>|\n|\z)/m) do |tokens|
[445] Fix | Delete
tokens.each do |token|
[446] Fix | Delete
next if token.empty?
[447] Fix | Delete
head = token unless head
[448] Fix | Delete
if token == "%>\n"
[449] Fix | Delete
yield('%>')
[450] Fix | Delete
if is_erb_stag?(head)
[451] Fix | Delete
yield(:cr)
[452] Fix | Delete
else
[453] Fix | Delete
yield("\n")
[454] Fix | Delete
end
[455] Fix | Delete
head = nil
[456] Fix | Delete
else
[457] Fix | Delete
yield(token)
[458] Fix | Delete
head = nil if token == "\n"
[459] Fix | Delete
end
[460] Fix | Delete
end
[461] Fix | Delete
end
[462] Fix | Delete
end
[463] Fix | Delete
[464] Fix | Delete
def explicit_trim_line(line)
[465] Fix | Delete
line.scan(/(.*?)(^[ \t]*<%\-|<%\-|<%%|%%>|<%=|<%#|<%|-%>\n|-%>|%>|\z)/m) do |tokens|
[466] Fix | Delete
tokens.each do |token|
[467] Fix | Delete
next if token.empty?
[468] Fix | Delete
if @stag.nil? && /[ \t]*<%-/ =~ token
[469] Fix | Delete
yield('<%')
[470] Fix | Delete
elsif @stag && token == "-%>\n"
[471] Fix | Delete
yield('%>')
[472] Fix | Delete
yield(:cr)
[473] Fix | Delete
elsif @stag && token == '-%>'
[474] Fix | Delete
yield('%>')
[475] Fix | Delete
else
[476] Fix | Delete
yield(token)
[477] Fix | Delete
end
[478] Fix | Delete
end
[479] Fix | Delete
end
[480] Fix | Delete
end
[481] Fix | Delete
[482] Fix | Delete
ERB_STAG = %w(<%= <%# <%)
[483] Fix | Delete
def is_erb_stag?(s)
[484] Fix | Delete
ERB_STAG.member?(s)
[485] Fix | Delete
end
[486] Fix | Delete
end
[487] Fix | Delete
[488] Fix | Delete
Scanner.default_scanner = TrimScanner
[489] Fix | Delete
[490] Fix | Delete
class SimpleScanner < Scanner # :nodoc:
[491] Fix | Delete
def scan
[492] Fix | Delete
@src.scan(/(.*?)(<%%|%%>|<%=|<%#|<%|%>|\n|\z)/m) do |tokens|
[493] Fix | Delete
tokens.each do |token|
[494] Fix | Delete
next if token.empty?
[495] Fix | Delete
yield(token)
[496] Fix | Delete
end
[497] Fix | Delete
end
[498] Fix | Delete
end
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function