Use String#remove

pull/90/head
Thibaut 11 years ago
parent a0b7959566
commit bcd4a5b522

@ -41,7 +41,7 @@ module Docs
end end
def slug def slug
@slug ||= subpath.sub(/\A\//, '').sub(/\.html\z/, '') @slug ||= subpath.sub(/\A\//, '').remove(/\.html\z/)
end end
def root_page? def root_page?

@ -34,7 +34,7 @@ module Docs
end end
def file_path_for(url) def file_path_for(url)
File.join self.class.dir, url.sub(base_url.to_s, '') File.join self.class.dir, url.remove(base_url.to_s)
end end
def read_file(path) def read_file(path)

@ -17,11 +17,11 @@ module Docs
end end
def format_url(url) def format_url(url)
url.to_s.sub %r{\Ahttps?://}, '' url.to_s.remove %r{\Ahttps?://}
end end
def format_path(path) def format_path(path)
path.to_s.sub File.join(File.expand_path('.'), ''), '' path.to_s.remove File.join(File.expand_path('.'), '')
end end
def justify(str) def justify(str)

@ -3,7 +3,7 @@ module Docs
class EntriesFilter < Docs::EntriesFilter class EntriesFilter < Docs::EntriesFilter
def get_name def get_name
name = slug.split(':').last name = slug.split(':').last
name.sub! %r{\Ang\.}, '' name.remove! %r{\Ang\.}
name << " (#{subtype})" if subtype == 'directive' || subtype == 'filter' name << " (#{subtype})" if subtype == 'directive' || subtype == 'filter'
name name
end end

@ -8,7 +8,7 @@ module Docs
css('[id]').each do |node| css('[id]').each do |node|
# Module # Module
if node.name == 'h2' if node.name == 'h2'
type = node.content.sub 'Backbone.', '' type = node.content.remove 'Backbone.'
if type.capitalize! # sync, history if type.capitalize! # sync, history
entries << [node.content, node['id'], type] entries << [node.content, node['id'], type]
end end

@ -35,7 +35,7 @@ module Docs
end end
css('area[href]').each do |node| css('area[href]').each do |node|
node['href'] = node['href'].sub('.html', '') node['href'] = node['href'].remove('.html')
end end
doc doc

@ -15,8 +15,8 @@ module Docs
def get_name def get_name
name = at_css('#firstHeading').content.strip name = at_css('#firstHeading').content.strip
name.sub! 'C keywords: ', '' name.remove! 'C keywords: '
name.sub! %r{\s\(.+\)}, '' name.remove! %r{\s\(.+\)}
name = name.split(',').first name = name.split(',').first
REPLACE_NAMES[name] || name REPLACE_NAMES[name] || name
end end
@ -24,8 +24,8 @@ module Docs
def get_type def get_type
if type = at_css('.t-navbar > div:nth-child(4) > :first-child').try(:content) if type = at_css('.t-navbar > div:nth-child(4) > :first-child').try(:content)
type.strip! type.strip!
type.sub! ' library', '' type.remove! ' library'
type.sub! ' utilities', '' type.remove! ' utilities'
type type
end end
end end

@ -4,7 +4,7 @@ module Docs
def call def call
html.strip! html.strip!
while html.gsub!(EMPTY_NODES_RGX, ''); end while html.remove!(EMPTY_NODES_RGX); end
html html
end end
end end

@ -21,7 +21,7 @@ module Docs
end end
def normalized_subpath def normalized_subpath
normalize_path subpath.sub(/\A\//, '') normalize_path subpath.remove(/\A\//)
end end
def normalize_href(href) def normalize_href(href)

@ -10,10 +10,10 @@ module Docs
def get_name def get_name
name = at_css('#firstHeading').content.strip name = at_css('#firstHeading').content.strip
name.sub! 'C++ concepts: ', '' name.remove! 'C++ concepts: '
name.sub! 'C++ keywords: ', '' name.remove! 'C++ keywords: '
name.sub! 'C++ ', '' name.remove! 'C++ '
name.sub! %r{\s\(.+\)}, '' name.remove! %r{\s\(.+\)}
name.sub! %r{\AStandard library header <(.+)>\z}, '\1' name.sub! %r{\AStandard library header <(.+)>\z}, '\1'
name = name.split(',').first name = name.split(',').first
REPLACE_NAMES[name] || name REPLACE_NAMES[name] || name
@ -24,9 +24,9 @@ module Docs
'Keywords' 'Keywords'
elsif type = at_css('.t-navbar > div:nth-child(4) > :first-child').try(:content) elsif type = at_css('.t-navbar > div:nth-child(4) > :first-child').try(:content)
type.strip! type.strip!
type.sub! ' library', '' type.remove! ' library'
type.sub! ' utilities', '' type.remove! ' utilities'
type.sub! 'C++ ', '' type.remove! 'C++ '
type.capitalize! type.capitalize!
type type
end end
@ -34,7 +34,7 @@ module Docs
def additional_entries def additional_entries
return [] unless include_default_entry? return [] unless include_default_entry?
names = at_css('#firstHeading').content.gsub(%r{\(.+?\)}, '').split(',')[1..-1] names = at_css('#firstHeading').content.remove(%r{\(.+?\)}).split(',')[1..-1]
names.each(&:strip!).reject! do |name| names.each(&:strip!).reject! do |name|
name.size <= 2 || name == '...' || name =~ /\A[<>]/ || name.start_with?('operator') name.size <= 2 || name == '...' || name =~ /\A[<>]/ || name.start_with?('operator')
end end

@ -60,7 +60,7 @@ module Docs
def get_name def get_name
case type case type
when 'Data Types' then "<#{super.gsub(' value', '')}>" when 'Data Types' then "<#{super.remove ' value'}>"
when 'Functions' then "#{super}()" when 'Functions' then "#{super}()"
else super else super
end end

@ -4,7 +4,7 @@ module Docs
def call def call
# Remove links inside <h2> and add "id" attributes # Remove links inside <h2> and add "id" attributes
css('h2 > a').each do |node| css('h2 > a').each do |node|
node.parent['id'] = node['name'].sub('wiki-', '') if node['name'] node.parent['id'] = node['name'].remove('wiki-') if node['name']
node.before(node.children).remove node.before(node.children).remove
end end
@ -26,7 +26,7 @@ module Docs
next unless node['name'] || node.content == '#' next unless node['name'] || node.content == '#'
parent = node.parent parent = node.parent
parent.name = 'h6' parent.name = 'h6'
parent['id'] = (node['name'] || node['href'].sub(/\A.+#/, '')).sub('wiki-', '') parent['id'] = (node['name'] || node['href'].remove(/\A.+#/)).remove('wiki-')
parent.css('a[name]').remove parent.css('a[name]').remove
node.remove node.remove
end end

@ -12,7 +12,7 @@ module Docs
def additional_entries def additional_entries
css('h6[id]').inject [] do |entries, node| css('h6[id]').inject [] do |entries, node|
name = node.content name = node.content
name.sub! %r{\(.*\z}, '' name.remove! %r{\(.*\z}
entries << [name, node['id']] unless name == entries.last.try(:first) entries << [name, node['id']] unless name == entries.last.try(:first)
entries entries
end end

@ -18,7 +18,7 @@ module Docs
end end
css('> h1').each do |node| css('> h1').each do |node|
node.content = node.content.sub(/\(\d\) Manual Page/, '') node.content = node.content.remove(/\(\d\) Manual Page/)
end end
unless at_css('> h2') unless at_css('> h2')

@ -18,7 +18,7 @@ module Docs
# Remove triangle character # Remove triangle character
css('h2', '.exampleHeading').each do |node| css('h2', '.exampleHeading').each do |node|
node.content = node.content.sub("\u25BE", '') node.content = node.content.remove("\u25BE")
node.name = 'h2' node.name = 'h2'
end end

@ -3,7 +3,7 @@ module Docs
class EntriesFilter < Docs::EntriesFilter class EntriesFilter < Docs::EntriesFilter
def get_name def get_name
name = at_css('h1').content name = at_css('h1').content
name.sub! 'Package ', '' name.remove! 'Package '
name name
end end

@ -19,9 +19,9 @@ module Docs
name name
else else
name = super name = super
name.sub! 'Functions and function scope.', '' name.remove! 'Functions and function scope.'
name.sub! 'Operators.', '' name.remove! 'Operators.'
name.sub! 'Statements.', '' name.remove! 'Statements.'
name name
end end
end end
@ -34,7 +34,7 @@ module Docs
elsif slug.start_with? 'Functions_and_function_scope' elsif slug.start_with? 'Functions_and_function_scope'
'Function' 'Function'
elsif slug.start_with? 'Global_Objects' elsif slug.start_with? 'Global_Objects'
object, method = *slug.sub('Global_Objects/', '').split('/') object, method = *slug.remove('Global_Objects/').split('/')
if object.end_with? 'Error' if object.end_with? 'Error'
'Errors' 'Errors'
elsif INTL_OBJECTS.include?(object) elsif INTL_OBJECTS.include?(object)

@ -6,7 +6,7 @@ module Docs
def get_name def get_name
name = at_css('h1').content.strip name = at_css('h1').content.strip
name.sub! ' Widget', '' name.remove! ' Widget'
name.prepend '.' if name.start_with? 'jqm' name.prepend '.' if name.start_with? 'jqm'
name << ' event' if type == 'Events' && !name.end_with?(' event') name << ' event' if type == 'Events' && !name.end_with?(' event')
name name

@ -6,7 +6,7 @@ module Docs
def get_name def get_name
name = at_css('h1').content.strip name = at_css('h1').content.strip
name.sub! ' Widget', '' name.remove! ' Widget'
name.gsub!(/ [A-Z]/) { |str| str.downcase! } name.gsub!(/ [A-Z]/) { |str| str.downcase! }
name name
end end

@ -15,7 +15,7 @@ module Docs
def get_name def get_name
return NAME_BY_SLUG[slug] if NAME_BY_SLUG.has_key?(slug) return NAME_BY_SLUG[slug] if NAME_BY_SLUG.has_key?(slug)
name = at_css('h1').content.strip name = at_css('h1').content.strip
name.sub! 'The ', '' name.remove! 'The '
name.sub! %r{"(.+?)"}, '\1' name.sub! %r{"(.+?)"}, '\1'
name.gsub!(/ [A-Z]/) { |str| str.downcase! } name.gsub!(/ [A-Z]/) { |str| str.downcase! }
name name

@ -6,7 +6,7 @@ module Docs
css('h2').each do |node| css('h2').each do |node|
type = node.content.split.first type = node.content.split.first
type.gsub! %r{\W}, '' # remove quotation marks type.remove! %r{\W} # remove quotation marks
node.parent.css('h3').each do |heading| node.parent.css('h3').each do |heading|
name = heading.content name = heading.content

@ -4,7 +4,7 @@ module Docs
def call def call
# Set id attributes on headings # Set id attributes on headings
css('a.target').each do |node| css('a.target').each do |node|
node.next_element['id'] = node['name'].sub(/\A\//, '').sub(/\/\z/, '').gsub('/', '-') node.next_element['id'] = node['name'].remove(/\A\//).remove(/\/\z/).gsub('/', '-')
end end
css('> article', '.prose', 'h2 > a', 'h3 > a', 'pre > code').each do |node| css('> article', '.prose', 'h2 > a', 'h3 > a', 'pre > code').each do |node|

@ -31,8 +31,8 @@ module Docs
name.prepend 'Language#' name.prepend 'Language#'
else else
name = node.content.strip name = node.content.strip
name.sub! %r{\s[\d\.]+\z}, '' # remove version number name.remove! %r{\s[\d\.]+\z} # remove version number
name.sub! %r{\s\(.+\)\z}, '' # remove parenthesis name.remove! %r{\s\(.+\)\z} # remove parenthesis
name.prepend 'Parse: ' if type == 'Parse' name.prepend 'Parse: ' if type == 'Parse'
end end

@ -54,8 +54,8 @@ module Docs
end end
# Classes # Classes
if name.sub! 'Class: ', '' if name.remove! 'Class: '
name.sub! 'events.', '' # EventEmitter name.remove! 'events.' # EventEmitter
klass = name klass = name
entries << [name, node['id']] entries << [name, node['id']]
next next
@ -70,7 +70,7 @@ module Docs
name.gsub! %r{\(.*?\)}, '()' name.gsub! %r{\(.*?\)}, '()'
name.gsub! %r{\[.+?\]}, '[]' name.gsub! %r{\[.+?\]}, '[]'
name.sub! 'assert(), ', '' # assert/assert.ok name.remove! 'assert(), ' # assert/assert.ok
# Skip all that start with an uppercase letter ("Example") or include a space ("exports alias") # Skip all that start with an uppercase letter ("Example") or include a space ("exports alias")
next unless (name.first.upcase! && !name.include?(' ')) || name.start_with?('Class Method') next unless (name.first.upcase! && !name.include?(' ')) || name.start_with?('Class Method')
@ -80,15 +80,15 @@ module Docs
# Differentiate socket classes (net, dgram, etc.) # Differentiate socket classes (net, dgram, etc.)
name.sub!('socket.') { "#{klass.sub('.', '_').downcase!}." } name.sub!('socket.') { "#{klass.sub('.', '_').downcase!}." }
name.sub! 'Class Method:', '' name.remove! 'Class Method:'
name.sub! 'buf.', 'buffer.' name.sub! 'buf.', 'buffer.'
name.sub! 'buf[', 'buffer[' name.sub! 'buf[', 'buffer['
name.sub! 'child.', 'childprocess.' name.sub! 'child.', 'childprocess.'
name.sub! 'decoder.', 'stringdecoder.' name.sub! 'decoder.', 'stringdecoder.'
name.sub! 'emitter.', 'eventemitter.' name.sub! 'emitter.', 'eventemitter.'
name.sub! %r{\Arl\.}, 'interface.' name.sub! %r{\Arl\.}, 'interface.'
name.sub! 'rs.', 'readstream.' name.sub! 'rs.', 'readstream.'
name.sub! 'ws.', 'writestream.' name.sub! 'ws.', 'writestream.'
# Skip duplicates (listen, connect, etc.) # Skip duplicates (listen, connect, etc.)
unless name == entries[-1].try(:first) || name == entries[-2].try(:first) unless name == entries[-1].try(:first) || name == entries[-2].try(:first)

@ -82,7 +82,7 @@ module Docs
def get_name def get_name
return 'IntlException' if slug == 'class.intlexception' return 'IntlException' if slug == 'class.intlexception'
name = css('> .sect1 > .title', 'h1', 'h2').first.content name = css('> .sect1 > .title', 'h1', 'h2').first.content
name.sub! 'The ', '' name.remove! 'The '
name.sub! ' class', ' (class)' name.sub! ' class', ' (class)'
name.sub! ' interface', ' (interface)' name.sub! ' interface', ' (interface)'
name name
@ -91,7 +91,7 @@ module Docs
def get_type def get_type
type = at_css('.up').content.strip type = at_css('.up').content.strip
type = 'SPL/Iterators' if type.end_with? 'Iterator' type = 'SPL/Iterators' if type.end_with? 'Iterator'
type.sub! ' Functions', '' type.remove! ' Functions'
TYPE_BY_NAME_STARTS_WITH.each_pair do |key, value| TYPE_BY_NAME_STARTS_WITH.each_pair do |key, value|
break type = value if name.start_with?(key) break type = value if name.start_with?(key)

@ -18,15 +18,15 @@ module Docs
if %w(Overview Introduction).include?(name) if %w(Overview Introduction).include?(name)
result[:pg_chapter_name] result[:pg_chapter_name]
else else
name.sub! ' (Common Table Expressions)', '' name.remove! ' (Common Table Expressions)'
REPLACE_NAMES[name] || name REPLACE_NAMES[name] || name
end end
end end
def clean_heading_name(name) def clean_heading_name(name)
name.sub! %r{\A[\d\.\s]+}, '' name.remove! %r{\A[\d\.\s]+}
name.sub! 'Using ', '' name.remove! 'Using '
name.sub! %r{\AThe }, '' name.remove! %r{\AThe }
name name
end end
@ -41,7 +41,7 @@ module Docs
if type.start_with?('Func') && (match = name.match(/\A(?!Form|Seq|Set|Enum)(.+) Func/)) if type.start_with?('Func') && (match = name.match(/\A(?!Form|Seq|Set|Enum)(.+) Func/))
"Functions: #{match[1]}" "Functions: #{match[1]}"
else else
type.sub 'SQL ', '' type.remove 'SQL '
end end
end end
end end
@ -104,10 +104,10 @@ module Docs
def get_custom_entries(selector) def get_custom_entries(selector)
css(selector).inject [] do |entries, node| css(selector).inject [] do |entries, node|
name = node.content name = node.content
name.gsub! %r{\(.*?\)}m, '' name.remove! %r{\(.*?\)}m
name.gsub! %r{\[.*?\]}m, '' name.remove! %r{\[.*?\]}m
name.squeeze! ' ' name.squeeze! ' '
name.sub! %r{\([^\)]*\z}, '' # bug fix: json_populate_record name.remove! %r{\([^\)]*\z} # bug fix: json_populate_record
name = '||' if name.include? ' || ' name = '||' if name.include? ' || '
id = name.gsub(/[^a-z0-9\-_]/) { |char| char.ord } id = name.gsub(/[^a-z0-9\-_]/) { |char| char.ord }
id = id.parameterize id = id.parameterize
@ -129,7 +129,7 @@ module Docs
end end
def additional_entry_prefix def additional_entry_prefix
type.dup.sub!('Functions: ', '') || self.name type.dup.remove!('Functions: ') || self.name
end end
def skip_additional_entries? def skip_additional_entries?

@ -38,7 +38,7 @@ module Docs
node.css('a').each do |link| node.css('a').each do |link|
link.before(link.children).remove link.before(link.children).remove
end end
node.child.content = node.child.content.sub @levelRegexp, '' node.child.content = node.child.content.remove @levelRegexp
end end
css('dt').each do |node| css('dt').each do |node|

@ -15,8 +15,8 @@ module Docs
def get_name def get_name
name = at_css('h1').content name = at_css('h1').content
name.sub! %r{\A[\d\.]+ }, '' # remove list number name.remove! %r{\A[\d\.]+ } # remove list number
name.sub! %r{ [\u{2013}\u{2014}].+\z}, '' # remove text after em/en dash name.remove! %r{ [\u{2013}\u{2014}].+\z} # remove text after em/en dash
name name
end end
@ -33,10 +33,10 @@ module Docs
type = 'Internet Data Handling' type = 'Internet Data Handling'
end end
type.sub! %r{\A\d+\.\s+}, '' # remove list number type.remove! %r{\A\d+\.\s+} # remove list number
type.sub! "\u{00b6}", '' # remove paragraph character type.remove! "\u{00b6}" # remove paragraph character
type.sub! ' and ', ' & ' type.sub! ' and ', ' & '
[' Services', ' Modules', ' Specific', 'Python '].each { |str| type.sub! str, '' } [' Services', ' Modules', ' Specific', 'Python '].each { |str| type.remove!(str) }
REPLACE_TYPES[type] || type REPLACE_TYPES[type] || type
end end
@ -74,7 +74,7 @@ module Docs
def clean_id_attributes def clean_id_attributes
css('.section > .target[id]').each do |node| css('.section > .target[id]').each do |node|
if dt = node.at_css('+ dl > dt') if dt = node.at_css('+ dl > dt')
dt['id'] ||= node['id'].sub(/\w+\-/, '') dt['id'] ||= node['id'].remove(/\w+\-/)
end end
node.remove node.remove
end end

@ -3,15 +3,15 @@ module Docs
class EntriesFilter < Docs::EntriesFilter class EntriesFilter < Docs::EntriesFilter
def get_name def get_name
name = at_css('h1').content.strip name = at_css('h1').content.strip
name.sub! 'class ', '' name.remove! 'class '
name.sub! 'module ', '' name.remove! 'module '
name name
end end
def get_type def get_type
type = name.dup type = name.dup
unless type.sub! %r{::.*\z}, '' unless type.remove! %r{::.*\z}
parent = at_css('.meta-parent').try(:content).to_s parent = at_css('.meta-parent').try(:content).to_s
return 'Errors' if type.end_with?('Error') || parent.end_with?('Error') || parent.end_with?('Exception') return 'Errors' if type.end_with?('Error') || parent.end_with?('Error') || parent.end_with?('Exception')
end end
@ -29,8 +29,8 @@ module Docs
css('.method-detail').inject [] do |entries, node| css('.method-detail').inject [] do |entries, node|
name = node['id'].dup name = node['id'].dup
name.sub! %r{\A\w+?\-.}, '' name.remove! %r{\A\w+?\-.}
name.sub! %r{\A-(?!\d)}, '' name.remove! %r{\A-(?!\d)}
name.gsub! '-', '%' name.gsub! '-', '%'
name = CGI.unescape(name) name = CGI.unescape(name)

@ -44,7 +44,7 @@ module Docs
# Remove links to type classes (e.g. Number) # Remove links to type classes (e.g. Number)
css('.type > code').each do |node| css('.type > code').each do |node|
node.before(node.content.sub('Sass::Script::Value::', '').sub('Sass::Script::', '')).remove node.before(node.content.remove('Sass::Script::Value::').remove('Sass::Script::')).remove
end end
end end
end end

@ -47,7 +47,7 @@ module Docs
next unless TYPES.include?(type) next unless TYPES.include?(type)
name = node.content.strip name = node.content.strip
name.sub! %r{\A.+?: }, '' name.remove! %r{\A.+?: }
next if SKIP_NAMES.include?(name) next if SKIP_NAMES.include?(name)

@ -3,7 +3,7 @@ module Docs
self.namespace = 'html_pipeline' self.namespace = 'html_pipeline'
def call_filter(event) def call_filter(event)
log "Filter: #{event.payload[:filter].sub('Docs::', '').sub('Filter', '')} [#{event.duration.round}ms]" log "Filter: #{event.payload[:filter].remove('Docs::').remove('Filter')} [#{event.duration.round}ms]"
end end
end end
end end

@ -17,7 +17,7 @@ class DocsCLI < Thor
Docs.all. Docs.all.
map { |doc| [doc.to_s.demodulize.underscore, doc] }. map { |doc| [doc.to_s.demodulize.underscore, doc] }.
each { |pair| max_length = pair.first.length if pair.first.length > max_length }. each { |pair| max_length = pair.first.length if pair.first.length > max_length }.
each { |pair| puts "#{pair.first.rjust max_length + 1}: #{pair.second.base_url.sub %r{\Ahttps?://}, ''}" } each { |pair| puts "#{pair.first.rjust max_length + 1}: #{pair.second.base_url.remove %r{\Ahttps?://}}" }
end end
desc 'page <doc> [path] [--verbose] [--debug]', 'Generate a page (no indexing)' desc 'page <doc> [path] [--verbose] [--debug]', 'Generate a page (no indexing)'

@ -124,7 +124,7 @@ class DocsFileStoreTest < MiniTest::Spec
describe "#each" do describe "#each" do
let :paths do let :paths do
paths = [] paths = []
store.each { |path| paths << path.sub(tmp_path, '') } store.each { |path| paths << path.remove(tmp_path) }
paths paths
end end

Loading…
Cancel
Save