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



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

def current_locale
  @locale
end

#current_userObject



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

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

#dynjs_include_tag(script_name) ⇒ Object



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

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



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
68
69
# File 'app/helpers/application_helper.rb', line 39

def pagetext(title, revision=nil, &block)
  content = capture(&block)
  b = Builder::XmlMarkup.new
  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.png", :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

#render_diff_table(chunks) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'app/helpers/application_helper.rb', line 71

def render_diff_table(chunks)
  Builder::XmlMarkup.new.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.td
            b.td('%s more lines' / chunk.num_lines.to_s, :colspan => '2')
            b.td
          end
        end
      else  
        b.tbody :class => chunk.action.to_s do
          chunk.lines.each do |line|
            b.tr do
              b.td {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.td {b << (line.modified_position || '&nbsp;').to_s}
            end
          end
        end
      end
    end
  end
end

#server_url_for(options = {}) ⇒ Object



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

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