Commit a4d5fd5b authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Rename JsDuck::HTML to JsDuck::Util::HTML.

parent 7c7a874c
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@ require 'rdiscount'
require 'jsduck/logger'
require 'jsduck/inline/img'
require 'jsduck/inline/video'
require 'jsduck/html'
require 'jsduck/util/html'

module JsDuck

@@ -274,7 +274,7 @@ module JsDuck
        when '%-'
          member ? "-" : ""
        when '%a'
          HTML.escape(anchor_text||"")
          Util::HTML.escape(anchor_text||"")
        else
          $1
        end
@@ -327,7 +327,7 @@ module JsDuck
    #   Blah blah blah some text.
    #
    def shorten(input)
      sent = first_sentence(HTML.strip_tags(input).strip)
      sent = first_sentence(Util::HTML.strip_tags(input).strip)
      # Use u-modifier to correctly count multi-byte characters
      chars = sent.scan(/./mu)
      if chars.length > @max_length
@@ -343,7 +343,7 @@ module JsDuck

    # Returns true when input should get shortened.
    def too_long?(input)
      stripped = HTML.strip_tags(input).strip
      stripped = Util::HTML.strip_tags(input).strip
      # for sentence v/s full - compare byte length
      # for full v/s max - compare char length
      first_sentence(stripped).length < stripped.length || stripped.scan(/./mu).length > @max_length
+2 −2
Original line number Diff line number Diff line
@@ -4,7 +4,7 @@ require 'jsduck/io'
require 'jsduck/null_object'
require 'jsduck/logger'
require 'jsduck/grouped_asset'
require 'jsduck/html'
require 'jsduck/util/html'
require 'fileutils'

module JsDuck
@@ -117,7 +117,7 @@ module JsDuck
      html.each_line do |line|
        if line =~ /^<h2>(.*)<\/h2>$/
          i += 1
          text = HTML.strip_tags($1)
          text = Util::HTML.strip_tags($1)
          toc << "<li><a href='#!/guide/#{guide['name']}-section-#{i}'>#{text}</a></li>\n"
          new_html << "<h2 id='#{guide['name']}-section-#{i}'>#{text}</h2>\n"
        else

lib/jsduck/html.rb

deleted100644 → 0
+0 −25
Original line number Diff line number Diff line
require 'cgi'

module JsDuck

  # Helpers for dealing with HTML
  class HTML

    # Strips tags from HTML text
    def self.strip_tags(html)
      html.gsub(/<.*?>/, "")
    end

    # Escapes HTML, replacing < with &lt; ...
    def self.escape(html)
      CGI.escapeHTML(html)
    end

    # Unescapes HTML, replacing &lt; with < ...
    def self.unescape(html)
      CGI.unescapeHTML(html)
    end

  end

end
+2 −2
Original line number Diff line number Diff line
require 'jsduck/html'
require 'jsduck/util/html'
require 'jsduck/logger'

module JsDuck
@@ -43,7 +43,7 @@ module JsDuck
          when '%u'
            @base_path ? (@base_path + "/" + url) : url
          when '%a'
            HTML.escape(alt_text||"")
            Util::HTML.escape(alt_text||"")
          else
            $1
          end
+2 −2
Original line number Diff line number Diff line
require 'jsduck/html'
require 'jsduck/util/html'
require 'jsduck/logger'

module JsDuck
@@ -48,7 +48,7 @@ module JsDuck
          when '%u'
            url
          when '%a'
            HTML.escape(alt_text||"")
            Util::HTML.escape(alt_text||"")
          else
            $1
          end
Loading