Sha256: 889c3a1cc906b48eff427af55458a5ded0b44d9538d81af2073a853e4d4d4cc9

Contents?: true

Size: 1.69 KB

Versions: 1

Compression:

Stored size: 1.69 KB

Contents

module MailyHerald
  module Webui
    class MenuManager
      module ControllerExtensions
        def self.included(base)
          base.extend ClassMethods
          base.send :include, InstanceMethods

          base.send :helper_method, :menu_manager, :set_menu_item, :current_menu_item
        end

        module ClassMethods
          protected

          def set_menu_item name
            before_filter do |controller|
              controller.send(:set_menu_item, name)
            end
          end
        end

        module InstanceMethods
          protected

          def set_menu_item name
            menu_manager.current_menu_item = name
          end

          def menu_manager 
            @menu_manager ||= MenuManager.new
          end

          def current_menu_item
            menu_manager.current_menu_item
          end
        end
      end

      attr_accessor :current_menu_item

      class << self
        @@items = nil

        def items
          @@items || setup
        end

        private

        def setup
          @items = [
            {:name => :dashboard, :title => :label_dashboard, :url => Proc.new{ root_path }},
            {:name => :lists, :title => :label_list_plural, :url => Proc.new{ lists_path }},
            {:name => :one_time_mailings, :title => :label_one_time_mailing_plural, :url => Proc.new{ one_time_mailings_path }},
            {:name => :periodical_mailings, :title => :label_periodical_mailing_plural, :url => Proc.new{ periodical_mailings_path }},
            {:name => :sequences, :title => :label_sequence_plural, :url => Proc.new{ sequences_path }},
          ]
        end
      end

      def items
        self.class.items
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
maily_herald-webui-0.8.0 lib/maily_herald/webui/menu_manager.rb