Class: SWS::Hyperlink

Inherits:
Component show all
Defined in:
lib/sws/Core/components/Hyperlink/Hyperlink.rb

Overview

Represents <A> tag Bindings:

  • href - href attribute of the tag

  • page_name - name of the page to display after clicking the link (new

instance of the page will be created)

  • action - methods to call of link click

  • other_tag_string - generic string to add to the tag

  • direct_action_class - name of DirectAction subclass to call. Defaults to

“default_direct_action_class” from application.yaml file

  • direct_action_method - method of object of class specified in

“direct_action_class” binding to call on hyperlink click.

  • direct_action_query_string - query_string to attach to DirectAction

requests. May be used freely.

Instance Attribute Summary

Attributes inherited from Component

#action_components, #definition_component, #encoding, #html_attrs, #method_to_call, #name, #parameters, #parent, #request, #request_number, #slots, #subcomponents, #tokens

Instance Method Summary collapse

Methods inherited from Component

#api_filename, #app, #append_to_response, #awake, #container?, #content?, create, #create_component_tree, #definition_filename, #page, #process_bindings, #process_parameters, #process_request, #remove_subcomponents, #session, #set_request_subcomponents, #sleep, #slot_bound?, #subcomponent_for_name, synchronize_slot, #synchronize_slot?, #synchronize_slots, #template_filename, #tokenize_binding, #update_binding, #url_string

Constructor Details

#initialize(*args) ⇒ Hyperlink

Returns a new instance of Hyperlink.



18
19
20
21
# File 'lib/sws/Core/components/Hyperlink/Hyperlink.rb', line 18

def initialize (*args)
	super
	@action = nil
end

Instance Method Details

#enable_actionObject

Enables the action of the receiver, so that the action will be performed. Called by request handler, when it finds this hyperlink id in url



42
43
44
# File 'lib/sws/Core/components/Hyperlink/Hyperlink.rb', line 42

def enable_action ()
	@action = @slots["action"].bound_object()
end

#perform_actionObject

Performs the action if it has been set up



48
49
50
# File 'lib/sws/Core/components/Hyperlink/Hyperlink.rb', line 48

def perform_action ()
	return @action ? @action.call() : nil;
end

#prefixObject

Returns opening <A> tag



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/sws/Core/components/Hyperlink/Hyperlink.rb', line 24

def prefix ()

	if ( slot_bound?( "href" ) )	#normal, href hyperlink
		return generate_href_link( @slots["href"].value() )
	elsif ( slot_bound?( "page_name" ) )	#page for name
		return generate_page_link( @slots["page_name"].value() )
	elsif ( slot_bound?( "action" ) ) #call method on the same component
		return generate_action_link()
	elsif ( slot_bound?( "direct_action_class" ) )
		return generate_direct_action_link()
	end	#TODO: throw exception if none found?

end

#suffixObject

Generates closing </A> tag



54
55
56
# File 'lib/sws/Core/components/Hyperlink/Hyperlink.rb', line 54

def suffix ()
	return "</A>"
end