module Accordion def open_page stack #scrolls through all the slots in the application #trying to determine which stack is active #this application consists of three slots -- each with two stacks. #In each slot, the second stack (the stack with the poem) is the #stack that you care about. By checking the height of the stack #with the detect function, you can determine if this is the #active stack. If the height is greater then zero, then the poem is #being shown to the user, thus, it IS the active stack, thus it #is returned to the user in the active variable active = app.contents.map { |x| x.contents[1] }. detect { |x| x.height > 0 } #if the stack is alreay active then return having #done nothing return if active == stack #animate the accordian like affect of hiding one poem #while showing another - animation is at 60 fps a = animate 60 do #add 20 pixles to the newly clicked stack height each go around #while subtracting the pixels from the previously active stack. stack.height += 20 active.height = 240 - stack.height if active #and stop when the newly clicked stack height is equal to 240 pixles a.stop if stack.height == 240 end end def page title, text #set pages equal to to the already existing array pages #or if it doesn't exist set it to a blank array @pages ||= [] #add the stack element to the @pages array @pages << #the stack is actually comprised of two stacks #the first one begins here and consist of the text #of the poem the second is the header bar to the poem #which contains the title stack do #set the initial page text to nil page_text = nil #begin the 'title bar' stack stack :width => "100%" do #set the background to a greyish gradient background "#fff".."#eed" #the 'hi' variable contains the background style that #the user will see when he hovers his mouse over the #title bar hi = background "#ddd".."#ba9", :hidden => true #the title name itself is made a link that when clicked #will call the 'open_page' function while sending in the #'page_text' variable para link(title). click { open_page page_text }, :size => 26 #if the user hovers with his mouse, the 'hi' background is shown hover { hi.show } #if the user's mouse leaves the title, the original background is shown leave { hi.hide } #if the title bar itself is clicked, the open_page function is called click { open_page page_text } end #now the the actual page_text is set. page_text = #if this is the first page, the height is set to 240 pixels #the rest of the pages are set to zero height to start stack :width => "100%", :height => (@pages.empty? ? 240 : 0) do stack :margin => 10 do #when two or more newlines are found, this means a line has been found #put that line in the stack text.split(/\n{2,}/).each do |pg| para text end end end end end end #This is where your shoes app begins! Shoes.app do extend Accordion #set the style of the various link attributes throughout the application style(Link, :stroke => black, :underline => nil, :weight => "strong") style(LinkHover, :stroke => black, :fill => nil, :underline => nil) #puts a call to the 'page' function in the accordian class while sending #in two variables. The first is 0.0. #<<-'END' means read all the text from here to 'END' #So the text starting from "There is" to "mental slippage.\n" is sent #to the page function page "0.0", <<-'END' There is a thought I have just had Which I don’t care to pass to Anyone at all at this time. I have even forgotten it now, But kept only the pleasures Of my property And of my controlled mental slippage. END #second call to the page function page "0.1", <<-'END' My eyes have blinked again And I have just realized This upright world I have been in. My eyelids wipe My eyes hundreds of times Reseting and renovating The scenery. END #third call to the page function page "0.2", <<-'END' Sister, without you, The universe would Have such a hole through it, Where infinity has been shot. This cannot be, though. There will always be room For you—all of us are Holding the way open. END end