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
134 135 136 137 138 139 140 141 142 |
# File 'lib/cuca/widget.rb', line 134 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
66 67 68 |
# File 'lib/cuca/widget.rb', line 66 def self.clear_hints @@_hints = {} end |
.define_attr_method(name, value = nil) ⇒ Object
this can be used by derrived classes
200 201 202 203 204 |
# File 'lib/cuca/widget.rb', line 200 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
207 208 209 210 211 |
# File 'lib/cuca/widget.rb', line 207 def self.run_attr_method(name) return nil unless self.respond_to?(name.intern) self.send(name.intern) end |
Instance Method Details
#app ⇒ Object
An accessor to the Cuca::app object
81 82 83 |
# File 'lib/cuca/widget.rb', line 81 def app $app end |
#cgi ⇒ Object
An accessor to the global cgi variables
71 72 73 |
# File 'lib/cuca/widget.rb', line 71 def cgi $app.cgi end |
#clear ⇒ Object
clear widgets generated content
160 161 162 |
# File 'lib/cuca/widget.rb', line 160 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
43 44 45 |
# File 'lib/cuca/widget.rb', line 43 def content @_content end |
#content=(newval) ⇒ Object
overwrite the content
48 49 50 |
# File 'lib/cuca/widget.rb', line 48 def content=(newval) @_content = newval end |
#controller ⇒ Object
an accessor to the current controller object - if available, otherwise nil
54 55 56 |
# File 'lib/cuca/widget.rb', line 54 def controller $controller_object || nil end |
#escape(text) ⇒ Object
Escape a string to use with URL etc..
108 109 110 |
# File 'lib/cuca/widget.rb', line 108 def escape(text) CGI::escape(text) end |
#escapeHTML(text) ⇒ Object
escape a string on HTML codes
118 119 120 |
# File 'lib/cuca/widget.rb', line 118 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
147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/cuca/widget.rb', line 147 def get_assigns a = @_assigns.clone self.instance_variables.each do |v| vs = v.to_s next if vs.match(/^\@\_/) next if vs.include?('cancel_execution') # this is some internal key a[vs.gsub(/\@/,'')] = self.instance_variable_get(v) end 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.
61 62 63 |
# File 'lib/cuca/widget.rb', line 61 def hints @@_hints end |
#log ⇒ Object
An accessor to the global logger variables
76 77 78 |
# File 'lib/cuca/widget.rb', line 76 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.
167 168 169 |
# File 'lib/cuca/widget.rb', line 167 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)
88 89 90 |
# File 'lib/cuca/widget.rb', line 88 def params $app.cgi.parameters end |
#query_parameters ⇒ Object
accessor to cgi query parameters (http GET)
93 94 95 |
# File 'lib/cuca/widget.rb', line 93 def query_parameters $app.cgi.query_parameters end |
#request_method ⇒ Object
an accessor to request_method
103 104 105 |
# File 'lib/cuca/widget.rb', line 103 def request_method return $app.cgi.request_method end |
#request_parameters ⇒ Object
accessor to the cgi request parameters (http POST)
98 99 100 |
# File 'lib/cuca/widget.rb', line 98 def request_parameters $app.cgi.request_parameters end |
#session ⇒ Object
165 166 167 |
# File 'lib/cuca/session.rb', line 165 def session $session end |
#to_s ⇒ Object
get cleartext for the widget
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/cuca/widget.rb', line 179 def to_s if @_profiler then require 'profiler' Profiler__::start_profile end output(*@_args, &@_block) before_to_s if self.respond_to?(:before_to_s) out = @_content.to_s if @_profiler then Profiler__::stop_profile @_profiler.puts "____________________PROFILER #{self.class.inspect} ______________________" Profiler__::print_profile(@_profiler) end out end |
#unescape(text) ⇒ Object
Unescape an escaped string
113 114 115 |
# File 'lib/cuca/widget.rb', line 113 def unescape(text) CGI::unescape(text) end |
#unescapeHTML(text) ⇒ Object
unescape an html escaped string
123 124 125 |
# File 'lib/cuca/widget.rb', line 123 def unescapeHTML(text) CGI::unescapeHTML(text) end |