Sha256: 92a7d7f2cf8832b3efc4350a2671c4130b3ea6932048c25a6ff3dcd51160b632

Contents?: true

Size: 998 Bytes

Versions: 5

Compression:

Stored size: 998 Bytes

Contents

# This module is intended to be mixed into the Weeler backend to allow
# checks if translation is html
#
#   I18n.backend = I18n::Backend::Weeler.new
#   I18n::Backend::Weeler::Translation.send(:include, I18n::Backend::Weeler::HtmlChecker)
#
# The HtmlChecker module requires html-scanner
# was extracted from the original backend.

begin
  require 'action_view/vendor/html-scanner'
rescue LoadError => e
  puts "can't use Html because: #{e.message}"
end

module I18n
  module Backend
    class Weeler
      module HtmlChecker

        def html?
          if html_safe_translation_key?(self.key) ||
            (self.value.present? && HTML::FullSanitizer.new.sanitize(self.value.to_s).length != self.value.to_s.length)
            return true
          else
            return false
          end
        end

      private

        def html_safe_translation_key?(key)
          key.to_s =~ /(\b|_|\.)html$/
        end

        Translation.send(:include, HtmlChecker)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
weeler-1.0.4 lib/i18n/backend/weeler/html_checker.rb
weeler-1.0.3 lib/i18n/backend/weeler/html_checker.rb
weeler-1.0.2 lib/i18n/backend/weeler/html_checker.rb
weeler-1.0.1 lib/i18n/backend/weeler/html_checker.rb
weeler-1.0.0 lib/i18n/backend/weeler/html_checker.rb