Module: Shortener::Server::ShortServerHelpers
- Defined in:
- lib/shortener/server/helpers.rb
Instance Method Summary collapse
- #authorize!(redir_url = '/u/login') ⇒ Object
- #available?(thing) ⇒ Boolean
- #bad!(message) ⇒ Object
- #base_url ⇒ Object
- #boxify_class(int, boxify_classes = '', nonbox_classes = '', other_classes = '') ⇒ Object
- #clippy(text, bgcolor = '#FFFFFF') ⇒ Object
- #logged_in? ⇒ Boolean
- #nope!(message = 'No luck.') ⇒ Object
- #ttl_display(ttl) ⇒ Object
Instance Method Details
#authorize!(redir_url = '/u/login') ⇒ Object
76 77 78 79 |
# File 'lib/shortener/server/helpers.rb', line 76 def (redir_url = '/u/login') return true unless $conf.authenticate? redirect redir_url unless env['warden'].authenticated? end |
#available?(thing) ⇒ Boolean
70 71 72 73 74 |
# File 'lib/shortener/server/helpers.rb', line 70 def available?(thing) return true unless $conf.authenticate? return true unless $conf.auth_route?(thing) return logged_in? end |
#bad!(message) ⇒ Object
5 6 7 |
# File 'lib/shortener/server/helpers.rb', line 5 def bad! halt 412, {}, end |
#base_url ⇒ Object
13 14 15 |
# File 'lib/shortener/server/helpers.rb', line 13 def base_url @base_url ||= "#{request.env['rack.url_scheme']}://#{request.env['HTTP_HOST']}" end |
#boxify_class(int, boxify_classes = '', nonbox_classes = '', other_classes = '') ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'lib/shortener/server/helpers.rb', line 55 def boxify_class(int, boxify_classes = '', nonbox_classes = '', other_classes = '') str = if @boxify "#{other_classes} #{boxify_classes}" else "#{other_classes} #{nonbox_classes}" end str = str + " offset#{int}" unless !int.nil? && @boxify str end |
#clippy(text, bgcolor = '#FFFFFF') ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/shortener/server/helpers.rb', line 17 def clippy(text, bgcolor='#FFFFFF') html = <<-EOF <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="110" height="25" id="clippy" > <param name="movie" value="/flash/clippy.swf"/> <param name="allowScriptAccess" value="always" /> <param name="quality" value="high" /> <param name="scale" value="noscale" /> <param NAME="FlashVars" value="text=#{text}"> <param name="bgcolor" value="#{bgcolor}"> <embed src="/flash/clippy.swf" width="110" height="14" name="clippy" quality="high" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" FlashVars="text=#{text}" bgcolor="#{bgcolor}" /> </object> EOF end |
#logged_in? ⇒ Boolean
65 66 67 68 |
# File 'lib/shortener/server/helpers.rb', line 65 def logged_in? return true unless $conf.authenticate? env['warden'].authenticated? end |
#nope!(message = 'No luck.') ⇒ Object
9 10 11 |
# File 'lib/shortener/server/helpers.rb', line 9 def nope!( = 'No luck.') halt 404, {}, end |
#ttl_display(ttl) ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/shortener/server/helpers.rb', line 44 def ttl_display(ttl) if ttl == -1 ret = 'expired' elsif ttl == nil ret = '∞' else ret = ttl end ret end |