aboutsummaryrefslogtreecommitdiffstats
path: root/guides/rails_guides.rb
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2017-02-12 10:21:20 +0100
committerXavier Noria <fxn@hashref.com>2017-02-12 10:33:50 +0100
commit771a802c374ebe7b2931ba6cf8ffa3b7bf0e92e0 (patch)
tree4b89b229a440a71ddcd394a5a14b91980918de5e /guides/rails_guides.rb
parent4fed08fa787a316fa51f14baca9eae11913f5050 (diff)
downloadrails-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.rb')
-rw-r--r--guides/rails_guides.rb36
1 files changed, 23 insertions, 13 deletions
diff --git a/guides/rails_guides.rb b/guides/rails_guides.rb
index 557d23f78c..0f611c8f2b 100644
--- a/guides/rails_guides.rb
+++ b/guides/rails_guides.rb
@@ -1,17 +1,27 @@
-pwd = File.dirname(__FILE__)
-$:.unshift pwd
+$:.unshift __dir__
-begin
- # Guides generation in the Rails repo.
- as_lib = File.join(pwd, "../activesupport/lib")
- ap_lib = File.join(pwd, "../actionpack/lib")
+as_lib = File.expand_path("../activesupport/lib", __dir__)
+ap_lib = File.expand_path("../actionpack/lib", __dir__)
+av_lib = File.expand_path("../actionview/lib", __dir__)
- $:.unshift as_lib if File.directory?(as_lib)
- $:.unshift ap_lib if File.directory?(ap_lib)
-rescue LoadError
- # Guides generation from gems.
- gem "actionpack", ">= 3.0"
-end
+$:.unshift as_lib if File.directory?(as_lib)
+$:.unshift ap_lib if File.directory?(ap_lib)
+$:.unshift av_lib if File.directory?(av_lib)
require "rails_guides/generator"
-RailsGuides::Generator.new.generate
+require "active_support/core_ext/object/blank"
+
+env_value = ->(name) { ENV[name].presence }
+env_flag = ->(name) { "1" == env_value[name] }
+
+version = env_value["RAILS_VERSION"]
+edge = `git rev-parse HEAD`.strip unless version
+
+RailsGuides::Generator.new(
+ edge: edge,
+ version: version,
+ all: env_flag["ALL"],
+ only: env_value["ONLY"],
+ kindle: env_flag["KINDLE"],
+ language: env_value["GUIDES_LANGUAGE"]
+).generate