<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>funkensturm. &#187; plugins</title>
	<atom:link href="http://funkensturm.de/category/ruby-on-rails/plugins/feed/" rel="self" type="application/rss+xml" />
	<link>http://funkensturm.de</link>
	<description>Das funkensturm. Weblog</description>
	<lastBuildDate>Tue, 15 Nov 2011 15:04:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>XML Sitemap Generator for&#160;Rails</title>
		<link>http://funkensturm.de/2010/01/10/xml-sitemap-generator-for-rails/</link>
		<comments>http://funkensturm.de/2010/01/10/xml-sitemap-generator-for-rails/#comments</comments>
		<pubDate>Sat, 09 Jan 2010 22:56:52 +0000</pubDate>
		<dc:creator>manuel</dc:creator>
				<category><![CDATA[plugins]]></category>
		<category><![CDATA[resources]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[GitHub]]></category>
		<category><![CDATA[Google Sitemaps]]></category>
		<category><![CDATA[Plugin]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[XML Sitemaps]]></category>

		<guid isPermaLink="false">http://blog.funkensturm.de/?p=263</guid>
		<description><![CDATA[I realy like the way the Google (XML) Sitemaps Generator for WordPress handles the generation of my sitemaps and informs Google about the changes on my blog. I was missing this in the Rails world for a long time, so I decided to build my own Rails plugin. Here it is: &#8220;XML Sitemap Generator for [...]]]></description>
			<content:encoded><![CDATA[<p>I realy like the way the <a href="http://www.arnebrachhold.de/projects/wordpress-plugins/google-xml-sitemaps-generator/" title="Google (XML) Sitemaps Generator for WordPress" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.arnebrachhold.de/projects/wordpress-plugins/google-xml-sitemaps-generator/?referer=');">Google (XML) Sitemaps Generator for WordPress</a> handles the generation of my sitemaps and informs Google about the changes on my blog.</p>
<p>I was missing this in the Rails world for a long time, so I decided to build my own Rails plugin.</p>
<p>Here it is: <a href="http://github.com/fsmanuel/xml_sitemap_generator" title="XML Sitemap Generator for Rails" target="_blank" onclick="pageTracker._trackPageview('/outgoing/github.com/fsmanuel/xml_sitemap_generator?referer=');">&#8220;XML Sitemap Generator for Rails&#8221;</a></p>
<p>It&#8217;s just a quick implementation of all the functionality you need to let your Rails App generate a XML Sitemap and ping Google about the updates.<br />
It&#8217;s not made to be scale more to give your small site the abillitiy to have a sitemap.</p>
<p>I&#8217;ll work on it in the future to make it easy to add some custom URL&#8217;s and maybe to have a version to scale&#8230;</p>
<p>Check it out on: <a href="http://github.com/fsmanuel/xml_sitemap_generator" title="XML Sitemap Generator for Rails @ GitHub.com" target="_blank" onclick="pageTracker._trackPageview('/outgoing/github.com/fsmanuel/xml_sitemap_generator?referer=');">GitHub</a><br />
If you have any suggestions fork the project and send me a pull request.</p>
]]></content:encoded>
			<wfw:commentRss>http://funkensturm.de/2010/01/10/xml-sitemap-generator-for-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>render_nested_form&#160;Helper</title>
		<link>http://funkensturm.de/2009/08/27/render_nested_form-helper/</link>
		<comments>http://funkensturm.de/2009/08/27/render_nested_form-helper/#comments</comments>
		<pubDate>Thu, 27 Aug 2009 16:57:06 +0000</pubDate>
		<dc:creator>manuel</dc:creator>
				<category><![CDATA[plugins]]></category>
		<category><![CDATA[Rails 2.3]]></category>
		<category><![CDATA[resources]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[accepts_nested_attributes_for]]></category>
		<category><![CDATA[nested forms]]></category>
		<category><![CDATA[render_nested_form]]></category>

		<guid isPermaLink="false">http://blog.funkensturm.de/?p=216</guid>
		<description><![CDATA[Die in Rails 2.3 eingeführten Nested Forms haben mir am Anfang sehr viele Kopfschmerzen bereitet und tun dies immer mal wieder. Dank schorsch vom SalesKing muss ich mir um diese Dinge keine Sorgen mehr machen. Sein render_nested_form Helper übernimmt alles und hat ein paar sehr nette Options. # Options are: # * &#60;tt&#62;:new&#60;/tt&#62; - specify [...]]]></description>
			<content:encoded><![CDATA[<p>Die in Rails 2.3 eingeführten Nested Forms haben mir am Anfang sehr viele Kopfschmerzen bereitet und tun dies immer mal wieder.</p>
<p>Dank schorsch vom <a href="http://www.salesking.eu" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.salesking.eu?referer=');">SalesKing</a> muss ich mir um diese Dinge keine Sorgen mehr machen.<br />
Sein <a href="http://gist.github.com/134652" target="_blank" onclick="pageTracker._trackPageview('/outgoing/gist.github.com/134652?referer=');">render_nested_form Helper</a> übernimmt alles und hat ein paar sehr nette Options.</p>

<div class="wp_syntax"><div class="code"><pre class="rails" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># Options are:</span>
<span style="color:#008000; font-style:italic;"># * &lt;tt&gt;:new&lt;/tt&gt; - specify a certain number of new elements to be added to the form. Useful for displaying a few blank elements at the bottom.</span>
<span style="color:#008000; font-style:italic;"># * &lt;tt&gt;:name&lt;/tt&gt; - override the name of the association, both for the field names, and the name of the partial</span>
<span style="color:#008000; font-style:italic;"># * &lt;tt&gt;:partial&lt;/tt&gt; - specify the name of the partial in which the form is located.</span>
<span style="color:#008000; font-style:italic;"># * &lt;tt&gt;:fields_for&lt;/tt&gt; - specify additional options for the fields_for_associated call</span>
<span style="color:#008000; font-style:italic;"># * &lt;tt&gt;:locals&lt;/tt&gt; - specify additional variables to be passed along to the partial</span>
<span style="color:#008000; font-style:italic;"># * &lt;tt&gt;:render&lt;/tt&gt; - specify additional options to be passed along to the render :partial call</span>
<span style="color:#008000; font-style:italic;"># * &lt;tt&gt;:skip&lt;/tt&gt; - array of elements which will be skipped, usefull if you already rendered a partial in the same form with parts of the data. eg. obj.addresses, render the firt address on top of form, render all the other addresses at the bottom</span>
&nbsp;
f.<span style="color:#9900CC;">render_nested_form</span><span style="color:#006600; font-weight:bold;">&#40;</span>@project.<span style="color:#9900CC;">tasks</span>, :<span style="color:#5A0A0A; font-weight:bold;">new</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">3</span>, <span style="color:#ff3333; font-weight:bold;">:partial</span><span style="color:#006600; font-weight:bold;">=&gt;</span><span style="color:#996600;">'some_partial'</span>, <span style="color:#ff3333; font-weight:bold;">:locals</span><span style="color:#006600; font-weight:bold;">=&gt;</span>..<span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p><strong>Update:</strong><br />
Ich hab den Helper geforked und die Option :as hinzugefügt. Damit kann man den Namen der lokalen Variable definieren, wenn man den Partial z.B. für unterschiedliche Objekte und Attribute nutzt (bei mir ist das ein Upload Form).<br />
Hier findet ihr den <a href="http://gist.github.com/193443" target="_blank" onclick="pageTracker._trackPageview('/outgoing/gist.github.com/193443?referer=');">Fork</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://funkensturm.de/2009/08/27/render_nested_form-helper/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Funkenrailsdav: Webdav with Rails e.g. for&#160;ical</title>
		<link>http://funkensturm.de/2009/06/08/funkenrailsdav-webdav-with-rails-eg-for-ical/</link>
		<comments>http://funkensturm.de/2009/06/08/funkenrailsdav-webdav-with-rails-eg-for-ical/#comments</comments>
		<pubDate>Mon, 08 Jun 2009 20:14:33 +0000</pubDate>
		<dc:creator>Captain Future</dc:creator>
				<category><![CDATA[plugins]]></category>
		<category><![CDATA[Rails 2.3]]></category>
		<category><![CDATA[resources]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[abonemment]]></category>
		<category><![CDATA[abonnieren]]></category>
		<category><![CDATA[ical]]></category>
		<category><![CDATA[icalendar]]></category>
		<category><![CDATA[publish]]></category>
		<category><![CDATA[railsdav]]></category>
		<category><![CDATA[synchronisieren]]></category>
		<category><![CDATA[synchronize]]></category>
		<category><![CDATA[webdav]]></category>

		<guid isPermaLink="false">http://blog.funkensturm.de/?p=189</guid>
		<description><![CDATA[So you want a rails application to give you a webdav? Good, railsdav can do this for you. However, it might take you an hour or two as well to figure out how it works :) This plugin is a copy of the original railsdav plugin with some modifications to make it run out-of-the-box. Just [...]]]></description>
			<content:encoded><![CDATA[<p>So you want a rails application to give you a webdav? Good, <a href="http://github.com/stueccles/railsdav" onclick="pageTracker._trackPageview('/outgoing/github.com/stueccles/railsdav?referer=');">railsdav</a> can do this for you. However, it might take you an hour or two as well to figure out how it works :)</p>
<p>This plugin is a copy of the original railsdav plugin with some modifications to make it run out-of-the-box. Just drop this plugin into your newly created rails application and it becomes a webdav-server. It comes with Authentication, so you can publish and synchronize your ical-files without fear :)</p>
<p>This was done using Rails 2.3.2.</p>
<p>Get it here: <a href="http://github.com/funkensturm/railsdav" onclick="pageTracker._trackPageview('/outgoing/github.com/funkensturm/railsdav?referer=');">http://github.com/funkensturm/railsdav</a></p>
]]></content:encoded>
			<wfw:commentRss>http://funkensturm.de/2009/06/08/funkenrailsdav-webdav-with-rails-eg-for-ical/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Presenting: The Funkengallery Demo&#160;App</title>
		<link>http://funkensturm.de/2009/02/19/presenting-the-funkengallery-demo-app/</link>
		<comments>http://funkensturm.de/2009/02/19/presenting-the-funkengallery-demo-app/#comments</comments>
		<pubDate>Thu, 19 Feb 2009 21:14:54 +0000</pubDate>
		<dc:creator>Captain Future</dc:creator>
				<category><![CDATA[introducing]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[Rails 2.3]]></category>
		<category><![CDATA[resources]]></category>
		<category><![CDATA[funkengallery]]></category>

		<guid isPermaLink="false">http://blog.funkensturm.de/?p=180</guid>
		<description><![CDATA[Still in beta mode, but we are proud to present a Rails 2.3 application, modularized in plugins, fully I18n (German, English, Swedish), and of course published at github. This funkengallery demo application includes demonstration of all our plugins: acts_as_category acts_as_identifiable funkengallery funkenlogin funkenlogin irobot manipulify Again, this is beta still, which means that for example [...]]]></description>
			<content:encoded><![CDATA[<p>Still in beta mode, but we are proud to present a <strong>Rails 2.3</strong> application, modularized in plugins, fully I18n (German, English, Swedish), and of course published at <a href="http://www.github.com/funkensturm" onclick="pageTracker._trackPageview('/outgoing/www.github.com/funkensturm?referer=');">github</a>.</p>
<p>This funkengallery demo application includes demonstration of all our plugins:</p>
<ul>
<li>acts_as_category</li>
<li>acts_as_identifiable</li>
<li>funkengallery</li>
<li>funkenlogin</li>
<li>funkenlogin</li>
<li>irobot</li>
<li>manipulify</li>
</ul>
<p>Again, this is beta still, which means that for example the admin area wants your models to be called exactly &#8220;Category&#8221; and &#8220;User&#8221;. So not 100% modularized yet, but we&#8217;re getting there and you can already use it as a perfect standalone application ;)</p>
<p>What&#8217;s so special about this gallery is the very dynamic user rights management and the simplicity. It is designed for a complex category tree with many thousands of pictures. However, you might expect flickr design and you get&#8230; well&#8230; funkengallery. It is different and simpler, but really neat if you want to share your pictures quick, private and with individual user rights.</p>
<h4>Screenshots and Demo</h4>
<p>Check out our <a href="http://blog.funkensturm.de/downloads/">Downloads</a> site to see how you can easily test your local demo.</p>
]]></content:encoded>
			<wfw:commentRss>http://funkensturm.de/2009/02/19/presenting-the-funkengallery-demo-app/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FINALLY! RailsICalendar ical ics publish with ruby on&#160;rails</title>
		<link>http://funkensturm.de/2008/02/10/finally-railsicalendar-ical-ics-publish-with-ruby-on-rails/</link>
		<comments>http://funkensturm.de/2008/02/10/finally-railsicalendar-ical-ics-publish-with-ruby-on-rails/#comments</comments>
		<pubDate>Sat, 09 Feb 2008 23:05:39 +0000</pubDate>
		<dc:creator>Captain Future</dc:creator>
				<category><![CDATA[introducing]]></category>
		<category><![CDATA[mac os x]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[resources]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[ical]]></category>
		<category><![CDATA[icalendar]]></category>
		<category><![CDATA[occurences]]></category>
		<category><![CDATA[ocurrs_within]]></category>
		<category><![CDATA[publish]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[recurrence]]></category>
		<category><![CDATA[rrule]]></category>
		<category><![CDATA[vpim]]></category>
		<category><![CDATA[webdav]]></category>

		<guid isPermaLink="false">http://blog.funkensturm.de/2008/02/10/finally-railsicalendar-ical-ics-publish-with-ruby-on-rails/</guid>
		<description><![CDATA[Das hat echt was Nerven gekostet, aber ich bin mehr als zufrieden mit dem Resultat. Ich darf vorstellen: Wenn man seinen Kalender in Mac OS X (z. B. per Webdav) auf seinen Server lädt (bzw. synchronisiert) und auf diesem Server auch Ruby on Rails läuft, dann kann man seinen Kalender jetzt auf seiner Webseite veröffentlichen. [...]]]></description>
			<content:encoded><![CDATA[<p>Das hat echt was Nerven gekostet, aber ich bin mehr als zufrieden mit dem Resultat.</p>
<p>Ich darf vorstellen: Wenn man seinen Kalender in Mac OS X (z. B. per Webdav) auf seinen Server lädt (bzw. synchronisiert) und auf diesem Server auch Ruby on Rails läuft, dann kann man seinen Kalender jetzt auf seiner Webseite veröffentlichen.</p>
<p>In fact I just realize I should better speak english, because someone&#8217;s German might be somewhat rusty :)</p>
<p>So again: You have ics files on your server (e.g. via webdav) and Ruby on Rails is running? Great, let&#8217;s publish your calendar. The idea came from the great PHPicalendar script.</p>
<p>This is what it will somewhat look like:<br />
<a href='http://blog.funkensturm.de/wp-content/uploads/2008/02/bild-1.png' title='bild-1.png'><img src='http://blog.funkensturm.de/wp-content/uploads/2008/02/bild-1.thumbnail.png' alt='bild-1.png' /></a></p>
<p>I am sorry to not have made a plugin out of this yet, but, hey, the basics are there, help yourself :) If you have any questions feel free to comment.</p>
<p>Requirements:</p>
<ul>
<li>Vpim plugin with <code>sudo gem install vpim</code></li>
</ul>
<p>Features:</p>
<ul>
<li>Read several ICS files from a directory on the server</li>
<li>Parse all the ical events in them</li>
<li>Cache the current calendar in yaml files</li>
<li>(The cache will be refreshed when a ICS file was updated meanwhile)</li>
<li>HTML will be presented for the calendar</li>
<li>Currently you can only choose a date and see the next X days</li>
</ul>
<p><b>A word on recurrence of events</b></p>
<ul>
<li>It does do most of the recurrence rules!</li>
<li>Specifically: All that <a href="http://vpim.rubyforge.org/" onclick="pageTracker._trackPageview('/outgoing/vpim.rubyforge.org/?referer=');">VPIM</a> supports</li>
<li><b>PLUS:</b> EXDATE is also supported!</li>
</ul>
<p><strong>The Code</strong></p>
<p><strong><em>Initializer</em></strong> (config/initializers/any_filename.rb)</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="rails" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># Path to icalendar *.ics files on your server</span>
PATH_ICS       = <span style="color:#996600;">&quot;#{RAILS_ROOT}/private/calendars/&quot;</span>
PATH_ICS_CACHE = <span style="color:#996600;">&quot;#{RAILS_ROOT}/tmp/calendars/&quot;</span>
<span style="color:#CC00FF; font-weight:bold;">FileUtils</span>::mkdir_p<span style="color:#006600; font-weight:bold;">&#40;</span>PATH_ICS<span style="color:#006600; font-weight:bold;">&#41;</span>       <span style="color:#9966CC; font-weight:bold;">unless</span> <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">exists</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>PATH_ICS<span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#CC00FF; font-weight:bold;">FileUtils</span>::mkdir_p<span style="color:#006600; font-weight:bold;">&#40;</span>PATH_ICS_CACHE<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">unless</span> <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">exists</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>PATH_ICS_CACHE<span style="color:#006600; font-weight:bold;">&#41;</span></pre></td></tr></table></div>

<p><strong><em>Controller</em></strong> (app/controllers/calendars_controller.rb)</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
</pre></td><td class="code"><pre class="rails" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'vpim'</span>
<span style="color:#9966CC; font-weight:bold;">class</span> CalendarsController <span style="color:#006600; font-weight:bold;">&lt;</span> ApplicationController
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> index
    <span style="color:#008000; font-style:italic;"># Load parameters if submitted</span>
    <span style="color:#5A0A0A; font-weight:bold;">session</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:date_year</span><span style="color:#006600; font-weight:bold;">&#93;</span>  = params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:options</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;date(1i)&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#9966CC; font-weight:bold;">if</span> !params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:options</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">blank</span>? <span style="color:#006600; font-weight:bold;">&amp;&amp;</span> !params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:options</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;date(1i)&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">empty</span>?
    <span style="color:#5A0A0A; font-weight:bold;">session</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:date_month</span><span style="color:#006600; font-weight:bold;">&#93;</span> = params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:options</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;date(2i)&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#9966CC; font-weight:bold;">if</span> !params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:options</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">blank</span>? <span style="color:#006600; font-weight:bold;">&amp;&amp;</span> !params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:options</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;date(2i)&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">empty</span>?
    <span style="color:#5A0A0A; font-weight:bold;">session</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:date_day</span><span style="color:#006600; font-weight:bold;">&#93;</span>   = params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:options</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;date(3i)&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#9966CC; font-weight:bold;">if</span> !params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:options</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">blank</span>? <span style="color:#006600; font-weight:bold;">&amp;&amp;</span> !params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:options</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;date(3i)&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">empty</span>?
&nbsp;
    <span style="color:#008000; font-style:italic;"># Load standard if nothing submitted</span>
    <span style="color:#5A0A0A; font-weight:bold;">session</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:date_year</span><span style="color:#006600; font-weight:bold;">&#93;</span>  = <span style="color:#CC00FF; font-weight:bold;">Time</span>.<span style="color:#9900CC;">now</span>.<span style="color:#9900CC;">year</span>  <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#5A0A0A; font-weight:bold;">session</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:date_year</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">blank</span>?
    <span style="color:#5A0A0A; font-weight:bold;">session</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:date_month</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#CC00FF; font-weight:bold;">Time</span>.<span style="color:#9900CC;">now</span>.<span style="color:#5A0A0A; font-weight:bold;">month</span> <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#5A0A0A; font-weight:bold;">session</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:date_month</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">blank</span>?
    <span style="color:#5A0A0A; font-weight:bold;">session</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:date_day</span><span style="color:#006600; font-weight:bold;">&#93;</span>   = <span style="color:#CC00FF; font-weight:bold;">Time</span>.<span style="color:#9900CC;">now</span>.<span style="color:#5A0A0A; font-weight:bold;">day</span>   <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#5A0A0A; font-weight:bold;">session</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:date_day</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">blank</span>?
&nbsp;
    <span style="color:#008000; font-style:italic;"># Set variables</span>
    <span style="color:#0066ff; font-weight:bold;">@scope</span>     = <span style="color:#006666;">7</span>
    <span style="color:#0066ff; font-weight:bold;">@events</span>   = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span>
    <span style="color:#0066ff; font-weight:bold;">@today</span>    = <span style="color:#CC00FF; font-weight:bold;">Time</span>.<span style="color:#9900CC;">gm</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#5A0A0A; font-weight:bold;">session</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:date_year</span><span style="color:#006600; font-weight:bold;">&#93;</span>, <span style="color:#5A0A0A; font-weight:bold;">session</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:date_month</span><span style="color:#006600; font-weight:bold;">&#93;</span>, <span style="color:#5A0A0A; font-weight:bold;">session</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:date_day</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    cachefile = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span>PATH_ICS_CACHE, <span style="color:#996600;">&quot;#{@today.to_s(:ical)}_#{@scope}.yml&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
    <span style="color:#008000; font-style:italic;"># Kill cache if outdated</span>
    <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">exists</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>cachefile<span style="color:#006600; font-weight:bold;">&#41;</span>
      killcache = <span style="color:#0000FF; font-weight:bold;">false</span>
      <span style="color:#CC00FF; font-weight:bold;">Dir</span>.<span style="color:#9900CC;">glob</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span>PATH_ICS, <span style="color:#996600;">'*.ics'</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#5A0A0A; font-weight:bold;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>file<span style="color:#006600; font-weight:bold;">|</span>
        killcache = <span style="color:#0000FF; font-weight:bold;">true</span> <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">mtime</span><span style="color:#006600; font-weight:bold;">&#40;</span>file<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&gt;</span> <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">mtime</span><span style="color:#006600; font-weight:bold;">&#40;</span>cachefile<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
      <span style="color:#9966CC; font-weight:bold;">if</span> killcache
        <span style="color:#CC00FF; font-weight:bold;">Dir</span>.<span style="color:#9900CC;">glob</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span>PATH_ICS_CACHE, <span style="color:#996600;">'*.*'</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#5A0A0A; font-weight:bold;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>file<span style="color:#006600; font-weight:bold;">|</span>
          <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#5A0A0A; font-weight:bold;">delete</span><span style="color:#006600; font-weight:bold;">&#40;</span>file<span style="color:#006600; font-weight:bold;">&#41;</span>
        <span style="color:#9966CC; font-weight:bold;">end</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    <span style="color:#008000; font-style:italic;"># Load calendar from cache</span>
    <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">exists</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>cachefile<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#0066ff; font-weight:bold;">@events</span> = <span style="color:#CC00FF; font-weight:bold;">YAML</span>.<span style="color:#9900CC;">load_file</span> cachefile 
    <span style="color:#9966CC; font-weight:bold;">else</span>
      <span style="color:#008000; font-style:italic;"># No cache, parse each icalendar *.ics file in PATH_ICS and check for event occurences</span>
      <span style="color:#CC00FF; font-weight:bold;">Dir</span>.<span style="color:#9900CC;">glob</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span>PATH_ICS, <span style="color:#996600;">'*.ics'</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#5A0A0A; font-weight:bold;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>file<span style="color:#006600; font-weight:bold;">|</span>
        category = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">basename</span><span style="color:#006600; font-weight:bold;">&#40;</span>file, <span style="color:#996600;">'.ics'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
        <span style="color:#6666ff; font-weight:bold;">Vpim::Icalendar</span>.<span style="color:#9900CC;">decode</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span>file<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#5A0A0A; font-weight:bold;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>calendar<span style="color:#006600; font-weight:bold;">|</span>
          calendar.<span style="color:#9900CC;">components</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>event<span style="color:#006600; font-weight:bold;">|</span>
            <span style="color:#9966CC; font-weight:bold;">for</span> <span style="color:#5A0A0A; font-weight:bold;">day</span> <span style="color:#9966CC; font-weight:bold;">in</span> <span style="color:#006666;">0</span>..@scope
              <span style="color:#9966CC; font-weight:bold;">if</span> start = event.<span style="color:#9900CC;">occurs_in</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>@today<span style="color:#006600; font-weight:bold;">+</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">60</span><span style="color:#006600; font-weight:bold;">*</span><span style="color:#006666;">60</span><span style="color:#006600; font-weight:bold;">*</span><span style="color:#006666;">24</span><span style="color:#006600; font-weight:bold;">*</span><span style="color:#5A0A0A; font-weight:bold;">day</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#0066ff; font-weight:bold;">@today</span><span style="color:#006600; font-weight:bold;">+</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">60</span><span style="color:#006600; font-weight:bold;">*</span><span style="color:#006666;">60</span><span style="color:#006600; font-weight:bold;">*</span><span style="color:#006666;">24</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">+</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">60</span><span style="color:#006600; font-weight:bold;">*</span><span style="color:#006666;">60</span><span style="color:#006600; font-weight:bold;">*</span><span style="color:#006666;">24</span><span style="color:#006600; font-weight:bold;">*</span><span style="color:#5A0A0A; font-weight:bold;">day</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
                myend = start <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#006600; font-weight:bold;">&#40;</span>event.<span style="color:#9900CC;">dtend</span> <span style="color:#006600; font-weight:bold;">-</span> event.<span style="color:#9900CC;">dtstart</span><span style="color:#006600; font-weight:bold;">&#41;</span>
                <span style="color:#0066ff; font-weight:bold;">@events</span> <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span>
                  <span style="color:#996600;">'category'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> category,
                  <span style="color:#996600;">'day'</span>      <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#5A0A0A; font-weight:bold;">day</span>,
                  <span style="color:#996600;">'start'</span>    <span style="color:#006600; font-weight:bold;">=&gt;</span> start,
                  <span style="color:#996600;">'duration'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#40;</span>event.<span style="color:#9900CC;">dtend</span> <span style="color:#006600; font-weight:bold;">-</span> event.<span style="color:#9900CC;">dtstart</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">/</span> <span style="color:#006666;">60</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">round</span>, <span style="color:#008000; font-style:italic;"># In minutes</span>
                  <span style="color:#996600;">'end'</span>      <span style="color:#006600; font-weight:bold;">=&gt;</span> myend,
                  <span style="color:#996600;">'allday'</span>   <span style="color:#006600; font-weight:bold;">=&gt;</span> start.<span style="color:#9900CC;">hour</span> == <span style="color:#006666;">0</span> <span style="color:#006600; font-weight:bold;">&amp;&amp;</span> start.<span style="color:#9900CC;">min</span> == <span style="color:#006666;">0</span> <span style="color:#006600; font-weight:bold;">&amp;&amp;</span> start.<span style="color:#9900CC;">sec</span> == <span style="color:#006666;">0</span> <span style="color:#006600; font-weight:bold;">&amp;&amp;</span> myend.<span style="color:#9900CC;">hour</span> == <span style="color:#006666;">0</span> <span style="color:#006600; font-weight:bold;">&amp;&amp;</span> myend.<span style="color:#9900CC;">min</span> == <span style="color:#006666;">0</span> <span style="color:#006600; font-weight:bold;">&amp;&amp;</span> myend.<span style="color:#9900CC;">sec</span> == <span style="color:#006666;">0</span>,
                  <span style="color:#996600;">'data'</span>     <span style="color:#006600; font-weight:bold;">=&gt;</span> event
                <span style="color:#006600; font-weight:bold;">&#125;</span>
              <span style="color:#9966CC; font-weight:bold;">end</span>
            <span style="color:#9966CC; font-weight:bold;">end</span>
          <span style="color:#9966CC; font-weight:bold;">end</span>
        <span style="color:#9966CC; font-weight:bold;">end</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
      <span style="color:#0066ff; font-weight:bold;">@events</span> = <span style="color:#0066ff; font-weight:bold;">@events</span>.<span style="color:#9900CC;">uniq</span> <span style="color:#008000; font-style:italic;"># Just in case :)</span>
      <span style="color:#008000; font-style:italic;"># Save cache</span>
      <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span>cachefile, <span style="color:#996600;">'w'</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>f<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#CC00FF; font-weight:bold;">YAML</span>.<span style="color:#9900CC;">dump</span><span style="color:#006600; font-weight:bold;">&#40;</span>@events, f<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p><strong><em>Single View</em></strong> (view/calendars/index.html.erb)</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
</pre></td><td class="code"><pre class="rails" style="font-family:monospace;">&lt; %
  width  = 110      # Width of one day
  height = 6        # height of 15 minutes in pixels
  buffer = 28       # free space for dates in day column (at top of each day)
  minh   = 20       # Minimum of event height
  cutmornings = 120 # I don't have events between 0:00 and 6:00, cut these pixels off
%&gt;
&nbsp;
&lt;div id=&quot;action&quot;&gt;
&nbsp;
&lt; % for day in 0...@scope + 1 do 
  today = (@today+(60*60*24*day))
  case today.wday  
    when 0  
      dayclass = 'class=&quot;sunday&quot;'
    when 6  
      dayclass = 'class=&quot;saturday&quot;'
    else  
      dayclass = 'class=&quot;otherday&quot;'
  end
  %&gt;
  &lt;div id=&quot;ical_day&quot; <span style="color:#006600; font-weight:bold;">&lt;%</span>= dayclass <span style="color:#006600; font-weight:bold;">%&gt;</span>
    style=&quot; width:  &lt; %= width %&gt;px;
            height: &lt; %= height*96 + buffer - cutmornings %&gt;px;
            left:   &lt; %= day*width + day*10 %&gt;px;&quot;&gt;
    &lt; % if today.year == Time.now.year &amp;&amp; today.month == Time.now.month &amp;&amp; today.day == Time.now.day %&gt;
      &lt;b&gt;&lt; %= 'Today' %&gt;&lt;/b&gt;
    &lt; % else %&gt;
      &lt; %= _(today.strftime(&quot;%a&quot;)) +', '+ today.to_s(:date) %&gt;
    &lt; % end %&gt;
  &lt;/div&gt;
&lt; % end %&gt;
&nbsp;
&lt; % tops = Array.new(@scope + 1, '')
@events.each do |event|
&nbsp;
  # Exclude recurrence rule hack
  today = (@today+(60*60*24*event['day']))
  exme = false
  event['data'].propvaluearray('EXDATE').each do |exdate|
    exdate = exdate.to_time
    exme = true if today.year == exdate.year &amp;&amp; today.mon == exdate.mon &amp;&amp; today.day == exdate.day
  end
  next if exme # Skip this event
&nbsp;
  if event['allday']
    # All-day events will be inserted later
    tops[event['day']] += '&amp;nbsp; ' + event['data'].summary.to_s + '&lt;br/&gt;'
  else 
    eventheight = ((event['duration']/15)*height).round
    eventheight = minh if eventheight &lt; minh
    %&gt;
    &lt;div id=&quot;ical_event&quot;
      style=&quot; background: #<span style="color:#006600; font-weight:bold;">&lt;%</span>= eventcolor<span style="color:#006600; font-weight:bold;">&#40;</span>event<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'category'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>;
              width:  &lt; %= width-2 %&gt;px;
              height: &lt; %= eventheight.to_s %&gt;px;
              top:    &lt; %= event['start'].hour*height*4 + (event['start'].min/15)*6 + buffer - cutmornings %&gt;px;
              left:   &lt; %= event['day']*width + event['day']*10 %&gt;px;&quot;&gt;
      &lt; %= '&lt;b&gt;'+ event['start'].to_s(:time) +' - '+ event['end'].to_s(:time) +'&lt;br /&gt;' %&gt;
      &lt; %= event['data'].summary %&gt;
    &lt;/div&gt;
  &lt; % end %&gt;
&lt; % end %&gt;
&nbsp;
&lt; % tops.each_with_index do |top, day| %&gt;
    &lt;div id=&quot;ical_event_top&quot;
      style=&quot; width: <span style="color:#006600; font-weight:bold;">&lt;%</span>= width<span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">2</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>px;
              height: &lt; %= height %&gt;px;
              top: &lt; %= buffer %&gt;px;
              left: &lt; %= day * width + day * 10 %&gt;px;&quot;&gt;
      &lt; %= top %&gt;
    &lt;/div&gt;
&lt; % end %&gt;
&nbsp;
&lt;div id=&quot;vertical_spacer&quot; style=&quot;height: <span style="color:#006600; font-weight:bold;">&lt;%</span>= height<span style="color:#006600; font-weight:bold;">*</span><span style="color:#006666;">96</span> <span style="color:#006600; font-weight:bold;">+</span> buffer<span style="color:#006600; font-weight:bold;">*</span><span style="color:#006666;">2</span> <span style="color:#006600; font-weight:bold;">-</span> cutmornings <span style="color:#006600; font-weight:bold;">%&gt;</span>px;&quot;&gt;&amp;nbsp;&lt;/div&gt;
&nbsp;
&lt;/div&gt;</pre></td></tr></table></div>

<p><strong><em>Layout View</em></strong> (views/layouts/calendars.html.erb)</p>

<div class="wp_syntax"><div class="code"><pre class="rails" style="font-family:monospace;">        <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#006600; font-weight:bold;">%</span> form_tag <span style="color:#ff3333; font-weight:bold;">:controller</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'calendars'</span>, <span style="color:#ff3333; font-weight:bold;">:action</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">nil</span>, <span style="color:#ff3333; font-weight:bold;">:id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">nil</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>f<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
          <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#006600; font-weight:bold;">%</span>= date_select<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;options&quot;</span>, <span style="color:#996600;">&quot;date&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:default</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0066ff; font-weight:bold;">@today</span>, <span style="color:#ff3333; font-weight:bold;">:order</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span>:<span style="color:#5A0A0A; font-weight:bold;">day</span>, :<span style="color:#5A0A0A; font-weight:bold;">month</span>, <span style="color:#ff3333; font-weight:bold;">:year</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
            <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#006600; font-weight:bold;">%</span>= submit_tag <span style="color:#996600;">'Show'</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">' &amp;raquo;'</span>, :<span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'date_button'</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
        <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#006600; font-weight:bold;">%</span> <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#006600; font-weight:bold;">%&gt;</span></pre></div></div>

<p><strong><em>Helper (for coloring events)</em></strong> (app/helpers/calendar_helper.rb)</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre></td><td class="code"><pre class="rails" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">module</span> CalendarsHelper
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> eventcolor<span style="color:#006600; font-weight:bold;">&#40;</span>category<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">case</span> category  
      <span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#996600;">'Wichtig'</span>   <span style="color:#008000; font-style:italic;"># This is the name of the .ics file</span>
        <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#996600;">'f66'</span>
      <span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#996600;">'Sonstiges'</span>
        <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#996600;">'4f4'</span>
      <span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#996600;">'Studium'</span>
        <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#996600;">'fb4'</span>
      <span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#996600;">'Privat'</span>
        <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#996600;">'77f'</span>
      <span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#996600;">'Freunde'</span>
        <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#996600;">'f4f'</span>
      <span style="color:#9966CC; font-weight:bold;">else</span>  
        <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#996600;">'fb4'</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p><strong><em>Stylesheet</em></strong> (public/stylesheets/calendar.css)</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/**************** DIVs ***************************/</span>
&nbsp;
div<span style="color: #cc00cc;">#action</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">margin-left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">margin-top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">4px</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">border-left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">0px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
div<span style="color: #cc00cc;">#ical_day</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">padding-top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">5px</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">center</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.otherday</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#ddd</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.sunday</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#fdd</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.saturday</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#ddf</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#ical_event</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #cc00cc;">#555</span> <span style="color: #993333;">solid</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#fb4</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">8px</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#ical_event_top</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #933;">0px</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">9px</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">bold</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/**************** Fonts ***************************/</span>
&nbsp;
<span style="color: #cc00cc;">#title</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#ddd</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">margin-top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">30px</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">margin-right</span><span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">line-height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">11px</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">16px</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#title</span> <span style="color: #6666ff;">.description</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#777</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p><strong><em>Routes (could be optional)</em></strong> (config/routes.rb)</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="rails" style="font-family:monospace;">  <span style="color:#008000; font-style:italic;"># CALENDAR Controllers</span>
  map.<span style="color:#9900CC;">connect</span> <span style="color:#996600;">'calendar'</span>, <span style="color:#ff3333; font-weight:bold;">:controller</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'calendars'</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://funkensturm.de/2008/02/10/finally-railsicalendar-ical-ics-publish-with-ruby-on-rails/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Localization Plugin: Improved&#160;generate_l10n_file</title>
		<link>http://funkensturm.de/2007/12/24/improved-generate_l10n_file/</link>
		<comments>http://funkensturm.de/2007/12/24/improved-generate_l10n_file/#comments</comments>
		<pubDate>Mon, 24 Dec 2007 12:38:43 +0000</pubDate>
		<dc:creator>Captain Future</dc:creator>
				<category><![CDATA[plugins]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[tasks]]></category>
		<category><![CDATA[generate]]></category>
		<category><![CDATA[l10n]]></category>
		<category><![CDATA[l14n]]></category>
		<category><![CDATA[localization]]></category>
		<category><![CDATA[localize]]></category>

		<guid isPermaLink="false">http://blog.funkensturm.de/2007/12/24/improved-generate_l10n_file/</guid>
		<description><![CDATA[Das Localization Plugin hat eine Methode generate_l10n_file um die zu lokalisierenden Strings auszulesen. Leider macht sie dies nicht besonders gut. Auf die Schnelle habe ich sie etwas abgeändert und siehe da: def self.generate_l10n_file &#34;Localization.define('de') do &#124;l&#124;&#34; &#60; &#60; Dir.glob(&#34;#{RAILS_ROOT}/app/**/*.*&#34;).collect do &#124;f&#124; [&#34;# #{f}&#34;] &#60;&#60; File.read(f).scan(/(&#60;%=_ &#124;_\&#40;&#41;&#91;\&#34;\'](.*?)[\&#34;\']/) end.uniq.flatten.collect do &#124;g&#124; g.starts_with?('#') ? &#34;&#34; : &#34; l.store [...]]]></description>
			<content:encoded><![CDATA[<p>Das <a href="http://dev.rubyonrails.org/browser/plugins/localization" onclick="pageTracker._trackPageview('/outgoing/dev.rubyonrails.org/browser/plugins/localization?referer=');">Localization Plugin</a> hat eine Methode generate_l10n_file um die zu lokalisierenden Strings auszulesen. Leider macht sie dies nicht besonders gut.</p>
<p>Auf die Schnelle habe ich sie etwas abgeändert und siehe da:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">def self.generate_l10n_file
  &quot;Localization.define('de') do |l|&quot; &lt; &lt;
  Dir.glob(&quot;#{RAILS_ROOT}/app/**/*.*&quot;).collect do |f| 
    [&quot;# #{f}&quot;] &lt;&lt; File.read(f).scan(/(<span style="color:#006600; font-weight:bold;">&lt;%</span>=_ <span style="color:#006600; font-weight:bold;">|</span>_\<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#91;</span>\<span style="color:#996600;">&quot;<span style="color:#000099;">\'</span>](.*?)[<span style="color:#000099;">\&quot;</span><span style="color:#000099;">\'</span>]/)
  end.uniq.flatten.collect do |g|
    g.starts_with?('#') ? &quot;</span><span style="color:#996600;">&quot; : &quot;</span>  l.<span style="color:#9900CC;">store</span> <span style="color:#996600;">'#{g}'</span>, <span style="color:#996600;">''</span><span style="color:#996600;">&quot;
  end.uniq.sort.join(&quot;</span>\n<span style="color:#996600;">&quot;).gsub(&quot;</span>  l.<span style="color:#9900CC;">store</span> <span style="color:#996600;">'_('</span>, <span style="color:#996600;">''</span><span style="color:#996600;">&quot;,'').gsub(&quot;</span>  l.<span style="color:#9900CC;">store</span> <span style="color:#996600;">'&lt;%=_ '</span>, <span style="color:#996600;">''</span><span style="color:#996600;">&quot;,'') &lt;&lt; &quot;</span>\nend<span style="color:#996600;">&quot;
end</span></pre></div></div>

<p>Jetzt werden sämtliche Controller ausgelesen und es werden deutlich mehr Strings gefunden (nämlich auch die wo nicht %= davor steht).</p>
<p>UPDATE: Zu &#8220;#{RAILS_ROOT}/app/**/*.*&#8221; müsste man noch &#8220;#{RAILS_ROOT}/app/views/**/*.*&#8221; irgendwie hinzunehmen.</p>
<p>Hier noch ein rake task dafür:
</pre>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">namespace <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:l10n</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    desc <span style="color:#996600;">'Verbose localization file (experimental)'</span>
    task <span style="color:#ff3333; font-weight:bold;">:generate</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:environment</span> <span style="color:#9966CC; font-weight:bold;">do</span>
      <span style="color:#CC0066; font-weight:bold;">puts</span>
      <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">'Creating localization file...'</span>
      <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">'----------- SNIP -----------'</span>
      <span style="color:#CC0066; font-weight:bold;">puts</span> Localization.<span style="color:#9900CC;">generate_l10n_file</span>
      <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">'----------- SNAP -----------'</span>
      <span style="color:#CC0066; font-weight:bold;">puts</span>
      <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">'Finished.'</span>
      <span style="color:#CC0066; font-weight:bold;">puts</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://funkensturm.de/2007/12/24/improved-generate_l10n_file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Plugin: acts_as_list_in_tree und descendants in&#160;acts_as_tree</title>
		<link>http://funkensturm.de/2007/12/15/acts_as_list_in_tree-und-descendants-in-acts_as_tree/</link>
		<comments>http://funkensturm.de/2007/12/15/acts_as_list_in_tree-und-descendants-in-acts_as_tree/#comments</comments>
		<pubDate>Sat, 15 Dec 2007 11:38:54 +0000</pubDate>
		<dc:creator>Captain Future</dc:creator>
				<category><![CDATA[plugins]]></category>
		<category><![CDATA[rails 2.0]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[acts_as_tree]]></category>
		<category><![CDATA[act_as_list_in_tree]]></category>
		<category><![CDATA[descendants]]></category>

		<guid isPermaLink="false">http://blog.funkensturm.de/2007/12/15/acts_as_list_in_tree-und-descendants-in-acts_as_tree/</guid>
		<description><![CDATA[Ich habe eine Kategorienliste mit Unterkategorien. Nun möchte ich acts_as_list verwenden, um die Reihenfolge mit den Feld &#8220;position&#8221; leichter ändern zu können. Das geht auch soweit (Dann hat man so tolle Funktionen wie Category.move_higher). Leider gibt es da aber immer wieder Probleme, da eine neu hinzugefügte Kategorie die Position max(alle_positionen)+1 erhält. Also die höchste ALLER [...]]]></description>
			<content:encoded><![CDATA[<p>Ich habe eine Kategorienliste mit Unterkategorien. Nun möchte ich acts_as_list verwenden, um die Reihenfolge mit den Feld &#8220;position&#8221; leichter ändern zu können. Das geht auch soweit (Dann hat man so tolle Funktionen wie Category.move_higher).</p>
<p>Leider gibt es da aber immer wieder Probleme, da eine neu hinzugefügte Kategorie die Position max(alle_positionen)+1 erhält. Also die höchste ALLER Positionen +1. Ich möchte aber, dass eine neu hinzugefügte Kategorie die position+1 bezogen auf seine Vaterkategorie erhält!</p>
<p>Also sich als Liste verhält, aber nur in Bezug auf seine Geschwister!</p>
<p>Dafür muss man das Plugin (Rails 2.0) &#8220;acts_as_list&#8221; ändern. Und zwar muss man die Zeile 64, auskommentieren:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;">##{scope_condition_method}</span></pre></div></div>

<p>Und die Funktion scope_condition() in Zeile 186 wie folgt ändern:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># Overwrite this method to define the scope of the list changes</span>
<span style="color:#008000; font-style:italic;">#def scope_condition() &quot;1&quot; end</span>
<span style="color:#9966CC; font-weight:bold;">def</span> scope_condition<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#996600;">&quot;parent_id = #{self.parent_id}&quot;</span> <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>So habe ich mir mein eigenes <a href='http://blog.funkensturm.de/wp-content/uploads/2007/12/acts_as_list_in_tree.zip' title='acts_as_list_in_tree.zip'>acts_as_list_in_tree (download)</a> Plugin gebaut.</p>
<p>Vielleicht noch als Anmerkung:<br />
In acts_as_tree gibt es KEINE DESCENDANTS Funktion! Das heißt, man kann sich in einem Tree nicht die Nachkommen ausgeben lassen. Die Vorfahren schon, mit .ancestors, aber halt nicht die Nachkommen.</p>
<p>Siehe da <a href="http://dev.rubyonrails.org/ticket/8345" target='_blank' onclick="pageTracker._trackPageview('/outgoing/dev.rubyonrails.org/ticket/8345?referer=');">HIER</a> habe ich die Lösung gefunden. Ich hatte nur gehofft, sie sei in Rails 2.0 schon implementiert, ist sie aber nicht!</p>
<p>Also selber hinzufügen (am besten unter die ancestors funktion) in<br />
/vendor/plugins/acts_as_tree/lib/active_record/acts/tree.rb:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># Bugfix - Returns list of descendants</span>
<span style="color:#9966CC; font-weight:bold;">def</span> descendants 
  descendants = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span> 
  <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">children</span>.<span style="color:#9900CC;">each</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>child<span style="color:#006600; font-weight:bold;">|</span> descendants <span style="color:#006600; font-weight:bold;">+</span>= <span style="color:#006600; font-weight:bold;">&#91;</span>child<span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">+</span> child.<span style="color:#9900CC;">descendants</span> <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">children</span>.<span style="color:#9900CC;">length</span> <span style="color:#006600; font-weight:bold;">&gt;</span> <span style="color:#006666;">0</span> 
  descendants
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Wenn es in Rails 2.x übernommen wird, kann man es wieder löschen ;)</p>
<p>Das war&#8217;s für heute :)</p>
]]></content:encoded>
			<wfw:commentRss>http://funkensturm.de/2007/12/15/acts_as_list_in_tree-und-descendants-in-acts_as_tree/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby on Rails: String&#160;manipulation</title>
		<link>http://funkensturm.de/2007/10/09/ruby-on-rails-string-manipulation/</link>
		<comments>http://funkensturm.de/2007/10/09/ruby-on-rails-string-manipulation/#comments</comments>
		<pubDate>Tue, 09 Oct 2007 13:29:00 +0000</pubDate>
		<dc:creator>Captain Future</dc:creator>
				<category><![CDATA[plugins]]></category>
		<category><![CDATA[resources]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[characters]]></category>
		<category><![CDATA[illegal]]></category>
		<category><![CDATA[string manipulation]]></category>
		<category><![CDATA[strip]]></category>

		<guid isPermaLink="false">http://blog.funkensturm.de/2007/10/09/ruby-on-rails-string-manipulation/</guid>
		<description><![CDATA[Es gibt einige Sachen, die ich gerne mit Strings machen möchte. Aber natürlich ist nicht ALLES in Rails schon drin. Also habe ich mir mit einem Plugin wie folgt geholfen. z. B.: &#8220;2&#8243;.numstring? gibt mir an, ob der string nur Ziffern enthält. /vendor/plugins/future/init.rb require 'string_manipulation' /vendor/plugins/future/lib/string_manipulation.rb require 'digest/sha1' module StringManipulation &#160; # Remove ALL unneccessary [...]]]></description>
			<content:encoded><![CDATA[<p>Es gibt einige Sachen, die ich gerne mit Strings machen möchte. Aber natürlich ist nicht ALLES in Rails schon drin. Also habe ich mir mit einem Plugin wie folgt geholfen.</p>
<p>z. B.: <b>&#8220;2&#8243;.numstring?</b> gibt mir an, ob der string nur Ziffern enthält.</p>
<p><b>/vendor/plugins/future/init.rb</b></p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'string_manipulation'</span></pre></div></div>

<p><b>/vendor/plugins/future/lib/string_manipulation.rb</b></p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'digest/sha1'</span>
<span style="color:#9966CC; font-weight:bold;">module</span> StringManipulation
&nbsp;
  <span style="color:#008000; font-style:italic;"># Remove ALL unneccessary whitespaces from string</span>
  <span style="color:#008000; font-style:italic;">#    &quot;   hello   world   &quot; #=&gt; &quot;hello world&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> strip_all
    <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#CC0066; font-weight:bold;">gsub</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span> <span style="color:#006600; font-weight:bold;">+/</span>, <span style="color:#996600;">' '</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">strip</span>.<span style="color:#CC0066; font-weight:bold;">chomp</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># Remove everything that is not a-z or 0-9 or space</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> strip_illegal
    <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#CC0066; font-weight:bold;">gsub</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#91;</span>^a<span style="color:#006600; font-weight:bold;">-</span>zA<span style="color:#006600; font-weight:bold;">-</span>Z0<span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">9</span> <span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">/</span>, <span style="color:#996600;">''</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># Returns the basename of a file</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> strip_extention
    <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#CC0066; font-weight:bold;">gsub</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#40;</span>\.<span style="color:#006600; font-weight:bold;">&#40;</span>.<span style="color:#006600; font-weight:bold;">*</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>$<span style="color:#006600; font-weight:bold;">/</span>,<span style="color:#996600;">''</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># Strips RAILS_ROOT/public from string</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> url_from_path
    <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#CC0066; font-weight:bold;">gsub</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;#{RAILS_ROOT}/public&quot;</span>, <span style="color:#996600;">''</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># Strips RAILS_ROOT from string</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> root_from_path
    <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#CC0066; font-weight:bold;">gsub</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;#{RAILS_ROOT}&quot;</span>, <span style="color:#996600;">''</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># Hashes a string with SHA1</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> hashed
    <span style="color:#6666ff; font-weight:bold;">Digest::SHA1</span>.<span style="color:#9900CC;">hexdigest</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">self</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># Make a nice downcase keyword list as string, seperated by single spaces</span>
  <span style="color:#008000; font-style:italic;">#    keyword_list(&quot;   My §$% KEY   wordlist   &quot;) #=&gt; &quot;my key wordlist&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> keywordlist
    <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">strip_illegal</span>.<span style="color:#9900CC;">downcase</span>.<span style="color:#9900CC;">strip_all</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># Checks if a string contains only numerical characters</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> numstring?
    <span style="color:#0000FF; font-weight:bold;">self</span> =~ <span style="color:#006600; font-weight:bold;">/</span>^\d<span style="color:#006600; font-weight:bold;">+</span><span style="color:#006600; font-weight:bold;">&#40;</span>\.\d<span style="color:#006600; font-weight:bold;">+|</span>\d<span style="color:#006600; font-weight:bold;">*</span><span style="color:#006600; font-weight:bold;">&#41;</span>$<span style="color:#006600; font-weight:bold;">/</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#CC0066; font-weight:bold;">String</span>
  <span style="color:#9966CC; font-weight:bold;">include</span> StringManipulation
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Als Unterfunktion von Object sind die Funktionen <b>überall</b> verfügbar. Sehr praktisch.</p>
]]></content:encoded>
			<wfw:commentRss>http://funkensturm.de/2007/10/09/ruby-on-rails-string-manipulation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
