diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,6 +1,7 @@ # Methods added to this helper will be available to all templates in the application. module ApplicationHelper + #new bootstrap header def navbar_user_header left_menu = '' right_menu = '' @@ -27,7 +28,7 @@ result = content_tag(:ul,left_menu.html_safe,class: 'nav navbar-nav') + content_tag(:ul,right_menu.html_safe,class: 'nav navbar-nav navbar-right') end - def add_menu(title, controller, action,html_option = {}) + def add_menu(title, controller, action, html_option = {}) link_option = {controller: controller, action: action} html_option[:class] = (html_option[:class] || '') + " active" if current_page?(link_option) content_tag(:li, link_to(title,link_option),html_option) @@ -84,11 +85,10 @@ end def format_short_time(time) - now = Time.now.gmtime + now = Time.zone.now st = '' - if (time.yday != now.yday) or - (time.year != now.year) - st = time.strftime("%x ") + if (time.yday != now.yday) or (time.year != now.year) + st = time.strftime("%d/%m/%y ") end st + time.strftime("%X") end @@ -99,6 +99,10 @@ return Time.at(d).gmtime.strftime("%X") end + def format_full_time_ago(time) + st = time_ago_in_words(time) + ' ago (' + format_short_time(time) + ')' + end + def read_textfile(fname,max_size=2048) begin File.open(fname).read(max_size) @@ -195,4 +199,26 @@ markdown.to_html.html_safe end + + BOOTSTRAP_FLASH_MSG = { + success: 'alert-success', + error: 'alert-danger', + alert: 'alert-danger', + notice: 'alert-info' + } + + def bootstrap_class_for(flash_type) + BOOTSTRAP_FLASH_MSG.fetch(flash_type.to_sym, flash_type.to_s) + end + + def flash_messages + flash.each do |msg_type, message| + concat(content_tag(:div, message, class: "alert #{bootstrap_class_for(msg_type)} fade in") do + concat content_tag(:button, 'x', class: "close", data: { dismiss: 'alert' }) + concat message + end) + end + nil + end + end