A jquery-like way for finding Shoes elements
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
README
demo.rb
shoe_query.rb

README

ShoeQuery (better name needed) was born out of a desire to be able to find and
manipulate elements in Shoes without having stashed away their locations ahead of time.
It was inspired by jQuery's mechanisms for finding and manipulating DOM objects in
Javascript. 

The fundamental object (a ShoeQuery object) is pretty much an array of Shoes Elements,
augmented with some extra functions.  ShoeQuery objects are created via a helper 
(unsurprisingly named shoe_query) that lives in the Shoes::App object, and so should
be accessible anywhere you want it.  You can pass into that helper a selector,
and it will return a ShoeQuery object containing the elements that match.  You can also
pass in an array of elements you already have handy, or an existing element, and it
will also return a ShoeQuery object containing those elements.  This form should be
familiar for those who've used jQuery.

Right now, the things it lets you do are pretty limited, though a lot of the
functionality jQuery specially provides already exists in Ruby.  The one big feature
is the ability to find elements by type, including css-like hierarchy.  You can do
this either by invoking shoe_query directly, or calling find on an existing shoe_query
object (to search within its children).  For example, given the demo app:

load 'shoe_query.rb'
Shoes.app do
  app = Shoes.app do
  para "foo"
  f = flow do
    para "bar"
    stack do
      para 'blah'
    end
  end
  b = button "click me to change all paragraphs"
  b.click do
    shoe_query('para').each {|p| p.text = "all ps" }
  end
  b2 = button "click me to just change the paragraphs inside the flow"
  b2.click do
    shoe_query('flow').find('para').each {|p| p.text = "flow ps"}
  end
  b3 = button "click me to change the button inside the stack"
  b3.click do
    shoe_query('stack para').each {|p| p.text = "stack p"}
  end
end

In this case, the first button modifies all three paragraph elements, while the latter
two use two different mechanisms to scope their changes to within the flow and within
the stack respectively