2007-03-30 04:36:52 +00:00
|
|
|
# Inspiration from Bruce Williams [http://codefluency.com/articles/2006/07/01/rails-views-getting-in-context/]
|
|
|
|
|
module Tracks
|
|
|
|
|
|
|
|
|
|
module SourceViewSwitching
|
|
|
|
|
|
|
|
|
|
class Responder
|
|
|
|
|
|
|
|
|
|
def initialize(source_view)
|
|
|
|
|
@source_view = source_view.underscore.gsub(/\s+/,'_').to_sym rescue nil
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def nil?
|
|
|
|
|
yield if @source_view.nil? && block_given?
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def method_missing(check_source_view,*args)
|
|
|
|
|
yield if check_source_view == @source_view && block_given?
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
module Controller
|
|
|
|
|
|
|
|
|
|
def self.included(base)
|
|
|
|
|
base.send(:helper, Tracks::SourceViewSwitching::Helper)
|
|
|
|
|
base.send(:helper_method, :source_view)
|
|
|
|
|
end
|
2007-09-10 04:17:01 +00:00
|
|
|
|
|
|
|
|
def source_view_is( s )
|
|
|
|
|
s == (params[:_source_view] || @source_view).to_sym
|
|
|
|
|
end
|
2007-11-05 05:42:43 +00:00
|
|
|
|
|
|
|
|
def source_view_is_one_of( *s )
|
|
|
|
|
s.include?(params[:_source_view].to_sym)
|
|
|
|
|
end
|
2007-03-30 04:36:52 +00:00
|
|
|
|
|
|
|
|
def source_view
|
2007-04-02 04:18:19 +00:00
|
|
|
responder = Tracks::SourceViewSwitching::Responder.new(params[:_source_view] || @source_view)
|
2007-03-30 04:36:52 +00:00
|
|
|
block_given? ? yield(responder) : responder
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
module Helper
|
|
|
|
|
|
|
|
|
|
def source_view_tag(name)
|
|
|
|
|
hidden_field_tag :_source_view, name.underscore.gsub(/\s+/,'_')
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def source_view_is( s )
|
|
|
|
|
s == (params[:_source_view] || @source_view).to_sym
|
|
|
|
|
end
|
|
|
|
|
|
2007-11-05 05:42:43 +00:00
|
|
|
def source_view_is_one_of( *s )
|
2007-03-30 04:36:52 +00:00
|
|
|
s.include?(params[:_source_view].to_sym)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
ActionController::Base.send(:include, Tracks::SourceViewSwitching::Controller)
|