Skip to content

Commit

Permalink
+ Switched from erubis to erubi for erb processing. (clive-devops)
Browse files Browse the repository at this point in the history
- Minor cleanup and top-level error handling changes.

[git-p4: depot-paths = "//src/flay/dev/": change = 13121]
  • Loading branch information
zenspider committed May 23, 2021
1 parent 9f2c00b commit 23e5dc5
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 37 deletions.
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Hoe.spec "flay" do

dependency "sexp_processor", "~> 4.0"
dependency "ruby_parser", "~> 3.0"
dependency "erubis", "~> 2.7.0"
dependency "erubi", "~> 1.10"
dependency "path_expander", "~> 1.0"

dependency "minitest", "~> 5.8.0", :dev
Expand Down
13 changes: 2 additions & 11 deletions lib/flay.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
#!/usr/bin/env ruby -w

require "optparse"
require "rubygems"
require "sexp_processor"
require "ruby_parser"
require "path_expander"
require "timeout"
require "zlib"

class File
RUBY19 = "<3".respond_to? :encoding unless defined? RUBY19 # :nodoc:

class << self
alias :binread :read unless RUBY19
end
end

class Flay
VERSION = "2.12.1" # :nodoc:

Expand Down Expand Up @@ -159,8 +150,8 @@ def self.load_plugins
end
end
@@plugins
rescue
# ignore
rescue => e
warn "Error loading plugins: #{e}" if option[:verbose]
end

# :stopdoc:
Expand Down
27 changes: 2 additions & 25 deletions lib/flay_erb.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#!/usr/bin/ruby

require "rubygems"
require "flay"
require "erubis"
require "erubi"

class Flay

Expand All @@ -13,32 +10,12 @@ class Flay
def process_erb file
erb = File.read file

ruby = Erubis.new(erb).src
ruby = Erubi::Engine.new(erb).src
begin
RubyParser.new.process(ruby, file)
rescue => e
warn ruby if option[:verbose]
raise e
end
end

class Erubis < ::Erubis::Eruby # :nodoc:
BLOCK_EXPR = /\s+(do|\{)(\s*\|[^|]*\|)?\s*\Z/

def add_expr_literal(src, code)
if code =~ BLOCK_EXPR
src << '@output_buffer.append= ' << code
else
src << '@output_buffer.append=(' << code << ');'
end
end

def add_expr_escaped(src, code)
if code =~ BLOCK_EXPR
src << "@output_buffer.safe_append= " << code
else
src << "@output_buffer.safe_append=(" << code << ");"
end
end
end
end

0 comments on commit 23e5dc5

Please sign in to comment.