| 1 |
|
| 2 |
module ApplicationHelper |
| 3 |
|
| 4 |
def default_css_tag_sizes |
| 5 |
%w(tag_size_1 tag_size_2 tag_size_3 tag_size_4) |
| 6 |
end |
| 7 |
|
| 8 |
def linked_tag_list_as_sentence(tags) |
| 9 |
tags.map do |tag| |
| 10 |
link_to(h(tag.name), search_path(:q => "category:#{h(tag.name)}")) |
| 11 |
end.to_sentence |
| 12 |
end |
| 13 |
|
| 14 |
def build_notice_for(object) |
| 15 |
out = %Q{<div class="being_constructed">} |
| 16 |
out << %Q{ <p>This #{object.class.name.humanize.downcase} is being created,<br />} |
| 17 |
out << %Q{ it will be ready pretty soon…</p>} |
| 18 |
out << %Q{</div>} |
| 19 |
out |
| 20 |
end |
| 21 |
|
| 22 |
def render_if_ready(object, &blk) |
| 23 |
if object.respond_to?(:ready?) && object.ready? |
| 24 |
yield |
| 25 |
else |
| 26 |
concat(build_notice_for(object), blk.binding) |
| 27 |
end |
| 28 |
end |
| 29 |
|
| 30 |
def selected_if_current_page(url_options, slack = false) |
| 31 |
if slack |
| 32 |
if controller.request.request_uri.index(CGI.escapeHTML(url_for(url_options))) == 0 |
| 33 |
"selected" |
| 34 |
end |
| 35 |
else |
| 36 |
"selected" if current_page?(url_options) |
| 37 |
end |
| 38 |
end |
| 39 |
|
| 40 |
def link_to_with_selected(name, options = {}, html_options = nil) |
| 41 |
html_options = current_page?(options) ? {:class => "selected"} : nil |
| 42 |
link_to(name, options = {}, html_options) |
| 43 |
end |
| 44 |
|
| 45 |
def syntax_themes_css |
| 46 |
out = [] |
| 47 |
if @load_syntax_themes |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
return stylesheet_link_tag("syntax_themes/idle") |
| 56 |
end |
| 57 |
out.join("\n") |
| 58 |
end |
| 59 |
|
| 60 |
def base_url(full_url) |
| 61 |
URI.parse(full_url).host |
| 62 |
end |
| 63 |
|
| 64 |
def flashes |
| 65 |
flash.map {|type, content| content_tag(:div, content_tag(:p, content), :class => "flash_message #{type}")} |
| 66 |
end |
| 67 |
|
| 68 |
def gravatar_url_for(email, options = {}) |
| 69 |
"http://www.gravatar.com/avatar.php?gravatar_id=" << |
| 70 |
Digest::MD5.hexdigest(email) << |
| 71 |
"&default=" << |
| 72 |
u("http://#{request.host}:#{request.port}/images/default_face.gif") << |
| 73 |
options.map { |k,v| "&#{k}=#{v}" }.join |
| 74 |
end |
| 75 |
|
| 76 |
def gravatar(email, options = {}) |
| 77 |
size = options[:size] |
| 78 |
image_options = { :alt => "avatar" } |
| 79 |
if size |
| 80 |
image_options.merge!(:width => size, :height => size) |
| 81 |
end |
| 82 |
image_tag(gravatar_url_for(email, options), image_options) |
| 83 |
end |
| 84 |
|
| 85 |
def gravatar_frame(email, options = {}) |
| 86 |
extra_css_class = options[:style] ? " gravatar_#{options[:style]}" : "" |
| 87 |
%{<div class="gravatar#{extra_css_class}">#{gravatar(email, options)}</div>} |
| 88 |
end |
| 89 |
|
| 90 |
def flashes |
| 91 |
flash.map { |type, content| content_tag(:div, content_tag(:p, content), :class => "flash_message #{type}")} |
| 92 |
end |
| 93 |
|
| 94 |
def commit_graph_tag(repository, ref = "master") |
| 95 |
filename = Gitorious::Graphs::CommitsBuilder.filename(repository, ref) |
| 96 |
if File.exist?(File.join(Gitorious::Graphs::Builder.graph_dir, filename)) |
| 97 |
image_tag("graphs/#{filename}") |
| 98 |
end |
| 99 |
end |
| 100 |
|
| 101 |
def commit_graph_by_author_tag(repository, ref = "master") |
| 102 |
filename = Gitorious::Graphs::CommitsByAuthorBuilder.filename(repository, ref) |
| 103 |
if File.exist?(File.join(Gitorious::Graphs::Builder.graph_dir, filename)) |
| 104 |
image_tag("graphs/#{filename}") |
| 105 |
end |
| 106 |
end |
| 107 |
|
| 108 |
def title (page_title) |
| 109 |
content_for(:title) { page_title } |
| 110 |
end |
| 111 |
|
| 112 |
def meta_description (text) |
| 113 |
content_for(:meta_description, %Q{<meta name="description" content="#{text}" />}) |
| 114 |
end |
| 115 |
|
| 116 |
def meta_noindex |
| 117 |
content_for(:noindex, %Q{<meta name="ROBOTS" content="NOINDEX">}) |
| 118 |
end |
| 119 |
|
| 120 |
def meta_nofollow |
| 121 |
content_for(:nofollow, %Q{<meta name="ROBOTS" content="NOFOLLOW">}) |
| 122 |
end |
| 123 |
|
| 124 |
def div_no_breadcrumb |
| 125 |
%Q{<div id='no_breadcrumb'></div>} |
| 126 |
end |
| 127 |
|
| 128 |
def div_breadcrumb_open |
| 129 |
%Q{<div id='breadcrumb'><ul><li><span>/</span></li>} |
| 130 |
end |
| 131 |
|
| 132 |
def div_breadcrumb_close |
| 133 |
%Q{</ul></div>} |
| 134 |
end |
| 135 |
|
| 136 |
def breadcrumb_root |
| 137 |
%Q{<li>Home<span> / </span></li>} |
| 138 |
end |
| 139 |
|
| 140 |
def breadcrumb_home |
| 141 |
%Q{<li>#{link_to("Home", root_path)}<span> / </span></li>} |
| 142 |
end |
| 143 |
|
| 144 |
def breadcrumb_title (title) |
| 145 |
%Q{<li><h1 class='bctitle'>#{title}</h1></li>} |
| 146 |
end |
| 147 |
|
| 148 |
def breadcrumb_projects |
| 149 |
%Q{<li>#{link_to("Projects", projects_path)}<span> / </span></li>} |
| 150 |
end |
| 151 |
|
| 152 |
def breadcrumb_project |
| 153 |
%Q{<li>#{link_to(@project.title, project_path(@project.slug))}<span> / </span></li>} |
| 154 |
end |
| 155 |
|
| 156 |
def breadcrumb_tickets |
| 157 |
%Q{<li>#{link_to("Tickets", project_tickets_path)}<span> / </span></li>} |
| 158 |
end |
| 159 |
|
| 160 |
|
| 161 |
def breadcrumb_repositories |
| 162 |
%Q{<li>#{link_to("Git", project_repositories_path(@project))}<span> / </span></li>} |
| 163 |
end |
| 164 |
|
| 165 |
def breadcrumb_repository |
| 166 |
%Q{<li>#{link_to("Repo: " << format_squo(@repository.name), project_repository_path(@project, @repository))}<span> / </span></li>} |
| 167 |
end |
| 168 |
|
| 169 |
def breadcrumb_repos_logs |
| 170 |
%Q{<li>#{link_to("Commits", project_repository_commits_path(@project, @repository))}<span> / </span></li>} |
| 171 |
end |
| 172 |
|
| 173 |
def breadcrumb_wikis |
| 174 |
|
| 175 |
%Q{<li>#{link_to("Wikis", @project == nil ? wikis_path : project_wikis_path(@project))}<span> / </span></li>} |
| 176 |
end |
| 177 |
|
| 178 |
def breadcrumb_archives |
| 179 |
%Q{<li>#{link_to("Archives", articles_path)}<span> / </span></li>} |
| 180 |
end |
| 181 |
|
| 182 |
def breadcrumb_profiles |
| 183 |
%Q{<li>#{link_to("Profiles", profiles_path)}<span> / </span></li>} |
| 184 |
end |
| 185 |
|
| 186 |
def breadcrumb_profile |
| 187 |
%Q{<li>#{link_to(@profile.fullname, user_path(@profile.slug))}<span> / </span></li>} |
| 188 |
end |
| 189 |
|
| 190 |
def div_content_open (style) |
| 191 |
style == STYLE_WITHRIGHTCOLUMN ? %Q{<div id='content_withrightcolumn'>} : %Q{<div id='content_norightcolumn'>} |
| 192 |
end |
| 193 |
|
| 194 |
def div_content_close |
| 195 |
%Q{</div>} |
| 196 |
end |
| 197 |
|
| 198 |
def div_rightcolumn_open |
| 199 |
%Q{<div id='rightcolumn'>} |
| 200 |
end |
| 201 |
|
| 202 |
def div_rightcolumn_close |
| 203 |
%Q{</div>} |
| 204 |
end |
| 205 |
|
| 206 |
def div_publicpage_open |
| 207 |
%Q{<div id='publicpage'>} |
| 208 |
end |
| 209 |
|
| 210 |
def div_publicpage_close |
| 211 |
%Q{</div>} |
| 212 |
end |
| 213 |
|
| 214 |
def div_formattedtext_open |
| 215 |
%Q{<div class='formattedtext'>} |
| 216 |
end |
| 217 |
|
| 218 |
def div_formattedtext_close |
| 219 |
%Q{</div>} |
| 220 |
end |
| 221 |
|
| 222 |
def article_permalink_path (article) |
| 223 |
%Q{/#{article.created_at.year.to_s}/#{article.created_at.month.to_s}/#{article.permalink}} |
| 224 |
end |
| 225 |
|
| 226 |
def link_to_article (article) |
| 227 |
link_to(article.title, article_permalink_path(article)) |
| 228 |
end |
| 229 |
|
| 230 |
def link_to_profile (user) |
| 231 |
link_to(user.fullname, user_path(user.slug)) |
| 232 |
end |
| 233 |
|
| 234 |
def get_project_count (user) |
| 235 |
count = user.projects.public_count(user, current_user) |
| 236 |
count > 0 ? link_to(count, profile_projects_path(user.slug)) : "0" |
| 237 |
end |
| 238 |
|
| 239 |
def get_article_count (user) |
| 240 |
count = user.articles.public_count(current_user) |
| 241 |
count > 0 ? link_to(count, profile_articles_path(user.slug)) : "0" |
| 242 |
end |
| 243 |
|
| 244 |
def get_user_comment_count (user) |
| 245 |
|
| 246 |
user.comments.count > 0 ? link_to(user.comments.count, profile_comments_path(user.slug)) : "0" |
| 247 |
end |
| 248 |
|
| 249 |
|
| 250 |
def format_datetime_ddmmyyhhmm (datetime) |
| 251 |
datetime.strftime("%d-%m-%y %H:%M") |
| 252 |
end |
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
def format_datetime_article (datetime) |
| 257 |
|
| 258 |
datetime.strftime("%d %b ") << datetime.strftime("%y %I:").gsub(/ 0(\d\D)/, ' \1') << datetime.strftime("%M%p").downcase |
| 259 |
end |
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
def format_datetime_long (datetime) |
| 264 |
datetime.day.to_s << "<sup>" << get_day_suffix(datetime.day) << "</sup>" << datetime.strftime(" %B %Y ") << datetime.hour.to_s << datetime.strftime(":%m%p").downcase |
| 265 |
end |
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
def format_date_ddbbyy (datetime) |
| 270 |
datetime.strftime("%d %b %y") |
| 271 |
end |
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
def format_date_ddmmyy (datetime) |
| 277 |
datetime.strftime("%d-%m-%y") |
| 278 |
end |
| 279 |
|
| 280 |
|
| 281 |
def format_filesize (filesize) |
| 282 |
if filesize > 1000000000 |
| 283 |
%Q{#{(filesize/1073741824).to_s}GB} |
| 284 |
else |
| 285 |
filesize > 1000000 ? %Q{#{(filesize/1048576).to_s}MB} : %Q{#{(filesize/1024).to_s}KB} |
| 286 |
end |
| 287 |
end |
| 288 |
|
| 289 |
|
| 290 |
def format_squo (s) |
| 291 |
%Q{‘#{s}’} |
| 292 |
end |
| 293 |
|
| 294 |
|
| 295 |
def get_day_suffix (day) |
| 296 |
case day |
| 297 |
when 1,21,31 |
| 298 |
"st" |
| 299 |
when 2,22 |
| 300 |
"nd" |
| 301 |
when 3,23 |
| 302 |
"rd" |
| 303 |
else |
| 304 |
"th" |
| 305 |
end |
| 306 |
end |
| 307 |
|
| 308 |
def actionbox_default (flags = {}) |
| 309 |
out = %Q{<ul>} |
| 310 |
if logged_in? |
| 311 |
|
| 312 |
%Q{<li>#{link_to("Add To Shortcuts", "")}</li>} if flags[:allow_shortcuts] |
| 313 |
|
| 314 |
out << %Q{<li>#{link_to("Dashboard (" << current_user.fullname << ")", dashboard_user_path(current_user.slug))}</li>} |
| 315 |
out << %Q{<li>#{link_to("Logout", logout_path)}</li>} |
| 316 |
else |
| 317 |
out << %Q{<li>#{link_to("Login", login_path)}</li>} |
| 318 |
out << %Q{<li>#{link_to("Register", new_user_path)}</li>} |
| 319 |
end |
| 320 |
out << %Q{</ul>} |
| 321 |
out |
| 322 |
end |
| 323 |
|
| 324 |
def actionbox_basic (flags = {}) |
| 325 |
out = %Q{<table class='right_default_table'>} |
| 326 |
out << %Q{<tr><th>Actions</th></tr>} |
| 327 |
out << %Q{<tr><td>#{actionbox_default(flags)}</td></tr>} |
| 328 |
out << %Q{</table>} |
| 329 |
out |
| 330 |
end |
| 331 |
|
| 332 |
def actionbox_complex (flags = {}) |
| 333 |
out = %Q{<table class='right_default_table'>} |
| 334 |
out << %Q{<tr><th>Actions</th></tr>} |
| 335 |
|
| 336 |
acts = "" |
| 337 |
|
| 338 |
acts << %Q{<li>#{link_to("Manage Wiki Pages", project_wikis_path(@project.slug))}</li>} if flags[:manage_project_wikis] |
| 339 |
acts << %Q{<li>#{link_to("Edit Wiki Page", edit_project_wiki_path(@project.slug, @wiki.slug))}</li>} if flags[:edit_project_wiki] && @is_member |
| 340 |
acts << %Q{<li>#{link_to("New Wiki Page", new_project_wiki_path(@project.slug))}</li>} if flags[:new_project_wiki] && @is_member |
| 341 |
acts << %Q{<li>#{link_to("Edit Article", edit_project_article_path(@project.slug, @article.slug))}</li>} if flags[:edit_article] && @is_member |
| 342 |
acts << %Q{<li>#{link_to("New Article", new_project_article_path(@project.slug))}</li>} if flags[:new_article] && @is_member |
| 343 |
acts << %Q{<li>#{link_to("New Ticket", new_project_ticket_path(@project.slug))}</li>} if flags[:new_ticket] |
| 344 |
acts << %Q{<li>#{link_to("Edit Ticket", edit_project_ticket_path(@project.slug))}</li>} if flags[:edit_ticket] |
| 345 |
acts << %Q{<li>#{link_to("Close Ticket", root_path)}</li>} if flags[:close_ticket] |
| 346 |
acts << %Q{<li>#{link_to("New Milestone", new_project_milestone_path(@project.slug))}</li>} if flags[:new_milestone] && @is_member |
| 347 |
|
| 348 |
|
| 349 |
acts << %Q{<li>#{link_to("Manage Milestones", project_milestones_path(@project.slug))}</li>} if flags[:manage_milestones] && @is_member |
| 350 |
acts << %Q{<li>#{link_to("Manage Components", project_components_path(@project.slug))}</li>} if flags[:manage_components] && @is_member |
| 351 |
acts << %Q{<li>#{link_to("Manage Tickets", project_tickets_path(@project.slug))}</li>} if flags[:manage_tickets] |
| 352 |
acts << %Q{<li>#{link_to("New Member", new_project_member_path(@project.slug))}</li>} if flags[:new_member] && @is_member |
| 353 |
acts << %Q{<li>#{link_to("List Members", project_members_path(@project.slug))}</li>} if flags[:list_members] |
| 354 |
acts << %Q{<li>#{link_to("Clone Mainline", new_project_repository_path(@project.slug, @repository))}</li>} if flags[:clone_mainline] && logged_in? |
| 355 |
out << %Q{<tr><td><ul>#{acts}</ul></td></tr>} if acts != "" |
| 356 |
out << %Q{<tr><td>#{actionbox_default(flags)}</td></tr>} |
| 357 |
out << %Q{</table>} |
| 358 |
out |
| 359 |
end |
| 360 |
|
| 361 |
end |