Module: Statixite::ApplicationHelper

Defined in:
app/helpers/statixite/application_helper.rb

Constant Summary collapse

ALERT_TYPES =
[:success, :info, :warning, :danger]

Instance Method Summary collapse

Instance Method Details

#bootstrap_flash(options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/helpers/statixite/application_helper.rb', line 6

def bootstrap_flash(options = {})
  flash_messages = []
  flash.each do |type, message|
    # Skip empty messages, e.g. for devise messages set to nothing in a locale file.
    next if message.blank?

    type = type.to_sym
    type = :success if type == :notice
    type = :danger  if type == :alert
    type = :danger  if type == :error
    next unless ALERT_TYPES.include?(type)

    tag_class = options.extract!(:class)[:class]
    tag_options = {
      class: "alert fade in alert-#{type} #{tag_class}"
    }.merge(options)

    close_button = (:button, raw("×"), class: "close", "data-dismiss" => "alert")

    Array(message).each do |msg|
      text = (:div, close_button + msg.html_safe, tag_options)
      flash_messages << text if msg
    end
  end
  flash_messages.join("\n").html_safe
end

#bootstrap_form_flash(obj) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/helpers/statixite/application_helper.rb', line 33

def bootstrap_form_flash(obj)
  errors = obj.errors
  return unless obj.errors.any?
  flash_messages = []
  errors.full_messages.each do |message|
    tag_options = {
      class: "alert fade in alert-danger"
    }
    close_button = (:button, raw("&times;"), class: "close", "data-dismiss" => "alert")
    flash_messages << (:div, close_button + message, tag_options)
  end
  flash_messages.join("\n").html_safe
end

#current_class?(path) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
50
# File 'app/helpers/statixite/application_helper.rb', line 47

def current_class?(path)
  return 'active' if current_page?(path)
  ''
end

#current_parent_class?(obj) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
55
# File 'app/helpers/statixite/application_helper.rb', line 52

def current_parent_class?(obj)
  return 'active' if current_page?(site_path(obj)) || (params[:site_id].present? && obj == Site.find(params[:site_id])) || current_page?(settings_site_path(id: params[:id]))
  ''
end

#post_date(post) ⇒ Object



57
58
59
60
61
# File 'app/helpers/statixite/application_helper.rb', line 57

def (post)
  return Date.today if post.new_record?
  return post.front_matter['date'].to_date if post.front_matter['date'].present?
  return post.updated_at.to_date
end