75 lines
2.8 KiB
Ruby
75 lines
2.8 KiB
Ruby
# DOC :
|
|
# ajouter =breadcrumb dans une vue
|
|
# pour personaliser le breadcrumb, il y a plusieurs options :
|
|
# passer un ou plusieurs parametre piur overrider l'existant par défaut
|
|
# :first_title premier element du breadcrumb
|
|
# :first_link premier path du breadcrumb
|
|
#
|
|
# :second_title second element du breadcrumb
|
|
# :second_link second path du breadcrumb
|
|
#
|
|
# :last_element le tout dernier element du breadcrumb
|
|
#
|
|
# :record est le nom du record pour un show ou un edit par exemple :record => @p_product.name
|
|
#
|
|
# :default_crud booléen qui active/neutralise la création du titre "Détail de .." ou "Modification .."
|
|
|
|
|
|
module BreadcrumbHelper
|
|
def breadcrumb(opts = {})
|
|
default_opts = {
|
|
action: @action,
|
|
first_title: @result[:first][:name],
|
|
first_link: @result[:first][:link],
|
|
default_crud: true
|
|
}
|
|
|
|
if @result[:second]
|
|
default_opts[:second_title] = @result[:second][:name]
|
|
default_opts[:second_link] = @result[:second][:link]
|
|
end
|
|
|
|
options = default_opts.merge opts
|
|
|
|
|
|
capture_haml do
|
|
haml_tag :h1 do
|
|
unless @result.present?
|
|
haml_concat "Erreur dans le BreadcrumbHelper"
|
|
else
|
|
if options[:record].present? || options[:last_element].present?
|
|
haml_concat(link_to options[:first_title], options[:first_link])
|
|
if options[:second_title].present? && options[:second_link].present?
|
|
haml_tag(:span) { haml_concat(link_to options[:second_title], options[:second_link]) }
|
|
elsif options[:second_title].present?
|
|
haml_tag(:span) {haml_concat( options[:second_title])}
|
|
end
|
|
else
|
|
if options[:second_title].present?
|
|
haml_concat(link_to options[:first_title], options[:first_link])
|
|
haml_tag(:span) { haml_concat( options[:second_title]) }
|
|
else
|
|
haml_concat( options[:first_title])
|
|
end
|
|
end
|
|
if options[:default_crud]
|
|
case options[:action]
|
|
when :new
|
|
haml_tag(:span) {haml_concat("Création #{options[:first_title].singularize.downcase}")}
|
|
when :edit
|
|
options[:record].present? ? haml_tag(:span) {haml_concat("Modification de : #{options[:record]}")} : haml_tag(:span) {haml_concat("Modification")}
|
|
when :index
|
|
haml_tag(:span) {haml_concat("Liste")}
|
|
when :show
|
|
options[:record].present? ? haml_tag(:span) {haml_concat("Détail de : #{options[:record]}")} : haml_tag(:span) {haml_concat("Détail")}
|
|
else
|
|
haml_tag(:span) {haml_concat(options[:record])} if options[:record].present?
|
|
end
|
|
end
|
|
haml_tag(:span) { haml_concat( options[:last_element]) } if options[:last_element].present?
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|