Sha256: 5af8162f7d44f47108a71669bb4534cc526709e3c16e1fe66d27af065765692e

Contents?: true

Size: 1.22 KB

Versions: 1

Compression:

Stored size: 1.22 KB

Contents

require 'i15r/base'

module I15R
  module PatternMatchers
    module Erb
      class TagContentMatcher < Base
        
        def self.run(text, prefix)
          super(text, prefix, :erb)
        end
        
        def self.match_tag_content_on_one_line
          patt = /^(.*)>(\s*)(\w[\s\w:'"!?\.,]+)\s*<\/(.*)$/
          matches(:erb) do |text, prefix|
            if m = patt.match(text)
              i18n_string = I15R::Base.get_i18n_message_string(m[3], prefix)
              ending_punctuation = m[3][/([?.!:\s]*)$/, 1]
              i15d_row = %(#{m[1]}>#{m[2]}<%= I18n.t("#{i18n_string}") %>#{ending_punctuation.to_s}</#{m[4]})
              [m[0], i15d_row]
            end
          end
        end
        register_matcher :match_tag_content_on_one_line

        def self.match_tag_content_multiline
          patt = /^(\s*)(\w[\w\s,]*)(.*)$/
          matches(:erb) do |text, prefix|
            if m = patt.match(text)
              i18n_string = I15R::Base.get_i18n_message_string(m[2], prefix)
              i15d_row = %(#{m[1]}<%= I18n.t("#{i18n_string}") %>#{m[3]})
              [m[0], i15d_row]
            end
          end
        end
        register_matcher :match_tag_content_multiline

      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
i15r-0.3.1 lib/i15r/pattern_matchers/erb/tag_content_matcher.rb