Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge docrails along with the new guides and guides generation code

  • Loading branch information...
commit 96d610553e5fdaabc923835ab1f194070ddb4477 1 parent bccd2c5
@lifo lifo authored
Showing with 18,543 additions and 9 deletions.
  1. +1 −0  .gitignore
  2. +16 −0 activerecord/lib/active_record/associations.rb
  3. +5 −0 railties/Rakefile
  4. +188 −0 railties/guides/files/javascripts/code_highlighter.js
  5. +8 −0 railties/guides/files/javascripts/guides.js
  6. +90 −0 railties/guides/files/javascripts/highlighters.js
  7. +436 −0 railties/guides/files/stylesheets/main.css
  8. +52 −0 railties/guides/files/stylesheets/print.css
  9. +43 −0 railties/guides/files/stylesheets/reset.css
  10. +13 −0 railties/guides/files/stylesheets/style.css
  11. +31 −0 railties/guides/files/stylesheets/syntax.css
  12. BIN  railties/guides/images/belongs_to.png
  13. BIN  railties/guides/images/book_icon.gif
  14. BIN  railties/guides/images/bullet.gif
  15. BIN  railties/guides/images/chapters_icon.gif
  16. BIN  railties/guides/images/check_bullet.gif
  17. BIN  railties/guides/images/credits_pic_blank.gif
  18. BIN  railties/guides/images/csrf.png
  19. BIN  railties/guides/images/customized_error_messages.png
  20. BIN  railties/guides/images/error_messages.png
  21. BIN  railties/guides/images/feature_tile.gif
  22. BIN  railties/guides/images/footer_tile.gif
  23. BIN  railties/guides/images/grey_bullet.gif
  24. BIN  railties/guides/images/habtm.png
  25. BIN  railties/guides/images/has_many.png
  26. BIN  railties/guides/images/has_many_through.png
  27. BIN  railties/guides/images/has_one.png
  28. BIN  railties/guides/images/has_one_through.png
  29. BIN  railties/guides/images/header_backdrop.png
  30. BIN  railties/guides/images/header_tile.gif
  31. BIN  railties/guides/images/i18n/demo_localized_pirate.png
  32. BIN  railties/guides/images/i18n/demo_translated_en.png
  33. BIN  railties/guides/images/i18n/demo_translated_pirate.png
  34. BIN  railties/guides/images/i18n/demo_translation_missing.png
  35. BIN  railties/guides/images/i18n/demo_untranslated.png
  36. +5 −0 railties/guides/images/icons/README
  37. BIN  railties/guides/images/icons/callouts/1.png
  38. BIN  railties/guides/images/icons/callouts/10.png
  39. BIN  railties/guides/images/icons/callouts/11.png
  40. BIN  railties/guides/images/icons/callouts/12.png
  41. BIN  railties/guides/images/icons/callouts/13.png
  42. BIN  railties/guides/images/icons/callouts/14.png
  43. BIN  railties/guides/images/icons/callouts/15.png
  44. BIN  railties/guides/images/icons/callouts/2.png
  45. BIN  railties/guides/images/icons/callouts/3.png
  46. BIN  railties/guides/images/icons/callouts/4.png
  47. BIN  railties/guides/images/icons/callouts/5.png
  48. BIN  railties/guides/images/icons/callouts/6.png
  49. BIN  railties/guides/images/icons/callouts/7.png
  50. BIN  railties/guides/images/icons/callouts/8.png
  51. BIN  railties/guides/images/icons/callouts/9.png
  52. BIN  railties/guides/images/icons/caution.png
  53. BIN  railties/guides/images/icons/example.png
  54. BIN  railties/guides/images/icons/home.png
  55. BIN  railties/guides/images/icons/important.png
  56. BIN  railties/guides/images/icons/next.png
  57. BIN  railties/guides/images/icons/note.png
  58. BIN  railties/guides/images/icons/prev.png
  59. BIN  railties/guides/images/icons/tip.png
  60. BIN  railties/guides/images/icons/up.png
  61. BIN  railties/guides/images/icons/warning.png
  62. BIN  railties/guides/images/nav_arrow.gif
  63. BIN  railties/guides/images/polymorphic.png
  64. BIN  railties/guides/images/posts_index.png
  65. BIN  railties/guides/images/rails_logo_remix.gif
  66. BIN  railties/guides/images/rails_welcome.png
  67. BIN  railties/guides/images/ruby_guides_logo.gif
  68. BIN  railties/guides/images/ruby_on_rails_by_mike_rundle2.gif
  69. BIN  railties/guides/images/session_fixation.png
  70. BIN  railties/guides/images/tab_grey.gif
  71. BIN  railties/guides/images/tab_info.gif
  72. BIN  railties/guides/images/tab_note.gif
  73. BIN  railties/guides/images/tab_red.gif
  74. BIN  railties/guides/images/tab_yellow.gif
  75. BIN  railties/guides/images/tab_yellow.png
  76. BIN  railties/guides/images/validation_error_messages.png
  77. +30 −0 railties/guides/rails_guides.rb
  78. +112 −0 railties/guides/rails_guides/generator.rb
  79. +34 −0 railties/guides/rails_guides/helpers.rb
  80. +51 −0 railties/guides/rails_guides/indexer.rb
  81. +38 −0 railties/guides/rails_guides/textile_extensions.rb
  82. +422 −0 railties/guides/source/2_2_release_notes.textile
  83. +501 −0 railties/guides/source/2_3_release_notes.textile
  84. +798 −0 railties/guides/source/action_controller_overview.textile
  85. +423 −0 railties/guides/source/action_mailer_basics.textile
  86. +135 −0 railties/guides/source/active_record_basics.textile
  87. +704 −0 railties/guides/source/active_record_querying.textile
  88. +921 −0 railties/guides/source/activerecord_validations_callbacks.textile
  89. +1,782 −0 railties/guides/source/association_basics.textile
  90. +429 −0 railties/guides/source/caching_with_rails.textile
  91. +511 −0 railties/guides/source/command_line.textile
  92. +234 −0 railties/guides/source/configuring.textile
  93. +38 −0 railties/guides/source/credits.erb.textile
  94. +709 −0 railties/guides/source/debugging_rails_applications.textile
  95. +770 −0 railties/guides/source/form_helpers.textile
  96. +1,297 −0 railties/guides/source/getting_started.textile
  97. +884 −0 railties/guides/source/i18n.textile
  98. +112 −0 railties/guides/source/index.erb.textile
  99. +99 −0 railties/guides/source/layout.html.erb
  100. +957 −0 railties/guides/source/layouts_and_rendering.textile
  101. +580 −0 railties/guides/source/migrations.textile
  102. +531 −0 railties/guides/source/performance_testing.textile
  103. +1,506 −0 railties/guides/source/plugins.textile
  104. +226 −0 railties/guides/source/rails_on_rack.textile
  105. +904 −0 railties/guides/source/routing.textile
  106. +964 −0 railties/guides/source/security.textile
  107. +951 −0 railties/guides/source/testing.textile
  108. +2 −9 railties/lib/tasks/documentation.rake
