aboutsummaryrefslogtreecommitdiffstats
path: root/guides/rails_guides/generator.rb
diff options
context:
space:
mode:
Diffstat (limited to 'guides/rails_guides/generator.rb')
-rw-r--r--guides/rails_guides/generator.rb75
1 files changed, 7 insertions, 68 deletions
diff --git a/guides/rails_guides/generator.rb b/guides/rails_guides/generator.rb
index f7c0ee3bd7..eda9fd03a6 100644
--- a/guides/rails_guides/generator.rb
+++ b/guides/rails_guides/generator.rb
@@ -15,7 +15,7 @@
#
# Internal links (anchors) are checked. If a reference is broken levenshtein
# distance is used to suggest an existing one. This is useful since IDs are
-# generated by Textile from headers and thus edits alter them.
+# generated by Markdown from headers and thus edits alter them.
#
# Also detects duplicated IDs. They happen if there are headers with the same
# text. Please do resolve them, if any, so guides are valid XHTML.
@@ -65,7 +65,7 @@ module RailsGuides
class Generator
attr_reader :guides_dir, :source_dir, :output_dir, :edge, :warnings, :all
- GUIDES_RE = /\.(?:textile|erb|md|markdown)$/
+ GUIDES_RE = /\.(?:erb|md|markdown)$/
def initialize(output=nil)
set_flags_from_environment
@@ -172,8 +172,8 @@ module RailsGuides
end
def output_file_for(guide)
- if guide =~ /\.(textile|markdown|md)$/
- guide.sub(/\.(textile|markdown|md)$/, '.html')
+ if guide =~ /\.(markdown|md)$/
+ guide.sub(/\.(markdown|md)$/, '.html')
else
guide.sub(/\.erb$/, '')
end
@@ -202,17 +202,9 @@ module RailsGuides
# Generate the special pages like the home.
# Passing a template handler in the template name is deprecated. So pass the file name without the extension.
result = view.render(:layout => layout, :formats => [$1], :file => $`)
- elsif guide =~ /\.(md|markdown)$/
- body = File.read(File.join(source_dir, guide))
- result = RailsGuides::Markdown.new(view, layout).render(body)
-
- warn_about_broken_links(result) if @warnings
else
body = File.read(File.join(source_dir, guide))
- body = set_header_section(body, view)
- body = set_index(body, view)
-
- result = view.render(:layout => layout, :text => textile(body))
+ result = RailsGuides::Markdown.new(view, layout).render(body)
warn_about_broken_links(result) if @warnings
end
@@ -221,70 +213,17 @@ module RailsGuides
end
end
- def set_header_section(body, view)
- new_body = body.gsub(/(.*?)endprologue\./m, '').strip
- header = $1
-
- header =~ /h2\.(.*)/
- page_title = "Ruby on Rails Guides: #{$1.strip}"
-
- header = textile(header)
-
- view.content_for(:page_title) { page_title.html_safe }
- view.content_for(:header_section) { header.html_safe }
- new_body
- end
-
- def set_index(body, view)
- index = <<-INDEX
- <div id="subCol">
- <h3 class="chapter"><img src="images/chapters_icon.gif" alt="" />Chapters</h3>
- <ol class="chapters">
- INDEX
-
- i = Indexer.new(body, warnings)
- i.index
-
- # Set index for 2 levels
- i.level_hash.each do |key, value|
- link = view.content_tag(:a, :href => key[:id]) { textile(key[:title], true).html_safe }
-
- children = value.keys.map do |k|
- view.content_tag(:li,
- view.content_tag(:a, :href => k[:id]) { textile(k[:title], true).html_safe })
- end
-
- children_ul = children.empty? ? "" : view.content_tag(:ul, children.join(" ").html_safe)
-
- index << view.content_tag(:li, link.html_safe + children_ul.html_safe)
- end
-
- index << '</ol>'
- index << '</div>'
-
- view.content_for(:index_section) { index.html_safe }
-
- i.result
- end
-
- def textile(body, lite_mode=false)
- t = RedCloth.new(body)
- t.hard_breaks = false
- t.lite_mode = lite_mode
- t.to_html(:notestuff, :plusplus, :code)
- end
-
def warn_about_broken_links(html)
anchors = extract_anchors(html)
check_fragment_identifiers(html, anchors)
end
def extract_anchors(html)
- # Textile generates headers with IDs computed from titles.
+ # Markdown generates headers with IDs computed from titles.
anchors = Set.new
html.scan(/<h\d\s+id="([^"]+)/).flatten.each do |anchor|
if anchors.member?(anchor)
- puts "*** DUPLICATE ID: #{anchor}, please use an explicit ID, e.g. h4(#explicit-id), or consider rewording"
+ puts "*** DUPLICATE ID: #{anchor}, please make sure that there're no headings with the same name at the same level."
else
anchors << anchor
end