From 5e2866cc3445646d8df049413aa5fbf03fa605ef Mon Sep 17 00:00:00 2001 From: Prem Sichanugrist Date: Fri, 7 Sep 2012 00:09:56 -0400 Subject: [PATCH] No more Textile guide generation support --- Gemfile | 1 - guides/Rakefile | 2 +- guides/rails_guides.rb | 10 +-- guides/rails_guides/generator.rb | 75 ++----------------- guides/rails_guides/textile_extensions.rb | 67 ----------------- guides/source/form_helpers.md | 2 +- .../source/ruby_on_rails_guides_guidelines.md | 4 +- 7 files changed, 14 insertions(+), 147 deletions(-) delete mode 100644 guides/rails_guides/textile_extensions.rb diff --git a/Gemfile b/Gemfile index 3df8a70aa3..f0c06a19e2 100644 --- a/Gemfile +++ b/Gemfile @@ -35,7 +35,6 @@ group :doc do # for some weeks unapplied. As a temporary solution # this is our own fork with the fix. gem 'sdoc', github: 'fxn/sdoc' - gem 'RedCloth', '~> 4.2' gem 'redcarpet', '~> 2.1.1' gem 'w3c_validators' end diff --git a/guides/Rakefile b/guides/Rakefile index be46bbae79..7881a3d9b3 100644 --- a/guides/Rakefile +++ b/guides/Rakefile @@ -1,6 +1,6 @@ namespace :guides do - desc 'Generate guides (for authors), use ONLY=foo to process just "foo.textile"' + desc 'Generate guides (for authors), use ONLY=foo to process just "foo.md"' task :generate => 'generate:html' namespace :generate do diff --git a/guides/rails_guides.rb b/guides/rails_guides.rb index d3ae019a8c..ab890f202c 100644 --- a/guides/rails_guides.rb +++ b/guides/rails_guides.rb @@ -21,14 +21,14 @@ rescue LoadError end begin - require 'redcloth' + require 'redcarpet' rescue Gem::LoadError # This can happen if doc:guides is executed in an application. - $stderr.puts('Generating guides requires RedCloth 4.1.1+.') + $stderr.puts('Generating guides requires Redcarpet 2.1.1+.') $stderr.puts(< 4.2' + gem 'redcarpet', '~> 2.1.1' to the Gemfile, run @@ -40,9 +40,5 @@ ERROR end require 'rails_guides/markdown' - -require "rails_guides/textile_extensions" -RedCloth.send(:include, RailsGuides::TextileExtensions) - require "rails_guides/generator" RailsGuides::Generator.new.generate 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 -
-

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 << '
' - index << '
' - - 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(/

#{$2.strip}

) - end - end - - def plusplus(body) - body.gsub!(/\+(.*?)\+/) do |m| - "#{$1}" - end - - # The real plus sign - body.gsub!('', '+') - end - - def brush_for(code_type) - case code_type - when 'ruby', 'sql', 'plain' - code_type - when 'erb' - 'ruby; html-script: true' - when 'html' - 'xml' # html is understood, but there are .xml rules in the CSS - else - 'plain' - end - end - - def code(body) - body.gsub!(%r{<(yaml|shell|ruby|erb|html|sql|plain)>(.*?)}m) do |m| - < -
-
-#{ERB::Util.h($2).strip}
-
-
- -HTML - end - end - end -end diff --git a/guides/source/form_helpers.md b/guides/source/form_helpers.md index e8e8a97791..ec1f1d4df1 100644 --- a/guides/source/form_helpers.md +++ b/guides/source/form_helpers.md @@ -201,7 +201,7 @@ Dealing with Model Objects ### Model Object Helpers -A particularly common task for a form is editing or creating a model object. While the `*_tag` helpers can certainly be used for this task they are somewhat verbose as for each tag you would have to ensure the correct parameter name is used and set the default value of the input appropriately. Rails provides helpers tailored to this task. These helpers lack the _tag suffix, for example `text_field`, `text_area`. +A particularly common task for a form is editing or creating a model object. While the `*_tag` helpers can certainly be used for this task they are somewhat verbose as for each tag you would have to ensure the correct parameter name is used and set the default value of the input appropriately. Rails provides helpers tailored to this task. These helpers lack the _tag suffix, for example `text_field`, `text_area`. For these helpers the first argument is the name of an instance variable and the second is the name of a method (usually an attribute) to call on that object. Rails will set the value of the input control to the return value of that method for the object and set an appropriate input name. If your controller has defined `@person` and that person's name is Henry then a form containing: diff --git a/guides/source/ruby_on_rails_guides_guidelines.md b/guides/source/ruby_on_rails_guides_guidelines.md index 0b070bf500..e589a3d093 100644 --- a/guides/source/ruby_on_rails_guides_guidelines.md +++ b/guides/source/ruby_on_rails_guides_guidelines.md @@ -74,10 +74,10 @@ bundle exec rake guides:generate:html (You may need to run `bundle install` first to install the required gems.) -To process `my_guide.textile` and nothing else use the `ONLY` environment variable: +To process `my_guide.md` and nothing else use the `ONLY` environment variable: ``` -touch my_guide.textile +touch my_guide.md bundle exec rake guides:generate ONLY=my_guide ```