1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Remove Indexer class from Rails Guide generator

This commit removes the orphaned Indexer class from the Rails Guide
generator. The indexer was removed in 2012 during the move from Textile
to Markdown in commit 5e2866cc34.
This commit is contained in:
Lukas_Skywalker 2020-05-13 22:16:22 +02:00
parent 67feba0c82
commit 0589fe4c3a
2 changed files with 0 additions and 70 deletions

View file

@ -9,7 +9,6 @@ require "action_controller"
require "action_view"
require "rails_guides/markdown"
require "rails_guides/indexer"
require "rails_guides/helpers"
require "rails_guides/levenshtein"

View file

@ -1,69 +0,0 @@
# frozen_string_literal: true
require "active_support/core_ext/object/blank"
require "active_support/core_ext/string/inflections"
module RailsGuides
class Indexer
attr_reader :body, :result, :warnings, :level_hash
def initialize(body, warnings)
@body = body
@result = @body.dup
@warnings = warnings
end
def index
@level_hash = process(body)
end
private
def process(string, current_level = 3, counters = [1])
s = StringScanner.new(string)
level_hash = {}
while !s.eos?
re = %r{^h(\d)(?:\((#.*?)\))?\s*\.\s*(.*)$}
s.match?(re)
if matched = s.matched
matched =~ re
level, idx, title = $1.to_i, $2, $3.strip
if level < current_level
# This is needed. Go figure.
return level_hash
elsif level == current_level
index = counters.join(".")
idx ||= "#" + title_to_idx(title)
raise "Parsing Fail" unless @result.sub!(matched, "h#{level}(#{idx}). #{index} #{title}")
key = {
title: title,
id: idx
}
# Recurse
counters << 1
level_hash[key] = process(s.post_match, current_level + 1, counters)
counters.pop
# Increment the current level
last = counters.pop
counters << last + 1
end
end
s.getch
end
level_hash
end
def title_to_idx(title)
idx = title.strip.parameterize.sub(/^\d+/, "")
if warnings && idx.blank?
puts "BLANK ID: please put an explicit ID for section #{title}, as in h5(#my-id)"
end
idx
end
end
end