Class: PostRunner::ViewButtons
- Inherits:
-
Object
- Object
- PostRunner::ViewButtons
- Defined in:
- lib/postrunner/ViewButtons.rb
Overview
This class generates a simple icon menue to select from a set of HTML pages (called views). The current page is represented as an inactive icon. All other icons are buttons that contain links to other pages.
Instance Method Summary collapse
-
#current_page ⇒ String
Get the URL of the current page.
-
#current_page=(page_url) ⇒ Object
Set the the current page.
-
#each ⇒ Object
Iterate over all buttons.
-
#initialize(views) ⇒ ViewButtons
constructor
Create a ViewButtons object.
Constructor Details
#initialize(views) ⇒ ViewButtons
Create a ViewButtons object.
22 23 24 25 26 27 28 |
# File 'lib/postrunner/ViewButtons.rb', line 22 def initialize(views) if views.empty? raise ArgumentError.new("'views' must not be empty") end @views = views self.current_page = views[0].url end |
Instance Method Details
#current_page ⇒ String
Get the URL of the current page
32 33 34 |
# File 'lib/postrunner/ViewButtons.rb', line 32 def current_page @current_view_url end |
#current_page=(page_url) ⇒ Object
Set the the current page. nil or a URL in the predefined set.
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/postrunner/ViewButtons.rb', line 39 def current_page=(page_url) unless page_url @current_view_url = nil return end if (current = @views.find { |v| v.url == page_url }) @current_view_url = current.url else raise ArgumentError.new("#{page_url} is not a URL of a known view") end end |
#each ⇒ Object
Iterate over all buttons. A NavButtonDef object is passed to the block that contains the icon and URL for the button. If no URL is set, the button is inactive.
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/postrunner/ViewButtons.rb', line 55 def each @views.each do |view| view = view.clone if @current_view_url == view.url view.url = nil end yield(view) end end |