diff options
author | Xavier Noria <fxn@hashref.com> | 2017-02-12 10:21:20 +0100 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2017-02-12 10:33:50 +0100 |
commit | 771a802c374ebe7b2931ba6cf8ffa3b7bf0e92e0 (patch) | |
tree | 4b89b229a440a71ddcd394a5a14b91980918de5e /guides/rails_guides/markdown | |
parent | 4fed08fa787a316fa51f14baca9eae11913f5050 (diff) | |
download | rails-771a802c374ebe7b2931ba6cf8ffa3b7bf0e92e0.tar.gz rails-771a802c374ebe7b2931ba6cf8ffa3b7bf0e92e0.tar.bz2 rails-771a802c374ebe7b2931ba6cf8ffa3b7bf0e92e0.zip |
refactors and fixes in guides generation [ci skip]
This commit is not precisely atomic, but the changes have evolved, summary:
* The ENV-based interface has been moved upwards, the generator has now a conventional
initializer.
* RAILS_VERSION is now assumed to be a Git tag. A blank RAILS_VERSION means edge guides.
* In consequence, the EDGE env variable is gone.
* The "local" version is also gone, the current SHA1 is computed for edge guides.
* Assumes guides are generated from a repo checkout (time ago users could
generate them from gems.)
* The WARNINGS flag is gone in consequence, you cannot disable warnings.
* The `api_link` Markdown helper is fixed.
* Docs about usage have one single place: rake guides:help.
* Links in guides have been revised.
Diffstat (limited to 'guides/rails_guides/markdown')
-rw-r--r-- | guides/rails_guides/markdown/renderer.rb | 40 |
1 files changed, 18 insertions, 22 deletions
diff --git a/guides/rails_guides/markdown/renderer.rb b/guides/rails_guides/markdown/renderer.rb index 8723ee0b4e..20cbd568c9 100644 --- a/guides/rails_guides/markdown/renderer.rb +++ b/guides/rails_guides/markdown/renderer.rb @@ -1,9 +1,7 @@ module RailsGuides class Markdown class Renderer < Redcarpet::Render::HTML - def initialize(options = {}) - super - end + cattr_accessor :edge, :version def block_code(code, language) <<-HTML @@ -93,32 +91,30 @@ HTML end def github_file_url(file_path) - root, rest = file_path.split("/", 2) + tree = version || edge - case root - when "abstract_controller", "action_controller", "action_dispatch" - path = ["actionpack", "lib", root, rest].join("/") - when "active_support", "active_record", "active_model", "action_view", - "action_cable", "action_mailer", "action_pack", "active_job" - path = [root.sub("_", ""), "lib", root, rest].join("/") - else - path = file_path - end + root = file_path[%r{(.+)/}, 1] + path = case root + when "abstract_controller", "action_controller", "action_dispatch" + "actionpack/lib/#{file_path}" + when /\A(action|active)_/ + "#{root.sub("_", "")}/lib/#{file_path}" + else + file_path + end - ["https://github.com/rails/rails/tree", version || "master", path].join("/") - end - def version - ENV["RAILS_VERSION"] + "https://github.com/rails/rails/tree/#{tree}/#{path}" end def api_link(url) - if version && !url.match(/v\d\.\d\.\d/) - url.insert(url.index(".org") + 4, "/#{version}") - url.sub("http://edgeapi", "http://api") if url.include?("edgeapi") + if url =~ %r{http://api\.rubyonrails\.org/v\d+\.} + url + elsif edge + url.sub("api", "edgeapi") + else + url.sub(/(?<=\.org)/, "/#{version}") end - - url end end end |