mirror of
https://github.com/TracksApp/tracks.git
synced 2026-01-14 21:28:51 +01:00
Removed superfluous 'tracks' directory at the root of the repository.
Testing commits to github.
This commit is contained in:
parent
6a42901514
commit
4cbf5a34d3
2269 changed files with 0 additions and 0 deletions
64
lib/source_view.rb
Normal file
64
lib/source_view.rb
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
# 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
|
||||
|
||||
def source_view_is( s )
|
||||
s == (params[:_source_view] || @source_view).to_sym
|
||||
end
|
||||
|
||||
def source_view_is_one_of( *s )
|
||||
s.include?(params[:_source_view].to_sym)
|
||||
end
|
||||
|
||||
def source_view
|
||||
responder = Tracks::SourceViewSwitching::Responder.new(params[:_source_view] || @source_view)
|
||||
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
|
||||
|
||||
def source_view_is_one_of( *s )
|
||||
s.include?(params[:_source_view].to_sym)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
ActionController::Base.send(:include, Tracks::SourceViewSwitching::Controller)
|
||||
Loading…
Add table
Add a link
Reference in a new issue