Sha256: 1cff5372e384a31b2adbb1785040368367492693e41f5aa514a98e3d591c2a95

Contents?: true

Size: 1.02 KB

Versions: 3

Compression:

Stored size: 1.02 KB

Contents

module RubyApp

  module Elements

    module Navigation
      require 'ruby_app/element'

      class PageMenu < RubyApp::Element

        class NavigatedEvent < RubyApp::Element::Event

          attr_reader :page

          def initialize(data)
            super(data)
            @page = eval(data['page'])
          end

          def to_hash
            super.merge('page' => @page)
          end

        end

        template_path(:all, File.dirname(__FILE__))

        attr_reader :pages

        def initialize
          super
          @pages = []
        end

        def current_page
          RubyApp::Session.pages.last.class
        end

        protected

          def on_event(event)
            on_navigated(event) if event.is_a?(RubyApp::Elements::Navigation::PageMenu::NavigatedEvent)
            super(event)
          end

          def on_navigated(event)
            RubyApp::Session.pages.pop
            RubyApp::Session.pages.push(event.page.new)
            event.refresh
          end

      end

    end

  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
RubyApp-0.0.8 lib/ruby_app/elements/navigation/page_menu.rb
RubyApp-0.0.7 lib/ruby_app/elements/navigation/page_menu.rb
RubyApp-0.0.6 lib/ruby_app/elements/navigation/page_menu.rb