Class: Cuca::Widget
- Inherits:
-
Object
- Object
- Cuca::Widget
- Defined in:
- lib/cuca/widget.rb,
lib/cuca/session.rb
Overview
end
Direct Known Subclasses
ARViewWidget, BaseList, Controller, Layout, FormErrorsWidget, FormWidget, LinkWidget, SLinkWidget
Class Method Summary collapse
-
.clear_hints ⇒ Object
clear all hints.
-
.define_attr_method(name, value = nil) ⇒ Object
this can be used by derrived classes.
-
.run_attr_method(name) ⇒ Object
tries to run a class method if defined and return it.
Instance Method Summary collapse
-
#app ⇒ Object
An accessor to the Cuca::app object.
-
#cgi ⇒ Object
An accessor to the global cgi variables.
-
#clear ⇒ Object
clear widgets generated content.
-
#content ⇒ Object
An accessor to @_content All ‘generators’ (like the mab -function) should append their generated clear text to @_content, latest with the before_to_s method.
-
#content=(newval) ⇒ Object
overwrite the content.
-
#controller ⇒ Object
an accessor to the current controller object - if available, otherwise nil.
-
#escape(text) ⇒ Object
Escape a string to use with URL etc..
-
#escapeHTML(text) ⇒ Object
escape a string on HTML codes.
-
#get_assigns ⇒ Object
will fetch a list of assigns to be passed to a code generator block this includes the :assigns from the constructor plus all instance variables from the widget.
-
#hints ⇒ Object
Hints is shared a shared container for all widgets.
-
#initialize(params = {}, &block) ⇒ Widget
constructor
initialize - don’t use widgets directly with .new.
-
#log ⇒ Object
An accessor to the global logger variables.
-
#output(*args, &block) ⇒ Object
Overwrite this method with a function that takes the arguments and optionally a block as you like.
-
#params ⇒ Object
an accessor to cgi.parameters variables.
-
#query_parameters ⇒ Object
accessor to cgi query parameters (http GET).
-
#request_method ⇒ Object
an accessor to request_method.
-
#request_parameters ⇒ Object
accessor to the cgi request parameters (http POST).
- #session ⇒ Object
-
#to_s ⇒ Object
get cleartext for the widget.
-
#unescape(text) ⇒ Object
Unescape an escaped string.
-
#unescapeHTML(text) ⇒ Object
unescape an html escaped string.
Constructor Details
#initialize(params = {}, &block) ⇒ Widget
139 140 141 142 143 144 145 146 147 |
# File 'lib/cuca/widget.rb', line 139 def initialize(params = {}, &block) @_assigns = params[:assigns] || {} @_args = params[:args] || {} @_profiler = params[:profiler] || nil @_block = block @_content = "" @@_hints ||= {} end |
Class Method Details
.clear_hints ⇒ Object
clear all hints
71 72 73 |
# File 'lib/cuca/widget.rb', line 71 def self.clear_hints @@_hints = {} end |
.define_attr_method(name, value = nil) ⇒ Object
this can be used by derrived classes
204 205 206 207 208 |
# File 'lib/cuca/widget.rb', line 204 def self.define_attr_method(name, value=nil) sing = class << self; self; end sing.class_eval "def #{name}; #{value.inspect}; end" # $stderr.puts "def #{name}; #{value.to_s.inspect}; end" end |
.run_attr_method(name) ⇒ Object
tries to run a class method if defined and return it
211 212 213 214 |
# File 'lib/cuca/widget.rb', line 211 def self.run_attr_method(name) return nil unless self.methods.include?(name) self.send(name.intern) end |
Instance Method Details
#app ⇒ Object
An accessor to the Cuca::app object
86 87 88 |
# File 'lib/cuca/widget.rb', line 86 def app $app end |
#cgi ⇒ Object
An accessor to the global cgi variables
76 77 78 |
# File 'lib/cuca/widget.rb', line 76 def cgi $app.cgi end |
#clear ⇒ Object
clear widgets generated content
164 165 166 |
# File 'lib/cuca/widget.rb', line 164 def clear @_content = "" end |
#content ⇒ Object
An accessor to @_content All ‘generators’ (like the mab -function) should append their generated clear text to @_content, latest with the before_to_s method
48 49 50 |
# File 'lib/cuca/widget.rb', line 48 def content @_content end |
#content=(newval) ⇒ Object
overwrite the content
53 54 55 |
# File 'lib/cuca/widget.rb', line 53 def content=(newval) @_content = newval end |
#controller ⇒ Object
an accessor to the current controller object - if available, otherwise nil
59 60 61 |
# File 'lib/cuca/widget.rb', line 59 def controller $controller_object || nil end |
#escape(text) ⇒ Object
Escape a string to use with URL etc..
113 114 115 |
# File 'lib/cuca/widget.rb', line 113 def escape(text) CGI::escape(text) end |
#escapeHTML(text) ⇒ Object
escape a string on HTML codes
123 124 125 |
# File 'lib/cuca/widget.rb', line 123 def escapeHTML(text) CGI::escapeHTML(text) end |
#get_assigns ⇒ Object
will fetch a list of assigns to be passed to a code generator block this includes the :assigns from the constructor plus all instance variables from the widget
152 153 154 155 156 157 158 159 160 161 |
# File 'lib/cuca/widget.rb', line 152 def get_assigns a = @_assigns.clone self.instance_variables.each do |v| next if v.match(/^\@\_/) next if v.include?('cancel_execution') # this is some internal key a[v.gsub(/\@/,'')] = self.instance_variable_get(v) end return a end |
#hints ⇒ Object
Hints is shared a shared container for all widgets. If you want to pass an information from one widget to another this can be useful. The last widget renered is the controller, then the Layout.
66 67 68 |
# File 'lib/cuca/widget.rb', line 66 def hints @@_hints end |
#log ⇒ Object
An accessor to the global logger variables
81 82 83 |
# File 'lib/cuca/widget.rb', line 81 def log $app.logger end |
#output(*args, &block) ⇒ Object
Overwrite this method with a function that takes the arguments and optionally a block as you like.
171 172 173 |
# File 'lib/cuca/widget.rb', line 171 def output(*args, &block) @_content = "This widget doesnt have any content" end |
#params ⇒ Object
an accessor to cgi.parameters variables. This is NOT params from the CGI class (see cgi_fix)
93 94 95 |
# File 'lib/cuca/widget.rb', line 93 def params $app.cgi.parameters end |
#query_parameters ⇒ Object
accessor to cgi query parameters (http GET)
98 99 100 |
# File 'lib/cuca/widget.rb', line 98 def query_parameters $app.cgi.query_parameters end |
#request_method ⇒ Object
an accessor to request_method
108 109 110 |
# File 'lib/cuca/widget.rb', line 108 def request_method return $app.cgi.request_method end |
#request_parameters ⇒ Object
accessor to the cgi request parameters (http POST)
103 104 105 |
# File 'lib/cuca/widget.rb', line 103 def request_parameters $app.cgi.request_parameters end |
#session ⇒ Object
163 164 165 |
# File 'lib/cuca/session.rb', line 163 def session $session end |
#to_s ⇒ Object
get cleartext for the widget
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/cuca/widget.rb', line 183 def to_s if @_profiler then require 'profiler' Profiler__::start_profile end output(*@_args, &@_block) before_to_s if self.methods.include?('before_to_s') content = @_content.to_s if @_profiler then Profiler__::stop_profile @_profiler.puts "____________________PROFILER #{self.class.inspect} ______________________" Profiler__::print_profile(@_profiler) end return content end |
#unescape(text) ⇒ Object
Unescape an escaped string
118 119 120 |
# File 'lib/cuca/widget.rb', line 118 def unescape(text) CGI::unescape(text) end |
#unescapeHTML(text) ⇒ Object
unescape an html escaped string
128 129 130 |
# File 'lib/cuca/widget.rb', line 128 def unescapeHTML(text) CGI::unescapeHTML(text) end |