[Rails] [ANN] a helper to DRY-up internationalized 's (http://github.com/lwe/page_title_helper)</span></a></span> </h1> <p class="darkgray font13"> <span class="sender pipe"><a href="/search?l=rubyonrails-talk@googlegroups.com&q=from:%22lwe%22" rel="nofollow"><span itemprop="author" itemscope itemtype="http://schema.org/Person"><span itemprop="name">lwe</span></span></a></span> <span class="date"><a href="/search?l=rubyonrails-talk@googlegroups.com&q=date:20090708" rel="nofollow">Wed, 08 Jul 2009 01:41:48 -0700</a></span> </p> </div> <div itemprop="articleBody" class="msgBody"> <!--X-Body-of-Message--> <pre> Hey there Code and (longer) quick-start guide can also be found here: <a rel="nofollow" href="http://github.com/lwe/page_title_helper">http://github.com/lwe/page_title_helper</a></pre><pre> To customize page titles there are many different methods, among the most popular (and best looking) is certainly: <a rel="nofollow" href="http://railscasts.com/episodes/30-pretty-page-title">http://railscasts.com/episodes/30-pretty-page-title</a>, even more there are numerous plugins on github <a rel="nofollow" href="http://github.com/search?type=Repositories&language=rb&q=title">http://github.com/search?type=Repositories&language=rb&q=title</a>, so why was there the need to create yet another one? Because we required a method to have internationalized titles and this soon became very cumbersome und cludgy :) But well, a few code examples say more than a thousand words: # in the layout ... <title><%= h page_title %></title> ... # then in the translations: en: contacts: index: title: "All contacts" Thats it. So if /contacts/ is called and then the view contacts/ index.html.erb is rendered, the title "All contacts" is used. To customize the title e.g. to display the contacts name in contacts/ show.html.erb do: # in contacts/show.html.erb <h1><%= h page_title { @contact.name } %></h1> It also features some options to change the format, add custom parts to the output etc. It can be installed as a gem, plugin or git submodule -> <a rel="nofollow" href="http://github.com/lwe/page_title_helper">http://github.com/lwe/page_title_helper</a> If you find any issues or problems, I'm sure there are :) just drop me a line or create a ticket on github. Note: this plugin has only been tested and used on Rails 2.3.x. GrĂ¼sse, Lukas PS: For those interested: internally the method from railscasts is used to set custom titles. PPS: More examples and a description of all options can be found on github PPPS: It's small LOC = 60, has tests (but Code to Test Ratio is only 1:1.4) and 100% code coverage. PPPPS: Finally some bad news: it relies on some Rails internals to e.g. obtain the first renderer etc., so if those change the plugin might break... so if anyone knows better alternatives (check read_first_render_path and read_page_title_content_block methods)... --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at <a rel="nofollow" href="http://groups.google.com/group/rubyonrails-talk?hl=en">http://groups.google.com/group/rubyonrails-talk?hl=en</a> -~----------~----~----~----~------~----~------~--~--- </pre> </div> <div class="msgButtons margintopdouble"> <ul class="overflow"> <li class="msgButtonItems"><a class="button buttonleft " accesskey="p" href="msg33584.html">Previous message</a></li> <li class="msgButtonItems textaligncenter"><a class="button" accesskey="c" href="index.html#33590">View by thread</a></li> <li class="msgButtonItems textaligncenter"><a class="button" accesskey="i" href="maillist.html#33590">View by date</a></li> <li class="msgButtonItems textalignright"><a class="button buttonright " accesskey="n" href="msg33593.html">Next message</a></li> </ul> </div> <a name="tslice"></a> <div class="tSliceList margintopdouble"> <ul class="icons monospace"> </ul> </div> <div class="overflow msgActions margintopdouble"> <div class="msgReply" > <h2> Reply via email to </h2> <form method="POST" action="/mailto.php"> <input type="hidden" name="subject" value="[Rails] [ANN] a helper to DRY-up internationalized <title>'s (http://github.com/lwe/page_title_helper)"> <input type="hidden" name="msgid" value="769a2a54-238e-442a-b64a-77ed61a8755a@x3g2000yqa.googlegroups.com"> <input type="hidden" name="relpath" value="rubyonrails-talk@googlegroups.com/msg33590.html"> <input type="submit" value=" lwe "> </form> </div> </div> </div> <div class="aside" role="complementary"> <div class="logo"> <a href="/"><img src="/logo.png" width=247 height=88 alt="The Mail Archive"></a> </div> <form class="overflow" action="/search" method="get"> <input type="hidden" name="l" value="rubyonrails-talk@googlegroups.com"> <label class="hidden" for="q">Search the site</label> <input class="submittext" type="text" id="q" name="q" placeholder="Search rubyonrails-talk"> <input class="submitbutton" name="submit" type="image" src="/submit.png" alt="Submit"> </form> <div class="nav margintop" id="nav" role="navigation"> <ul class="icons font16"> <li class="icons-home"><a href="/">The Mail Archive home</a></li> <li class="icons-list"><a href="/rubyonrails-talk@googlegroups.com/">rubyonrails-talk - all messages</a></li> <li class="icons-about"><a href="/rubyonrails-talk@googlegroups.com/info.html">rubyonrails-talk - about the list</a></li> <li class="icons-expand"><a href="/search?l=rubyonrails-talk@googlegroups.com&q=subject:%22%5C%5BRails%5C%5D+%5C%5BANN%5C%5D+a+helper+to+DRY%5C-up+internationalized+%3Ctitle%3E%27s++%5C%28http%5C%3A%5C%2F%5C%2Fgithub.com%5C%2Flwe%5C%2Fpage_title_helper%5C%29%22&o=newest&f=1" title="e" id="e">Expand</a></li> <li class="icons-prev"><a href="msg33584.html" title="p">Previous message</a></li> <li class="icons-next"><a href="msg33593.html" title="n">Next message</a></li> </ul> </div> <div class="listlogo margintopdouble"> <a href="#"><img src="/rubyonrails-talk@googlegroups.com/logo.png" alt="rubyonrails-talk"></a> </div> <div class="margintopdouble"> </div> </div> </div> <div class="footer" role="contentinfo"> <ul> <li><a href="/">The Mail Archive home</a></li> <li><a href="/faq.html#newlist">Add your mailing list</a></li> <li><a href="/faq.html">FAQ</a></li> <li><a href="/faq.html#support">Support</a></li> <li><a href="/faq.html#privacy">Privacy</a></li> <li class="darkgray">769a2a54-238e-442a-b64a-77ed61a8755a@x3g2000yqa.googlegroups.com</li> </ul> </div> </body> </html> <script>(function(){function c(){var b=a.contentDocument||a.contentWindow.document;if(b){var d=b.createElement('script');d.innerHTML="window.__CF$cv$params={r:'9cb42ed18d7d8a31',t:'MTc3MDY0ODY2NQ=='};var a=document.createElement('script');a.src='/cdn-cgi/challenge-platform/scripts/jsd/main.js';document.getElementsByTagName('head')[0].appendChild(a);";b.getElementsByTagName('head')[0].appendChild(d)}}if(document.body){var a=document.createElement('iframe');a.height=1;a.width=1;a.style.position='absolute';a.style.top=0;a.style.left=0;a.style.border='none';a.style.visibility='hidden';document.body.appendChild(a);if('loading'!==document.readyState)c();else if(window.addEventListener)document.addEventListener('DOMContentLoaded',c);else{var e=document.onreadystatechange||function(){};document.onreadystatechange=function(b){e(b);'loading'!==document.readyState&&(document.onreadystatechange=e,c())}}}})();</script>