Commit 09d43878 authored by azul's avatar azul

cleanup: remove unused utility helper functions

parent 98751743
......@@ -171,6 +171,16 @@ module Common::Ui::LayoutHelper
block_to_partial('common/dialog_page', options, &block)
end
# from http://www.igvita.com/2007/03/15/block-helpers-and-dry-views-in-rails/
# Only need this helper once, it will provide an interface to convert a block into a partial.
# 1. Capture is a Rails helper which will 'capture' the output of a block into a variable
# 2. Merge the 'body' variable into our options hash
# 3. Render the partial with the given options hash. Just like calling the partial directly.
def block_to_partial(partial_name, options = {}, &block)
options[:body] = capture(&block)
concat(render(partial: partial_name, locals: options))
end
##
## MISC. LAYOUT HELPERS
##
......
module Common::Utility::CacheHelper
def entity_cache_key(entity, options = {})
options.reverse_merge! version: entity.version,
updated_at: entity.updated_at.to_i,
path: nil,
authenticity_token: nil,
_context: nil
options.reverse_merge(params).values.compact.join('-')
end
def group_cache_key(group, options = {})
options.reverse_merge! lang: session[:language_code],
may_admin: current_user.may?(:admin, group),
access: @access
entity_cache_key(group, options)
end
def me_cache_key
params.merge user_id: current_user.id,
version: current_user.version,
path: nil,
authenticity_token: nil
end
def menu_cache_key(options = {})
options.reverse_merge! site: current_site.id,
user: current_user.cache_key,
v: 2
cache_key 'menu', options
end
# example input: cache_key('wiki', :version => 1, :editable => false)
# output "wiki/version=1&editable=false"
def cache_key(path, options = {})
path = "#{path}/" + options.to_query
end
end
module Common::Utility::GeneralHelper
##
## GENERAL UTILITY
##
#
# just like content_tag, but skips the tag if passed empty content.
#
def content_tag_if_any(name, content_or_options_with_block = nil, options = nil, escape = true, &block)
content = nil
opts = nil
if block
opts = content_or_options_with_block
content = yield block
else
opts = options
content = content_or_options_with_block
end
if content.present?
return content_tag(name, content, opts, escape)
else
return ''
end
end
#
# create ul list by calling block repeatedly for each item.
#
......@@ -74,7 +50,7 @@ module Common::Utility::GeneralHelper
args.last
end
## converts bytes into something more readable
# converts bytes into something more readable
def friendly_size(bytes)
return unless bytes
if bytes > 1.megabyte
......@@ -112,37 +88,4 @@ module Common::Utility::GeneralHelper
def first(key)
once?(key) ? 'first' : ''
end
def logged_in_since
session[:logged_in_since] || Time.now
end
#
# if method is a proc or a symbol for a defined method, then it is called.
# otherwise, nothing happens.
#
def safe_call(method, *args)
if method.is_a? Proc
method.call(*args)
elsif method.is_a?(Symbol) && respond_to?(method, true)
send(method, *args)
else
false
end
end
# from http://www.igvita.com/2007/03/15/block-helpers-and-dry-views-in-rails/
# Only need this helper once, it will provide an interface to convert a block into a partial.
# 1. Capture is a Rails helper which will 'capture' the output of a block into a variable
# 2. Merge the 'body' variable into our options hash
# 3. Render the partial with the given options hash. Just like calling the partial directly.
def block_to_partial(partial_name, options = {}, &block)
options[:body] = capture(&block)
concat(render(partial: partial_name, locals: options))
end
def browser_is_ie?
user_agent = request.env['HTTP_USER_AGENT'].try.downcase
user_agent =~ /msie/ and user_agent !~ /opera/
end
end
##
## RSS SUPPORT
##
module Common::Utility::RssHelper
protected
def group_search_rss
format('<link rel="alternate" href="%s" title="%s" type="application/rss+xml" />', url_for(group_search_url(action: params[:action], path: current_rss_path)), I18n.t(:rss_feed))
end
def me_rss
# TODO: - fix rss
# '<link rel="alternate" href="/me/inbox/list/rss" title="%s %s" type="application/rss+xml" />' % [current_user.name, I18n.t(:me_inbox_link)]
end
# TODO: rewrite this using the rails 2.0 way, with respond_to do |format| ...
# although, this will be hard, since it seems *path globbing doesn't work
# with :format.
def handle_rss(locals)
if rss_request?
response.headers['Content-Type'] = 'application/rss+xml'
render partial: '/pages/rss', locals: locals
true
else
false
end
end
# return true if this is an rss request. Unfornately, for routes with
# glob *paths, we can't use :format. the ParsedPath @path, however, does
# a good job of identifying trailing format codes that are not otherwise
# unparsable as part of the path.
def rss_request?
@path.format == 'rss'
end
# used to build an rss link from the current params[:path]
def current_rss_path
@path.format('rss') # returns a copy of @path with format set
end
end
......@@ -59,12 +59,6 @@ module Common::Utility::TimeHelper
end
end
def localize_month(month)
# for example => :month_short_january
month_sym = ('month_short_' + month.downcase).to_sym
I18n.t(month_sym)
end
# formats a time, in full detail
# for example: Sunday 2007/July/3 2:13PM PST
def full_time(time)
......@@ -72,64 +66,4 @@ module Common::Utility::TimeHelper
time.strftime('%A %Y/%b/%d %I:%M%p') :
I18n.l(time)
end
def full_date(date)
date.strftime('%A %d/%b/%Y')
end
def to_utc(time)
Time.zone.local_to_utc(time)
end
def local_now
Time.zone.now
end
def after_day_start?(time)
local_now.at_beginning_of_day < time
end
def after_yesterday_start?(time)
local_now.yesterday.at_beginning_of_day < time
end
def after_week_start?(time)
(local_now.at_beginning_of_day - 7.days) < time
end
##
## This are used as a cheap time based expiry of fragment caches.
##
## for example:
## cache(:expires_in => hours(3))
##
## this does NOT actually expire the fragment cache, but it makes it invalid
## after three hours, which is just as good so long as you have an external
## job that cleans up after old files.
##
def hours(num)
(Time.now.to_i / num.hour).floor
end
def days(num)
(Time.now.to_i / num.days).floor
end
##############################################
## UI helpers
def calendar_tag(_field_id, date = nil)
include_calendar_tags
calendar_date_select_tag(date ? date.to_date.to_formatted_s(:long) : nil)
end
def include_calendar_tags
unless @calendar_tags_included
@calendar_tags_included = true
content_for :end_tags do
calendar_date_select_includes 'default'
end
end
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment