Sha256: e23e571af230ad424ccca40edc08f985da15812c835ae4dbefc767938b278017

Contents?: true

Size: 1.96 KB

Versions: 5

Compression:

Stored size: 1.96 KB

Contents

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

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

  # 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
  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

  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

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

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

  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
  
  def link_path(section, link, *args)
    link.body_html
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
adva-0.2.4 app/helpers/base_helper.rb
adva-0.2.3 app/helpers/base_helper.rb
adva-0.2.2 app/helpers/base_helper.rb
adva-0.2.1 app/helpers/base_helper.rb
adva-0.2.0 app/helpers/base_helper.rb