Sha256: bbaa9268501bc24e743d4cd2eaedb38c7371ca28d754f6ce27dc2d73e27c6524

Contents?: true

Size: 1.48 KB

Versions: 45

Compression:

Stored size: 1.48 KB

Contents

module Abstractor
  ##
  # A collection of helper methods used in the Abstactor user interface.
  module UserInterface
    #2/16/2014 MGURLEY Stolen from http://api.rubyonrails.org/classes/ActionView/Helpers/TextHelper.html.  Rails 3.2.16.
    #                 Removed the cleverness trying skip highlighting content it thinks is html markup.
    def self.highlight(text, phrases, *args)
      options = args.extract_options!
      unless args.empty?
        options[:highlighter] = args[0] || '<strong class="highlight">\1</strong>'
      end
      options.reverse_merge!(:highlighter => '<strong class="highlight">\1</strong>')

      # text = sanitize(text) unless options[:sanitize] == false
      if text.blank? || phrases.blank?
        text
      else
        match = Array(phrases).map { |p| Regexp.escape(p) }.join('|')
        text.gsub(/(#{match})/i, options[:highlighter])
      end.html_safe
    end

    ##
    # Transforms a path to account for a relative url root.
    # URL helpers in Rails Engine views and partials embedded in view in the host application don't play well with relative url roots.
    # @param path [String] the URL path that should have a relative prefix added if needed
    # @return [String] the processed URL
    def self.abstractor_relative_path(path)
      prefix = Rails.application.config.action_controller.relative_url_root

      if prefix.blank? || path.include?(prefix)
        url = path
      else
        url = prefix + path
      end

      url
    end
  end
end

Version data entries

45 entries across 45 versions & 1 rubygems

Version Path
abstractor-4.4.7 lib/abstractor/user_interface.rb
abstractor-4.4.6 lib/abstractor/user_interface.rb
abstractor-4.4.5 lib/abstractor/user_interface.rb
abstractor-4.4.4 lib/abstractor/user_interface.rb
abstractor-4.4.3 lib/abstractor/user_interface.rb
abstractor-4.4.2 lib/abstractor/user_interface.rb
abstractor-4.4.1 lib/abstractor/user_interface.rb
abstractor-4.4.0 lib/abstractor/user_interface.rb
abstractor-4.3.3 lib/abstractor/user_interface.rb
abstractor-4.3.2 lib/abstractor/user_interface.rb
abstractor-4.3.1 lib/abstractor/user_interface.rb
abstractor-4.3.0 lib/abstractor/user_interface.rb
abstractor-4.2.3 lib/abstractor/user_interface.rb
abstractor-4.2.2 lib/abstractor/user_interface.rb
abstractor-4.2.1 lib/abstractor/user_interface.rb
abstractor-4.2.0 lib/abstractor/user_interface.rb
abstractor-4.1.5 lib/abstractor/user_interface.rb
abstractor-4.1.4 lib/abstractor/user_interface.rb
abstractor-4.1.3 lib/abstractor/user_interface.rb
abstractor-4.1.2 lib/abstractor/user_interface.rb