Initial import
This commit is contained in:
65
app/helpers/application_helper.rb
Normal file
65
app/helpers/application_helper.rb
Normal file
@@ -0,0 +1,65 @@
|
||||
# Engenharia de Software 2007.1
|
||||
# Copyright (C) 2007, Adriano, Alinson, Andre, Rafael e Bustamante
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
|
||||
require 'digest/md5'
|
||||
|
||||
module ApplicationHelper
|
||||
|
||||
# Converte para o timezone local
|
||||
def tz(time_at)
|
||||
TzTime.zone.utc_to_local(time_at.utc)
|
||||
end
|
||||
|
||||
FLASH_NAMES = [:notice, :warning, :message]
|
||||
|
||||
def flash_div
|
||||
output = ""
|
||||
for name in FLASH_NAMES
|
||||
if flash[name]
|
||||
output << "<div id='validation' class='validation #{name}' style='display: none'>#{flash[name]}"
|
||||
output << ". " + link_to("Undo"[] + "?", flash[:undo], :method => 'post') if flash[:undo]
|
||||
output << "</div>"
|
||||
end
|
||||
end
|
||||
return output
|
||||
end
|
||||
|
||||
def logged_in?
|
||||
session[:user_id]
|
||||
end
|
||||
|
||||
def current_user
|
||||
User.find(session[:user_id]) if logged_in?
|
||||
end
|
||||
|
||||
def admin?
|
||||
logged_in? and current_user.admin?
|
||||
end
|
||||
|
||||
def wiki(text)
|
||||
BlueCloth.new(text).to_html
|
||||
end
|
||||
|
||||
def highlight(name)
|
||||
return {:class => 'highlight'} if (flash[:highlight] == name)
|
||||
end
|
||||
|
||||
def gravatar_url_for(email, size=80)
|
||||
"http://www.gravatar.com/avatar.php?gravatar_id=#{Digest::MD5.hexdigest(email)}&size=#{size}&default=#{App.default_avatar}"
|
||||
end
|
||||
|
||||
def action_icon(action_name, description, options = {}, html_options = {})
|
||||
html_options.merge!({:class => 'icon', :alt => description, :title => description})
|
||||
link_to(image_tag("action/#{action_name}.gif"), options, html_options)
|
||||
end
|
||||
end
|
||||
15
app/helpers/attachments_helper.rb
Normal file
15
app/helpers/attachments_helper.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
# Engenharia de Software 2007.1
|
||||
# Copyright (C) 2007, Adriano, Alinson, Andre, Rafael e Bustamante
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
|
||||
module AttachmentsHelper
|
||||
end
|
||||
39
app/helpers/courses_helper.rb
Normal file
39
app/helpers/courses_helper.rb
Normal file
@@ -0,0 +1,39 @@
|
||||
# Engenharia de Software 2007.1
|
||||
# Copyright (C) 2007, Adriano, Alinson, Andre, Rafael e Bustamante
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
|
||||
module CoursesHelper
|
||||
def mime_class(str)
|
||||
str.strip!
|
||||
case str
|
||||
when "application/octet-stream"
|
||||
return "mime_binary"
|
||||
|
||||
when
|
||||
"application/pdf",
|
||||
"application/postscript",
|
||||
"application/msword"
|
||||
return "mime_document"
|
||||
|
||||
when "application/pdf"
|
||||
return "mime_document"
|
||||
|
||||
when
|
||||
"application/zip",
|
||||
"application/x-gzip",
|
||||
"application/x-gtar"
|
||||
return "mime_zip"
|
||||
|
||||
else "mime_plain_text"
|
||||
end
|
||||
end
|
||||
end
|
||||
15
app/helpers/events_helper.rb
Normal file
15
app/helpers/events_helper.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
# Engenharia de Software 2007.1
|
||||
# Copyright (C) 2007, Adriano, Alinson, Andre, Rafael e Bustamante
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
|
||||
module EventsHelper
|
||||
end
|
||||
2
app/helpers/log_helper.rb
Normal file
2
app/helpers/log_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
module LogHelper
|
||||
end
|
||||
15
app/helpers/news_helper.rb
Normal file
15
app/helpers/news_helper.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
# Engenharia de Software 2007.1
|
||||
# Copyright (C) 2007, Adriano, Alinson, Andre, Rafael e Bustamante
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
|
||||
module NewsHelper
|
||||
end
|
||||
47
app/helpers/stylesheets_helper.rb
Normal file
47
app/helpers/stylesheets_helper.rb
Normal file
@@ -0,0 +1,47 @@
|
||||
# Engenharia de Software 2007.1
|
||||
# Copyright (C) 2007, Adriano, Alinson, Andre, Rafael e Bustamante
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
|
||||
module StylesheetsHelper
|
||||
|
||||
def browser_is? name
|
||||
name = name.to_s.strip
|
||||
return true if browser_name == name
|
||||
return true if name == 'mozilla' && browser_name == 'gecko'
|
||||
return true if name == 'ie' && browser_name.index('ie')
|
||||
return true if name == 'webkit' && browser_name == 'safari'
|
||||
|
||||
end
|
||||
|
||||
def browser_name
|
||||
@browser_name ||= begin
|
||||
ua = request.env['HTTP_USER_AGENT'].downcase
|
||||
if ua.index('msie') && !ua.index('opera') && !ua.index('webtv')
|
||||
'ie'+ua[ua.index('msie')+5].chr
|
||||
elsif ua.index('gecko/')
|
||||
'gecko'
|
||||
elsif ua.index('opera')
|
||||
'opera'
|
||||
elsif ua.index('konqueror')
|
||||
'konqueror'
|
||||
elsif ua.index('applewebkit/')
|
||||
'safari'
|
||||
elsif ua.index('mozilla/')
|
||||
'gecko'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def ie?
|
||||
return browser_is?('ie')
|
||||
end
|
||||
end
|
||||
15
app/helpers/user_helper.rb
Normal file
15
app/helpers/user_helper.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
# Engenharia de Software 2007.1
|
||||
# Copyright (C) 2007, Adriano, Alinson, Andre, Rafael e Bustamante
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
|
||||
module UserHelper
|
||||
end
|
||||
48
app/helpers/wiki_helper.rb
Normal file
48
app/helpers/wiki_helper.rb
Normal file
@@ -0,0 +1,48 @@
|
||||
# Engenharia de Software 2007.1
|
||||
# Copyright (C) 2007, Adriano, Alinson, Andre, Rafael e Bustamante
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
|
||||
module WikiHelper
|
||||
|
||||
def format_diff(text)
|
||||
last = 0
|
||||
result = ""
|
||||
text << "\n"
|
||||
style = { '+' => 'add', '-' => 'del', ' ' => 'line' }
|
||||
|
||||
text.each do |line|
|
||||
# Ignora o cabecalho
|
||||
next if line.match(/^---/)
|
||||
next if line.match(/^\+\+\+/)
|
||||
|
||||
# Divisao entre pedacos
|
||||
if line[0].chr == '@'
|
||||
result << "<tr><td class='diff_space diff_border_#{style[last.chr]}' ></td></tr>"
|
||||
last = 0
|
||||
else
|
||||
# Verifica se mudou de contexto (add para del, linha normal para add, etc)
|
||||
if line[0] != last
|
||||
last = line[0] if last == 0 or line[0].chr == '+' or line[0].chr == '-'
|
||||
result << "<tr><td class='diff_border_#{style[last.chr]} "
|
||||
last = line[0]
|
||||
|
||||
else
|
||||
result << "<tr><td class='"
|
||||
end
|
||||
result << "diff_#{style[line[0].chr]}'>" +
|
||||
" #{line[1..-1]} </td></td>"
|
||||
end
|
||||
end
|
||||
|
||||
return "<table class='diff'>#{result}</table>"
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user