Module: ApplicationHelper

Defined in:
app/helpers/application_helper.rb

Overview

Methods added to this helper will be available to all templates in the application.

Constant Summary collapse

@@locale =

or ‘ja’ etc etc

'en'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.locale=(locale) ⇒ Object



5
6
7
# File 'app/helpers/application_helper.rb', line 5

def self.locale= (locale)
  @@locale = locale
end

Instance Method Details

#help_popup(html_file_partial) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/helpers/application_helper.rb', line 25

def help_popup(html_file_partial)
  if base_path
    dir = File.join(base_path, controller.controller_name)
  elsif defined?(finder)
    dir = File.join(finder.view_paths[0], controller.controller_name)
  else
    dir = File.join(view_paths.to_a[0], controller.controller_name)
  end
  prefix = dir + '/__help_' + html_file_partial
  if File.exists?( path = prefix+'.'+@@locale+'.html' ) ||
	File.exists?( path = prefix+'.html' ) || 
	File.exists?( path = prefix+'.en.html' )
    help_text = File.read( path )
  else
    help_text = '[BUG] Sorry, no help text was found for '+html_file_partial
  end

  html =<<-EOS
    <label id='#{'help_'+html_file_partial}' style="cursor:pointer">
    #{image_tag('helpmark16.png', :title=>'Help')}
    </label>
    <script>
      new PopupMenu('#{'help_'+html_file_partial}', 
                    '#{escape_javascript(help_text)}',
                    'Help' );
    </script>
  EOS
  html
end

#host_information_tableObject



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/helpers/application_helper.rb', line 55

def host_information_table
  request = controller.request
  html =<<-"EOS"
    <table>
      <tr><td>Host</td><td>#{request.host_with_port}</td></tr>
      <tr><td>Gfdnavi Root</td><td>/#{request.relative_url_root}</td></tr>
      <tr><td>Path</td><td>#{request.path}</td></tr>
      <tr><td>Env</td><td>#{RAILS_ENV}</td></tr>
      <tr><td>Server Software</td><td>#{request.server_software}</td></tr>
    </table>
  EOS
  return html
end

#image_path(obj) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
# File 'app/helpers/application_helper.rb', line 69

def image_path(obj)
  case obj
  when Image, Node
    data_dl_url(:path => obj.path.sub(/^\//,""))
  when DiagramCache
    url_for(:controller => 'analysis', :action => 'show_image', :id => obj.id)
  when String
    image_tag(obj)
  else
    nil
  end
end

#relative_url_rootObject



13
14
15
16
17
18
19
20
21
22
23
# File 'app/helpers/application_helper.rb', line 13

def relative_url_root
  if ActionController::Base.respond_to?(:relative_url_root)
    # for >= 2.2.2
    return ActionController::Base.relative_url_root  || ""
  elsif controller.request.respond_to?(:relative_url_root)
    # for < 2.2.2
    return controller.request.relative_url_root
  else
    raise "bug"
  end
end

#render_erb(src) ⇒ Object



9
10
11
# File 'app/helpers/application_helper.rb', line 9

def render_erb(src)
  ::ERB.new(src).result(binding)
end

#tree_lines(dir, user, first = true) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'app/helpers/application_helper.rb', line 82

def tree_lines(dir, user, first=true)
  lines = ""
  if (parent = dir.parent)
    if parent.directory_nodes(:user=>user)[-1] == dir
      if first
        type = "last"
      else
        type = "none"
      end
    else
      if first
        type = "t"
      else

        type = "tate"
      end
    end
    lines += tree_lines(parent, user, false)
    lines += image_tag("tree/#{type}.gif", :border => "0", :align => "middle", :class => "tree")+"<span class=\"tree\">\n</span>"
  end
  return lines
end