Module: Tapestry::Factory
- Defined in:
- lib/tapestry/factory.rb
Instance Method Summary collapse
-
#on(definition, visit = false) {|@context| ... } ⇒ Object
(also: #on_page, #while_on)
Creates a definition context for actions.
-
#on_new(definition, &block) ⇒ Object
Creates a definition context for actions.
-
#on_view(definition, &block) ⇒ Object
(also: #on_visit)
Creates a definition context for actions and establishes the context for execution.
Instance Method Details
#on(definition, visit = false) {|@context| ... } ⇒ Object Also known as: on_page, while_on
Creates a definition context for actions. If an existing context exists, that context will be re-used. You can use this simply to keep the context for a script clear. For example, say you have the following interface definitions for pages:
class Home
include Tapestry
url_is "http://localhost:9292"
end
class
include Tapestry
end
You could then do this:
on_view(Home)
on()
The Home definition needs the url_is attribute in order for the on_view factory to work. But Navigation does not because the ‘on` method is not attempting to visit, simply to reference. Note that you can use `on` to visit, just by doing this:
on(Home, true)
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/tapestry/factory.rb', line 50 def on(definition, visit = false, &block) unless @context.is_a?(definition) @context = definition.new(@browser) if @browser @context = definition.new unless @browser @context.visit if visit end verify_page(@context) yield @context if block @context end |
#on_new(definition, &block) ⇒ Object
Creates a definition context for actions. Unlike the ‘on` factory, the `on_new` factory will always create a new context and will never re-use an existing one. The reason for using this factory might be that you are on the same page, but a given action has changed it so much that you want to reference it as a new version of that page, meaning a new context is established.
It’s doubtful that you will want to rely on this factory too much.
71 72 73 74 |
# File 'lib/tapestry/factory.rb', line 71 def on_new(definition, &block) @context = nil on(definition, &block) end |
#on_view(definition, &block) ⇒ Object Also known as: on_visit
Creates a definition context for actions and establishes the context for execution. Given an interface definition for a page like this:
class TestPage
include Tapestry
url_is "http://localhost:9292"
end
You can do the following:
on_view(TestPage)
Note that the actual factory creation is handled by ‘on`. This method exists as a way to differentiate when an interface needs to be visited.
19 20 21 |
# File 'lib/tapestry/factory.rb', line 19 def on_view(definition, &block) on(definition, true, &block) end |