<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: Robd's Code Snippets</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Fri, 29 Aug 2008 23:02:39 GMT</pubDate>
    <description>DZone Snippets: Robd's Code Snippets</description>
    <item>
      <title>Rails 2.1.0 monkey patch to add the recognized or matched rails route to the request</title>
      <link>http://snippets.dzone.com/posts/show/5824</link>
      <description>This was based on code I found here from Chris Cruft - http://cho.hapgoods.com/wordpress/?p=151&lt;br /&gt;&lt;br /&gt;Enhanced to support rails 2.1.0 and also allows alias method chains for recognize from other plugins still to work.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;module ActionController&lt;br /&gt;  class AbstractRequest&lt;br /&gt;    attr_reader :recognized_route&lt;br /&gt;    &lt;br /&gt;    def init_recognized_route_from_path_parameters&lt;br /&gt;      recognized_route = path_parameters.delete(:recognized_route) &lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt;&lt;br /&gt;  module Routing&lt;br /&gt;    &lt;br /&gt;    class RouteSet&lt;br /&gt;      def recognize_with_route(request)&lt;br /&gt;        result = recognize_without_route(request)&lt;br /&gt;        request.init_recognized_route_from_path_parameters&lt;br /&gt;        result&lt;br /&gt;      end&lt;br /&gt;      alias_method_chain :recognize, :route&lt;br /&gt;&lt;br /&gt;      def write_recognize_optimized_with_route&lt;br /&gt;        tree = segment_tree(routes)&lt;br /&gt;        body = generate_code(tree)&lt;br /&gt;        instance_eval %{&lt;br /&gt;          def recognize_optimized(path, env)&lt;br /&gt;            segments = to_plain_segments(path)&lt;br /&gt;            index = #{body}&lt;br /&gt;            return nil unless index&lt;br /&gt;            while index &lt; routes.size&lt;br /&gt;              result = routes[index].recognize(path, env) and result[:recognized_route] = routes[index] and return result&lt;br /&gt;              index += 1&lt;br /&gt;            end&lt;br /&gt;            nil&lt;br /&gt;          end&lt;br /&gt;        }, __FILE__, __LINE__&lt;br /&gt;      end&lt;br /&gt;      alias_method_chain :write_recognize_optimized, :route&lt;br /&gt;&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 25 Jul 2008 15:10:27 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5824</guid>
      <author>robd (Rob Dupuis)</author>
    </item>
    <item>
      <title>Code to disable YUI calendar previous and next month links icons</title>
      <link>http://snippets.dzone.com/posts/show/5198</link>
      <description>This solution does not require modifying the yui source and works on YUI version 2.5.0. It will disable the next and previous arrows based on the out of bounds dates you specify with mindate and maxdate when you configure the calendar. Requires YUI dom and a namespace called your_app.&lt;br /&gt;&lt;br /&gt;1) attach an onRender event when you configure the calendar and before you call render&lt;br /&gt;&lt;br /&gt;&lt;code&gt;calendar.renderEvent.subscribe(YAHOO.your_app.calendar().initArrows, calendar);&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;2) add the following function:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;YAHOO.your_app.calendar = function() {&lt;br /&gt;	&lt;br /&gt;	var addDays = function(date, days) {&lt;br /&gt;		return YAHOO.widget.DateMath.add(date, YAHOO.widget.DateMath.DAY, days);&lt;br /&gt;	};&lt;br /&gt;	&lt;br /&gt;	var showPreviousArrow = function(cal) {&lt;br /&gt;		return showArrow(cal, cal.toDate(cal.cellDates[0]), 1);&lt;br /&gt;	};&lt;br /&gt;&lt;br /&gt;	var showNextArrow = function(cal) {&lt;br /&gt;		return showArrow(cal, cal.toDate(cal.cellDates[cal.cellDates.length-1]), -1);&lt;br /&gt;	};&lt;br /&gt;	&lt;br /&gt;	var showArrow = function(cal, startingDate, step) {&lt;br /&gt;		if (!cal.isDateOOM(startingDate)) { //ie not overlapping&lt;br /&gt;			return !cal.isDateOOB(addDays(startingDate, (-1 * step)));&lt;br /&gt;		}&lt;br /&gt;		for (var i=0; (i * step) &lt; 7; i += step) { //iterate forwards for previous month check, backwards for next month check&lt;br /&gt;			var date = addDays(startingDate, i);&lt;br /&gt;			if (!cal.isDateOOM(date)) { //shortcut exit; as soon as we find an in month date we can supress the arrow&lt;br /&gt;				return false;&lt;br /&gt;			} else if (!cal.isDateOOB(date)) {&lt;br /&gt;				return true;&lt;br /&gt;			}&lt;br /&gt;		}&lt;br /&gt;		return false;&lt;br /&gt;	};&lt;br /&gt;	&lt;br /&gt;	return {&lt;br /&gt;		initArrows: function(type, args, cal) {&lt;br /&gt;			if (!showPreviousArrow(cal)) {&lt;br /&gt;				hideArrow(cal, cal.Style.CSS_NAV_LEFT);&lt;br /&gt;			}&lt;br /&gt;&lt;br /&gt;			if (!showNextArrow(cal)) {&lt;br /&gt;				hideArrow(cal, cal.Style.CSS_NAV_RIGHT);&lt;br /&gt;			}&lt;br /&gt;		}&lt;br /&gt;	};&lt;br /&gt;};&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 03 Mar 2008 20:57:33 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5198</guid>
      <author>robd (Rob Dupuis)</author>
    </item>
  </channel>
</rss>
