Module: GeneratorIfBlocks
- Defined in:
- lib/rjs/if/generator_if_blocks.rb
Instance Method Summary collapse
-
#else ⇒ Object
Close javascript block and open an ‘else’ block.
- #elsif(expression) ⇒ Object
-
#if(expression) ⇒ Object
Produces if block, e.g.
-
#unless(expression) ⇒ Object
Same as
if
method, but produces if_not block.
Instance Method Details
#else ⇒ Object
Close javascript block and open an ‘else’ block
40 41 42 43 44 |
# File 'lib/rjs/if/generator_if_blocks.rb', line 40 def else self << "else {" yield if block_given? self << "}" end |
#elsif(expression) ⇒ Object
33 34 35 36 37 |
# File 'lib/rjs/if/generator_if_blocks.rb', line 33 def elsif(expression) self << "else if( #{javascript_for(expression) } ) {" yield if block_given? self << "}" end |
#if(expression) ⇒ Object
Produces if block, e.g.
page.if "$('element_id').visible()" do
page['element_id'].hide
end
will produce
if( $('element_id').visible() ) {
$("element_id").hide()
}
You can simplify if expression by using element proxies:
page.if page['element_id'].visible do
page['element_id'].hide
end
20 21 22 23 24 |
# File 'lib/rjs/if/generator_if_blocks.rb', line 20 def if(expression) self << "if( #{ javascript_for(expression) } ) {" yield if block_given? self << "}" end |
#unless(expression) ⇒ Object
Same as if
method, but produces if_not block
27 28 29 30 31 |
# File 'lib/rjs/if/generator_if_blocks.rb', line 27 def unless(expression) self << "if( !( #{javascript_for(expression) } ) ) {" yield if block_given? self << "}" end |