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-1.31.1 lib/synvert/core/engine/erb.rb
synvert-core-1.31.0 lib/synvert/core/engine/erb.rb
synvert-core-1.30.3 lib/synvert/core/engine/erb.rb
synvert-core-1.30.2 lib/synvert/core/engine/erb.rb
synvert-core-1.30.1 lib/synvert/core/engine/erb.rb
synvert-core-1.30.0 lib/synvert/core/engine/erb.rb
synvert-core-1.29.4 lib/synvert/core/engine/erb.rb
synvert-core-1.29.3 lib/synvert/core/engine/erb.rb
synvert-core-1.29.2 lib/synvert/core/engine/erb.rb
synvert-core-1.29.1 lib/synvert/core/engine/erb.rb
synvert-core-1.29.0 lib/synvert/core/engine/erb.rb
synvert-core-1.28.5 lib/synvert/core/engine/erb.rb
synvert-core-1.28.4 lib/synvert/core/engine/erb.rb
synvert-core-1.28.3 lib/synvert/core/engine/erb.rb
synvert-core-1.28.2 lib/synvert/core/engine/erb.rb
synvert-core-1.28.1 lib/synvert/core/engine/erb.rb
synvert-core-1.28.0 lib/synvert/core/engine/erb.rb
synvert-core-1.27.1 lib/synvert/core/engine/erb.rb
synvert-core-1.27.0 lib/synvert/core/engine/erb.rb
synvert-core-1.26.3 lib/synvert/core/engine/erb.rb