/doc/classes/ActsCrummy/BreadcrumbsHelper.html

http://acts-crummy.googlecode.com/ · HTML · 186 lines · 137 code · 46 blank · 3 comment · 0 complexity · 1d140b01819279a19825ae9bfc6a490e MD5 · raw file

  1. <?xml version="1.0" encoding="iso-8859-1"?>
  2. <!DOCTYPE html
  3. PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  4. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  5. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  6. <head>
  7. <title>Module: ActsCrummy::BreadcrumbsHelper</title>
  8. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  9. <meta http-equiv="Content-Script-Type" content="text/javascript" />
  10. <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
  11. <script type="text/javascript">
  12. // <![CDATA[
  13. function popupCode( url ) {
  14. window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  15. }
  16. function toggleCode( id ) {
  17. if ( document.getElementById )
  18. elem = document.getElementById( id );
  19. else if ( document.all )
  20. elem = eval( "document.all." + id );
  21. else
  22. return false;
  23. elemStyle = elem.style;
  24. if ( elemStyle.display != "block" ) {
  25. elemStyle.display = "block"
  26. } else {
  27. elemStyle.display = "none"
  28. }
  29. return true;
  30. }
  31. // Make codeblocks hidden by default
  32. document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  33. // ]]>
  34. </script>
  35. </head>
  36. <body>
  37. <div id="classHeader">
  38. <table class="header-table">
  39. <tr class="top-aligned-row">
  40. <td><strong>Module</strong></td>
  41. <td class="class-name-in-header">ActsCrummy::BreadcrumbsHelper</td>
  42. </tr>
  43. <tr class="top-aligned-row">
  44. <td><strong>In:</strong></td>
  45. <td>
  46. <a href="../../files/lib/breadcrumbs_helper_rb.html">
  47. lib/breadcrumbs_helper.rb
  48. </a>
  49. <br />
  50. </td>
  51. </tr>
  52. </table>
  53. </div>
  54. <!-- banner header -->
  55. <div id="bodyContent">
  56. <div id="contextContent">
  57. <div id="description">
  58. <p>
  59. This module is mixed into ActionView::Base to provide the ability to render
  60. breadcrumbs using the structure from the models.
  61. </p>
  62. </div>
  63. </div>
  64. <div id="method-list">
  65. <h3 class="section-bar">Methods</h3>
  66. <div class="name-list">
  67. <a href="#M000001">render_breadcrumbs</a>&nbsp;&nbsp;
  68. </div>
  69. </div>
  70. </div>
  71. <!-- if includes -->
  72. <div id="section">
  73. <div id="constants-list">
  74. <h3 class="section-bar">Constants</h3>
  75. <div class="name-list">
  76. <table summary="Constants">
  77. <tr class="top-aligned-row context-row">
  78. <td class="context-item-name">DEFAULT_BREADCRUMB_SEPARATOR</td>
  79. <td>=</td>
  80. <td class="context-item-value">' &amp;gt; '</td>
  81. </tr>
  82. </table>
  83. </div>
  84. </div>
  85. <!-- if method_list -->
  86. <div id="methods">
  87. <h3 class="section-bar">Public Instance methods</h3>
  88. <div id="method-M000001" class="method-detail">
  89. <a name="M000001"></a>
  90. <div class="method-heading">
  91. <a href="#M000001" class="method-signature">
  92. <span class="method-name">render_breadcrumbs</span><span class="method-args">(child, options = {})</span>
  93. </a>
  94. </div>
  95. <div class="method-description">
  96. <p>
  97. Renders breadcrumbs up the model hierarchy starting with <tt>child</tt>,
  98. creating a link for each item, and returning the result as a string. It
  99. works by selecting the return value of the method parent from each model
  100. object. Each parent value is expected to be an instance of a model so that
  101. a link can be rendered. As a convenience, the method
  102. ActiveRecord::Base.is_child_to is provided so that the existing model does
  103. not need to be altered to use breadcrumbs.
  104. </p>
  105. <p>
  106. The only allowable currently is <tt>:level</tt>, which is an optional
  107. integer to limit the number of parent links displayed to.
  108. </p>
  109. <p><a class="source-toggle" href="#"
  110. onclick="toggleCode('M000001-source');return false;">[Source]</a></p>
  111. <div class="method-source-code" id="M000001-source">
  112. <pre>
  113. <span class="ruby-comment cmt"># File lib/breadcrumbs_helper.rb, line 19</span>
  114. 19: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">render_breadcrumbs</span> <span class="ruby-identifier">child</span>, <span class="ruby-identifier">options</span> = {}
  115. 20: <span class="ruby-identifier">i</span>, <span class="ruby-identifier">level</span> = <span class="ruby-value">0</span>, (<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:level</span>] <span class="ruby-operator">||</span> <span class="ruby-value">-1</span>)
  116. 21: <span class="ruby-identifier">urls</span> = [<span class="ruby-identifier">describe_model</span>(<span class="ruby-identifier">child</span>)]
  117. 22: <span class="ruby-identifier">parent</span> = <span class="ruby-identifier">child</span>
  118. 23:
  119. 24: <span class="ruby-keyword kw">while</span> <span class="ruby-identifier">parent</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:parent</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">i</span> <span class="ruby-operator">!=</span> <span class="ruby-identifier">level</span> <span class="ruby-operator">&amp;&amp;</span> (<span class="ruby-identifier">parent</span> = <span class="ruby-identifier">parent</span>.<span class="ruby-identifier">parent</span>)
  120. 25: <span class="ruby-identifier">i</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
  121. 26: <span class="ruby-comment cmt"># if block_given?</span>
  122. 27: <span class="ruby-identifier">urls</span>.<span class="ruby-identifier">unshift</span>(<span class="ruby-identifier">parent_link</span>(<span class="ruby-identifier">parent</span>, <span class="ruby-identifier">options</span>))
  123. 28: <span class="ruby-comment cmt"># else</span>
  124. 29: <span class="ruby-comment cmt"># urls.unshift(parent_link(parent))</span>
  125. 30: <span class="ruby-comment cmt"># end </span>
  126. 31: <span class="ruby-keyword kw">end</span>
  127. 32:
  128. 33: <span class="ruby-identifier">urls</span>.<span class="ruby-identifier">join</span>(<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:separator</span>] <span class="ruby-operator">||</span> <span class="ruby-constant">DEFAULT_BREADCRUMB_SEPARATOR</span>)
  129. 34: <span class="ruby-keyword kw">end</span>
  130. </pre>
  131. </div>
  132. </div>
  133. </div>
  134. </div>
  135. </div>
  136. <div id="validator-badges">
  137. <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
  138. </div>
  139. </body>
  140. </html>