Sha256: 2a80a27158d0adcd1bb9d86a52cba1b4f3cd39c3e102a30bdea649382a883d0c

Contents?: true

Size: 1.69 KB

Versions: 1

Compression:

Stored size: 1.69 KB

Contents

module I15R
  module PatternMatchers
    module Haml
      class TagContentMatcher < Base
        
        def self.run(text, prefix)
          super(text, prefix, :haml)
        end
        
        def self.match_haml_implicit_div_tag_content
          #TODO: really ugly. so many negative groups
          # to prevent #new-user-link= link_to '...', new_user_path to match
          patt = /^(.*#[^\s=]+)\s+([^\s=]+[^=]*)$/
          matches(:haml) do |text, prefix|
            if m = patt.match(text)
              i18n_string = I15R::Base.get_i18n_message_string(m[2], prefix)
              i18ned_row = %(#{m[1]}= I18n.t("#{i18n_string}"))
              [m[0], i18ned_row]
            end
          end
        end
        register_matcher :match_haml_implicit_div_tag_content

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

        def self.match_haml_tag_content_just_text_on_line
          patt = /^(\s*)([^.#\s][\w\s\d\!\-\.\?]+)$/
          matches(:haml) do |text, prefix|
            if m = patt.match(text)
              i18n_string = I15R::Base.get_i18n_message_string(m[2], prefix)
              i18ned_row = %(#{m[1]}= I18n.t("#{i18n_string}"))
              [m[0], i18ned_row]
            end
          end
        end
        register_matcher :match_haml_tag_content_just_text_on_line

      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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