Use String#remove

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

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

@ -34,7 +34,7 @@ module Docs
end
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
def read_file(path)

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

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

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

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

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

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

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

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

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

@ -4,7 +4,7 @@ module Docs
def call
# Remove links inside <h2> and add "id" attributes
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
end
@ -26,7 +26,7 @@ module Docs
next unless node['name'] || node.content == '#'
parent = node.parent
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
node.remove
end

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

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

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

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

@ -19,9 +19,9 @@ module Docs
name
else
name = super
name.sub! 'Functions and function scope.', ''
name.sub! 'Operators.', ''
name.sub! 'Statements.', ''
name.remove! 'Functions and function scope.'
name.remove! 'Operators.'
name.remove! 'Statements.'
name
end
end
@ -34,7 +34,7 @@ module Docs
elsif slug.start_with? 'Functions_and_function_scope'
'Function'
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'
'Errors'
elsif INTL_OBJECTS.include?(object)

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

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

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

@ -6,7 +6,7 @@ module Docs
css('h2').each do |node|
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|
name = heading.content

@ -4,7 +4,7 @@ module Docs
def call
# Set id attributes on headings
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
css('> article', '.prose', 'h2 > a', 'h3 > a', 'pre > code').each do |node|

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

@ -54,8 +54,8 @@ module Docs
end
# Classes
if name.sub! 'Class: ', ''
name.sub! 'events.', '' # EventEmitter
if name.remove! 'Class: '
name.remove! 'events.' # EventEmitter
klass = name
entries << [name, node['id']]
next
@ -70,7 +70,7 @@ module Docs
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")
next unless (name.first.upcase! && !name.include?(' ')) || name.start_with?('Class Method')
@ -80,15 +80,15 @@ module Docs
# Differentiate socket classes (net, dgram, etc.)
name.sub!('socket.') { "#{klass.sub('.', '_').downcase!}." }
name.sub! 'Class Method:', ''
name.sub! 'buf.', 'buffer.'
name.sub! 'buf[', 'buffer['
name.sub! 'child.', 'childprocess.'
name.sub! 'decoder.', 'stringdecoder.'
name.sub! 'emitter.', 'eventemitter.'
name.sub! %r{\Arl\.}, 'interface.'
name.sub! 'rs.', 'readstream.'
name.sub! 'ws.', 'writestream.'
name.remove! 'Class Method:'
name.sub! 'buf.', 'buffer.'
name.sub! 'buf[', 'buffer['
name.sub! 'child.', 'childprocess.'
name.sub! 'decoder.', 'stringdecoder.'
name.sub! 'emitter.', 'eventemitter.'
name.sub! %r{\Arl\.}, 'interface.'
name.sub! 'rs.', 'readstream.'
name.sub! 'ws.', 'writestream.'
# Skip duplicates (listen, connect, etc.)
unless name == entries[-1].try(:first) || name == entries[-2].try(:first)

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

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

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

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

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

@ -44,7 +44,7 @@ module Docs
# Remove links to type classes (e.g. Number)
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

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

@ -3,7 +3,7 @@ module Docs
self.namespace = 'html_pipeline'
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

@ -17,7 +17,7 @@ class DocsCLI < Thor
Docs.all.
map { |doc| [doc.to_s.demodulize.underscore, doc] }.
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
desc 'page <doc> [path] [--verbose] [--debug]', 'Generate a page (no indexing)'

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

Loading…
Cancel
Save