Module: ApplicationHelper

Included in:
ApplicationController
Defined in:
app/helpers/application_helper.rb

Overview

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

Instance Method Summary collapse

Instance Method Details

#current_localeObject



24
25
26
# File 'app/helpers/application_helper.rb', line 24

def current_locale
  @locale
end

#current_userObject



20
21
22
# File 'app/helpers/application_helper.rb', line 20

def current_user
  session[:user] || NullUser.new
end

#dynjs_include_tag(script_name) ⇒ Object



32
33
34
35
36
# File 'app/helpers/application_helper.rb', line 32

def dynjs_include_tag(script_name)
  ("script", "", { "type" => "text/javascript",
                              "src" => url_for(:controller => 'javascript',
                                               :action => script_name) })
end

#pagetext(title, revision = nil, &block) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/helpers/application_helper.rb', line 38

def pagetext(title, revision=nil, &block)
  content = capture(&block)
  xml = b.div(:class => 'pagetext') do
    b.a(:href => url_for(:controller => 'wiki', :action => 'history',
                         :page_name => @page.name, :locale => @locale,
                         :format => 'xml'),
        :class => 'rss') do
      b << image_tag("rss.gif", :border => 0, :class => 'rss',
                                :alt => 'Changes to %s' / @page.name) 
    end unless @page.nil?
    b.div(:id => 'crumbs') do
       b.text!('You are here: '.t)
       last = @crumbs.delete_at(@crumbs.length - 1)
       @crumbs.each do |h|
         b.a(h.keys.first,
             :href => url_for(h.values.first.update(:only_path => true)))
         b << ' > '
       end
       b.a(last.keys.first,
           :href => url_for(last.values.first.update(:only_path => true)))
    end unless params[:context] == 'partial'
    b.div(:class => 'page-title') do
      b.span(title, :class => 'page-title')
      b << ' '
      b.span(revision, :id => 'revision') unless revision.nil?
    end
    b << content
  end
  concat(xml, block.binding)
end

#parsing_error_boxObject



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

def parsing_error_box
  (:div,
                image_tag('error.gif') +
                (:p, ('The following wiki code contains an ' +
                                 'error that prevents it from being ' +
                                 'correctly formatted.').t),
              :class => 'message wikierror')
end

#render_diff_table(chunks) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'app/helpers/application_helper.rb', line 86

def render_diff_table(chunks)
  b.table :class => 'diff', :cellspacing => '0' do |b|
    b.colgroup do
      b.col :class => 'line_number'
      b.col :class => 'left'
      b.col :class => 'right'
      b.col :class => 'line_number'
    end
    chunks.each do |chunk|
      if chunk.separator?
        b.tbody :class => 'separator' do
          b.tr do
            b.th
            b.td('%s more lines' / chunk.num_lines.to_s, :colspan => '2')
            b.th
          end
        end
      else  
        b.tbody :class => chunk.action.to_s do
          chunk.lines.each do |line|
            b.tr do
              b.th {b << (line.original_position || '&nbsp;').to_s}
              b.td {b.pre {b << (h(line.original_text) || '&nbsp;')}}
              b.td {b.pre {b << (h(line.modified_text) || '&nbsp;')}}
              b.th {b << (line.modified_position || '&nbsp;').to_s}
            end
          end
        end
      end
    end
  end
end

#render_wiki(text) ⇒ Object



78
79
80
81
82
83
84
# File 'app/helpers/application_helper.rb', line 78

def render_wiki(text)
  begin
    @renderer.render_wiki_text(text)
  rescue
    parsing_error_box + (:pre, h(text), :class => 'wikisource')
  end
end

#server_url_for(options = {}) ⇒ Object



28
29
30
# File 'app/helpers/application_helper.rb', line 28

def server_url_for(options = {})
  url_for options.update(:only_path => false)
end