module TypusHelper ## # Applications list on the dashboard # def applications returning(String.new) do |html| Typus.applications.each do |app| available = Typus.application(app).map do |resource| resource if @current_user.resources.include?(resource) end next if available.compact.empty? html << <<-HTML HTML available.compact.each do |model| description = Typus.module_description(model) admin_items_path = { :controller => "admin/#{model.tableize}" } new_admin_item_path = { :controller => "admin/#{model.tableize}", :action => 'new'} html << <<-HTML HTML end html << <<-HTML
#{app}
#{link_to model.constantize.typus_human_name.pluralize, admin_items_path}
#{description}
#{link_to _("Add"), new_admin_item_path if @current_user.can_perform?(model, 'create')}
HTML end end end ## # Resources (wich are not models) on the dashboard. # def resources available = Typus.resources.map do |resource| resource if @current_user.resources.include?(resource) end return if available.compact.empty? returning(String.new) do |html| html << <<-HTML HTML available.compact.each do |resource| resource_path = { :controller => "admin/#{resource.underscore}" } html << <<-HTML HTML end html << <<-HTML
#{_("Resources")}
#{link_to _(resource.humanize), resource_path}
HTML end end def typus_block(*args) options = args.extract_options! partials_path = "admin/#{options[:location]}" resources_partials_path = 'admin/resources' partials = ActionController::Base.view_paths.map do |view_path| path = Rails.vendor_rails? ? view_path.path : "#{Rails.root}/#{view_path}" Dir["#{path}/#{partials_path}/*"].map { |f| File.basename(f, '.html.erb') } end.flatten resources_partials = Dir["#{Rails.root}/app/views/#{resources_partials_path}/*"].map { |f| File.basename(f, '.html.erb') } partial = "_#{options[:partial]}" path = if partials.include?(partial) then partials_path elsif resources_partials.include?(partial) then resources_partials_path end render :partial => "#{path}/#{options[:partial]}" if path end def page_title(action = params[:action]) crumbs = [ ] crumbs << @resource[:class].typus_human_name.pluralize if @resource crumbs << _(action.humanize) unless %w( index ).include?(action) return "#{Typus::Configuration.options[:app_name]} - " + crumbs.compact.map { |x| x }.join(' › ') end def header links = [] links << "
  • #{link_to_unless_current _("Dashboard"), admin_dashboard_path}
  • " Typus.models_on_header.each do |model| links << "
  • #{link_to_unless_current model.constantize.typus_human_name.pluralize, :controller => "/admin/#{model.tableize}"}
  • " end if ActionController::Routing::Routes.named_routes.routes.keys.include?(:root) links << "
  • #{link_to _("View site"), root_path, :target => 'blank'}
  • " end <<-HTML

    #{Typus::Configuration.options[:app_name]}

    HTML end def login_info(user = @current_user) admin_edit_typus_user_path = { :controller => "admin/#{Typus::Configuration.options[:user_class_name].tableize}", :action => 'edit', :id => user.id } <<-HTML HTML end def display_flash_message(message = flash) return if message.empty? flash_type = message.keys.first <<-HTML

    #{message[flash_type]}

    HTML end def typus_message(message, html_class = 'notice') <<-HTML

    #{message}

    HTML end def locales(uri = admin_set_locale_path) return unless Typus.locales.many? locale_links = Typus.locales.map { |l| "#{l.first.downcase}" } <<-HTML

    #{_("Set language to")} #{locale_links.join(', ')}.

    HTML end end