Sha256: ee8b5fa7a7e54d5fc1269971ea6b07c16a615852bd65b4118aed3489ed1fee7a

Contents?: true

Size: 982 Bytes

Versions: 26

Compression:

Stored size: 982 Bytes

Contents

require 'action_view'
require_relative 'runtime_checks'

class BetterHtml::BetterErb
  class ErubisImplementation < ActionView::Template::Handlers::Erubis
    include RuntimeChecks

    def add_text(src, 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_expr_literal(src, code)
      add_expr_auto_escaped(src, code, true)
    end

    def add_expr_escaped(src, code)
      add_expr_auto_escaped(src, code, false)
    end

    def add_stmt(src, code)
      flush_newline_if_pending(src)

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

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
better_html-0.0.9 lib/better_html/better_erb/erubis_implementation.rb
better_html-0.0.8 lib/better_html/better_erb/erubis_implementation.rb
better_html-0.0.7 lib/better_html/better_erb/erubis_implementation.rb
better_html-0.0.5 lib/better_html/better_erb/erubis_implementation.rb
better_html-0.0.4 lib/better_html/better_erb/erubis_implementation.rb
better_html-0.0.3 lib/better_html/better_erb/erubis_implementation.rb