Module: BaseHelper

Defined in:
app/helpers/base_helper.rb

Instance Method Summary collapse

Instance Method Details

#author_options(users) ⇒ Object



40
41
42
43
44
# File 'app/helpers/base_helper.rb', line 40

def author_options(users)
  authors = [[current_user.name, current_user.id]]
  authors += users.map { |author| [author.name, author.id] }
  authors.uniq
end

#author_selected(content = nil) ⇒ Object



46
47
48
49
50
51
# File 'app/helpers/base_helper.rb', line 46

def author_selected(content = nil)
  # FIXME why would we want to preselect the previous author of the
  #       content when we are editing it?
  # content.try(:author_id) || current_user.id
  current_user.id
end

#buttons(&block) ⇒ Object



6
7
8
# File 'app/helpers/base_helper.rb', line 6

def buttons(&block)
  (:p, :class => 'buttons', &block)
end

#column(&block) ⇒ Object



2
3
4
# File 'app/helpers/base_helper.rb', line 2

def column(&block)
  (:div, :class => 'col', &block)
end

#datetime_with_microformat(datetime, options = {}) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'app/helpers/base_helper.rb', line 22

def datetime_with_microformat(datetime, options={})
  return datetime unless datetime.respond_to?(:strftime)
  options.symbolize_keys!
  options[:format] ||= :default
  options[:type]   ||= :time
  # yuck ... use the localized_dates plugin as soon as we're on Rails 2.2?
  # formatted_datetime = options[:format].is_a?(Symbol) ? datetime.clone.in_time_zone.to_s(options[:format]) : datetime.clone.in_time_zone.strftime(options[:format])
  formatted_datetime = l(datetime.in_time_zone.send(options[:type].to_sym == :time ? :to_time : :to_date), :format => options[:format])

  %{<abbr class="datetime" title="#{datetime.utc.xmlschema}">#{formatted_datetime}</abbr>}.html_safe
end

#filter_optionsObject



34
35
36
37
38
# File 'app/helpers/base_helper.rb', line 34

def filter_options
  FilteredColumn.filters.keys.inject([]) do |arr, key|
    arr << [FilteredColumn.filters[key].filter_name, key.to_s]
  end.unshift ["Plain HTML", '']
end


53
54
55
# File 'app/helpers/base_helper.rb', line 53

def link_path(section, link, *args)
  link.body_html
end

#split_form_for(*args, &block) ⇒ Object

does exactly the same as the form_for helper does, but splits off the form head tag and captures it to the content_for :form collector



12
13
14
15
16
17
18
19
20
# File 'app/helpers/base_helper.rb', line 12

def split_form_for(*args, &block)
  # for some weird reasons Passenger and Mongrel behave differently when using Rails' capture method
  # with_output_buffer -> works, so we use it for now
  lines = (form_for(*args, &block) || '').split("\n")
  content_for :form, lines.shift.html_safe
  lines.pop

  lines.join("\n").html_safe
end