require 'nokogiri' module ExtractI18n module HTMLExtractor class ErbDocument ERB_REGEXPS = [ TwoWayRegexp.new(/<%=(?.+?)%>/m, /@@=(?[a-z0-9\-\._]+)@@/m), TwoWayRegexp.new(/<%#(?.+?)%>/m, /@@#(?[a-z0-9\-\._]+)@@/m), TwoWayRegexp.new(/<%(?.+?)%>/m, /@@(?[a-z0-9\-\._]+)@@/m) ].freeze attr_reader :erb_directives def initialize(document, erb_directives) @document = document @erb_directives = erb_directives end def save result = @document.to_html(indent: 2, encoding: 'UTF-8') ERB_REGEXPS.each do |regexp| regexp.inverse_replace!(result) do |string_format, data| string_format % { inner_text: erb_directives[data[:inner_text]] } end end result end def method_missing(name, *args, &block) @document.public_send(name, *args, &block) if @document.respond_to? name end class <