class PostRunner::ViewButtons
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.
Public Class Methods
new(views)
click to toggle source
Create a ViewButtons
object. @param views [Array of NavButtonDef] icons and URLs for all pages.
# 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
Public Instance Methods
current_page()
click to toggle source
Get the URL of the current page @return [String]
# File lib/postrunner/ViewButtons.rb, line 32 def current_page @current_view_url end
current_page=(page_url)
click to toggle source
Set the the current page. @param page_url [String] URL of the current page. This must either be nil or a URL in the predefined set.
# 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() { |view| ... }
click to toggle source
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.
# 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