Sha256: c579d74cd30e656f3a3d76d81e926873b639c51505f694246368c3f21c075429

Contents?: true

Size: 1.06 KB

Versions: 26

Compression:

Stored size: 1.06 KB

Contents

require 'action_view'
require_relative 'runtime_checks'

class BetterHtml::BetterErb
  class ErubiImplementation < ActionView::Template::Handlers::ERB::Erubi
    include RuntimeChecks

    def add_text(text)
      return if text.empty?

      if text == "\n"
        @parser.parse("\n")
        @newline_pending += 1
      else
        src << "@output_buffer.safe_append='"
        src << "\n" * @newline_pending if @newline_pending > 0
        src << escape_text(text)
        src << "'.freeze;"

        @parser.parse(text) do |*args|
          check_token(*args)
        end

        @newline_pending = 0
      end
    end

    def add_expression(indicator, code)
      if (indicator == "==") || @escape
        add_expr_auto_escaped(src, code, false)
      else
        add_expr_auto_escaped(src, code, true)
      end
    end

    def add_code(code)
      flush_newline_if_pending(src)

      block_check(src, "<%#{code}%>")
      @parser.append_placeholder(code)
      super
    end

    private

    def escape_text(text)
      text.gsub(/['\\]/, '\\\\\&')
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
better_html-1.0.16 lib/better_html/better_erb/erubi_implementation.rb
better_html-1.0.15 lib/better_html/better_erb/erubi_implementation.rb
better_html-1.0.14 lib/better_html/better_erb/erubi_implementation.rb
better_html-1.0.13 lib/better_html/better_erb/erubi_implementation.rb
better_html-1.0.12 lib/better_html/better_erb/erubi_implementation.rb
better_html-1.0.11 lib/better_html/better_erb/erubi_implementation.rb
better_html-1.0.10 lib/better_html/better_erb/erubi_implementation.rb
better_html-1.0.9 lib/better_html/better_erb/erubi_implementation.rb
better_html-1.0.8 lib/better_html/better_erb/erubi_implementation.rb
better_html-1.0.7 lib/better_html/better_erb/erubi_implementation.rb
better_html-1.0.6 lib/better_html/better_erb/erubi_implementation.rb
better_html-1.0.5 lib/better_html/better_erb/erubi_implementation.rb
better_html-1.0.4 lib/better_html/better_erb/erubi_implementation.rb
better_html-1.0.3 lib/better_html/better_erb/erubi_implementation.rb
better_html-1.0.2 lib/better_html/better_erb/erubi_implementation.rb
better_html-1.0.1 lib/better_html/better_erb/erubi_implementation.rb
better_html-1.0.0 lib/better_html/better_erb/erubi_implementation.rb
better_html-0.0.12 lib/better_html/better_erb/erubi_implementation.rb
better_html-0.0.11 lib/better_html/better_erb/erubi_implementation.rb
better_html-0.0.10 lib/better_html/better_erb/erubi_implementation.rb