Sha256: ad574799781df3db2d8cb91c34d51f41781ebbe87a327e63f8dae6c91b0fe8fe
Contents?: true
Size: 1.36 KB
Versions: 5
Compression:
Stored size: 1.36 KB
Contents
require 'spiderfw/templates/template_blocks' require 'strscan' module Spider; module TemplateBlocks ExpressionOutputRegexp = /\{\s([^\s].*?)\s\}/ GettextRegexp = /_\(([^\)]+)?\)(\s%\s([^\s,]+)(,\s*\S+\s*\])?)?/ ERBRegexp = /(<%(.+)?%>)/ class Text < Block def compile(options={}) text = @el.content scanner = ::StringScanner.new(text) pos = 0 c = "" while scanner.scan_until(Regexp.union(ExpressionOutputRegexp, GettextRegexp, ERBRegexp)) text = scanner.pre_match[pos..-1] pos = scanner.pos c += "$out << '#{escape_text(text)}'\n" if (text && text.length > 0) case scanner.matched when ExpressionOutputRegexp c += "$out << #{vars_to_scene($1)}\n" when GettextRegexp c += "$out << _('#{escape_text($1)}')" if $2 c += " #{vars_to_scene($2)}" end c += "\n" when ERBRegexp c += $1 end end text = scanner.rest c += "$out << '#{escape_text(text)}'\n" if (text && text.length > 0) return CompiledBlock.new(nil, c) end end end; end
Version data entries
5 entries across 5 versions & 1 rubygems