Module: Flunkey::Helpers

Defined in:
lib/flunkey/helpers.rb

Constant Summary collapse

DOWNLOAD_SPEEDS =

Byte per second

{
  'Modem'=>7000,
  'EDGE'=>24500,
  'DSL Light'=>96000,
  'DSL 3000'=>375000,
  'DSL 16000'=>2000000
}

Instance Method Summary collapse

Instance Method Details



38
39
40
41
42
43
# File 'lib/flunkey/helpers.rb', line 38

def breadcrumbs(root, path)
  b = [root.dup]
  return b if root==path
  path.relative_path_from(root).descend{|p| b << root + p }
  b
end

#configObject



13
14
15
# File 'lib/flunkey/helpers.rb', line 13

def config
  settings
end

#debug(obj) ⇒ Object



59
60
61
# File 'lib/flunkey/helpers.rb', line 59

def debug(obj)
  "<pre>#{Rack::Utils.escape_html obj.inspect}</pre>"
end

#download_estimates(size) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/flunkey/helpers.rb', line 45

def download_estimates(size)
  result = []
  DOWNLOAD_SPEEDS.each do |name, speed|
    result << [name, (size/speed).round(1)]
  end
  result.sort{|a,b| b[1]<=>a[1]}
end

#icon_for(path) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/flunkey/helpers.rb', line 25

def icon_for(path)
  icon = case
    when path.directory? then "fa-folder"
    when path.bundle? then "fa-file-o"
    else "fa-file-o"
  end
  "<i class='fa #{icon}'></i>"
end

#localize(date) ⇒ Object Also known as: l



53
54
55
# File 'lib/flunkey/helpers.rb', line 53

def localize(date)
  date.strftime('%d.%m.%Y %H:%M')
end

#titleObject



17
18
19
20
21
22
23
# File 'lib/flunkey/helpers.rb', line 17

def title
  return @title if @title
  if @path && @root
    return (@root.basename + @path.relative_path_from(@root)).to_s
  end
  "Flunkey #{Flunkey::VERSION}"
end

#to_url(root, path) ⇒ Object



34
35
36
# File 'lib/flunkey/helpers.rb', line 34

def to_url(root, path)
  "/#{root.basename + path.relative_path_from(root)}"
end