Sha256: 5f3f6b75e890974b6ab63c503d2a73ed4d3b98108e25871cde62378e8e3eeb68

Contents?: true

Size: 907 Bytes

Versions: 42

Compression:

Stored size: 907 Bytes

Contents

# frozen_string_literal: true

module Synvert::Core
  module Engine
    class Erb
      class << self
        # Encode erb string, leave only ruby code, replace other erb code with whitespace.
        #
        # @param source [String] erb code.
        # @return [String] encoded ruby code.
        def encode(source)
          source.gsub(/%>.*?<%=?/m) { |str| ';' + replace_all_code_but_white_space_characters(str[1..-1]) }
                .sub(/^.*<%=?/m) { |str| replace_all_code_but_white_space_characters(str) }
                .sub(/%>.*$/m) { |str| ';' + replace_all_code_but_white_space_characters(str[1..-1]) }
        end

        # Generate an empty proc.
        def generate_transform_proc(_encoded_source)
          proc {}
        end

        private

        def replace_all_code_but_white_space_characters(source)
          source.gsub(/\S/, ' ')
        end
      end
    end
  end
end

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
synvert-core-2.2.0 lib/synvert/core/engine/erb.rb
synvert-core-2.1.2 lib/synvert/core/engine/erb.rb
synvert-core-2.1.1 lib/synvert/core/engine/erb.rb
synvert-core-2.1.0 lib/synvert/core/engine/erb.rb
synvert-core-2.0.3 lib/synvert/core/engine/erb.rb
synvert-core-2.0.2 lib/synvert/core/engine/erb.rb
synvert-core-2.0.1 lib/synvert/core/engine/erb.rb
synvert-core-2.0.0 lib/synvert/core/engine/erb.rb
synvert-core-1.35.4 lib/synvert/core/engine/erb.rb
synvert-core-1.35.3 lib/synvert/core/engine/erb.rb
synvert-core-1.35.2 lib/synvert/core/engine/erb.rb
synvert-core-1.35.1 lib/synvert/core/engine/erb.rb
synvert-core-1.35.0 lib/synvert/core/engine/erb.rb
synvert-core-1.34.0 lib/synvert/core/engine/erb.rb
synvert-core-1.33.3 lib/synvert/core/engine/erb.rb
synvert-core-1.33.2 lib/synvert/core/engine/erb.rb
synvert-core-1.33.1 lib/synvert/core/engine/erb.rb
synvert-core-1.33.0 lib/synvert/core/engine/erb.rb
synvert-core-1.32.1 lib/synvert/core/engine/erb.rb
synvert-core-1.32.0 lib/synvert/core/engine/erb.rb