Module: Base::Project::App::Helpers::BaseHelper

Defined in:
lib/base/project/app/helpers/base_helper.rb

Instance Method Summary collapse

Instance Method Details

#bootstrap_class_for(flash_type) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/base/project/app/helpers/base_helper.rb', line 3

def bootstrap_class_for(flash_type)
  case flash_type.to_sym
  when :success
    'alert-success' # Green
  when :error
    'alert-danger' # Red
  when :alert
    'alert-warning' # Yellow
  when :notice
    'alert-success' # Blue
  when :info
    'alert-info' # Blue
  else
    flash_type.to_s
  end
end


81
82
83
# File 'lib/base/project/app/helpers/base_helper.rb', line 81

def brand_link
  link_to(t('application_name'), authenticated_user_path, class: 'navbar-brand')
end


95
96
97
# File 'lib/base/project/app/helpers/base_helper.rb', line 95

def cancel_link(destination)
  round_icon_link(path: destination, type: :button, icon: 'fa-close', button: 'btn-default', class: 'pull-right m-l-5', title: t('wizard.button.cancel'))
end


91
92
93
# File 'lib/base/project/app/helpers/base_helper.rb', line 91

def edit_link(destination)
  link_to((:span, '', class: 'fa fa-pencil'), destination, class: 'pull-right')
end


73
74
75
76
77
78
79
# File 'lib/base/project/app/helpers/base_helper.rb', line 73

def icon_link(path, icon, text)
  link_to(path) do
    concat (:span, '', class: icon)
    concat ' '
    concat text
  end
end


85
86
87
88
89
# File 'lib/base/project/app/helpers/base_helper.rb', line 85

def link_image(image, options = {})
  link_to(image.url(:big), target: '_blank', title: options[:title]) do
    image_tag(image.url(:thumb), class: 'text-center img-circle', title: options[:title])
  end
end

#log_out_menu_item(path, icon, text) ⇒ Object



69
70
71
# File 'lib/base/project/app/helpers/base_helper.rb', line 69

def log_out_menu_item(path, icon, text)
  menu_item(path, icon, text, method: :delete)
end


58
59
60
61
62
63
64
65
66
67
# File 'lib/base/project/app/helpers/base_helper.rb', line 58

def menu_item(path, icon, text, additional = {})
  options = { method: :get, remote: false }.merge(additional)

  (:li) do
    link_to path, method: options[:method], remote: options[:remote] do
      concat((:i, '', class: "#{icon.split('-').first} #{icon}"))
      concat(text)
    end
  end
end

#nested_select(options = {}) ⇒ Object



54
55
56
# File 'lib/base/project/app/helpers/base_helper.rb', line 54

def nested_select(options = {})
  select_tag(options[:field_name], options[:value], class: "form-control tag-select #{options[:class]}")
end

#nested_text_field(options = {}) ⇒ Object



50
51
52
# File 'lib/base/project/app/helpers/base_helper.rb', line 50

def nested_text_field(options = {})
  text_field_tag(options[:field_name], options[:value], type: :text, class: "form-control #{options[:class]}")
end

#page_title(text) ⇒ Object



45
46
47
48
# File 'lib/base/project/app/helpers/base_helper.rb', line 45

def page_title(text)
  title = t('application_name')
  text.blank? ? title : "#{title} - #{text}"
end


103
104
105
106
107
108
109
110
111
112
113
# File 'lib/base/project/app/helpers/base_helper.rb', line 103

def round_icon_link(params)
  params[:method] ||= :get
  params[:remote] ||= false
  data = {}

  data[:confirm] = params[:confirm] if params[:confirm]

  link_to(params[:path], method: params[:method], data: data, remote: params[:remote]) do
    round_icon_button(params)
  end
end

#show_flash(type, message) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/base/project/app/helpers/base_helper.rb', line 20

def show_flash(type, message)
  klass = bootstrap_class_for(type)

  (:div, class: "alert alert-dismissible fade in #{klass} flash-message", role: 'alert') do
    concat(button_tag(type: 'button', class: 'close', data: { dismiss: 'alert', label: 'Close' }) do
      (:span, 'x', aria: { hidden: true })
    end)

    concat(message)
  end
end

#show_flashes(flash) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/base/project/app/helpers/base_helper.rb', line 32

def show_flashes(flash)
  flash.each do |type, message|
    if message.is_a?(Array)
      message.each do |text|
        show_flash(type, text)
      end

    else
      show_flash(type, message)
    end
  end
end


99
100
101
# File 'lib/base/project/app/helpers/base_helper.rb', line 99

def submit_link
  round_icon_button type: :submit, icon: 'fa-save', button: 'btn-success', class: 'pull-right', title: t('wizard.button.finish')
end


115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/base/project/app/helpers/base_helper.rb', line 115

def text_icon_link(params)
  params[:shape] = ''
  params[:text] = params[:title]
  params[:method] ||= :get
  params[:remote] ||= false
  data = {}

  data[:confirm] = params[:confirm] if params[:confirm]

  link_to(params[:path], method: params[:method], data: data, remote: params[:remote]) do
    text_icon_button(params)
  end
end