Use String#sub instead of String#gsub when possible

pull/29/head
Thibaut 11 years ago
parent 8d5cb69aca
commit 864188e24c

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

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

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

@ -6,8 +6,6 @@ module Docs
xpath('./text()', './/text()[not(ancestor::pre) and not(ancestor::code)]').each do |node|
content = node.content
next unless content.valid_encoding?
content.gsub! %r{\A[[:space:]]+}, ' '
content.gsub! %r{[[:space:]]+\z}, ' '
content.gsub! %r{[[:space:]]+}, ' '
node.content = content
end

@ -2,7 +2,7 @@ module Docs
class Http
class EntriesFilter < Docs::EntriesFilter
def get_type
at_css('h1').content.gsub(/\A\s*HTTP\s+(.+)\s+Definitions\s*\z/, '\1').pluralize
at_css('h1').content.sub(/\A\s*HTTP\s+(.+)\s+Definitions\s*\z/, '\1').pluralize
end
def include_default_entry?

@ -33,7 +33,7 @@ module Docs
# Remove "- " before method names
css('.signature', 'span.overload').each do |node|
node.child.content = node.child.content.gsub(/\A\s*-\s*/, '')
node.child.content = node.child.content.sub(/\A\s*-\s*/, '')
end
# Remove links to type classes (e.g. Number)

@ -3,7 +3,7 @@ module Docs
self.namespace = 'html_pipeline'
def call_filter(event)
log "Filter: #{event.payload[:filter].gsub('Docs::', '').gsub('Filter', '')} [#{event.duration.round}ms]"
log "Filter: #{event.payload[:filter].sub('Docs::', '').sub('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.gsub %r{https?://}, ''}" }
each { |pair| puts "#{pair.first.rjust max_length + 1}: #{pair.second.base_url.sub %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.gsub(tmp_path, '') }
store.each { |path| paths << path.sub(tmp_path, '') }
paths
end

Loading…
Cancel
Save