Sha256: cb22e3685b1da7737973d89a7033f88dc353684ac6a3a8c78bf788aa285b10ac

Contents?: true

Size: 944 Bytes

Versions: 1

Compression:

Stored size: 944 Bytes

Contents

require 'erb'

module Erb
  class Comment < ERB
    VERSION = '0.1.0'

    class CommentScanner < ERB::Compiler::TrimScanner
      def stags
        [*super, '<#--']
      end

      def etags
        [*super, '--#>']
      end
    end

    class CommentCompiler < ERB::Compiler
      def initialize(*)
        super
        @in_comment = false
      end

      def compile_stag(stag, _, scanner)
        case stag
        when '<#--'
          scanner.stag = stag
          @in_comment = true
        else
          super
        end
      end

      def compile_etag(etag, _, scanner)
        case etag
        when '--#>'
          scanner.stag = nil
          @in_comment = false
        else
          super unless @in_comment
        end
      end

      def make_scanner(src)
        CommentScanner.new(src, @trim_mode, @percent)
      end
    end

    def make_compiler(trim_mode)
      CommentCompiler.new(trim_mode)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
erb-comment-0.1.0 lib/erb/comment.rb