View
1  .gitignore
@@ -14,6 +14,7 @@ railties/pkg
railties/test/500.html
railties/doc/guides/html/images
railties/doc/guides/html/stylesheets
+railties/guides/output
*.rbc
*.swp
*.swo
View
16 activerecord/lib/active_record/associations.rb
@@ -1090,6 +1090,22 @@ def belongs_to(association_id, options = {})
# but it in fact generates a join table name of "paper_boxes_papers". Be aware of this caveat, and use the
# custom <tt>:join_table</tt> option if you need to.
#
+ # The join table should not have a primary key or a model associated with it. You must manually generate the
+ # join table with a migration such as this:
+ #
+ # class CreateDevelopersProjectsJoinTable < ActiveRecord::Migration
+ # def self.up
+ # create_table :developers_projects, :id => false do |t|
+ # t.integer :developer_id
+ # t.integer :project_id
+ # end
+ # end
+ #
+ # def self.down
+ # drop_table :developers_projects
+ # end
+ # end
+ #
# Deprecated: Any additional fields added to the join table will be placed as attributes when pulling records out through
# +has_and_belongs_to_many+ associations. Records returned from join tables with additional attributes will be marked as
# readonly (because we can't save changes to the additional attributes). It's strongly recommended that you upgrade any
View
5 railties/Rakefile
@@ -244,6 +244,11 @@ def copy_with_rewritten_ruby_path(src_file, dest_file)
end
end
+desc 'Generate guides (for authors), use ONLY=foo to process just "foo.textile"'
+task :guides do
+ ruby "guides/rails_guides.rb"
+end
+
# Generate documentation ------------------------------------------------------------------
View
188 railties/guides/files/javascripts/code_highlighter.js
@@ -0,0 +1,188 @@
+/* Unobtrustive Code Highlighter By Dan Webb 11/2005
+ Version: 0.4
+
+ Usage:
+ Add a script tag for this script and any stylesets you need to use
+ to the page in question, add correct class names to CODE elements,
+ define CSS styles for elements. That's it!
+
+ Known to work on:
+ IE 5.5+ PC
+ Firefox/Mozilla PC/Mac
+ Opera 7.23 + PC
+ Safari 2
+
+ Known to degrade gracefully on:
+ IE5.0 PC
+
+ Note: IE5.0 fails due to the use of lookahead in some stylesets. To avoid script errors
+ in older browsers use expressions that use lookahead in string format when defining stylesets.
+
+ This script is inspired by star-light by entirely cunning Dean Edwards
+ http://dean.edwards.name/star-light/.
+*/
+
+// replace callback support for safari.
+if ("a".replace(/a/, function() {return "b"}) != "b") (function(){
+ var default_replace = String.prototype.replace;
+ String.prototype.replace = function(search,replace){
+ // replace is not function
+ if(typeof replace != "function"){
+ return default_replace.apply(this,arguments)
+ }
+ var str = "" + this;
+ var callback = replace;
+ // search string is not RegExp
+ if(!(search instanceof RegExp)){
+ var idx = str.indexOf(search);
+ return (
+ idx == -1 ? str :
+ default_replace.apply(str,[search,callback(search, idx, str)])
+ )
+ }
+ var reg = search;
+ var result = [];
+ var lastidx = reg.lastIndex;
+ var re;
+ while((re = reg.exec(str)) != null){
+ var idx = re.index;
+ var args = re.concat(idx, str);
+ result.push(
+ str.slice(lastidx,idx),
+ callback.apply(null,args).toString()
+ );
+ if(!reg.global){
+ lastidx += RegExp.lastMatch.length;
+ break
+ }else{
+ lastidx = reg.lastIndex;
+ }
+ }
+ result.push(str.slice(lastidx));
+ return result.join("")
+ }
+})();
+
+var CodeHighlighter = { styleSets : new Array };
+
+CodeHighlighter.addStyle = function(name, rules) {
+ // using push test to disallow older browsers from adding styleSets
+ if ([].push) this.styleSets.push({
+ name : name,
+ rules : rules,
+ ignoreCase : arguments[2] || false
+ })
+
+ function setEvent() {
+ // set highlighter to run on load (use LowPro if present)
+ if (typeof Event != 'undefined' && typeof Event.onReady == 'function')
+ return Event.onReady(CodeHighlighter.init.bind(CodeHighlighter));
+
+ var old = window.onload;
+
+ if (typeof window.onload != 'function') {
+ window.onload = function() { CodeHighlighter.init() };
+ } else {
+ window.onload = function() {
+ old();
+ CodeHighlighter.init();
+ }
+ }
+ }
+
+ // only set the event when the first style is added
+ if (this.styleSets.length==1) setEvent();
+}
+
+CodeHighlighter.init = function() {
+ if (!document.getElementsByTagName) return;
+ if ("a".replace(/a/, function() {return "b"}) != "b") return; // throw out Safari versions that don't support replace function
+ // throw out older browsers
+
+ var codeEls = document.getElementsByTagName("CODE");
+ // collect array of all pre elements
+ codeEls.filter = function(f) {
+ var a = new Array;
+ for (var i = 0; i < this.length; i++) if (f(this[i])) a[a.length] = this[i];
+ return a;
+ }
+
+ var rules = new Array;
+ rules.toString = function() {
+ // joins regexes into one big parallel regex
+ var exps = new Array;
+ for (var i = 0; i < this.length; i++) exps.push(this[i].exp);
+ return exps.join("|");
+ }
+
+ function addRule(className, rule) {
+ // add a replace rule
+ var exp = (typeof rule.exp != "string")?String(rule.exp).substr(1, String(rule.exp).length-2):rule.exp;
+ // converts regex rules to strings and chops of the slashes
+ rules.push({
+ className : className,
+ exp : "(" + exp + ")",
+ length : (exp.match(/(^|[^\\])\([^?]/g) || "").length + 1, // number of subexps in rule
+ replacement : rule.replacement || null
+ });
+ }
+
+ function parse(text, ignoreCase) {
+ // main text parsing and replacement
+ return text.replace(new RegExp(rules, (ignoreCase)?"gi":"g"), function() {
+ var i = 0, j = 1, rule;
+ while (rule = rules[i++]) {
+ if (arguments[j]) {
+ // if no custom replacement defined do the simple replacement
+ if (!rule.replacement) return "<span class=\"" + rule.className + "\">" + arguments[0] + "</span>";
+ else {
+ // replace $0 with the className then do normal replaces
+ var str = rule.replacement.replace("$0", rule.className);
+ for (var k = 1; k <= rule.length - 1; k++) str = str.replace("$" + k, arguments[j + k]);
+ return str;
+ }
+ } else j+= rule.length;
+ }
+ });
+ }
+
+ function highlightCode(styleSet) {
+ // clear rules array
+ var parsed, clsRx = new RegExp("(\\s|^)" + styleSet.name + "(\\s|$)");
+ rules.length = 0;
+
+ // get stylable elements by filtering out all code elements without the correct className
+ var stylableEls = codeEls.filter(function(item) { return clsRx.test(item.className) });
+
+ // add style rules to parser
+ for (var className in styleSet.rules) addRule(className, styleSet.rules[className]);
+
+
+ // replace for all elements
+ for (var i = 0; i < stylableEls.length; i++) {
+ // EVIL hack to fix IE whitespace badness if it's inside a <pre>
+ if (/MSIE/.test(navigator.appVersion) && stylableEls[i].parentNode.nodeName == 'PRE') {
+ stylableEls[i] = stylableEls[i].parentNode;
+
+ parsed = stylableEls[i].innerHTML.replace(/(<code[^>]*>)([^<]*)<\/code>/i, function() {
+ return arguments[1] + parse(arguments[2], styleSet.ignoreCase) + "</code>"
+ });
+ parsed = parsed.replace(/\n( *)/g, function() {
+ var spaces = "";
+ for (var i = 0; i < arguments[1].length; i++) spaces+= "&nbsp;";
+ return "\n" + spaces;
+ });
+ parsed = parsed.replace(/\t/g, "&nbsp;&nbsp;&nbsp;&nbsp;");
+ parsed = parsed.replace(/\n(<\/\w+>)?/g, "<br />$1").replace(/<br \/>[\n\r\s]*<br \/>/g, "<p><br></p>");
+
+ } else parsed = parse(stylableEls[i].innerHTML, styleSet.ignoreCase);
+
+ stylableEls[i].innerHTML = parsed;
+ }
+ }
+
+ // run highlighter on all stylesets
+ for (var i=0; i < this.styleSets.length; i++) {
+ highlightCode(this.styleSets[i]);
+ }
+}
View
8 railties/guides/files/javascripts/guides.js
@@ -0,0 +1,8 @@
+function guideMenu(){
+
+ if (document.getElementById('guides').style.display == "none") {
+ document.getElementById('guides').style.display = "block";
+ } else {
+ document.getElementById('guides').style.display = "none";
+ }
+}
View
90 railties/guides/files/javascripts/highlighters.js
@@ -0,0 +1,90 @@
+CodeHighlighter.addStyle("css", {
+ comment : {
+ exp : /\/\*[^*]*\*+([^\/][^*]*\*+)*\//
+ },
+ keywords : {
+ exp : /@\w[\w\s]*/
+ },
+ selectors : {
+ exp : "([\\w-:\\[.#][^{};>]*)(?={)"
+ },
+ properties : {
+ exp : "([\\w-]+)(?=\\s*:)"
+ },
+ units : {
+ exp : /([0-9])(em|en|px|%|pt)\b/,
+ replacement : "$1<span class=\"$0\">$2</span>"
+ },
+ urls : {
+ exp : /url\([^\)]*\)/
+ }
+ });
+
+CodeHighlighter.addStyle("ruby",{
+ comment : {
+ exp : /#[^\n]+/
+ },
+ brackets : {
+ exp : /\(|\)/
+ },
+ string : {
+ exp : /'[^']*'|"[^"]*"/
+ },
+ keywords : {
+ exp : /\b(do|end|self|class|def|if|module|yield|then|else|for|until|unless|while|elsif|case|when|break|retry|redo|rescue|require|raise)\b/
+ },
+ /* Added by Shelly Fisher (shelly@agileevolved.com) */
+ symbol : {
+ exp : /([^:])(:[A-Za-z0-9_!?]+)/
+ },
+ ivar : {
+ exp : /\@[A-Za-z0-9_!?]+/
+ }
+});
+
+CodeHighlighter.addStyle("html", {
+ comment : {
+ exp: /&lt;!\s*(--([^-]|[\r\n]|-[^-])*--\s*)&gt;/
+ },
+ tag : {
+ exp: /(&lt;\/?)([a-zA-Z1-9]+\s?)/,
+ replacement: "$1<span class=\"$0\">$2</span>"
+ },
+ string : {
+ exp : /'[^']*'|"[^"]*"/
+ },
+ attribute : {
+ exp: /\b([a-zA-Z-:]+)(=)/,
+ replacement: "<span class=\"$0\">$1</span>$2"
+ },
+ doctype : {
+ exp: /&lt;!DOCTYPE([^&]|&[^g]|&g[^t])*&gt;/
+ }
+});
+
+CodeHighlighter.addStyle("javascript",{
+ comment : {
+ exp : /(\/\/[^\n]*(\n|$))|(\/\*[^*]*\*+([^\/][^*]*\*+)*\/)/
+ },
+ brackets : {
+ exp : /\(|\)/
+ },
+ string : {
+ exp : /'[^']*'|"[^"]*"/
+ },
+ keywords : {
+ exp : /\b(arguments|break|case|continue|default|delete|do|else|false|for|function|if|in|instanceof|new|null|return|switch|this|true|typeof|var|void|while|with)\b/
+ },
+ global : {
+ exp : /\b(toString|valueOf|window|element|prototype|constructor|document|escape|unescape|parseInt|parseFloat|setTimeout|clearTimeout|setInterval|clearInterval|NaN|isNaN|Infinity)\b/
+ }
+});
+
+CodeHighlighter.addStyle("yaml", {
+ keyword : {
+ exp : /\/\*[^*]*\*+([^\/][^*]*\*+)*\//
+ },
+ value : {
+ exp : /@\w[\w\s]*/
+ },
+});
View
436 railties/guides/files/stylesheets/main.css
@@ -0,0 +1,436 @@
+/* Guides.rubyonrails.org */
+/* Main.css */
+/* Created January 30, 2009 */
+/* Modified January 31, 2009
+--------------------------------------- */
+
+/* General
+--------------------------------------- */
+
+.left {float: left; margin-right: 1em;}
+.right {float: right; margin-left: 1em;}
+.small {font-size: smaller;}
+.large {font-size: larger;}
+.hide {display: none;}
+
+li ul, li ol { margin:0 1.5em; }
+ul, ol { margin: 0 1.5em 1.5em 1.5em; }
+
+ul { list-style-type: disc; }
+ol { list-style-type: decimal; }
+
+dl { margin: 0 0 1.5em 0; }
+dl dt { font-weight: bold; }
+dd { margin-left: 1.5em;}
+
+pre,code { margin: 1.5em 0; white-space: pre; }
+pre,code,tt { font: 1em 'andale mono', 'lucida console', monospace; line-height: 1.5; }
+
+abbr, acronym { border-bottom: 1px dotted #666; }
+address { margin: 0 0 1.5em; font-style: italic; }
+del { color:#666; }
+
+blockquote { margin: 1.5em; color: #666; font-style: italic; }
+strong { font-weight: bold; }
+em, dfn { font-style: italic; }
+dfn { font-weight: bold; }
+sup, sub { line-height: 0; }
+p {margin: 0 0 1.5em;}
+
+label { font-weight: bold; }
+fieldset { padding:1.4em; margin: 0 0 1.5em 0; border: 1px solid #ccc; }
+legend { font-weight: bold; font-size:1.2em; }
+
+input.text, input.title,
+textarea, select {
+ margin:0.5em 0;
+ border:1px solid #bbb;
+}
+
+table {
+ margin: 1em 0;
+ border: 1px solid #ddd;
+ background: #f4f4f4;
+ border-spacing: 0;
+}
+
+ table th, table td {
+ padding: 0.25em;
+ border-right: 1px dotted #e0e0e0;
+ border-bottom: 1px dotted #e0e0e0;
+ }
+
+ table th:last-child, table td:last-child {
+ border-right: none;
+ }
+
+ table th {
+ border-bottom: 1px solid #ddd;
+ background: #f0f0f0;
+ font-weight: bold;
+ }
+
+ table td {
+ }
+
+ table tt {
+ padding: 0.1em;
+ }
+
+
+/* Structure and Layout
+--------------------------------------- */
+
+body {
+ text-align: center;
+ font-family: Helvetica, Arial, sans-serif;
+ font-size: 87.5%;
+ line-height: 1.5em;
+ background: #222;
+ color: #999;
+ }
+
+.wrapper {
+ text-align: left;
+ margin: 0 auto;
+ width: 69em;
+ }
+
+#topNav {
+ padding: 1em 0;
+ color: #565656;
+}
+
+#header {
+ background: #c52f24 url(../../images/header_tile.gif) repeat-x;
+ color: #FFF;
+ padding: 1.5em 0;
+ position: relative;
+ z-index: 99;
+ }
+
+#feature {
+ background: #d5e9f6 url(../../images/feature_tile.gif) repeat-x;
+ color: #333;
+ padding: 0.5em 0 1.5em;
+}
+
+#container {
+ background: #FFF;
+ color: #333;
+ padding: 0.5em 0 1.5em 0;
+ }
+
+#mainCol {
+ width: 45em;
+ margin-left: 2em;
+ }
+
+#subCol {
+ position: absolute;
+ z-index: 0;
+ top: 0;
+ right: 0;
+ background: #FFF;
+ padding: 1em 1.5em 1em 1.25em;
+ width: 17em;
+ font-size: 0.9285em;
+ line-height: 1.3846em;
+ }
+
+#extraCol {display: none;}
+
+#footer {
+ padding: 2em 0;
+ background: url(../../images/footer_tile.gif) repeat-x;
+ }
+#footer .wrapper {
+ padding-left: 2em;
+ width: 67em;
+}
+
+#header .wrapper, #topNav .wrapper, #feature .wrapper {padding-left: 1em; width: 68em;}
+#feature .wrapper {width: 45em; padding-right: 23em; position: relative; z-index: 0;}
+
+/* Links
+--------------------------------------- */
+
+a, a:link, a:visited {
+ color: #ee3f3f;
+ text-decoration: underline;
+ }
+
+#mainCol a, #subCol a {color: #980905;}
+
+
+/* Navigation
+--------------------------------------- */
+
+.nav {margin: 0; padding: 0;}
+.nav li {display: inline; list-style: none;}
+
+#header .nav {
+ float: right;
+ margin-top: 1.5em;
+ font-size: 1.2857em;
+}
+
+#header .nav li {margin: 0 0 0 0.5em;}
+#header .nav a {color: #FFF; text-decoration: none;}
+#header .nav a:hover {text-decoration: underline;}
+
+#header .nav .index {
+ padding: 0.5em 1.5em;
+ border-radius: 1em;
+ -webkit-border-radius: 1em;
+ -moz-border-radius: 1em;
+ background: #980905;
+ position: relative;
+}
+
+#header .nav .index a {
+ background: #980905 url(../../images/nav_arrow.gif) no-repeat right top;
+ padding-right: 1em;
+ position: relative;
+ z-index: 15;
+ padding-bottom: 0.125em;
+}
+#header .nav .index:hover a, #header .nav .index a:hover {background-position: right -81px;}
+
+#guides {
+ width: 27em;
+ display: block;
+ background: #980905;
+ border-radius: 1em;
+ -webkit-border-radius: 1em;
+ -moz-border-radius: 1em;
+ -webkit-box-shadow: 0.25em 0.25em 1em rgba(0,0,0,0.25);
+ -moz-box-shadow: rgba(0,0,0,0.25) 0.25em 0.25em 1em;
+ color: #f1938c;
+ padding: 1.5em 2em;
+ position: absolute;
+ z-index: 10;
+ top: -0.25em;
+ right: 0;
+ padding-top: 2em;
+}
+
+#guides dt, #guides dd {
+ font-weight: normal;
+ font-size: 0.722em;
+ margin: 0;
+ padding: 0;
+}
+#guides dt {padding:0; margin: 0.5em 0 0;}
+#guides a {color: #FFF; background: none !important;}
+#guides .L, #guides .R {float: left; width: 50%; margin: 0; padding: 0;}
+#guides .R {float: right;}
+#guides hr {
+ display: block;
+ border: none;
+ height: 1px;
+ color: #f1938c;
+ background: #f1938c;
+}
+
+/* Headings
+--------------------------------------- */
+
+h1 {
+ font-size: 2.5em;
+ line-height: 1em;
+ margin: 0.6em 0 .2em;
+ font-weight: bold;
+ }
+
+h2 {
+ font-size: 2.1428em;
+ line-height: 1em;
+ margin: 0.7em 0 .2333em;
+ font-weight: bold;
+ }
+
+h3 {
+ font-size: 1.7142em;
+ line-height: 1.286em;
+ margin: 0.875em 0 0.2916em;
+ font-weight: bold;
+ }
+
+h4 {
+ font-size: 1.2857em;
+ line-height: 1.2em;
+ margin: 1.6667em 0 .3887em;
+ font-weight: bold;
+ }
+
+h5 {
+ font-size: 1em;
+ line-height: 1.5em;
+ margin: 1em 0 .5em;
+ font-weight: bold;
+}
+
+h6 {
+ font-size: 1em;
+ line-height: 1.5em;
+ margin: 1em 0 .5em;
+ font-weight: normal;
+ }
+
+/* Content
+--------------------------------------- */
+
+.pic {
+ margin: 0 2em 2em 0;
+}
+
+#topNav strong {color: #999; margin-right: 0.5em;}
+#topNav strong a {color: #FFF;}
+
+#header h1 {
+ float: left;
+ background: url(../../images/ruby_guides_logo.gif) no-repeat;
+ width: 492px;
+ text-indent: -9999em;
+ margin: 0;
+ padding: 0;
+}
+
+#header h1 a {
+ text-decoration: none;
+ display: block;
+ height: 77px;
+}
+
+#feature p {
+ font-size: 1.2857em;
+ margin-bottom: 0.75em;
+}
+
+#feature ul {margin-left: 0;}
+#feature ul li {
+ list-style: none;
+ background: url(../../images/check_bullet.gif) no-repeat left 0.5em;
+ padding: 0.5em 1.75em 0.5em 1.75em;
+ font-size: 1.1428em;
+ font-weight: bold;
+}
+
+#mainCol dd, #subCol dd {
+ padding: 0.25em 0 1em;
+ border-bottom: 1px solid #CCC;
+ margin-bottom: 1em;
+ margin-left: 0;
+ padding-left: 28px;
+}
+
+#mainCol dt, #subCol dt {
+ font-size: 1.2857em;
+ padding: 0.125em 0 0.25em 28px;
+ margin-bottom: 0;
+ background: url(../../images/book_icon.gif) no-repeat left top;
+}
+
+#mainCol dd.ticket, #subCol dd.ticket {
+ background: #fff9d8 url(../../images/tab_yellow.gif) no-repeat left top;
+ border: none;
+ padding: 1.25em 1em 1.25em 48px;
+ margin-left: 0;
+ margin-top: 0.25em;
+}
+
+#mainCol dd.warning, #subCol dd.warning {
+ background: #f9d9d8 url(../../images/tab_red.gif) no-repeat left top;
+ border: none;
+ padding: 1.25em 1.25em 1.25em 48px;
+ margin-left: 0;
+ margin-top: 0.25em;
+}
+
+#subCol .chapters {color: #980905;}
+#subCol .chapters a {font-weight: bold;}
+#subCol .chapters ul a {font-weight: normal;}
+#subCol .chapters li {margin-bottom: 0.75em;}
+#subCol h3.chapter {margin-top: 0.25em;}
+#subCol h3.chapter img {vertical-align: text-bottom;}
+#subCol .chapters ul {margin-left: 0; margin-top: 0.5em;}
+#subCol .chapters ul li {
+ list-style: none;
+ padding: 0 0 0 1em;
+ background: url(../../images/bullet.gif) no-repeat left 0.45em;
+ margin-left: 0;
+ font-size: 1em;
+ font-weight: normal;
+}
+
+tt {
+ background: #EEE;
+ border: 1px solid #CCC;
+ padding: 0.25em 0.5em;
+ font-family: monaco, "Bitstream Vera Sans Mono", "Courier New", courier, monospace;
+}
+
+code, pre {
+ font-family: monaco, "Bitstream Vera Sans Mono", "Courier New", courier, monospace;
+ background: #EEE url(../../images/tab_grey.gif) no-repeat left top;
+ border: none;
+ padding: 0.25em 1em 0.5em 48px;
+ margin-left: 0;
+ margin-top: 0.25em;
+ display: block;
+}
+
+.note {
+ background: #fff9d8 url(../../images/tab_note.gif) no-repeat left top;
+ border: none;
+ padding: 1em 1em 0.25em 48px;
+ margin-left: 0;
+ margin-top: 0.25em;
+}
+
+.info {
+ background: #d5e9f6 url(../../images/tab_info.gif) no-repeat left top;
+ border: none;
+ padding: 1em 1em 0.25em 48px;
+ margin-left: 0;
+ margin-top: 0.25em;
+}
+
+.warning {
+ background: #f9d9d8 url(../../images/tab_red.gif) no-repeat left top;
+ border: none;
+ padding: 1em 1em 0.25em 48px;
+ margin-left: 0;
+ margin-top: 0.25em;
+}
+
+.warning tt, .note tt, .info tt {border:none; background: none; padding: 0;}
+
+em.highlight {
+ background: #fffcdb;
+ padding: 0 0.25em;
+}
+
+#mainCol ul li {
+ list-style:none;
+ background: url(../../images/grey_bullet.gif) no-repeat left 0.5em;
+ padding-left: 1em;
+ margin-left: 0;
+}
+
+/* Clearing
+--------------------------------------- */
+
+.clearfix:after {
+ content: ".";
+ display: block;
+ height: 0;
+ clear: both;
+ visibility: hidden;
+}
+
+.clearfix {display: inline-block;}
+* html .clearfix {height: 1%;}
+.clearfix {display: block;}
+.clear { clear:both; }
View
52 railties/guides/files/stylesheets/print.css
@@ -0,0 +1,52 @@
+/* Guides.rubyonrails.org */
+/* Print.css */
+/* Created January 30, 2009 */
+/* Modified January 31, 2009
+--------------------------------------- */
+
+body, .wrapper, .note, .info, code, #topNav, .L, .R, #frame, #container, #header, #navigation, #footer, #feature, #mainCol, #subCol, #extraCol, .content {position: static; text-align: left; text-indent: 0; background: White; color: Black; border-color: Black; width: auto; height: auto; display: block; float: none; min-height: 0; margin: 0; padding: 0;}
+
+body {
+ background: #FFF;
+ font-size: 10pt !important;
+ font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
+ line-height: 1.5;
+ color: #000;
+ padding: 0 3%;
+ }
+
+.hide, .nav {
+ display: none !important;
+ }
+
+a:link, a:visited {
+ background: transparent;
+ font-weight: bold;
+ text-decoration: underline;
+ }
+
+hr {
+ background:#ccc;
+ color:#ccc;
+ width:100%;
+ height:2px;
+ margin:2em 0;
+ padding:0;
+ border:none;
+}
+
+h1,h2,h3,h4,h5,h6 { font-family: "Helvetica Neue", Arial, "Lucida Grande", sans-serif; }
+code { font:.9em "Courier New", Monaco, Courier, monospace; }
+
+img { float:left; margin:1.5em 1.5em 1.5em 0; }
+a img { border:none; }
+
+blockquote {
+ margin:1.5em;
+ padding:1em;
+ font-style:italic;
+ font-size:.9em;
+}
+
+.small { font-size: .9em; }
+.large { font-size: 1.1em; }
View
43 railties/guides/files/stylesheets/reset.css
@@ -0,0 +1,43 @@
+/* Guides.rubyonrails.org */
+/* Reset.css */
+/* Created January 30, 2009
+--------------------------------------- */
+
+html, body, div, span, applet, object, iframe,
+h1, h2, h3, h4, h5, h6, p, blockquote, pre,
+a, abbr, acronym, address, big, cite, code,
+del, dfn, em, font, img, ins, kbd, q, s, samp,
+small, strike, strong, sub, sup, tt, var,
+b, u, i, center,
+dl, dt, dd, ol, ul, li,
+fieldset, form, label, legend,
+table, caption, tbody, tfoot, thead, tr, th, td {
+ margin: 0;
+ padding: 0;
+ border: 0;
+ outline: 0;
+ font-size: 100%;
+ background: transparent;
+}
+
+body {line-height: 1; color: black; background: white;}
+a img {border:none;}
+ins {text-decoration: none;}
+del {text-decoration: line-through;}
+
+:focus {
+ -moz-outline:0;
+ outline:0;
+ outline-offset:0;
+}
+
+/* tables still need 'cellspacing="0"' in the markup */
+table {border-collapse: collapse; border-spacing: 0;}
+caption, th, td {text-align: left; font-weight: normal;}
+
+blockquote, q {quotes: none;}
+blockquote:before, blockquote:after,
+q:before, q:after {
+ content: '';
+ content: none;
+}
View
13 railties/guides/files/stylesheets/style.css
@@ -0,0 +1,13 @@
+/* Guides.rubyonrails.org */
+/* Style.css */
+/* Created January 30, 2009
+--------------------------------------- */
+
+/*
+---------------------------------------
+Import advanced style sheet
+---------------------------------------
+*/
+
+@import url("reset.css");
+@import url("main.css");
View
31 railties/guides/files/stylesheets/syntax.css
@@ -0,0 +1,31 @@
+.html .tag {
+ color : green;
+}
+
+.html .doctype {
+ color: #708090;
+}
+
+.erb .tag {
+ color : green;
+}
+
+.erb .doctype {
+ color: #708090;
+}
+
+.ruby .keywords {
+ color : red;
+}
+
+.ruby .ivar {
+ color : blue;
+}
+
+.ruby .comment {
+ color: #708090;
+}
+
+.ruby .symbol {
+ color: green;
+}
View
BIN  railties/guides/images/belongs_to.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  railties/guides/images/book_icon.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  railties/guides/images/bullet.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  railties/guides/images/chapters_icon.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  railties/guides/images/check_bullet.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  railties/guides/images/credits_pic_blank.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  railties/guides/images/csrf.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  railties/guides/images/customized_error_messages.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  railties/guides/images/error_messages.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  railties/guides/images/feature_tile.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  railties/guides/images/footer_tile.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  railties/guides/images/grey_bullet.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  railties/guides/images/habtm.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  railties/guides/images/has_many.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  railties/guides/images/has_many_through.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  railties/guides/images/has_one.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  railties/guides/images/has_one_through.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  railties/guides/images/header_backdrop.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  railties/guides/images/header_tile.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  railties/guides/images/i18n/demo_localized_pirate.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  railties/guides/images/i18n/demo_translated_en.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  railties/guides/images/i18n/demo_translated_pirate.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  railties/guides/images/i18n/demo_translation_missing.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  railties/guides/images/i18n/demo_untranslated.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
5 railties/guides/images/icons/README
@@ -0,0 +1,5 @@
+Replaced the plain DocBook XSL admonition icons with Jimmac's DocBook
+icons (http://jimmac.musichall.cz/ikony.php3). I dropped transparency
+from the Jimmac icons to get round MS IE and FOP PNG incompatibilies.
+
+Stuart Rackham
View
BIN  railties/guides/images/icons/callouts/1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  railties/guides/images/icons/callouts/10.png
Diff not rendered
View
BIN  railties/guides/images/icons/callouts/11.png
Diff not rendered
View
BIN  railties/guides/images/icons/callouts/12.png
Diff not rendered
View
BIN  railties/guides/images/icons/callouts/13.png
Diff not rendered
View
BIN  railties/guides/images/icons/callouts/14.png
Diff not rendered
View
BIN  railties/guides/images/icons/callouts/15.png
Diff not rendered
View
BIN  railties/guides/images/icons/callouts/2.png
Diff not rendered
View
BIN  railties/guides/images/icons/callouts/3.png
Diff not rendered
View
BIN  railties/guides/images/icons/callouts/4.png
Diff not rendered
View
BIN  railties/guides/images/icons/callouts/5.png
Diff not rendered
View
BIN  railties/guides/images/icons/callouts/6.png
Diff not rendered
View
BIN  railties/guides/images/icons/callouts/7.png
Diff not rendered
View
BIN  railties/guides/images/icons/callouts/8.png
Diff not rendered
View
BIN  railties/guides/images/icons/callouts/9.png
Diff not rendered
View
BIN  railties/guides/images/icons/caution.png
Diff not rendered
View
BIN  railties/guides/images/icons/example.png
Diff not rendered
View
BIN  railties/guides/images/icons/home.png
Diff not rendered
View
BIN  railties/guides/images/icons/important.png
Diff not rendered
View
BIN  railties/guides/images/icons/next.png
Diff not rendered
View
BIN  railties/guides/images/icons/note.png
Diff not rendered
View
BIN  railties/guides/images/icons/prev.png
Diff not rendered
View
BIN  railties/guides/images/icons/tip.png
Diff not rendered
View
BIN  railties/guides/images/icons/up.png
Diff not rendered
View
BIN  railties/guides/images/icons/warning.png
Diff not rendered
View
BIN  railties/guides/images/nav_arrow.gif
Diff not rendered
View
BIN  railties/guides/images/polymorphic.png
Diff not rendered
View
BIN  railties/guides/images/posts_index.png
Diff not rendered
View
BIN  railties/guides/images/rails_logo_remix.gif
Diff not rendered
View
BIN  railties/guides/images/rails_welcome.png
Diff not rendered
View
BIN  railties/guides/images/ruby_guides_logo.gif
Diff not rendered
View
BIN  railties/guides/images/ruby_on_rails_by_mike_rundle2.gif
Diff not rendered
View
BIN  railties/guides/images/session_fixation.png
Diff not rendered
View
BIN  railties/guides/images/tab_grey.gif
Diff not rendered
View
BIN  railties/guides/images/tab_info.gif
Diff not rendered
View
BIN  railties/guides/images/tab_note.gif
Diff not rendered
View
BIN  railties/guides/images/tab_red.gif
Diff not rendered
View
BIN  railties/guides/images/tab_yellow.gif
Diff not rendered
View
BIN  railties/guides/images/tab_yellow.png
Diff not rendered
View
BIN  railties/guides/images/validation_error_messages.png
Diff not rendered
View
30 railties/guides/rails_guides.rb
@@ -0,0 +1,30 @@
+pwd = File.dirname(__FILE__)
+$: << pwd
+$: << File.join(pwd, "../../activesupport/lib")
+$: << File.join(pwd, "../../actionpack/lib")
+
+require "action_view"
+
+# Require rubygems after loading Action View
+require 'rubygems'
+begin
+ gem 'RedCloth', '= 4.1.1'# Need exactly 4.1.1
+rescue Gem::LoadError
+ $stderr.puts %(Missing the RedCloth 4.1.1 gem.\nPlease `gem install -v=4.1.1 RedCloth` to generate the guides.)
+ exit 1
+end
+
+require 'redcloth'
+
+module RailsGuides
+ autoload :Generator, "rails_guides/generator"
+ autoload :Indexer, "rails_guides/indexer"
+ autoload :Helpers, "rails_guides/helpers"
+ autoload :TextileExtensions, "rails_guides/textile_extensions"
+end
+
+RedCloth.send(:include, RailsGuides::TextileExtensions)
+
+if $0 == __FILE__
+ RailsGuides::Generator.new.generate
+end
View
112 railties/guides/rails_guides/generator.rb
@@ -0,0 +1,112 @@
+module RailsGuides
+ class Generator
+ attr_reader :output, :view_path, :view, :guides_dir
+
+ def initialize(output = nil)
+ @guides_dir = File.join(File.dirname(__FILE__), '..')
+
+ @output = output || File.join(@guides_dir, "output")
+
+ unless ENV["ONLY"]
+ FileUtils.rm_r(@output) if File.directory?(@output)
+ FileUtils.mkdir(@output)
+ end
+
+ @view_path = File.join(@guides_dir, "source")
+ end
+
+ def generate
+ guides = Dir.entries(view_path).find_all {|g| g =~ /textile$/ }
+
+ if ENV["ONLY"]
+ only = ENV["ONLY"].split(",").map{|x| x.strip }.map {|o| "#{o}.textile" }
+ guides = guides.find_all {|g| only.include?(g) }
+ puts "GENERATING ONLY #{guides.inspect}"
+ end
+
+ guides.each do |guide|
+ guide =~ /(.*?)(\.erb)?\.textile/
+ name = $1
+
+ puts "Generating #{name}"
+
+ file = File.join(output, "#{name}.html")
+ File.open(file, 'w') do |f|
+ @view = ActionView::Base.new(view_path)
+ @view.extend(Helpers)
+
+ if guide =~ /\.erb\.textile/
+ # Generate the erb pages with textile formatting - e.g. index/authors
+ result = view.render(:layout => 'layout', :file => guide)
+ f.write textile(result)
+ else
+ body = File.read(File.join(view_path, guide))
+ body = set_header_section(body, @view)
+ body = set_index(body, @view)
+
+ result = view.render(:layout => 'layout', :text => textile(body))
+ f.write result
+ end
+ end
+ end
+
+ # Copy images and css files to html directory
+ FileUtils.cp_r File.join(guides_dir, 'images'), File.join(output, 'images')
+ FileUtils.cp_r File.join(guides_dir, 'files'), File.join(output, 'files')
+ end
+
+ def set_header_section(body, view)
+ new_body = body.gsub(/(.*?)endprologue\./m, '').strip
+ header = $1
+
+ header =~ /h2\.(.*)/
+ page_title = $1.strip
+
+ header = textile(header)
+
+ view.content_for(:page_title) { page_title }
+ view.content_for(:header_section) { header }
+ 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)
+ i.index
+
+ # Set index for 2 levels
+ i.level_hash.each do |key, value|
+ bookmark = '#' + key.gsub(/[^a-z0-9\-_\+]+/i, '').underscore.dasherize
+ link = view.content_tag(:a, :href => bookmark) { key }
+
+ children = value.keys.map do |k|
+ bm = '#' + k.gsub(/[^a-z0-9\-_\+]+/i, '').underscore.dasherize
+ l = view.content_tag(:a, :href => bm) { k }
+ view.content_tag(:li, l)
+ end
+
+ children_ul = view.content_tag(:ul, children)
+
+ index << view.content_tag(:li, link + children_ul)
+ end
+
+ index << '</ol>'
+ index << '</div>'
+
+ view.content_for(:index_section) { index }
+
+ i.result
+ end
+
+ def textile(body)
+ t = RedCloth.new(body)
+ t.hard_breaks = false
+ t.to_html(:notestuff, :plusplus, :code, :tip)
+ end
+ end
+end
View
34 railties/guides/rails_guides/helpers.rb
@@ -0,0 +1,34 @@
+module RailsGuides
+ module Helpers
+ def guide(name, url, options = {}, &block)
+ link = content_tag(:a, :href => url) { name }
+ result = content_tag(:dt, link)
+
+ if ticket = options[:ticket]
+ result << content_tag(:dd, lh(ticket), :class => 'ticket')
+ end
+
+ result << content_tag(:dd, capture(&block))
+ concat(result)
+ end
+
+ def lh(id, label = "Lighthouse Ticket")
+ url = "http://rails.lighthouseapp.com/projects/16213/tickets/#{id}"
+ content_tag(:a, label, :href => url)
+ end
+
+ def author(name, nick, image = 'credits_pic_blank.gif', &block)
+ image = "images/#{image}"
+
+ result = content_tag(:img, nil, :src => image, :class => 'left pic', :alt => name)
+ result << content_tag(:h3, name)
+ result << content_tag(:p, capture(&block))
+ concat content_tag(:div, result, :class => 'clearfix', :id => nick)
+ end
+
+ def code(&block)
+ c = capture(&block)
+ content_tag(:code, c)
+ end
+ end
+end
View
51 railties/guides/rails_guides/indexer.rb
@@ -0,0 +1,51 @@
+module RailsGuides
+ class Indexer
+ attr_reader :body, :result, :level_hash
+
+ def initialize(body)
+ @body = body
+ @result = @body.dup
+ end
+
+ def index
+ @level_hash = process(body)
+ end
+
+ private
+
+ def process(string, current_level= 3, counters = [1])
+ s = StringScanner.new(string)
+
+ level_hash = ActiveSupport::OrderedHash.new
+
+ while !s.eos?
+ s.match?(/\h[0-9]\..*$/)
+ if matched = s.matched
+ matched =~ /\h([0-9])\.(.*)$/
+ level, title = $1.to_i, $2
+
+ if level < current_level
+ # This is needed. Go figure.
+ return level_hash
+ elsif level == current_level
+ index = counters.join(".")
+ bookmark = '#' + title.gsub(/[^a-z0-9\-_\+]+/i, '').underscore.dasherize
+
+ raise "Parsing Fail" unless @result.sub!(matched, "h#{level}(#{bookmark}). #{index}#{title}")
+
+ # Recurse
+ counters << 1
+ level_hash[title.strip] = 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
+ end
+end
View
38 railties/guides/rails_guides/textile_extensions.rb
@@ -0,0 +1,38 @@
+module RailsGuides
+ module TextileExtensions
+ def notestuff(body)
+ body.gsub!(/^(IMPORTANT|CAUTION|WARNING|NOTE|INFO)(?:\.|\:)(.*)$/) do |m|
+ css_class = $1.downcase
+ css_class = 'warning' if ['caution', 'important'].include?(css_class)
+
+ result = "<div class='#{css_class}'><p>"
+ result << $2.strip
+ result << '</p></div>'
+ result
+ end
+ end
+
+ def tip(body)
+ body.gsub!(/^(TIP)\:(.*)$/) do |m|
+ result = "<div class='info'><p>"
+ result << $2.strip
+ result << '</p></div>'
+ result
+ end
+ end
+
+ def plusplus(body)
+ body.gsub!(/\+(.*?)\+/) do |m|
+ "<notextile><tt>#{$1}</tt></notextile>"
+ end
+ end
+
+ def code(body)
+ body.gsub!(/\<(yaml|shell|ruby|erb|html|sql)\>(.*?)\<\/\1\>/m) do |m|
+ es = ERB::Util.h($2)
+ css_class = ['erb', 'shell'].include?($1) ? 'html' : $1
+ "<notextile><code class='#{css_class}'>#{es}\n</code></notextile>"
+ end
+ end
+ end
+end
View
422 railties/guides/source/2_2_release_notes.textile
@@ -0,0 +1,422 @@
+h2. Ruby on Rails 2.2 Release Notes
+
+Rails 2.2 delivers a number of new and improved features. This list covers the major upgrades, but doesn't include every little bug fix and change. If you want to see everything, check out the "list of commits":http://github.com/rails/rails/commits/master in the main Rails repository on GitHub.
+
+Along with Rails, 2.2 marks the launch of the "Ruby on Rails Guides":http://guides.rubyonrails.org/, the first results of the ongoing "Rails Guides hackfest":http://hackfest.rubyonrails.org/guide. This site will deliver high-quality documentation of the major features of Rails.
+
+endprologue.
+
+h3. Infrastructure
+
+Rails 2.2 is a significant release for the infrastructure that keeps Rails humming along and connected to the rest of the world.
+
+h4. Internationalization
+
+Rails 2.2 supplies an easy system for internationalization (or i18n, for those of you tired of typing).
+
+* Lead Contributors: Rails i18 Team
+* More information :
+** "Official Rails i18 website":http://rails-i18n.org
+** "Finally. Ruby on Rails gets internationalized":http://www.artweb-design.de/2008/7/18/finally-ruby-on-rails-gets-internationalized
+** "Localizing Rails : Demo application":http://i18n-demo.phusion.nl
+
+h4. Compatibility with Ruby 1.9 and JRuby
+
+Along with thread safety, a lot of work has been done to make Rails work well with JRuby and the upcoming Ruby 1.9. With Ruby 1.9 being a moving target, running edge Rails on edge Ruby is still a hit-or-miss proposition, but Rails is ready to make the transition to Ruby 1.9 when the latter is released.
+
+h3. Documentation
+
+The internal documentation of Rails, in the form of code comments, has been improved in numerous places. In addition, the "Ruby on Rails Guides":http://guides.rubyonrails.org/ project is the definitive source for information on major Rails components. In its first official release, the Guides page includes:
+
+* "Getting Started with Rails":http://guides.rubyonrails.org/getting_started_with_rails.html
+* "Rails Database Migrations":http://guides.rubyonrails.org/migrations.html
+* "Active Record Associations":http://guides.rubyonrails.org/association_basics.html
+* "Active Record Finders":http://guides.rubyonrails.org/finders.html
+* "Layouts and Rendering in Rails":http://guides.rubyonrails.org/layouts_and_rendering.html
+* "Action View Form Helpers":http://guides.rubyonrails.org/form_helpers.html
+* "Rails Routing from the Outside In":http://guides.rubyonrails.org/routing_outside_in.html
+* "Basics of Action Controller":http://guides.rubyonrails.org/actioncontroller_basics.html
+* "Rails Caching":http://guides.rubyonrails.org/caching_with_rails.html
+* "Testing Rails Applications":http://guides.rubyonrails.org/testing_rails_applications.html
+* "Securing Rails Applications":http://guides.rubyonrails.org/security.html
+* "Debugging Rails Applications":http://guides.rubyonrails.org/debugging_rails_applications.html
+* "Benchmarking and Profiling Rails Applications":http://guides.rubyonrails.org/benchmarking_and_profiling.html
+* "The Basics of Creating Rails Plugins":http://guides.rubyonrails.org/creating_plugins.html
+
+All told, the Guides provide tens of thousands of words of guidance for beginning and intermediate Rails developers.
+
+If you want to generate these guides locally, inside your application:
+
+<ruby>
+rake doc:guides
+</ruby>
+
+This will put the guides inside +RAILS_ROOT/doc/guides+ and you may start surfing straight away by opening +RAILS_ROOT/doc/guides/index.html+ in your favourite browser.
+
+* Lead Contributors: "Rails Documentation Team":http://guides.rails.info/credits.html
+* Major contributions from "Xavier Noria":http://advogato.org/person/fxn/diary.html and "Hongli Lai":http://izumi.plan99.net/blog/.
+* More information:
+** "Rails Guides hackfest":http://hackfest.rubyonrails.org/guide
+** "Help improve Rails documentation on Git branch":http://weblog.rubyonrails.org/2008/5/2/help-improve-rails-documentation-on-git-branch
+
+h3. Better integration with HTTP : Out of the box ETag support
+
+Supporting the etag and last modified timestamp in HTTP headers means that Rails can now send back an empty response if it gets a request for a resource that hasn't been modified lately. This allows you to check whether a response needs to be sent at all.
+
+<ruby>
+class ArticlesController < ApplicationController
+ def show_with_respond_to_block
+ @article = Article.find(params[:id])
+
+ # If the request sends headers that differs from the options provided to stale?, then
+ # the request is indeed stale and the respond_to block is triggered (and the options
+ # to the stale? call is set on the response).
+ #
+ # If the request headers match, then the request is fresh and the respond_to block is
+ # not triggered. Instead the default render will occur, which will check the last-modified
+ # and etag headers and conclude that it only needs to send a "304 Not Modified" instead
+ # of rendering the template.
+ if stale?(:last_modified => @article.published_at.utc, :etag => @article)
+ respond_to do |wants|
+ # normal response processing
+ end
+ end
+ end
+
+ def show_with_implied_render
+ @article = Article.find(params[:id])
+
+ # Sets the response headers and checks them against the request, if the request is stale
+ # (i.e. no match of either etag or last-modified), then the default render of the template happens.
+ # If the request is fresh, then the default render will return a "304 Not Modified"
+ # instead of rendering the template.
+ fresh_when(:last_modified => @article.published_at.utc, :etag => @article)
+ end
+end
+</ruby>
+
+h3. Thread Safety
+
+The work done to make Rails thread-safe is rolling out in Rails 2.2. Depending on your web server infrastructure, this means you can handle more requests with fewer copies of Rails in memory, leading to better server performance and higher utilization of multiple cores.
+
+To enable multithreaded dispatching in production mode of your application, add the following line in your +config/environments/production.rb+:
+
+<ruby>
+config.threadsafe!
+</ruby>
+
+* More information :
+** "Thread safety for your Rails":http://m.onkey.org/2008/10/23/thread-safety-for-your-rails
+** "Thread safety project announcement":http://weblog.rubyonrails.org/2008/8/16/josh-peek-officially-joins-the-rails-core
+** "Q/A: What Thread-safe Rails Means":http://blog.headius.com/2008/08/qa-what-thread-safe-rails-means.html
+
+h3. Active Record
+
+There are two big additions to talk about here: transactional migrations and pooled database transactions. There's also a new (and cleaner) syntax for join table conditions, as well as a number of smaller improvements.
+
+h4. Transactional Migrations
+
+Historically, multiple-step Rails migrations have been a source of trouble. If something went wrong during a migration, everything before the error changed the database and everything after the error wasn't applied. Also, the migration version was stored as having been executed, which means that it couldn't be simply rerun by +rake db:migrate:redo+ after you fix the problem. Transactional migrations change this by wrapping migration steps in a DDL transaction, so that if any of them fail, the entire migration is undone. In Rails 2.2, transactional migrations are supported on PostgreSQL out of the box. The code is extensible to other database types in the future - and IBM has already extended it to support the DB2 adapter.
+
+* Lead Contributor: "Adam Wiggins":http://adam.blog.heroku.com/
+* More information:
+** "DDL Transactions":http://adam.blog.heroku.com/past/2008/9/3/ddl_transactions/
+** "A major milestone for DB2 on Rails":http://db2onrails.com/2008/11/08/a-major-milestone-for-db2-on-rails/
+
+h4. Connection Pooling
+
+Connection pooling lets Rails distribute database requests across a pool of database connections that will grow to a maximum size (by default 5, but you can add a +pool+ key to your +database.yml+ to adjust this). This helps remove bottlenecks in applications that support many concurrent users. There's also a +wait_timeout+ that defaults to 5 seconds before giving up. +ActiveRecord::Base.connection_pool+ gives you direct access to the pool if you need it.
+
+<ruby>
+development:
+ adapter: mysql
+ username: root
+ database: sample_development
+ pool: 10
+ wait_timeout: 10
+</ruby>
+
+* Lead Contributor: "Nick Sieger":http://blog.nicksieger.com/
+* More information:
+** "What's New in Edge Rails: Connection Pools":http://ryandaigle.com/articles/2008/9/7/what-s-new-in-edge-rails-connection-pools
+
+h4. Hashes for Join Table Conditions
+
+You can now specify conditions on join tables using a hash. This is a big help if you need to query across complex joins.
+
+<ruby>
+class Photo < ActiveRecord::Base
+ belongs_to :product
+end
+
+class Product < ActiveRecord::Base
+ has_many :photos
+end
+
+# Get all products with copyright-free photos:
+Product.all(:joins => :photos, :conditions => { :photos => { :copyright => false }})
+</ruby>
+
+* More information:
+** "What's New in Edge Rails: Easy Join Table Conditions":http://ryandaigle.com/articles/2008/7/7/what-s-new-in-edge-rails-easy-join-table-conditions
+
+h4. New Dynamic Finders
+
+Two new sets of methods have been added to Active Record's dynamic finders family.
+
+h5. +find_last_by_<attribute>+
+
+The +find_last_by_<attribute>+ method is equivalent to +Model.last(:conditions => {:attribute => value})+
+
+<ruby>
+# Get the last user who signed up from London
+User.find_last_by_city('London')
+</ruby>
+
+* Lead Contributor: "Emilio Tagua":http://www.workingwithrails.com/person/9147-emilio-tagua
+
+h5. +find_by_<attribute>!+
+
+The new bang! version of +find_by_<attribute>!+ is equivalent to +Model.first(:conditions => {:attribute => value}) || raise ActiveRecord::RecordNotFound+ Instead of returning +nil+ if it can't find a matching record, this method will raise an exception if it cannot find a match.
+
+<ruby>
+# Raise ActiveRecord::RecordNotFound exception if 'Moby' hasn't signed up yet!
+User.find_by_name!('Moby')
+</ruby>
+
+* Lead Contributor: "Josh Susser":http://blog.hasmanythrough.com
+
+h4. Associations Respect Private/Protected Scope
+
+Active Record association proxies now respect the scope of methods on the proxied object. Previously (given User has_one :account) +@user.account.private_method+ would call the private method on the associated Account object. That fails in Rails 2.2; if you need this functionality, you should use +@user.account.send(:private_method)+ (or make the method public instead of private or protected). Please note that if you're overriding +method_missing+, you should also override +respond_to+ to match the behavior in order for associations to function normally.
+
+* Lead Contributor: Adam Milligan
+* More information:
+** "Rails 2.2 Change: Private Methods on Association Proxies are Private":http://afreshcup.com/2008/10/24/rails-22-change-private-methods-on-association-proxies-are-private/
+
+h4. Other ActiveRecord Changes
+
+* +rake db:migrate:redo+ now accepts an optional VERSION to target that specific migration to redo
+* Set +config.active_record.timestamped_migrations = false+ to have migrations with numeric prefix instead of UTC timestamp.
+* Counter cache columns (for associations declared with +:counter_cache => true+) do not need to be initialized to zero any longer.
+* +ActiveRecord::Base.human_name+ for an internationalization-aware humane translation of model names
+
+h3. Action Controller
+
+On the controller side, there are several changes that will help tidy up your routes. There are also some internal changes in the routing engine to lower memory usage on complex applications.
+
+h4. Shallow Route Nesting
+
+Shallow route nesting provides a solution to the well-known difficulty of using deeply-nested resources. With shallow nesting, you need only supply enough information to uniquely identify the resource that you want to work with.
+
+<ruby>
+map.resources :publishers, :shallow => true do |publisher|
+ publisher.resources :magazines do |magazine|
+ magazine.resources :photos
+ end
+end
+</ruby>
+
+This will enable recognition of (among others) these routes:
+
+<ruby>
+/publishers/1 ==> publisher_path(1)
+/publishers/1/magazines ==> publisher_magazines_path(1)
+/magazines/2 ==> magazine_path(2)
+/magazines/2/photos ==> magazines_photos_path(2)
+/photos/3 ==> photo_path(3)
+</ruby>
+
+* Lead Contributor: "S. Brent Faulkner":http://www.unwwwired.net/
+* More information:
+** "Rails Routing from the Outside In":http://guides.rails.info/routing/routing_outside_in.html#_nested_resources
+** "What's New in Edge Rails: Shallow Routes":http://ryandaigle.com/articles/2008/9/7/what-s-new-in-edge-rails-shallow-routes
+
+h4. Method Arrays for Member or Collection Routes
+
+You can now supply an array of methods for new member or collection routes. This removes the annoyance of having to define a route as accepting any verb as soon as you need it to handle more than one. With Rails 2.2, this is a legitimate route declaration:
+
+<ruby>
+map.resources :photos, :collection => { :search => [:get, :post] }
+</ruby>
+
+* Lead Contributor: "Brennan Dunn":http://brennandunn.com/
+
+h4. Resources With Specific Actions
+
+By default, when you use +map.resources+ to create a route, Rails generates routes for seven default actions (index, show, create, new, edit, update, and destroy). But each of these routes takes up memory in your application, and causes Rails to generate additional routing logic. Now you can use the +:only+ and +:except+ options to fine-tune the routes that Rails will generate for resources. You can supply a single action, an array of actions, or the special +:all+ or +:none+ options. These options are inherited by nested resources.
+
+<ruby>
+map.resources :photos, :only => [:index, :show]
+map.resources :products, :except => :destroy
+</ruby>
+
+* Lead Contributor: "Tom Stuart":http://experthuman.com/
+
+h4. Other Action Controller Changes
+
+* You can now easily "show a custom error page":http://m.onkey.org/2008/7/20/rescue-from-dispatching for exceptions raised while routing a request.
+* The HTTP Accept header is disabled by default now. You should prefer the use of formatted URLs (such as +/customers/1.xml+) to indicate the format that you want. If you need the Accept headers, you can turn them back on with +config.action_controller.use_accept_header = true+.
+* Benchmarking numbers are now reported in milliseconds rather than tiny fractions of seconds
+* Rails now supports HTTP-only cookies (and uses them for sessions), which help mitigate some cross-site scripting risks in newer browsers.
+* +redirect_to+ now fully supports URI schemes (so, for example, you can redirect to a svn+ssh: URI).
+* +render+ now supports a +:js+ option to render plain vanilla javascript with the right mime type.
+* Request forgery protection has been tightened up to apply to HTML-formatted content requests only.
+* Polymorphic URLs behave more sensibly if a passed parameter is nil. For example, calling +polymorphic_path([@project, @date, @area])+ with a nil date will give you +project_area_path+.
+
+h3. Action View
+
+* +javascript_include_tag+ and +stylesheet_link_tag+ support a new +:recursive+ option to be used along with +:all+, so that you can load an entire tree of files with a single line of code.
+* The included Prototype javascript library has been upgraded to version 1.6.0.3.
+* +RJS#page.reload+ to reload the browser's current location via javascript
+* The +atom_feed+ helper now takes an +:instruct+ option to let you insert XML processing instructions.
+
+h3. Action Mailer
+
+Action Mailer now supports mailer layouts. You can make your HTML emails as pretty as your in-browser views by supplying an appropriately-named layout - for example, the +CustomerMailer+ class expects to use +layouts/customer_mailer.html.erb+.
+
+* More information:
+** "What's New in Edge Rails: Mailer Layouts":http://ryandaigle.com/articles/2008/9/7/what-s-new-in-edge-rails-mailer-layouts
+
+Action Mailer now offers built-in support for GMail's SMTP servers, by turning on STARTTLS automatically. This requires Ruby 1.8.7 to be installed.
+
+h3. Active Support
+
+Active Support now offers built-in memoization for Rails applications, the +each_with_object+ method, prefix support on delegates, and various other new utility methods.
+
+h4. Memoization
+
+Memoization is a pattern of initializing a method once and then stashing its value away for repeat use. You've probably used this pattern in your own applications:
+
+<ruby>
+def full_name
+ @full_name ||= "#{first_name} #{last_name}"
+end
+</ruby>
+
+Memoization lets you handle this task in a declarative fashion:
+
+<ruby>
+extend ActiveSupport::Memoizable
+
+def full_name
+ "#{first_name} #{last_name}"
+end
+memoize :full_name
+</ruby>
+
+Other features of memoization include +unmemoize+, +unmemoize_all+, and +memoize_all+ to turn memoization on or off.
+
+* Lead Contributor: "Josh Peek":http://joshpeek.com/
+* More information:
+** "What's New in Edge Rails: Easy Memoization":http://ryandaigle.com/articles/2008/7/16/what-s-new-in-edge-rails-memoization
+** "Memo-what? A Guide to Memoization":http://www.railway.at/articles/2008/09/20/a-guide-to-memoization
+
+h4. each_with_object
+
+The +each_with_object+ method provides an alternative to +inject+, using a method backported from Ruby 1.9. It iterates over a collection, passing the current element and the memo into the block.
+
+<ruby>
+%w(foo bar).each_with_object({}) { |str, hsh| hsh[str] = str.upcase } #=> {'foo' => 'FOO', 'bar' => 'BAR'}
+</ruby>
+
+Lead Contributor: "Adam Keys":http://therealadam.com/
+
+h4. Delegates With Prefixes
+
+If you delegate behavior from one class to another, you can now specify a prefix that will be used to identify the delegated methods. For example:
+
+<ruby>
+class Vendor < ActiveRecord::Base
+ has_one :account
+ delegate :email, :password, :to => :account, :prefix => true
+end
+</ruby>
+
+This will produce delegated methods +vendor#account_email+ and +vendor#account_password+. You can also specify a custom prefix:
+
+<ruby>
+class Vendor < ActiveRecord::Base
+ has_one :account
+ delegate :email, :password, :to => :account, :prefix => :owner
+end
+</ruby>
+
+This will produce delegated methods +vendor#owner_email+ and +vendor#owner_password+.
+
+Lead Contributor: "Daniel Schierbeck":http://workingwithrails.com/person/5830-daniel-schierbeck
+
+h4. Other Active Support Changes
+
+* Extensive updates to +ActiveSupport::Multibyte+, including Ruby 1.9 compatibility fixes.
+* The addition of +ActiveSupport::Rescuable+ allows any class to mix in the +rescue_from+ syntax.
+* +past?+, +today?+ and +future?+ for +Date+ and +Time+ classes to facilitate date/time comparisons.
+* +Array#second+ through +Array#fifth+ as aliases for +Array#[1]+ through +Array#[4]+
+* +Enumerable#many?+ to encapsulate +collection.size > 1+
+* +Inflector#parameterize+ produces a URL-ready version of its input, for use in +to_param+.
+* +Time#advance+ recognizes fractional days and weeks, so you can do +1.7.weeks.ago+, +1.5.hours.since+, and so on.
+* The included TzInfo library has been upgraded to version 0.3.12.
+* +ActiveSuport::StringInquirer+ gives you a pretty way to test for equality in strings: +ActiveSupport::StringInquirer.new("abc").abc? => true+
+
+h3. Railties
+
+In Railties (the core code of Rails itself) the biggest changes are in the +config.gems+ mechanism.
+
+h4. config.gems
+
+To avoid deployment issues and make Rails applications more self-contained, it's possible to place copies of all of the gems that your Rails application requires in +/vendor/gems+. This capability first appeared in Rails 2.1, but it's much more flexible and robust in Rails 2.2, handling complicated dependencies between gems. Gem management in Rails includes these commands:
+
+* +config.gem _gem_name_+ in your +config/environment.rb+ file
+* +rake gems+ to list all configured gems, as well as whether they (and their dependencies) are installed, frozen, or framework (framework gems are those loaded by Rails before the gem dependency code is executed; such gems cannot be frozen)
+* +rake gems:install+ to install missing gems to the computer
+* +rake gems:unpack+ to place a copy of the required gems into +/vendor/gems+
+* +rake gems:unpack:dependencies+ to get copies of the required gems and their dependencies into +/vendor/gems+
+* +rake gems:build+ to build any missing native extensions
+* +rake gems:refresh_specs+ to bring vendored gems created with Rails 2.1 into alignment with the Rails 2.2 way of storing them
+
+You can unpack or install a single gem by specifying +GEM=_gem_name_+ on the command line.
+
+* Lead Contributor: "Matt Jones":http://github.com/al2o3cr
+* More information:
+** "What's New in Edge Rails: Gem Dependencies":http://ryandaigle.com/articles/2008/4/1/what-s-new-in-edge-rails-gem-dependencies
+** "Rails 2.1.2 and 2.2RC1: Update Your RubyGems":http://afreshcup.com/2008/10/25/rails-212-and-22rc1-update-your-rubygems/
+** "Detailed discussion on Lighthouse":http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/1128
+
+h4. Other Railties Changes
+
+* If you're a fan of the "Thin":http://code.macournoyer.com/thin/ web server, you'll be happy to know that +script/server+ now supports Thin directly.
+* +script/plugin install <plugin> -r <revision>+ now works with git-based as well as svn-based plugins.
+* +script/console+ now supports a +--debugger+ option
+* Instructions for setting up a continuous integration server to build Rails itself are included in the Rails source
+* +rake notes:custom ANNOTATION=MYFLAG+ lets you list out custom annotations.
+* Wrapped +Rails.env+ in +StringInquirer+ so you can do +Rails.env.development?+
+* To eliminate deprecation warnings and properly handle gem dependencies, Rails now requires rubygems 1.3.1 or higher.
+
+h3. Deprecated
+
+A few pieces of older code are deprecated in this release:
+
+* +Rails::SecretKeyGenerator+ has been replaced by +ActiveSupport::SecureRandom+
+* +render_component+ is deprecated. There's a "render_components plugin":http://github.com/rails/render_component/tree/master available if you need this functionality.
+* Implicit local assignments when rendering partials has been deprecated.
+
+<ruby>
+def partial_with_implicit_local_assignment
+ @customer = Customer.new("Marcel")
+ render :partial => "customer"
+end
+</ruby>
+
+Previously the above code made available a local variable called +customer+ inside the partial 'customer'. You should explicitly pass all the variables via :locals hash now.
+
+* +country_select+ has been removed. See the "deprecation page":http://www.rubyonrails.org/deprecation/list-of-countries for more information and a plugin replacement.
+* +ActiveRecord::Base.allow_concurrency+ no longer has any effect.
+* +ActiveRecord::Errors.default_error_messages+ has been deprecated in favor of +I18n.translate('activerecord.errors.messages')+
+* The +%s+ and +%d+ interpolation syntax for internationalization is deprecated.
+* +String#chars+ has been deprecated in favor of +String#mb_chars+.
+* Durations of fractional months or fractional years are deprecated. Use Ruby's core +Date+ and +Time+ class arithmetic instead.
+* +Request#relative_url_root+ is deprecated. Use +ActionController::Base.relative_url_root+ instead.
+
+h3. Credits
+
+Release notes compiled by "Mike Gunderloy":http://afreshcup.com
View
501 railties/guides/source/2_3_release_notes.textile
@@ -0,0 +1,501 @@
+h2. Ruby on Rails 2.3 Release Notes
+
+Rails 2.3 delivers a variety of new and improved features, including pervasive Rack integration, refreshed support for Rails Engines, nested transactions for Active Record, dynamic and default scopes, unified rendering, more efficient routing, application templates, and quiet backtraces. This list covers the major upgrades, but doesn't include every little bug fix and change. If you want to see everything, check out the "list of commits":http://github.com/rails/rails/commits/master in the main Rails repository on GitHub or review the +CHANGELOG+ files for the individual Rails components.
+
+endprologue.
+
+h3. Application Architecture
+
+There are two major changes in the architecture of Rails applications: complete integration of the "Rack":http://rack.rubyforge.org/ modular web server interface, and renewed support for Rails Engines.
+
+h4. Rack Integration
+
+Rails has now broken with its CGI past, and uses Rack everywhere. This required and resulted in a tremendous number of internal changes (but if you use CGI, don't worry; Rails now supports CGI through a proxy interface.) Still, this is a major change to Rails internals. After upgrading to 2.3, you should test on your local environment and your production environment. Some things to test:
+
+* Sessions
+* Cookies
+* File uploads
+* JSON/XML APIs
+
+Here's a summary of the rack-related changes:
+
+* +script/server+ has been switched to use Rack, which means it supports any Rack compatible server. +script/server+ will also pick up a rackup configuration file if one exists. By default, it will look for a +config.ru+ file, but you can override this with the +-c+ switch.
+* The FCGI handler goes through Rack
+* +ActionController::Dispatcher+ maintains its own default middleware stack. Middlewares can be injected in, reordered, and removed. The stack is compiled into a chain on boot. You can configure the middleware stack in +environment.rb+
+* The +rake middleware+ task has been added to inspect the middleware stack. This is useful for debugging the order of the middleware stack.
+* The integration test runner has been modified to execute the entire middleware and application stack. This makes integration tests perfect for testing Rack middleware.
+* +ActionController::CGIHandler+ is a backwards compatible CGI wrapper around Rack. The +CGIHandler+ is meant to take an old CGI object and convert its environment information into a Rack compatible form.
+* +CgiRequest+ and +CgiResponse+ have been removed
+* Session stores are now lazy loaded. If you never access the session object during a request, it will never attempt to load the session data (parse the cookie, load the data from memcache, or lookup an Active Record object).
+* +CGI::Session::CookieStore+ has been replaced by +ActionController::Session::CookieStore+
+* +CGI::Session::MemCacheStore+ has been replaced by +ActionController::Session::MemCacheStore+
+* +CGI::Session::ActiveRecordStore+ has been replaced by +ActiveRecord::SessionStore+
+* You can still change your session store with +ActionController::Base.session_store = :active_record_store+
+* Default sessions options are still set with +ActionController::Base.session = { :key => "..." }+
+* The mutex that normally wraps your entire request has been moved into middleware, +ActionController::Lock+
+* +ActionController::AbstractRequest+ and +ActionController::Request+ have been unified. The new +ActionController::Request+ inherits from +Rack::Request+. This affects access to +response.headers['type']+ in test requests. Use +response.content_type+ instead.
+* +ActiveRecord::QueryCache+ middleware is automatically inserted onto the middleware stack if +ActiveRecord+ has been loaded. This middleware sets up and flushes the per-request Active Record query cache.
+* The Rails router and controller classes follow the Rack spec. You can call a controller directly with +SomeController.call(env)+. The router stores the routing parameters in +rack.routing_args+.
+* +ActionController::Request+ inherits from +Rack::Request+
+* Instead of +config.action_controller.session = { :session_key => 'foo', ...+ use +config.action_controller.session = { :key => 'foo', ...+
+* Using the +ParamsParser+ middleware preprocesses any XML, JSON, or YAML requests so they can be read normally with any +Rack::Request+ object after it.
+
+h4. Renewed Support for Rails Engines
+
+After some versions without an upgrade, Rails 2.3 offers some new features for Rails Engines (Rails applications that can be embedded within other applications). First, routing files in engines are automatically loaded and reloaded now, just like your +routes.rb+ file (this also applies to routing files in other plugins). Second, if your plugin has an app folder, then app/[models|controllers|helpers] will automatically be added to the Rails load path. Engines also support adding view paths now.
+
+h3. Documentation
+
+The "Ruby on Rails guides":http://guides.rubyonrails.org/ project has published several additional guides for Rails 2.3. In addition, a "separate site":http://guides.rails.info/ maintains updated copies of the Guides for Edge Rails. Other documentation efforts include a relaunch of the "Rails wiki":http://newwiki.rubyonrails.org/ and early planning for a Rails Book.
+
+* More Information: "Rails Documentation Projects":http://weblog.rubyonrails.org/2009/1/15/rails-documentation-projects
+
+h3. Active Record
+
+Active Record gets quite a number of new features and bug fixes in Rails 2.3. The highlights include nested attributes, nested transactions, dynamic scopes, and default scopes.
+
+h4. Nested Attributes
+
+Active Record can now update the attributes on nested models directly, provided you tell it to do so:
+
+<ruby>
+class Book < ActiveRecord::Base
+ has_one :author
+ has_many :pages
+
+ accepts_nested_attributes_for :author, :pages
+end
+</ruby>
+
+Turning on nested attributes enables a number of things: automatic (and atomic) saving of a record together with its associated children, child-aware validations, and support for nested forms (discussed later).
+
+* Lead Contributor: "Eloy Duran":http://www.superalloy.nl/blog/
+* More Information: "Nested Model Forms":http://weblog.rubyonrails.org/2009/1/26/nested-model-forms
+
+h4. Nested Transactions
+
+Active Record now supports nested transactions, a much-requested feature. Now you can write code like this:
+
+<ruby>
+User.transaction do
+ User.create(:username => 'Admin')
+ User.transaction(:requires_new => true) do
+ User.create(:username => 'Regular')
+ raise ActiveRecord::Rollback
+ end
+ end
+
+ User.find(:all) # => Returns only Admin
+</ruby>
+
+Nested transactions let you roll back an inner transaction without affecting the state of the outer transaction. If you want a transaction to be nested, you must explicitly add the +:requires_new+ option; otherwise, a nested transaction simply becomes part of the parent transaction (as it does currently on Rails 2.2). Under the covers, nested transactions are "using savepoints":http://rails.lighthouseapp.com/projects/8994/tickets/383, so they're supported even on databases that don't have true nested transactions. There is also a bit of magic going on to make these transactions play well with transactional fixtures during testing.
+
+* Lead Contributors: "Jonathan Viney":http://www.workingwithrails.com/person/4985-jonathan-viney and "Hongli Lai":http://izumi.plan99.net/blog/
+
+h4. Dynamic Scopes
+
+You know about dynamic finders in Rails (which allow you to concoct methods like +find_by_color_and_flavor+ on the fly) and named scopes (which allow you to encapsulate reusable query conditions into friendly names like +currently_active+). Well, now you can have dynamic scope methods. The idea is to put together syntax that allows filtering on the fly _and_ method chaining. For example:
+
+<ruby>
+Order.scoped_by_customer_id(12)
+Order.scoped_by_customer_id(12).find(:all,
+ :conditions => "status = 'open'")
+Order.scoped_by_customer_id(12).scoped_by_status("open")
+</ruby>
+
+There's nothing to define to use dynamic scopes: they just work.
+
+* Lead Contributor: "Yaroslav Markin":http://evilmartians.com/
+* More Information: "What's New in Edge Rails: Dynamic Scope Methods":http://ryandaigle.com/articles/2008/12/29/what-s-new-in-edge-rails-dynamic-scope-methods.
+
+h4. Default Scopes
+
+Rails 2.3 will introduce the notion of _default scopes_ similar to named scopes, but applying to all named scopes or find methods within the model. For example, you can write +default_scope :order => 'name ASC'+ and any time you retrieve records from that model they'll come out sorted by name (unless you override the option, of course).
+
+* Lead Contributor: Paweł Kondzior
+* More Information: "What's New in Edge Rails: Default Scoping":http://ryandaigle.com/articles/2008/11/18/what-s-new-in-edge-rails-default-scoping
+
+h4. Multiple Conditions for Callbacks
+
+When using Active Record callbacks, you can now combine +:if+ and +:unless+ options on the same callback, and supply multiple conditions as an array:
+
+<ruby>
+before_save :update_credit_rating, :if => :active,
+ :unless => [:admin, :cash_only]
+</ruby>
+* Lead Contributor: L. Caviola
+
+h4. Find with having
+
+Rails now has a +:having+ option on find (as well as on +has_many+ and +has_and_belongs_to_many+ associations) for filtering records in grouped finds. As those with heavy SQL backgrounds know, this allows filtering based on grouped results:
+
+<ruby>
+developers = Developer.find(:all, :group => "salary",
+ :having => "sum(salary) > 10000", :select => "salary")
+</ruby>
+
+* Lead Contributor: "Emilio Tagua":http://github.com/miloops
+
+h4. Hash Conditions for has_many relationships
+
+You can once again use a hash in conditions for a +has_many+ relationship:
+
+<ruby>
+has_many :orders, :conditions => {:status => 'confirmed'}
+</ruby>
+
+That worked in Rails 2.1, fails in Rails 2.2, and will now work again in Rails 2.3 (if you're dealing with this issue in Rails 2.2, you can use a string rather than a hash to specify conditions).
+
+* Lead Contributor: "Frederick Cheung":http://www.spacevatican.org/
+
+h4. Reconnecting MySQL Connections
+
+MySQL supports a reconnect flag in its connections - if set to true, then the client will try reconnecting to the server before giving up in case of a lost connection. You can now set +reconnect = true+ for your MySQL connections in +database.yml+ to get this behavior from a Rails application. The default is +false+, so the behavior of existing applications doesn't change.
+
+* Lead Contributor: "Dov Murik":http://twitter.com/dubek
+* More information:
+** "Controlling Automatic Reconnection Behavior":http://dev.mysql.com/doc/refman/5.0/en/auto-reconnect.html
+** "MySQL auto-reconnect revisited":http://groups.google.com/group/rubyonrails-core/browse_thread/thread/49d2a7e9c96cb9f4
+
+h4. Other Active Record Changes
+
+* An extra +AS+ was removed from the generated SQL for has_and_belongs_to_many preloading, making it work better for some databases.
+* +ActiveRecord::Base#new_record?+ now returns +false+ rather than +nil+ when confronted with an existing record.
+* A bug in quoting table names in some +has_many :through+ associations was fixed.
+* You can now specify a particular timestamp for +updated_at+ timestamps: +cust = Customer.create(:name => "ABC Industries", :updated_at => 1.day.ago)+
+* Better error messages on failed +find_by_attribute!+ calls.
+* Active Record's +to_xml+ support gets just a little bit more flexible with the addition of a +:camelize+ option.
+* A bug in canceling callbacks from +before_update+ or +before_create_ was fixed.
+* Rake tasks for testing databases via JDBC have been added.
+* +validates_length_of+ will use a custom error message with the +:in+ or +:within+ options (if one is supplied)
+
+h3. Action Controller
+
+Action Controller rolls out some significant changes to rendering, as well as improvements in routing and other areas, in this release.
+
+h4. Unified Rendering
+
++ActionController::Base#render+ is a lot smarter about deciding what to render. Now you can just tell it what to render and expect to get the right results. In older versions of Rails, you often need to supply explicit information to render:
+
+<ruby>
+render :file => '/tmp/random_file.erb'
+render :template => 'other_controller/action'
+render :action => 'show'
+</ruby>
+
+Now in Rails 2.3, you can just supply what you want to render:
+
+<ruby>
+render '/tmp/random_file.erb'
+render 'other_controller/action'
+render 'show'
+render :show
+</ruby>
+Rails chooses between file, template, and action depending on whether there is a leading slash, an embedded slash, or no slash at all in what's to be rendered. Note that you can also use a symbol instead of a string when rendering an action. Other rendering styles (+:inline+, +:text+, +:update+, +:nothing+, +:json+, +:xml+, +:js+) still require an explicit option.
+
+h4. Application Controller Renamed
+
+If you're one of the people who has always been bothered by the special-case naming of +application.rb+, rejoice! It's been reworked to be application_controller.rb in Rails 2.3. In addition, there's a new rake task, +rake rails:update:application_controller+ to do this automatically for you - and it will be run as part of the normal +rake rails:update+ process.
+
+* More Information:
+** "The Death of Application.rb":http://afreshcup.com/2008/11/17/rails-2x-the-death-of-applicationrb/
+** "What's New in Edge Rails: Application.rb Duality is no More":http://ryandaigle.com/articles/2008/11/19/what-s-new-in-edge-rails-application-rb-duality-is-no-more
+
+h4. HTTP Digest Authentication Support
+
+Rails now has built-in support for HTTP digest authentication. To use it, you call +authenticate_or_request_with_http_digest+ with a block that returns the user’s password (which is then hashed and compared against the transmitted credentials):
+
+<ruby>
+class PostsController < ApplicationController
+ Users = {"dhh" => "secret"}
+ before_filter :authenticate
+
+ def secret
+ render :text => "Password Required!"
+ end
+
+ private
+ def authenticate
+ realm = "Application"
+ authenticate_or_request_with_http_digest(realm) do |name|
+ Users[name]
+ end
+ end
+end
+</ruby>
+
+* Lead Contributor: "Gregg Kellogg":http://www.kellogg-assoc.com/
+* More Information: "What's New in Edge Rails: HTTP Digest Authentication":http://ryandaigle.com/articles/2009/1/30/what-s-new-in-edge-rails-http-digest-authentication
+
+h4. More Efficient Routing
+
+There are a couple of significant routing changes in Rails 2.3. The +formatted_+ route helpers are gone, in favor just passing in +:format+ as an option. This cuts down the route generation process by 50% for any resource - and can save a substantial amount of memory (up to 100MB on large applications). If your code uses the +formatted_+ helpers, it will still work for the time being - but that behavior is deprecated and your application will be more efficient if you rewrite those routes using the new standard. Another big change is that Rails now supports multiple routing files, not just +routes.rb+. You can use +RouteSet#add_configuration_file+ to bring in more routes at any time - without clearing the currently-loaded routes. While this change is most useful for Engines, you can use it in any application that needs to load routes in batches.
+
+* Lead Contributors: "Aaron Batalion":http://blog.hungrymachine.com/
+
+h4. Rack-based Lazy-loaded Sessions
+
+A big change pushed the underpinnings of Action Controller session storage down to the Rack level. This involved a good deal of work in the code, though it should be completely transparent to your Rails applications (as a bonus, some icky patches around the old CGI session handler got removed). It's still significant, though, for one simple reason: non-Rails Rack applications have access to the same session storage handlers (and therefore the same session) as your Rails applications. In addition, sessions are now lazy-loaded (in line with the loading improvements to the rest of the framework). This means that you no longer need to explicitly disable sessions if you don't want them; just don't refer to them and they won't load.
+
+h4. MIME Type Handling Changes
+
+There are a couple of changes to the code for handling MIME types in Rails. First, +MIME::Type+ now implements the +=~+ operator, making things much cleaner when you need to check for the presence of a type that has synonyms:
+
+<ruby>
+if content_type && Mime::JS =~ content_type
+ # do something cool
+end
+
+Mime::JS =~ "text/javascript" => true
+Mime::JS =~ "application/javascript" => true
+</ruby>
+
+The other change is that the framework now uses the +Mime::JS+ when checking for javascript in various spots, making it handle those alternatives cleanly.
+
+* Lead Contributor: "Seth Fitzsimmons":http://www.workingwithrails.com/person/5510-seth-fitzsimmons
+
+h4. Optimization of +respond_to+
+
+In some of the first fruits of the Rails-Merb team merger, Rails 2.3 includes some optimizations for the +respond_to+ method, which is of course heavily used in many Rails applications to allow your controller to format results differently based on the MIME type of the incoming request. After eliminating a call to +method_missing+ and some profiling and tweaking, we're seeing an 8% improvement in the number of requests per second served with a simple +respond_to+ that switches between three formats. The best part? No change at all required to the code of your application to take advantage of this speedup.
+
+h4. Improved Caching Performance
+
+Rails now keeps a per-request local cache of requests, cutting down on unnecessary reads and leading to better site performance. While this work was originally limited to +MemCacheStore+, it is available to any remote store than implements the required methods.
+
+* Lead Contributor: "Nahum Wild":http://www.motionstandingstill.com/
+
+h4. Localized Views
+
+Rails can now provide localized views, depending on the locale that you have set. For example, suppose you have a +Posts+ controller with a +show+ action. By default, this will render +app/views/posts/show.html.erb+. But if you set +I18n.locale = :da+, it will render +app/views/posts/show.da.html.erb+. If the localized template isn't present, the undecorated version will be used. Rails also includes +I18n#available_locales+ and +I18n::SimpleBackend#available_locales+, which return an array of the translations that are available in the current Rails project.
+
+h4. Other Action Controller Changes
+
+* ETag handling has been cleaned up a bit: Rails will now skip sending an ETag header when there's no body to the response or when sending files with +send_file+.
+* The fact that Rails checks for IP spoofing can be a nuisance for sites that do heavy traffic with cell phones, because their proxies don't generally set things up right. If that's you, you can now set +ActionController::Base.ip_spoofing_check = false+ to disable the check entirely.
+* +ActionController::Dispatcher+ now implements its own middleware stack, which you can see by running +rake middleware+.
+* Cookie sessions now have persistent session identifiers, with API compatibility with the server-side stores.
+* You can now use symbols for the +:type+ option of +send_file+ and +send_data+, like this: +send_file("fabulous.png", :type => :png)+.
+* The +:only+ and +:except+ options for +map.resources+ are no longer inherited by nested resources.
+
+h3. Action View
+
+Action View in Rails 2.3 picks up nested model forms, improvements to +render+, more flexible prompts for the date select helpers, and a speedup in asset caching, among other things.
+
+h4. Nested Object Forms
+
+Provided the parent model accepts nested attributes for the child objects (as discussed in the Active Record section), you can create nested forms using +form_for+ and +field_for+. These forms can be nested arbitrarily deep, allowing you to edit complex object hierarchies on a single view without excessive code. For example, given this model:
+
+<ruby>
+class Customer < ActiveRecord::Base
+ has_many :orders
+
+ accepts_nested_attributes_for :orders, :allow_destroy => true
+end
+</ruby>
+
+You can write this view in Rails 2.3:
+
+<erb>
+<% form_for @customer do |customer_form| %>
+ <div>
+ <%= customer_form.label :name, 'Customer Name:' %>
+ <%= customer_form.text_field :name %>
+ </div>
+
+ <!-- Here we call fields_for on the customer_form builder instance.
+ The block is called for each member of the orders collection. -->
+ <% customer_form.fields_for :orders do |order_form| %>
+ <p>
+ <div>