Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Rob Dupuis

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS 

Rails 2.1.0 monkey patch to add the recognized or matched rails route to the request

This was based on code I found here from Chris Cruft - http://cho.hapgoods.com/wordpress/?p=151

Enhanced to support rails 2.1.0 and also allows alias method chains for recognize from other plugins still to work.

module ActionController
  class AbstractRequest
    attr_reader :recognized_route
    
    def init_recognized_route_from_path_parameters
      recognized_route = path_parameters.delete(:recognized_route) 
    end
  end

  module Routing
    
    class RouteSet
      def recognize_with_route(request)
        result = recognize_without_route(request)
        request.init_recognized_route_from_path_parameters
        result
      end
      alias_method_chain :recognize, :route

      def write_recognize_optimized_with_route
        tree = segment_tree(routes)
        body = generate_code(tree)
        instance_eval %{
          def recognize_optimized(path, env)
            segments = to_plain_segments(path)
            index = #{body}
            return nil unless index
            while index < routes.size
              result = routes[index].recognize(path, env) and result[:recognized_route] = routes[index] and return result
              index += 1
            end
            nil
          end
        }, __FILE__, __LINE__
      end
      alias_method_chain :write_recognize_optimized, :route

    end
  end
end

Code to disable YUI calendar previous and next month links icons

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.

1) attach an onRender event when you configure the calendar and before you call render

calendar.renderEvent.subscribe(YAHOO.your_app.calendar().initArrows, calendar);


2) add the following function:

YAHOO.your_app.calendar = function() {
	
	var addDays = function(date, days) {
		return YAHOO.widget.DateMath.add(date, YAHOO.widget.DateMath.DAY, days);
	};
	
	var showPreviousArrow = function(cal) {
		return showArrow(cal, cal.toDate(cal.cellDates[0]), 1);
	};

	var showNextArrow = function(cal) {
		return showArrow(cal, cal.toDate(cal.cellDates[cal.cellDates.length-1]), -1);
	};
	
	var showArrow = function(cal, startingDate, step) {
		if (!cal.isDateOOM(startingDate)) { //ie not overlapping
			return !cal.isDateOOB(addDays(startingDate, (-1 * step)));
		}
		for (var i=0; (i * step) < 7; i += step) { //iterate forwards for previous month check, backwards for next month check
			var date = addDays(startingDate, i);
			if (!cal.isDateOOM(date)) { //shortcut exit; as soon as we find an in month date we can supress the arrow
				return false;
			} else if (!cal.isDateOOB(date)) {
				return true;
			}
		}
		return false;
	};
	
	return {
		initArrows: function(type, args, cal) {
			if (!showPreviousArrow(cal)) {
				hideArrow(cal, cal.Style.CSS_NAV_LEFT);
			}

			if (!showNextArrow(cal)) {
				hideArrow(cal, cal.Style.CSS_NAV_RIGHT);
			}
		}
	};
};
« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS