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