mirror of
https://github.com/TracksApp/tracks.git
synced 2026-02-04 15:01:48 +01:00
More code climate style fixes
This commit is contained in:
parent
d8acf60049
commit
67a426a2e9
28 changed files with 157 additions and 172 deletions
|
|
@ -1,14 +1,11 @@
|
|||
# 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
|
||||
|
|
@ -16,53 +13,46 @@ module Tracks
|
|||
def context
|
||||
yield if :context == @source_view && block_given?
|
||||
end
|
||||
|
||||
def method_missing(check_source_view,*args)
|
||||
|
||||
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 )
|
||||
|
||||
def source_view_is(s)
|
||||
s == (params[:_source_view] || @source_view).to_sym
|
||||
end
|
||||
|
||||
def source_view_is_one_of( *s )
|
||||
|
||||
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 )
|
||||
|
||||
def source_view_is(s)
|
||||
s == (params[:_source_view] || @source_view).to_sym
|
||||
end
|
||||
|
||||
def source_view_is_one_of( *s )
|
||||
|
||||
def source_view_is_one_of(*s)
|
||||
s.include?((params[:_source_view] || @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