Browse files

Breadcrumb helper

  • Loading branch information...
1 parent 41e3306 commit 91f5ef6ea873846872b84055ef06f2cf634b39f7 miguel.camba committed May 9, 2012
View
BIN app/assets/images/thoughtbot.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
7 app/assets/stylesheets/common.css.scss
@@ -1,3 +1,6 @@
+/* Variables */
+$btnBackgroundHighlight: #E6E6E6;
+
/* Espaciado */
.margin-1em {
margin-top: 1em;
@@ -15,4 +18,8 @@
}
.text-right {
text-align: right;
+}
+/* Colors */
+ul.dropdown-menu a.active{
+ background-color: $btnBackgroundHighlight;
}
View
27 app/helpers/application_helper.rb
@@ -1,11 +1,11 @@
# -*- encoding : utf-8 -*-
module ApplicationHelper
- # Sobreescribo link_to para que acepte opciones útiles.
+ # Override link_to so it can accept some useful options
#
- # icon: Genera un enlace con icono al estilo de twitter-bootstrap
- # Ejemplo:
- # link_to 'Mi cuenta', '#', icon: 'user' # => <a href="#"><i class="icon-user"></i>Mi cuenta</a>
+ # icon: Generates a link with a bootstrap-style icon
+ # Example:
+ # link_to 'Profile', '#', icon: 'user' # => <a href="#"><i class="icon-user"></i>Profile</a>
#
def link_to(body, url, html_options = {})
if (icon_class = html_options.delete(:icon))
@@ -28,22 +28,22 @@ def default_text_for_bootstrap_alert(level)
text.html_safe
end
- # Renderiza un alert estilado para bootstrap, con boton de cerrar.
+ # Renders a bootstrap-styled alert with close button and fade in effect.
def bootstrap_alert(text = nil, level = nil)
text ||= default_text_for_bootstrap_alert(level)
content_tag :div, class: "alert fade in #{flash_class(level)}" do
button_tag('×', class: 'close', data: { dismiss: "alert" }) + content_tag(:div, text, class: 'text-center')
end
end
- # Renderiza los flashes (:notice, :error, :success ...) con estilo de alerts de bootstrap
+ # Renders the flashes (:notice, :error, :success ...) on the bootstrap way.
def bootstrap_flashes
[:notice, :error, :alert, :success].map do |level|
bootstrap_alert(flash[level], level) unless flash[level].blank?
end.join.html_safe
end
- # Dado un tipo de mensaje flash, devuelve la clase del alert de bootstrap correspondiente
+ # Given a message type, return the bootrtrap's class for this king of alert
def flash_class(level)
case level.to_sym
when :notice then "alert-info"
@@ -53,4 +53,17 @@ def flash_class(level)
end
end
+ # Renders a bootstrap breadcrumbs for any number of links
+ def bootstrap_breadcrumb(*links)
+ content_tag :ul, class: 'breadcrumb' do
+ links.each_with_index.map do |link, index|
+ content_tag :li, class: ('active' if index == links.size - 1) do
+ content = link
+ content << (index < links.size - 1 ? content_tag(:span, '/', class: 'divider') : '')
+ content.html_safe
+ end
+ end.join.html_safe
+ end
+ end
+
end
View
4 app/helpers/issues_helper.rb
@@ -41,7 +41,9 @@ def issue_status_dropdown(issue)
content_tag :div, class: 'btn-group' do
link_to(link_content.html_safe, '#', class: 'btn btn-small dropdown-toggle', data: { toggle: "dropdown"} ) +
content_tag(:ul, class: 'dropdown-menu') do
- Issue::VALID_STATUS.map { |status| link_to(status, '#') }.join.html_safe
+ Issue::VALID_STATUS.map do |status|
+ link_to status, '#', class: ('active' if status == issue.status), data: { status: status }
+ end.join.html_safe
end
end
end
View
14 app/views/issues/show.html.haml
@@ -1,15 +1,5 @@
.row-fluid
.span12
- %ul.breadcrumb
- %li
- = link_to 'Home', root_path
- %span.divider /
- %li
- = link_to 'Projects', projects_path
- %span.divider /
- %li
- = link_to project.name, project
- %span.divider /
- %li.active
- = link_to "# #{issue.code} - #{issue.title}", '#'
+ = bootstrap_breadcrumb link_to('Home', root_path), link_to('Projects', projects_path),
+ link_to(project.name, '#'), link_to("# #{issue.code} - #{issue.title}", '#')
%p Bla bla esta issue bla bla
View
9 app/views/projects/index.html.haml
@@ -1,11 +1,6 @@
.row-fluid
.span12
- %ul.breadcrumb
- %li
- = link_to 'Home', root_path
- %span.divider /
- %li.active
- = link_to 'Projects', projects_path
+ = bootstrap_breadcrumb link_to('Home', root_path), link_to('Projects', projects_path)
.row-fluid
.span2
.sidebar-nav.well
@@ -17,7 +12,7 @@
%ul.thumbnails
%li.span2= link_to image_tag('la_o.png'), projects.first, class: 'thumbnail'
%li.span2= link_to image_tag('t.png'), '#', class: 'thumbnail'
- %li.span2= link_to image_tag('256x256.gif'), '#', class: 'thumbnail'
+ %li.span2= link_to image_tag('thoughtbot.png'), '#', class: 'thumbnail'
%li.span2= link_to image_tag('256x256.gif'), '#', class: 'thumbnail'
%li.span2= link_to image_tag('256x256.gif'), '#', class: 'thumbnail'
%li.span2= link_to image_tag('256x256.gif'), '#', class: 'thumbnail'
View
17 app/views/projects/show.html.haml
@@ -1,14 +1,8 @@
.row-fluid
.span12
- %ul.breadcrumb
- %li
- = link_to 'Home', root_path
- %span.divider /
- %li
- = link_to 'Projects', projects_path
- %span.divider /
- %li.active
- = link_to project.name, '#'
+ = bootstrap_breadcrumb link_to('Home', root_path), link_to('Projects', projects_path), link_to(project.name, '#')
+ .well
+ Opciones de búsqueda
.row-fluid
.span2
.sidebar-nav.well
@@ -17,7 +11,8 @@
%li= link_to 'Estadísticas', '#personal', icon: 'book'
%li= link_to 'Settings', '#associations', icon: 'home'
.span10
- %table.table.table-bordered.table-striped
+
+ %table.table.table-bordered.table-striped.table-condensed
%thead
%tr
%th #
@@ -27,7 +22,6 @@
%th Description
%th Assigned
%th Progress
- / %th Updated at
%tbody
- project.issues.each do |issue|
%tr
@@ -38,4 +32,3 @@
%td= truncate(issue.description, length: 50)
%td= link_to issue.responsable, issue.responsable if issue.responsable
%td= issue_progress_bar(issue)
- / %td= issue.updated_at.strftime '%d/%m/%y %H:%M'
View
11 spec/helpers/application_helper_spec.rb
@@ -55,4 +55,15 @@
end
end
+ describe '#bootstrap_breadcrumb' do
+ it "should render a breadcrumb for the given links" do
+ bootstrap_breadcrumb('a', 'b', 'c', 'd').should have_tag('ul.breadcrumb') do
+ with_tag('li', count: 4)
+ with_tag('li.active')
+ with_tag('span.divider', count: 3)
+ with_tag('span.divider', count: 3)
+ end
+ end
+ end
+
end
View
4 spec/helpers/issues_helper_spec.rb
@@ -39,7 +39,11 @@
dropdown.should have_tag('.btn-group') do
with_tag('a.btn.dropdown-toggle')
with_tag('ul.dropdown-menu')
+ # As many links as possible status
with_tag('.dropdown-menu a', count: Issue::VALID_STATUS.size)
+ # Only the one of the current status is active
+ with_tag('.dropdown-menu a.active', count: 1)
+ with_tag('.dropdown-menu a.active[data-status=in_progress]')
end
end
end

0 comments on commit 91f5ef6

Please sign in to comment.