module Silw::Helpers
Public Instance Methods
base_url()
click to toggle source
# File lib/silw/helpers.rb, line 11 def base_url "#{env['rack.url_scheme']}://#{env['HTTP_HOST']}/" end
find_template(views, name, engine, &block)
click to toggle source
Calls superclass method
# File lib/silw/helpers.rb, line 7 def find_template(views, name, engine, &block) Array(views).each { |v| super(v, name, engine, &block) } end
h(*args)
click to toggle source
# File lib/silw/helpers.rb, line 3 def h(*args) escape_html(*args) end
like_filesize(nr)
click to toggle source
# File lib/silw/helpers.rb, line 46 def like_filesize(nr) {'bytes' => 1024 ** 1, 'KB' => 1024 ** 2, 'MB' => 1024 ** 3, 'GB' => 1024 ** 4, 'TB' => 1024 ** 5, }.each_pair { |e, s| return "#{(nr.to_f / (s / 1024)).round(2)}#{e}" if nr < s } end
link_to(title, target = "", options = {})
click to toggle source
# File lib/silw/helpers.rb, line 39 def link_to(title, target = "", options = {}) options[:href] = target.respond_to?(:to_url) ? target.to_url : target options[:data] ||= {} [:method, :confirm].each { |a| options[:data][a] = options.delete(a) } haml "%a#{options} #{title}" end
partial(thing, locals = {})
click to toggle source
# File lib/silw/helpers.rb, line 15 def partial(thing, locals = {}) name = case thing when String then thing else thing.class.to_s.demodulize.underscore end haml :"partials/_#{name}", :locals => {name.to_sym => thing}.merge(locals) end
production?()
click to toggle source
# File lib/silw/helpers.rb, line 31 def production? settings.environment.to_sym == :production end
url_for(thing, options = {})
click to toggle source
# File lib/silw/helpers.rb, line 25 def url_for(thing, options = {}) url = thing.respond_to?(:to_url) ? thing.to_url : thing.to_s url = "#{base_url.sub(/\/$/, '')}#{url}" if options[:absolute] url end
user_logged_in?()
click to toggle source
# File lib/silw/helpers.rb, line 35 def user_logged_in? session[:auth].present? end