diff --git a/Rakefile b/Rakefile index 2861ecd..45328d0 100644 --- a/Rakefile +++ b/Rakefile @@ -16,6 +16,13 @@ task :test do sh 'mspec -I./lib -f s test/component_spec.rb' end +task :install do +unless File.read('lib/wee.rb') =~ /Version\s+=\s+"(\d+\.\d+\.\d+)"/ + raise "no version" +end + sh "sudo gem install wee-#{$1}.gem" +end + task :package do sh 'gem build wee.gemspec' end @@ -23,3 +30,4 @@ end task :clean => [:clobber_rdoc] task :default => [:test, :rdoc, :clean] + diff --git a/doc/rdoc/classes/Array.html b/doc/rdoc/classes/Array.html deleted file mode 100644 index a853436..0000000 --- a/doc/rdoc/classes/Array.html +++ /dev/null @@ -1,120 +0,0 @@ - - - - -
-| Class | -Array | -
| In: | -
-
- lib/wee/state.rb
-
- - |
-
| Parent: | -- - Object - - | -
| Class | -Hash | -
| In: | -
-
- lib/wee/state.rb
-
- - |
-
| Parent: | -- - Object - - | -
| Class | -Object | -
| In: | -
-
- lib/wee/state.rb
-
- - |
-
| Parent: | -- - Object - - | -
-Extend base classes with snapshot functionality -
- -| Class | -String | -
| In: | -
-
- lib/wee/state.rb
-
- - |
-
| Parent: | -- - Object - - | -
| Class | -Struct | -
| In: | -
-
- lib/wee/state.rb
-
- - |
-
| Parent: | -- - Object - - | -
| Module | -Wee | -
| In: | -
-
- lib/wee.rb
-
- - - lib/wee/task.rb - - - - lib/wee/request.rb - - - - lib/wee/call_answer.rb - - - - lib/wee/presenter.rb - - - - lib/wee/session.rb - - - - lib/wee/application.rb - - - - lib/wee/conversation.rb - - - - lib/wee/jquery/jquery.rb - - - - lib/wee/id_generator.rb - - - - lib/wee/html_brushes.rb - - - - lib/wee/html_canvas.rb - - - - lib/wee/state.rb - - - - lib/wee/callback.rb - - - - lib/wee/html_writer.rb - - - - lib/wee/component.rb - - - - lib/wee/response.rb - - - - lib/wee/html_document.rb - - - - lib/wee/lru_cache.rb - - - - lib/wee/renderer.rb - - - - lib/wee/decoration.rb - - - |
-
| Version | -= | -"2.1.0" | -
-# File lib/wee.rb, line 33 -def Wee.run(component_class=nil, mount_path='/', port=2000, public_local_path=nil, &block) - raise ArgumentError if component_class and block - - require 'rack/handler/webrick' - app = Rack::Builder.app do - map mount_path do - if block - a = Wee::Application.new(&block) - else - a = Wee::Application.new { Wee::Session.new(component_class.instanciate) } - end - if public_local_path - run Rack::Cascade.new([Rack::File.new(public_local_path), a]) - else - run a - end - end - end - Rack::Handler::WEBrick.run(app, :Port => port) -end --
| Class | -Wee::AnswerDecoration | -
| In: | -
-
- lib/wee/call_answer.rb
-
- - |
-
| Parent: | -- - Decoration - - | -
-A Wee::AnswerDecoration is wrapped -around a component that will call Component#answer. This makes it possible -to use such components without the need to call them (Component#call), e.g. -as child components of other components. -
- -| answer_callback | -[RW] | -- |
-# File lib/wee/call_answer.rb, line 21 - def initialize(&answer_callback) - super() - @answer_callback = answer_callback - end --
-When a component answers, @answer_callback.call(answer) will be -executed, where answer is of class Answer which includes the arguments -passed to Component#answer. -
- --# File lib/wee/call_answer.rb, line 46 - def process_callbacks(callbacks) - if action_callback = super - Interceptor.new(action_callback, @answer_callback) - else - nil - end - end --
| Class | -Wee::AnswerDecoration::Answer | -
| In: | -
-
- lib/wee/call_answer.rb
-
- - |
-
| Parent: | -- Exception - | -
-Used to unwind the component call chain in Component#answer. -
- -| args | -[R] | -- |
-# File lib/wee/call_answer.rb, line 16 - def initialize(args) @args = args end --
| Class | -Wee::AnswerDecoration::Interceptor | -
| In: | -
-
- lib/wee/call_answer.rb
-
- - |
-
| Parent: | -- - Object - - | -
| action_callback | -[RW] | -- |
| answer_callback | -[RW] | -- |
-# File lib/wee/call_answer.rb, line 29 - def initialize(action_callback, answer_callback) - @action_callback, @answer_callback = action_callback, answer_callback - end --
-# File lib/wee/call_answer.rb, line 33 - def call - @action_callback.call - rescue Answer => answer - # return to the calling component - @answer_callback.call(answer) - end --
| Class | -Wee::Application | -
| In: | -
-
- lib/wee/application.rb
-
- - |
-
| Parent: | -- - Object - - | -
-A Wee::Application manages all Session‘s of a single application. It -dispatches the request to the correct handler by examining the request. -
- --# File lib/wee/application.rb, line 13 - def self.for(component_class, session_class=Wee::Session, *component_args) - new { session_class.new(component_class.new(*component_args)) } - end --
-Creates a new application. The -block, when called, must return a new Session -instance. -
-
- Wee::Application.new { Wee::Session.new(root_component) }
-
-
- -# File lib/wee/application.rb, line 29 - def initialize(max_sessions=10_000, &block) - @session_factory = block || raise(ArgumentError) - @session_ids ||= Wee::IdGenerator::Secure.new - @sessions = SessionCache.new(max_sessions) - @mutex = Mutex.new - end --
-Handles a web request -
- --# File lib/wee/application.rb, line 46 - def call(env) - request = Wee::Request.new(env) - - if request.session_id - session = @mutex.synchronize { @sessions[request.session_id] } - if session and session.alive? - session.call(env) - else - url = request.build_url(:session_id => nil, :page_id => nil) - Wee::RefreshResponse.new("Invalid or expired session", url).finish - end - else - session = new_session() - url = request.build_url(:session_id => session.id, :page_id => nil) - Wee::RedirectResponse.new(url).finish - end - end --
-Garbage collect dead sessions -
- --# File lib/wee/application.rb, line 39 - def cleanup_sessions - @mutex.synchronize { @sessions.garbage_collect } - end --
-# File lib/wee/application.rb, line 73 - def insert_session(session, retries=3) - retries.times do - @mutex.synchronize { - id = @session_ids.next - if @sessions[id].nil? - @sessions[id] = session - session.id = id - return - end - } - end - raise - end --
| Class | -Wee::Application::SessionCache | -
| In: | -
-
- lib/wee/application.rb
-
- - |
-
| Parent: | -- - Wee::LRUCache - - | -
| Class | -Wee::BlockComponent | -
| In: | -
-
- lib/wee/conversation.rb
-
- - |
-
| Parent: | -- - Component - - | -
-# File lib/wee/conversation.rb, line 6 - def initialize(&block) - @block = block - end --
-# File lib/wee/conversation.rb, line 10 - def render(r) - instance_exec(r, &@block) - end --
| Class | -Wee::Brush | -
| In: | -
-
- lib/wee/html_brushes.rb
-
- - |
-
| Parent: | -- - Object - - | -
| canvas | -[RW] | -- |
| document | -[RW] | -- |
-# File lib/wee/html_brushes.rb, line 29 - def self.nesting?() true end --
-# File lib/wee/html_brushes.rb, line 25 - def close - with if @document - end --
-This method is called right after initialize. It‘s only here to -simplify the implementation of Brushes, mainly to avoid passing all those -arguments to super. -
--There is a bit of redundancy with canvas -and document here. It‘s there to avoid method calls. -
--A brush is considered to be closed, when @document is nil. -
- --# File lib/wee/html_brushes.rb, line 15 - def setup(canvas, document) - @canvas = canvas - @document = document - end --
| Class | -Wee::Brush::ActionInputTag | -
| In: | -
-
- lib/wee/html_brushes.rb
-
- - |
-
| Parent: | -- Brush::InputTag - | -
-# File lib/wee/html_brushes.rb, line 471 - def __callback; name(@canvas.register_callback(:action, @callback)) end --
| Class | -Wee::Brush::AnchorTag | -
| In: | -
-
- lib/wee/html_brushes.rb
-
- - |
-
| Parent: | -- Brush::GenericTagBrush - | -
| HTML_TAG | -= | -'a'.freeze | -
| aliases | -[HtmlAttribute] | -- |
| aliases | -[HtmlAttribute] | -- |
| href | -[HtmlAttribute] | -- |
| title | -[HtmlAttribute] | -- |
-# File lib/wee/html_brushes.rb, line 708 - def initialize - super(HTML_TAG) - end --
-# File lib/wee/html_brushes.rb, line 719 - def __callback - url(@canvas.url_for_callback(@callback, :action, @info ? {:info => @info} : {})) - end --
| Class | -Wee::Brush::CheckboxTag | -
| In: | -
-
- lib/wee/html_brushes.rb
-
- - |
-
| Parent: | -- Brush::InputTag - | -
| HTML_TYPE | -= | -'checkbox'.freeze | -
-# File lib/wee/html_brushes.rb, line 434 - def initialize - super(HTML_TYPE) - end --
-# File lib/wee/html_brushes.rb, line 438 - def __callback; end --
-# File lib/wee/html_brushes.rb, line 440 - def with - if @callback - n = @canvas.register_callback(:input, proc {|input| - @callback.call(input.send(input.kind_of?(Array) ? :include? : :==, '1')) - }) - @document.single_tag('input', :type => 'hidden', :name => n, :value => '0') - name(n) - value('1') - end - super - end --
| Class | -Wee::Brush::FileUploadTag | -
| In: | -
-
- lib/wee/html_brushes.rb
-
- - |
-
| Parent: | -- Brush::InputTag - | -
-Use a <form> tag with enctype_multipart! -
- -| HTML_TYPE | -= | -'file'.freeze | -
| Class | -Wee::Brush::FormTag | -
| In: | -
-
- lib/wee/html_brushes.rb
-
- - |
-
| Parent: | -- Brush::GenericTagBrush - | -
| HTML_TAG | -= | -'form'.freeze | -
| HTML_METHOD_POST | -= | -'POST'.freeze | -
| action | -[HtmlAttribute] | -- |
| enctype | -[HtmlAttribute] | -- |
-# File lib/wee/html_brushes.rb, line 354 - def initialize - super(HTML_TAG) - @attributes[:method] = HTML_METHOD_POST - end --
-# File lib/wee/html_brushes.rb, line 369 - def __callback; action(@canvas.url_for_callback(@callback)) end --
-Use this enctype when you have a FileUploadTag field. -
- --# File lib/wee/html_brushes.rb, line 350 - def enctype_multipart - enctype('multipart/form-data') - end --
-# File lib/wee/html_brushes.rb, line 359 - def with(&block) - # If no action was specified, use a dummy one. - unless @attributes.has_key?(:action) - @attributes[:action] = @canvas.build_url - end - super - end --
| Class | -Wee::Brush::GenericEncodedTextBrush | -
| In: | -
-
- lib/wee/html_brushes.rb
-
- - |
-
| Parent: | -- Brush::GenericTextBrush - | -
-# File lib/wee/html_brushes.rb, line 42 - def with(text) - @document.encode_text(text) - @document = @canvas = nil - end --
| Class | -Wee::Brush::GenericSingleTagBrush | -
| In: | -
-
- lib/wee/html_brushes.rb
-
- - |
-
| Parent: | -- Brush::GenericTagBrush - | -
-# File lib/wee/html_brushes.rb, line 184 - def self.nesting?() false end --
-# File lib/wee/html_brushes.rb, line 179 - def with - @document.single_tag(@tag, @attributes) - @document = @canvas = nil - end --
| Class | -Wee::Brush::GenericTagBrush | -
| In: | -
-
- lib/wee/html_brushes.rb
-
- - |
-
| Parent: | -- Brush - | -
| EVENTS | -= | -{:click => 'onclick'.freeze, :dblclick => 'ondblclick'.freeze, :mouseover => 'onmouseover'.freeze, :mouseout => 'onmouseout'.freeze}.freeze | -- | -generic support for onXXX events - - | -
| css_class | -[HtmlAttribute] | -- |
| css_style | -[HtmlAttribute] | -- |
| html_name | -[HtmlAttribute] | -- |
| html_name | -[HtmlAttribute] | -- |
| id | -[HtmlAttribute] | -- |
| name | -[HtmlAttribute] | -- |
| onclick | -[HtmlAttribute] | -- |
| ondblclick | -[HtmlAttribute] | -- |
-# File lib/wee/html_brushes.rb, line 49 - def self.html_attr(attr, hash={}) - name = hash[:html_name] || attr - if hash[:type] == :bool - class_eval %{ - def #{ attr }(bool=true) - if bool - @attributes[:"#{ name }"] = nil - else - @attributes.delete(:"#{ name }") - end - self - end - } - else - class_eval %{ - def #{ attr }(value) - if value == nil - @attributes.delete(:"#{ name }") - else - @attributes[:"#{ name }"] = value - end - self - end - } - end - - (hash[:aliases] || []).each do |a| - class_eval "alias #{ a } #{ attr }" - end - - (hash[:shortcuts] || {}).each_pair do |k, v| - class_eval "def #{ k }() #{ attr }(#{ v.inspect }) end" - end - end --
-# File lib/wee/html_brushes.rb, line 93 - def initialize(tag) - super() - @tag = tag - @attributes = Hash.new - end --
-# File lib/wee/html_brushes.rb, line 129 - def callback_on(event, &block) - raise ArgumentError unless block - url = @canvas.url_for_callback(block) - javascript_on(event, "document.location.href='#{ url }'") - self - end --
-Returns a unique DOM id for the underlying component -
- --# File lib/wee/html_brushes.rb, line 109 - def get_oid - "wee_#{@canvas.current_component.object_id}" - end --
-# File lib/wee/html_brushes.rb, line 122 - def javascript_on(event, javascript) - ev = EVENTS[event] - raise ArgumentError unless ev - @attributes[ev] = "javascript: #{javascript};" - self - end --
-Assigns a unique DOM id -
- --# File lib/wee/html_brushes.rb, line 102 - def oid - id(get_oid()) - end --
-# File lib/wee/html_brushes.rb, line 160 - def onclick_callback(&block) - callback_on(:click, &block) - end --
-# File lib/wee/html_brushes.rb, line 156 - def onclick_javascript(v) - javascript_on(:click, v) - end --
-# File lib/wee/html_brushes.rb, line 164 - def ondblclick_callback(&block) - callback_on(:dblclick, &block) - end --
-# File lib/wee/html_brushes.rb, line 143 - def update_component_on(event, component=nil, &callback_block) - component ||= @canvas.current_component - - render_block = proc {|r| - callback_block.call if callback_block - r.render(component) - } - - url = @canvas.url_for_callback(@canvas.session.render_ajax_proc(render_block, component)) - javascript_on(event, "wee.update('#{ url }')") - self - end --
-# File lib/wee/html_brushes.rb, line 136 - def update_on(event, &render_block) - raise ArgumentError unless render_block - url = @canvas.url_for_callback(@canvas.session.render_ajax_proc(render_block, @canvas.current_component)) - javascript_on(event, "wee.update('#{ url }')") - self - end --
| Class | -Wee::Brush::GenericTextBrush | -
| In: | -
-
- lib/wee/html_brushes.rb
-
- - |
-
| Parent: | -- Brush - | -
-# File lib/wee/html_brushes.rb, line 38 - def self.nesting?() false end --
-# File lib/wee/html_brushes.rb, line 33 - def with(text) - @document.text(text) - @document = @canvas = nil - end --
| Class | -Wee::Brush::HiddenInputTag | -
| In: | -
-
- lib/wee/html_brushes.rb
-
- - |
-
| Parent: | -- Brush::InputTag - | -
| HTML_TYPE | -= | -'hidden'.freeze | -
| Class | -Wee::Brush::ImageButtonTag | -
| In: | -
-
- lib/wee/html_brushes.rb
-
- - |
-
| Parent: | -- Brush::ActionInputTag - | -
-NOTE: The form-fields returned by a image-button-tag is browser-specific. -Most browsers do not send the "name" key together with the value -specified by "value", only "name.x" and -"name.y". This conforms to the standard. But Firefox also sends -"name"="value". This is why I raise an exception from -the value method. Note that it‘s neccessary to parse the passed -form-fields and generate a "name" fields in the request, to make -this image-button work. -
- -| HTML_TYPE | -= | -'image'.freeze | -
| Class | -Wee::Brush::ImageTag | -
| In: | -
-
- lib/wee/html_brushes.rb
-
- - |
-
| Parent: | -- Brush::GenericSingleTagBrush - | -
| HTML_TAG | -= | -'img'.freeze | -
| alt | -[HtmlAttribute] | -- |
| border | -[HtmlAttribute] | -- |
| height | -[HtmlAttribute] | -- |
| src | -[HtmlAttribute] | -- |
| width | -[HtmlAttribute] | -- |
| Class | -Wee::Brush::InputTag | -
| In: | -
-
- lib/wee/html_brushes.rb
-
- - |
-
| Parent: | -- Brush::GenericSingleTagBrush - | -
| HTML_TAG | -= | -'input'.freeze | -
| checked | -[HtmlAttribute] | -- |
| disabled | -[HtmlAttribute] | -- |
| maxlength | -[HtmlAttribute] | -- |
| name | -[HtmlAttribute] | -- |
| readonly | -[HtmlAttribute] | -- |
| size | -[HtmlAttribute] | -- |
| src | -[HtmlAttribute] | -- |
| type | -[HtmlAttribute] | -- |
| type | -[HtmlAttribute] | -- |
| type | -[HtmlAttribute] | -- |
| type | -[HtmlAttribute] | -- |
| value | -[HtmlAttribute] | -- |
-# File lib/wee/html_brushes.rb, line 397 - def initialize(_type) - super(HTML_TAG) - type(_type) - end --
-# File lib/wee/html_brushes.rb, line 404 - def __callback; name(@canvas.register_callback(:input, @callback)) end --
| Class | -Wee::Brush::JavascriptTag | -
| In: | -
-
- lib/wee/html_brushes.rb
-
- - |
-
| Parent: | -- Brush::GenericTagBrush - | -
| HTML_TAG | -= | -'script'.freeze | -
| HTML_TYPE | -= | -'text/javascript'.freeze | -
| src | -[HtmlAttribute] | -- |
| type | -[HtmlAttribute] | -- |
| Class | -Wee::Brush::LinkTag | -
| In: | -
-
- lib/wee/html_brushes.rb
-
- - |
-
| Parent: | -- Brush::GenericTagBrush - | -
| HTML_TAG | -= | -'link'.freeze | -
| aliases | -[HtmlAttribute] | -- |
| href | -[HtmlAttribute] | -- |
| rel | -[HtmlAttribute] | -- |
| type | -[HtmlAttribute] | -- |
| Class | -Wee::Brush::Page | -
| In: | -
-
- lib/wee/html_brushes.rb
-
- - |
-
| Parent: | -- Brush - | -
| HTML_HTML | -= | -'html'.freeze | -
| HTML_HEAD | -= | -'head'.freeze | -
| HTML_TITLE | -= | -'title'.freeze | -
| HTML_BODY | -= | -'body'.freeze | -
-# File lib/wee/html_brushes.rb, line 765 - def head(&block) - raise ArgumentError unless block - @head = block - self - end --
-# File lib/wee/html_brushes.rb, line 760 - def title(t) - @title = t - self - end --
-# File lib/wee/html_brushes.rb, line 730 - def with(text=nil, &block) - @document.start_tag(HTML_HTML) - @document.start_tag(HTML_HEAD) - - if @title - @document.start_tag(HTML_TITLE) - @document.text(@title) - @document.end_tag(HTML_TITLE) - end - - if @head - @canvas.nest(&@head) - end - - @document.end_tag(HTML_HEAD) - @document.start_tag(HTML_BODY) - - if text - raise ArgumentError if block - @document.text(text) - else - @canvas.nest(&block) if block - end - - @document.end_tag(HTML_BODY) - @document.end_tag(HTML_HTML) - - @document = @canvas = nil - end --
| Class | -Wee::Brush::PasswordInputTag | -
| In: | -
-
- lib/wee/html_brushes.rb
-
- - |
-
| Parent: | -- Brush::InputTag - | -
| HTML_TYPE | -= | -'password'.freeze | -
| Class | -Wee::Brush::RadioButtonTag | -
| In: | -
-
- lib/wee/html_brushes.rb
-
- - |
-
| Parent: | -- Brush::InputTag - | -
| HTML_TYPE | -= | -'radio'.freeze | -
-# File lib/wee/html_brushes.rb, line 663 - def initialize - super(HTML_TYPE) - end --
-# File lib/wee/html_brushes.rb, line 674 - def __callback; end --
-# File lib/wee/html_brushes.rb, line 667 - def group(radio_group) - @group = radio_group - self - end --
-# File lib/wee/html_brushes.rb, line 676 - def with - if @group - n, v = @group.add_callback(@callback) - name(n) - value(v) - end - super - end --
| Class | -Wee::Brush::RadioGroup | -
| In: | -
-
- lib/wee/html_brushes.rb
-
- - |
-
| Parent: | -- - Object - - | -
-# File lib/wee/html_brushes.rb, line 638 - def initialize(canvas) - @name = canvas.register_callback(:input, self) - @callbacks = {} - @ids = Wee::IdGenerator::Sequential.new - end --
-# File lib/wee/html_brushes.rb, line 644 - def add_callback(callback) - value = @ids.next.to_s - @callbacks[value] = callback - return [@name, value] - end --
-# File lib/wee/html_brushes.rb, line 650 - def call(value) - if @callbacks.has_key?(value) - cb = @callbacks[value] - cb.call(value) if cb - else - raise "invalid radio button/group value" - end - end --
| Class | -Wee::Brush::SelectListTag | -
| In: | -
-
- lib/wee/html_brushes.rb
-
- - |
-
| Parent: | -- Brush::GenericTagBrush - | -
| HTML_TAG | -= | -'select'.freeze | -
| disabled | -[HtmlAttribute] | -- |
| multiple | -[HtmlAttribute] | -- |
| readonly | -[HtmlAttribute] | -- |
| size | -[HtmlAttribute] | -- |
| type | -[HtmlAttribute] | -- |
| type | -[HtmlAttribute] | -- |
| type | -[HtmlAttribute] | -- |
-# File lib/wee/html_brushes.rb, line 550 - def initialize(items) - super(HTML_TAG) - @items = items - end --
-# File lib/wee/html_brushes.rb, line 578 - def __callback - # - # A callback was specified. We have to wrap it inside another - # callback, as we want to perform some additional actions. - # - name(@canvas.register_callback(:input, method(:handler)) + "[]") - end --
-# File lib/wee/html_brushes.rb, line 555 - def items(items) - @items = items - self - end --
-# File lib/wee/html_brushes.rb, line 566 - def labels(arg=nil, &block) - raise ArgumentError if arg and block - if block - @labels = proc {|i| block.call(@items[i])} - else - @labels = arg - end - self - end --
-# File lib/wee/html_brushes.rb, line 560 - def selected(arg=nil, &block) - raise ArgumentError if arg and block - @selected = block || arg - self - end --
-# File lib/wee/html_brushes.rb, line 604 - def with - @labels ||= @items.collect {|i| i.to_s} - - if @attributes.has_key?(:multiple) - @selected ||= Array.new - meth = @selected.kind_of?(Proc) ? (:call) : (:include?) - else - meth = @selected.kind_of?(Proc) ? (:call) : (:==) - end - - super { - @items.each_index do |i| - @canvas.option.value(i).selected(@selected.send(meth, @items[i])).with(@labels[i]) - end - } - end --
-# File lib/wee/html_brushes.rb, line 586 - def handler(input) - choosen = input.map {|idx| - idx = Integer(idx) - raise IndexError if idx < 0 or idx > @items.size - @items[idx] - } - - if @attributes.has_key?(:multiple) - @callback.call(choosen) - elsif choosen.size > 1 - raise "more than one element was choosen from a not-multiple SelectListTag" - else - @callback.call(choosen.first) - end - end --
| Class | -Wee::Brush::SelectOptionTag | -
| In: | -
-
- lib/wee/html_brushes.rb
-
- - |
-
| Parent: | -- Brush::GenericTagBrush - | -
| HTML_TAG | -= | -'option'.freeze | -
| selected | -[HtmlAttribute] | -- |
| type | -[HtmlAttribute] | -- |
| value | -[HtmlAttribute] | -- |
| Class | -Wee::Brush::SubmitButtonTag | -
| In: | -
-
- lib/wee/html_brushes.rb
-
- - |
-
| Parent: | -- Brush::ActionInputTag - | -
| HTML_TYPE | -= | -'submit'.freeze | -
| Class | -Wee::Brush::TableDataTag | -
| In: | -
-
- lib/wee/html_brushes.rb
-
- - |
-
| Parent: | -- Brush::GenericTagBrush - | -
| HTML_TAG | -= | -'td'.freeze | -
| align | -[HtmlAttribute] | -- |
| colspan | -[HtmlAttribute] | -- |
| shortcuts | -[HtmlAttribute] | -- |
| Class | -Wee::Brush::TableHeaderTag | -
| In: | -
-
- lib/wee/html_brushes.rb
-
- - |
-
| Parent: | -- Brush::GenericTagBrush - | -
| HTML_TAG | -= | -'th'.freeze | -
| align | -[HtmlAttribute] | -- |
| colspan | -[HtmlAttribute] | -- |
| shortcuts | -[HtmlAttribute] | -- |
| Class | -Wee::Brush::TableRowTag | -
| In: | -
-
- lib/wee/html_brushes.rb
-
- - |
-
| Parent: | -- Brush::GenericTagBrush - | -
| HTML_TAG | -= | -'tr'.freeze | -
| align | -[HtmlAttribute] | -- |
| shortcuts | -[HtmlAttribute] | -- |
-# File lib/wee/html_brushes.rb, line 236 - def initialize - super(HTML_TAG) - end --
-# File lib/wee/html_brushes.rb, line 240 - def columns(*cols, &block) - with { - cols.each {|col| - @canvas.table_data.with { - if block - block.call(col) - else - @canvas.text(col) - end - } - } - } - end --
-# File lib/wee/html_brushes.rb, line 254 - def headings(*headers, &block) - with { - headers.each {|header| - @canvas.table_header.with { - if block - block.call(header) - else - @canvas.text(header) - end - } - } - } - end --
-# File lib/wee/html_brushes.rb, line 272 - def spacer - with { @canvas.table_data { @canvas.space } } - end --
| Class | -Wee::Brush::TableTag | -
| In: | -
-
- lib/wee/html_brushes.rb
-
- - |
-
| Parent: | -- Brush::GenericTagBrush - | -
| HTML_TAG | -= | -'table'.freeze | -
| border | -[HtmlAttribute] | -- |
| cellspacing | -[HtmlAttribute] | -- |
| Class | -Wee::Brush::TextAreaTag | -
| In: | -
-
- lib/wee/html_brushes.rb
-
- - |
-
| Parent: | -- Brush::GenericTagBrush - | -
| HTML_TAG | -= | -'textarea'.freeze | -
| accesskey | -[HtmlAttribute] | -- |
| cols | -[HtmlAttribute] | -- |
| disabled | -[HtmlAttribute] | -- |
| name | -[HtmlAttribute] | -- |
| onblur | -[HtmlAttribute] | -- |
| onchange | -[HtmlAttribute] | -- |
| onfocus | -[HtmlAttribute] | -- |
| onselect | -[HtmlAttribute] | -- |
| readonly | -[HtmlAttribute] | -- |
| rows | -[HtmlAttribute] | -- |
| tabindex | -[HtmlAttribute] | -- |
| type | -[HtmlAttribute] | -- |
| type | -[HtmlAttribute] | -- |
-# File lib/wee/html_brushes.rb, line 520 - def initialize - super(HTML_TAG) - end --
-# File lib/wee/html_brushes.rb, line 535 - def __callback; name(@canvas.register_callback(:input, @callback)) end --
-# File lib/wee/html_brushes.rb, line 524 - def value(val) - @value = val - self - end --
| Class | -Wee::Brush::TextInputTag | -
| In: | -
-
- lib/wee/html_brushes.rb
-
- - |
-
| Parent: | -- Brush::InputTag - | -
| HTML_TYPE | -= | -'text'.freeze | -
| Module | -Wee::CallAnswerMixin | -
| In: | -
-
- lib/wee/call_answer.rb
-
- - |
-
-Call another component. The calling component is neither rendered nor are -it‘s callbacks processed until the called component answers using -method answer. -
--How it works -
--The component to be called is wrapped with an AnswerDecoration and a Delegate decoration. The latter is used to -redirect to the called component. Once the decorations are installed, we -end the processing of callbacks prematurely. -
--When at a later point in time the called component invokes answer, this will raise a AnswerDecoration::Answer exception -which is catched by the AnswerDecoration we installed before -calling this component, and as such, whose process_callbacks method was -called before we gained control. -
--The AnswerDecoration then invokes the -answer_callback to cleanup the decorations we added during call and finally passes control to -the return_callback. -
- --# File lib/wee/call_answer.rb, line 85 - def call(component, &return_callback) - delegate = Wee::Delegate.new(component) - answer = Wee::AnswerDecoration.new {|answ| - remove_decoration(delegate) - component.remove_decoration(answer) - return_callback.call(*answ.args) if return_callback - } - add_decoration(delegate) - component.add_decoration(answer) - session.send_response(nil) - end --
-Similar to method call, but -using continuations. -
- --# File lib/wee/call_answer.rb, line 100 - def callcc(component) - delegate = Wee::Delegate.new(component) - answer = Wee::AnswerDecoration.new - - add_decoration(delegate) - component.add_decoration(answer) - - answ = Kernel.callcc {|cc| - answer.answer_callback = cc - session.send_response(nil) - } - remove_decoration(delegate) - component.remove_decoration(answer) - - args = answ.args - case args.size - when 0 - return - when 1 - return args.first - else - return *args - end - end --
| Module | -Wee::CallbackMixin | -
| In: | -
-
- lib/wee/html_brushes.rb
-
- - |
-
-Is called when callback_method was -used. -
- --# File lib/wee/html_brushes.rb, line 329 - def call(*args) - args.push(*@callback_args) - @callback_object.send(@callback_id, *args) - end --
-# File lib/wee/html_brushes.rb, line 320 - def callback(&block) - @callback = block - __callback() - return self - end --
| Class | -Wee::CallbackRegistry | -
| In: | -
-
- lib/wee/callback.rb
-
- - |
-
| Parent: | -- - Object - - | -
-# File lib/wee/callback.rb, line 4 - def initialize(prefix="") - @prefix = prefix - @next_id = 0 - @callbacks = {} # {callback_id1 => callback1, callback_id2 => callback2} - @triggered = nil - @obj_map = {} # obj => [callback_id1, callback_id2, ...] - end --
-# File lib/wee/callback.rb, line 53 - def each_triggered(object) - if ary = @obj_map[object] - for id in ary - yield @callbacks[id], @triggered[id] if @triggered.has_key?(id) - end - end - end --
-# File lib/wee/callback.rb, line 61 - def each_triggered_call_with_value(object) - if ary = @obj_map[object] - for id in ary - @callbacks[id].call(@triggered[id]) if @triggered.has_key?(id) - end - end - end --
-# File lib/wee/callback.rb, line 69 - def first_triggered(object) - if ary = @obj_map[object] - for id in ary - return @callbacks[id] if @triggered.has_key?(id) - end - end - return nil - end --
-NOTE that if fields named "xxx" and "xxx.yyy" occur, -the value of @fields[‘xxx’] is { nil => …, -‘yyy’ => … }. This is required to make image buttons -work correctly. -
- --# File lib/wee/callback.rb, line 31 - def prepare_triggered(ids_and_values) - @triggered = {} - ids_and_values.each do |id, value| - if id =~ /^#{@prefix}(\d+)([.](.*))?$/ - id, suffix = Integer($1), $3 - next unless @callbacks[id] - - if @triggered[id].kind_of?(Hash) - @triggered[id][suffix] = value - elsif suffix - @triggered[id] = {nil => @triggered[id], suffix => value} - else - @triggered[id] = value - end - end - end - end --
-# File lib/wee/callback.rb, line 12 - def register(object, callback) - id = @next_id - @next_id += 1 - @callbacks[id] = callback - (@obj_map[object] ||= []) << id - return "#{@prefix}#{id}" - end --
-# File lib/wee/callback.rb, line 49 - def reset_triggered - @triggered = nil - end --
| Class | -Wee::Callbacks | -
| In: | -
-
- lib/wee/callback.rb
-
- - |
-
| Parent: | -- - Object - - | -
| action_callbacks | -[R] | -- |
| input_callbacks | -[R] | -- |
-# File lib/wee/callback.rb, line 84 - def initialize - @input_callbacks = CallbackRegistry.new("") - @action_callbacks = CallbackRegistry.new("a") - end --
-# File lib/wee/callback.rb, line 89 - def unregister(object) - @input_callbacks.unregister(object) - @action_callbacks.unregister(object) - end --
| Class | -Wee::Component | -
| In: | -
-
- lib/wee/conversation.rb
-
- - - lib/wee/component.rb - - - |
-
| Parent: | -- - Object - - | -
-The base class of all components. You should at least overwrite method render in your own subclasses. -
- -| NO_CHILDREN | -= | -[].freeze | -
-Constructs a new instance of the -component and adds neccessary decorations. -
- --# File lib/wee/component.rb, line 17 - def self.instanciate(*args, &block) - obj = new(*args, &block) - unless obj.respond_to?(:root?) and obj.root? - obj.add_decoration Wee::PageDecoration.new - obj.add_decoration Wee::FormDecoration.new - end - obj - end --
-Initializes a newly created component. -
- --# File lib/wee/component.rb, line 37 - def initialize - end --
-Return all child components. -
--OVERWRITE this method and return all child components collected in -an array. -
- --# File lib/wee/component.rb, line 90 - def children - return NO_CHILDREN - end --
-# File lib/wee/conversation.rb, line 35 - def choose_from(items, caption=nil) - display do |r| - r.h3 caption if caption - selection = nil - r.select_list(items).callback {|s| selection = s } - r.break - r.submit_button.callback { answer selection }.value("Ok"); r.space - r.submit_button.callback { answer nil }.value("Cancel") - end - end --
-# File lib/wee/conversation.rb, line 20 - def confirm(question) - display do |r| - r.h3 question - r.submit_button.callback { answer true }.value("Yes"); r.space - r.submit_button.callback { answer false }.value("No") - end - end --
-# File lib/wee/conversation.rb, line 16 - def display(&block) - callcc BlockComponent.new(&block) - end --
-# File lib/wee/conversation.rb, line 28 - def inform(message) - display do |r| - r.h3 message - r.submit_button.callback { answer }.value("Ok") - end - end --
-Process and invoke all input callbacks specified for this component and all -of it‘s child components. -
--Returns the action callback to be invoked. -
- --# File lib/wee/component.rb, line 100 - def process_callbacks(callbacks) - callbacks.input_callbacks.each_triggered_call_with_value(self) - - action_callback = nil - - # process callbacks of all children - for child in self.children - if act = child.decoration.process_callbacks(callbacks) - raise "Duplicate action callback" if action_callback - action_callback = act - end - end - - if act = callbacks.action_callbacks.first_triggered(self) - raise "Duplicate action callback" if action_callback - action_callback = act - end - - return action_callback - end --
-This method renders the content of the component. -
--OVERWRITE this method in your own component classes to implement the -view. By default this method does nothing! -
--# File lib/wee/component.rb, line 49 - def render(r) - end --
-Is this a root component, which doesn‘t need to be wrapped with a PageDecoration and FormDecoration. -
- --# File lib/wee/component.rb, line 30 - def root? - false - end --
-Take snapshots of objects that should correctly be backtracked. -
--Backtracking means that you can go back in time of the components’ state. Therefore it is neccessary to take -snapshots of those objects that want to participate in backtracking. Taking -snapshots of the whole component tree would be too expensive and -unflexible. Note that methods take_snapshot and -restore_snapshot are called for those objects to take the snapshot -(they behave like marshal_dump and marshal_load). -Overwrite them if you want to define special behaviour. -
--By default only the decoration chain is backtracked. This is required to -correctly backtrack called components. To disable backtracking of the -decorations, change method Component#state_decoration to a -no-operation: -
-- def state_decoration(s) - # nothing here - end --
-# File lib/wee/component.rb, line 76 - def state(s) - state_decoration(s) - for child in self.children - child.decoration.state(s) - end - end --
| Class | -Wee::Decoration | -
| In: | -
-
- lib/wee/decoration.rb
-
- - |
-
| Parent: | -- - Presenter - - | -
-Abstract base class of all decorations. Forwards the methods process_callbacks, render_on and state to the next decoration in the -chain. Subclasses should provide special behaviour in these methods, -otherwise the decoration does not make sense. -
--For example, a HeaderFooterDecoration class could draw a header and footer -around the decorations or components below itself: -
-- class HeaderFooterDecoration < Wee::Decoration - alias render_on render_presenter_on - def render(r) - r.text "header" - r.render_decoration(@next) - r.text "footer" - end - end -- -
| render_on | --> | -render_presenter_on | -
| next | -[RW] | --Points to the next decoration in the chain. A decoration is responsible for -all decorations or components "below" it (everything that follows -this decoration in the chain). In other words, it‘s the owner of -everything "below" itself. - - | -
-Is this decoration a global or a local one? By default all decorations are -local unless this method is overwritten. -
--A global decoration is added in front of the decoration chain, a local -decoration is added in front of all other local decorations but after all -global decorations. -
- --# File lib/wee/decoration.rb, line 41 - def global?() false end --
-Forwards method call to the next decoration in the chain. -
- --# File lib/wee/decoration.rb, line 46 - def process_callbacks(callbacks) - @next.process_callbacks(callbacks) - end --
-Forwards method call to the next decoration in the chain. -
- --# File lib/wee/decoration.rb, line 54 - def render_on(r) - @next.render_on(r) - end --
-We have to save the @next attribute to be able to correctly backtrack -calls, as method Wee::Component#call modifies it in the call to -component.remove_decoration(answer). Removing the -answer-decoration has the advantage to be able to call a component more -than once! -
- --# File lib/wee/decoration.rb, line 65 - def state(s) - @next.state(s) - s.add_ivar(self, :@next, @next) - end --
| Module | -Wee::DecorationMixin | -
| In: | -
-
- lib/wee/decoration.rb
-
- - |
-
-Adds decoration d to -the decoration chain. -
--A global decoration is added in -front of the decoration chain, a -local decoration is added in -front of all other local decorations but after all global decorations. -
--Returns: self -
- --# File lib/wee/decoration.rb, line 97 - def add_decoration(d) - if d.global? - d.next = self.decoration - self.decoration = d - else - last_global = nil - each_decoration {|i| - if i.global? - last_global = i - else - break - end - } - if last_global.nil? - # no global decorations specified -> add in front - d.next = self.decoration - self.decoration = d - else - # add after last_global - d.next = last_global.next - last_global.next = d - end - end - - return self - end --
-# File lib/wee/decoration.rb, line 75 - def decoration() @decoration || self end --
-# File lib/wee/decoration.rb, line 74 - def decoration=(d) @decoration = d end --
-Iterates over all decorations (note that the component itself is excluded). -
- --# File lib/wee/decoration.rb, line 80 - def each_decoration # :yields: decoration - d = @decoration - while d and d != self - yield d - d = d.next - end - end --
-Remove decoration d -from the decoration chain. -
--Returns the removed decoration -or nil if it did not exist in the decoration chain. -
- --# File lib/wee/decoration.rb, line 130 - def remove_decoration(d) - if d == self.decoration # 'd' is in front - self.decoration = d.next - else - last_decoration = self.decoration - next_decoration = nil - loop do - return nil if last_decoration == self or last_decoration.nil? - next_decoration = last_decoration.next - break if d == next_decoration - last_decoration = next_decoration - end - last_decoration.next = d.next - end - d.next = nil # decoration 'd' no longer is an owner of anything! - return d - end --
-Remove all decorations that match the block condition. -
--Example (removes all decorations of class HaloDecoration): -
-
- remove_decoration_if {|d| d.class == HaloDecoration}
-
-
- -# File lib/wee/decoration.rb, line 155 - def remove_decoration_if # :yields: decoration - to_remove = [] - each_decoration {|d| to_remove << d if yield d} - to_remove.each {|d| remove_decoration(d)} - end --
| Class | -Wee::Delegate | -
| In: | -
-
- lib/wee/decoration.rb
-
- - |
-
| Parent: | -- - Decoration - - | -
-A Wee::Delegate breaks the decoration chain and -forwards the methods process_callbacks, -render_on and state to the corresponding chain -method of it‘s delegate component (a Wee::Component). -
- --# File lib/wee/decoration.rb, line 170 - def initialize(delegate) - @delegate = delegate - end --
-Forwards method to the corresponding top-level chain method of the -delegate component. -
- --# File lib/wee/decoration.rb, line 178 - def process_callbacks(callbacks) - @delegate.decoration.process_callbacks(callbacks) - end --
-Forwards method to the corresponding top-level chain method of the -delegate component. -
- --# File lib/wee/decoration.rb, line 186 - def render_on(r) - @delegate.decoration.render_on(r) - end --
-Forwards method to the corresponding top-level chain method of the -delegate component. We also take snapshots of all non-visible -components, thus we follow the @next decoration (via super). -
- --# File lib/wee/decoration.rb, line 195 - def state(s) - super - @delegate.decoration.state(s) - end --
| Module | -Wee::DupReplaceSnapshotMixin | -
| In: | -
-
- lib/wee/state.rb
-
- - |
-
| Class | -Wee::ErrorResponse | -
| In: | -
-
- lib/wee/response.rb
-
- - |
-
| Parent: | -- - Response - - | -
-# File lib/wee/response.rb, line 49 - def initialize(exception) - super() - self << "<html><head><title>Error occured</title></head><body>" - self << "<p>#{ escape_html(@exception.inspect) }<br/>" - self << exception.backtrace.map{|s| escape_html(s)}.join("<br/>") - self << "</p>" - self << "</body></html>" - end --
| Class | -Wee::FormDecoration | -
| In: | -
-
- lib/wee/decoration.rb
-
- - |
-
| Parent: | -- - WrapperDecoration - - | -
-# File lib/wee/decoration.rb, line 234 - def global?() true end --
-# File lib/wee/decoration.rb, line 236 - def render(r) - r.form { render_inner(r) } - end --
| Class | -Wee::GenericResponse | -
| In: | -
-
- lib/wee/response.rb
-
- - |
-
| Parent: | -- - Response - - | -
| EXPIRE_OFFSET | -= | -3600*24*365*20 | -
| EXPIRES_HEADER | -= | -'Expires'.freeze | -
-# File lib/wee/response.rb, line 14 - def initialize(*args) - super - self[EXPIRES_HEADER] ||= (Time.now + EXPIRE_OFFSET).rfc822 - end --
| Class | -Wee::HtmlCanvas | -
| In: | -
-
- lib/wee/html_canvas.rb
-
- - |
-
| Parent: | -- - Renderer - - | -
| HTML_NBSP | -= | -" ".freeze | -
| HTML_TYPE_CSS | -= | -'text/css'.freeze | -
| HTML_REL_STYLESHEET | -= | -'stylesheet'.freeze | -
| check_box | --> | -checkbox | -
| anchor | -[Brush] | -- |
| body | -[GenericTagBrush] | -- |
| bold | -[Brush] | -- |
| break | -[Brush] | -- |
| check_box | -[Brush] | -- |
| div | -[GenericTagBrush] | -- |
| file_upload | -[Brush] | -- |
| form | -[Brush] | -- |
| h1 | -[GenericTagBrush] | -- |
| h2 | -[GenericTagBrush] | -- |
| h3 | -[GenericTagBrush] | -- |
| h4 | -[GenericTagBrush] | -- |
| h5 | -[GenericTagBrush] | -- |
| head | -[GenericTagBrush] | -- |
| hidden_input | -[Brush] | -- |
| hr | -[GenericSingleTagBrush] | -- |
| html | -[GenericTagBrush] | -- |
| image | -[Brush] | -- |
| image_button | -[Brush] | -- |
| input | -[Brush] | -- |
| javascript | -[Brush] | -- |
| label | -[GenericTagBrush] | -- |
| li | -[GenericTagBrush] | -- |
| link | -[Brush] | -- |
| ol | -[GenericTagBrush] | -- |
| option | -[Brush] | -- |
| page | -[Brush] | -- |
| paragraph | -[Brush] | -- |
| password_input | -[Brush] | -- |
| pre | -[GenericTagBrush] | -- |
| radio_button | -[Brush] | -- |
| span | -[GenericTagBrush] | -- |
| style | -[GenericTagBrush] | -- |
| submit_button | -[Brush] | -- |
| table | -[Brush] | -- |
| table_data | -[Brush] | -- |
| table_header | -[Brush] | -- |
| table_row | -[Brush] | -- |
| text_area | -[Brush] | -- |
| text_input | -[Brush] | -- |
| title | -[GenericTagBrush] | -- |
| ul | -[GenericTagBrush] | -- |
-# File lib/wee/html_canvas.rb, line 27 - def self.brush_tag(attr, klass, *args_to_new) - args_to_new = args_to_new.map {|a| a.inspect}.join(", ") - if klass.instance_method(:with).arity != 0 - class_eval %{ - def #{attr}(*args, &block) - handle(#{klass}.new(#{args_to_new}), *args, &block) - end - } - elsif klass.nesting? - class_eval %{ - def #{attr}(&block) - handle2(#{klass}.new(#{args_to_new}), &block) - end - } - else - class_eval %{ - def #{attr} - handle3(#{klass}.new(#{args_to_new})) - end - } - end - end --
-# File lib/wee/html_canvas.rb, line 54 - def self.generic_single_tag(*attrs) - attrs.each {|attr| brush_tag attr, Brush::GenericSingleTagBrush, attr } - end --
-# File lib/wee/html_canvas.rb, line 50 - def self.generic_tag(*attrs) - attrs.each {|attr| brush_tag attr, Brush::GenericTagBrush, attr } - end --
-# File lib/wee/html_canvas.rb, line 7 - def initialize(*args) - super - @current_brush = nil - end --
-# File lib/wee/html_canvas.rb, line 186 - def build_url(*args) - @request.build_url(*args) - end --
-# File lib/wee/html_canvas.rb, line 12 - def close - @current_brush.close if @current_brush - @current_brush = nil - end --
-# File lib/wee/html_canvas.rb, line 115 - def css(str) - @current_brush.close if @current_brush - @current_brush = nil - @document.start_tag(:style, 'type' => 'text/css') - @document.write("<!--\n") - @document.text(str) - @document.write("-->\n") - @document.end_tag(:style) - end --
-# File lib/wee/html_canvas.rb, line 108 - def encode_text(str) - @current_brush.close if @current_brush - @current_brush = nil - @document.encode_text(str) - nil - end --
-# File lib/wee/html_canvas.rb, line 166 - def link_css(url) - link.type(HTML_TYPE_CSS).rel(HTML_REL_STYLESHEET).href(url) - end --
-converts \n into <br/> -
- --# File lib/wee/html_canvas.rb, line 128 - def multiline_text(str, encode=true) - @current_brush.close if @current_brush - @current_brush = nil - - first = true - str.each_line do |line| - @document.single_tag(:br) unless first - first = false - - if encode - @document.encode_text(line) - else - @document.text(line) - end - end - end --
-# File lib/wee/html_canvas.rb, line 17 - def nest - old_brush = @current_brush - # we don't want that Brush#close is calledas #nest - # is called from #with -> this avoids an infinite loop - @current_brush = nil - yield - @current_brush.close if @current_brush - @current_brush = old_brush - end --
-# File lib/wee/html_canvas.rb, line 170 - def new_radio_group - Wee::Brush::RadioButtonTag::RadioGroup.new(self) - end --
-# File lib/wee/html_canvas.rb, line 190 - def register_callback(type, callback) - cbs = @callbacks - if cbs.respond_to?("#{type}_callbacks") - cbs.send("#{type}_callbacks").register(@current_component, callback) - else - raise - end - end --
-# File lib/wee/html_canvas.rb, line 89 - def select_list(items, &block) - handle2(Brush::SelectListTag.new(items), &block) - end --
-# File lib/wee/html_canvas.rb, line 95 - def space(n=1) - text(HTML_NBSP*n) - end --
-# File lib/wee/html_canvas.rb, line 99 - def text(str) - @current_brush.close if @current_brush - @current_brush = nil - @document.text(str) - nil - end --
-# File lib/wee/html_canvas.rb, line 174 - def url_for_callback(callback, type=:action, hash=nil) - url_for_callback_id(register_callback(type, callback), hash) - end --
-# File lib/wee/html_canvas.rb, line 178 - def url_for_callback_id(callback_id, hash=nil) - if hash - build_url(hash.update(:callback_id => callback_id)) - else - build_url(:callback_id => callback_id) - end - end --
-# File lib/wee/html_canvas.rb, line 210 - def handle(brush, *args, &block) - if block or not args.empty? - set_brush(brush) - brush.with(*args, &block) - else - set_brush(brush) - end - end --
-# File lib/wee/html_canvas.rb, line 219 - def handle2(brush, &block) - if block - set_brush(brush) - brush.with(&block) - else - set_brush(brush) - end - end --
| Class | -Wee::HtmlDocument | -
| In: | -
-
- lib/wee/html_document.rb
-
- - |
-
| Parent: | -- - HtmlWriter - - | -
-Represents a complete HTML document. -
- --# File lib/wee/html_document.rb, line 9 - def initialize - super([]) - end --
-# File lib/wee/html_document.rb, line 17 - def divert(tag, txt=nil, &block) - raise ArgumentError if txt and block - @divert ||= {} - - unless divert = @divert[tag] - @divert[tag] = divert = [] - @port << divert - end - - if txt - divert << txt - end - - if block - old_port = @port - begin - @port = divert - block.call - ensure - @port = old_port - end - end - end --
-# File lib/wee/html_document.rb, line 13 - def set - @set ||= {} - end --
-# File lib/wee/html_document.rb, line 41 - def to_s - @port.join - end --
| Class | -Wee::HtmlWriter | -
| In: | -
-
- lib/wee/html_writer.rb
-
- - |
-
| Parent: | -- - Object - - | -
-A class used to write out HTML -documents easily. -
--Usage: -
-
- w = Wee::HtmlWriter.new(doc='')
- w.start_tag('html')
- w.start_tag('body')
- w.start_tag('a', 'href' => 'http://...')
- w.text('link')
- w.end_tag('a')
- w.end_tag('body')
- w.end_tag('html')
-
- p doc # => '<html><body><a href="http://...">link</a></body></html>'
-
-
- | CLOSING | -= | -">".freeze | -
| SINGLE_CLOSING | -= | -" />".freeze | -
| port | -[RW] | -- |
-# File lib/wee/html_writer.rb, line 25 - def initialize(port=[]) - @port = port - end --
-# File lib/wee/html_writer.rb, line 60 - def encode_text(str) - @port << Rack::Utils.escape_html(str.to_s) - end --
-# File lib/wee/html_writer.rb, line 52 - def end_tag(tag) - @port << "</#{tag}>" - end --
-# File lib/wee/html_writer.rb, line 48 - def single_tag(tag, attributes=nil) - start_tag(tag, attributes, true) - end --
-# File lib/wee/html_writer.rb, line 32 - def start_tag(tag, attributes=nil, single=false) - if attributes - @port << "<#{tag}" - attributes.each {|k, v| - if v - @port << %[ #{ k }="#{ v }"] - else - @port << %[ #{ k }] - end - } - @port << (single ? SINGLE_CLOSING : CLOSING) - else - @port << (single ? "<#{tag} />" : "<#{tag}>") - end - end --
-# File lib/wee/html_writer.rb, line 56 - def text(str) - @port << str.to_s - end --
-# File lib/wee/html_writer.rb, line 64 - def write(str) - @port << str - end --
| Class | -Wee::IdGenerator | -
| In: | -
-
- lib/wee/id_generator.rb
-
- - |
-
| Parent: | -- - Object - - | -
-Abstract base class of all id generators. -
- --# File lib/wee/id_generator.rb, line 7 - def next - raise "subclass responsibility" - end --
| Class | -Wee::IdGenerator::Secure | -
| In: | -
-
- lib/wee/id_generator.rb
-
- - |
-
| Parent: | -- IdGenerator - | -
-Returned ids are unique with a very high probability and it‘s very -hard to guess the next or any used id. -
- --# File lib/wee/id_generator.rb, line 39 - def initialize(salt='wee') - @salt = salt - end --
-# File lib/wee/id_generator.rb, line 60 - def next - str = defined?(::SecureRandom) ? next_secure : next_md5 - packed = [str].pack('m') - packed.tr!("=\r\n", '') - packed.tr!('+/', '-_') - packed - end --
-# File lib/wee/id_generator.rb, line 43 - def next_md5 - now = Time.now - dig = Digest::MD5.new - dig.update(now.to_s) - dig.update(now.usec.to_s) - dig.update(rand(0).to_s) - dig.update($$.to_s) - dig.update(@salt.to_s) - dig.digest - end --
| Class | -Wee::IdGenerator::Sequential | -
| In: | -
-
- lib/wee/id_generator.rb
-
- - |
-
| Parent: | -- IdGenerator - | -
-Sequential id generator. -
--Returned ids are guaranteed to be unique, but they are easily guessable. -
- --# File lib/wee/id_generator.rb, line 18 - def initialize(initial_value=0) - @value = initial_value - 1 - end --
-# File lib/wee/id_generator.rb, line 22 - def next - (@value += 1).to_s(36) - end --
| Class | -Wee::JQuery | -
| In: | -
-
- lib/wee/jquery/jquery.rb
-
- - |
-
| Parent: | -- - Object - - | -
| FILES | -= | -%w(jquery-1.3.2.min.js wee-jquery.js) | -
| PUBLIC_DIR | -= | -File.expand_path(File.join(File.dirname(__FILE__), 'public')) | -
-# File lib/wee/jquery/jquery.rb, line 6 - def self.install(mount_path, builder) - builder.map(@mount_path = mount_path) do - run Rack::File.new(Wee::JQuery::PUBLIC_DIR) - end - end --
| Class | -Wee::LRUCache | -
| In: | -
-
- lib/wee/lru_cache.rb
-
- - |
-
| Parent: | -- - Object - - | -
-Implementation of a Least Recently Used (LRU) Cache -
- --# File lib/wee/lru_cache.rb, line 19 - def initialize(capacity=20, &replace_callback) - @capacity = capacity - @replace_callback = replace_callback - @store = Hash.new - @time = 0 - end --
-# File lib/wee/lru_cache.rb, line 30 - def delete(key) - @store.delete(key) - end --
-# File lib/wee/lru_cache.rb, line 34 - def delete_if - @store.delete_if {|id, item| - yield id, item.value - } - end --
-# File lib/wee/lru_cache.rb, line 71 - def each(&block) - @store.each(&block) - end --
-# File lib/wee/lru_cache.rb, line 40 - def fetch(key, default_value=nil) - if item = @store[key] - item.time = (@time += 1) - item.value - else - default_value - end - end --
-# File lib/wee/lru_cache.rb, line 26 - def has_key?(key) - @store.has_key?(key) - end --
-# File lib/wee/lru_cache.rb, line 49 - def store(key, value) - if item = @store[key] - # update item only - item.time = (@time += 1) - item.value = value - else - # insert new item - item = Item.new - item.time = (@time += 1) - item.value = value - garbage_collect() if @store.size >= @capacity - while @store.size >= @capacity - old_item = @store.delete(min_key()) || raise - @replace_callback.call(old_item) if @replace_callback - end - @store[key] = item - end - end --
-Returns the key of the minimum item -
- --# File lib/wee/lru_cache.rb, line 83 - def min_key - min_k, min_time = nil, @time - @store.each {|k, v| - if v.time < min_time - min_k, min_time = k, v.time - end - } - return min_k - end --
| Class | -Wee::LRUCache::Item | -
| In: | -
-
- lib/wee/lru_cache.rb
-
- - |
-
| Parent: | -- - Object - - | -
| time | -[RW] | -- |
| value | -[RW] | -- |
-# File lib/wee/lru_cache.rb, line 10 - def initialize(value=nil, time=nil) - @value, @time = value, time - end --
-# File lib/wee/lru_cache.rb, line 14 - def <=>(other) - @time <=> other.time - end --
| Module | -Wee::ObjectSnapshotMixin | -
| In: | -
-
- lib/wee/state.rb
-
- - |
-
-# File lib/wee/state.rb, line 72 - def restore_snapshot(snap) - snap.each do |k,v| - instance_variable_set(k, v) - end - end --
| Class | -Wee::OidDecoration | -
| In: | -
-
- lib/wee/decoration.rb
-
- - |
-
| Parent: | -- - WrapperDecoration - - | -
-Renders a <div> tag with a unique "id" around the wrapped -component. Useful for components that want to update their content in-place -using AJAX. -
- --# File lib/wee/decoration.rb, line 227 - def render(r) - r.div.oid.with { render_inner(r) } - end --
| Class | -Wee::PageDecoration | -
| In: | -
-
- lib/wee/decoration.rb
-
- - |
-
| Parent: | -- - WrapperDecoration - - | -
-# File lib/wee/decoration.rb, line 244 - def initialize(title='', stylesheets=[], javascripts=[]) - @title = title - @stylesheets = stylesheets - @javascripts = javascripts - super() - end --
-# File lib/wee/decoration.rb, line 251 - def global?() true end --
-# File lib/wee/decoration.rb, line 253 - def render(r) - r.page.title(@title).head { - @stylesheets.each {|s| r.link_css(s) } - @javascripts.each {|j| r.javascript.src(j) } - }.with { - render_inner(r) - } - end --
| Class | -Wee::Presenter | -
| In: | -
-
- lib/wee/presenter.rb
-
- - |
-
| Parent: | -- - Object - - | -
-Presenter is the superclass of all classes -that want to participate in rendering and callback-processing. It merely -specifies an interface without actual implementation. -
--Class Component and Decoration are it‘s two most important -subclasses. -
- --# File lib/wee/presenter.rb, line 19 - def process_callbacks(callbacks); raise end --
-# File lib/wee/presenter.rb, line 16 - def render(r); raise end --
-# File lib/wee/presenter.rb, line 12 - def render_on(r) - r.with(self) {|new_r| render(new_r)} - end --
-Returns the class used as Renderer for this -presenter. Overwrite this method if you want to use a different Renderer than the default one. -
--Returned class must be a subclass of Wee::Renderer. -
- --# File lib/wee/presenter.rb, line 27 - def renderer_class - Wee::DefaultRenderer - end --
-# File lib/wee/presenter.rb, line 17 - def state(s); raise end --
-Returns the current session. A -presenter (or component) has always an associated session. The returned object is of class -Wee::Session or a subclass thereof. -
- --# File lib/wee/presenter.rb, line 38 - def session - Wee::Session.current - end --
| Class | -Wee::RedirectResponse | -
| In: | -
-
- lib/wee/response.rb
-
- - |
-
| Parent: | -- - Response - - | -
| LOCATION_HEADER | -= | -'Location'.freeze | -
| Class | -Wee::RefreshResponse | -
| In: | -
-
- lib/wee/response.rb
-
- - |
-
| Parent: | -- - Response - - | -
-# File lib/wee/response.rb, line 31 - def initialize(message, location, seconds=5) - super([%[<html> - <head> - <meta http-equiv="REFRESH" content="#{seconds};URL=#{location}"> - <title>#{message}</title> - </head> - <body> - <h1>#{message}</h1> - You are being redirected to <a href="#{location}">#{location}</a> - in #{seconds} seconds. - </body> - </html>]]) - end --
| Class | -Wee::Renderer | -
| In: | -
-
- lib/wee/renderer.rb
-
- - |
-
| Parent: | -- - Object - - | -
-Base class of all Renderer classes. -
- -| callbacks | -[RW] | -- |
| current_component | -[RW] | -- |
| document | -[RW] | -- |
| request | -[RW] | -- |
| response | -[RW] | -- |
| session | -[RW] | -- |
-# File lib/wee/renderer.rb, line 14 - def initialize(session=nil, request=nil, response=nil, callbacks=nil, document=nil, current_component=nil) - @session = session - @request = request - @response = response - @callbacks = callbacks - @document = document - @current_component = current_component - end --
-Subclass responsibility. -
- --# File lib/wee/renderer.rb, line 67 - def close - end --
-NOTE: unregister will do nothing for a regular request, only for an AJAX -request. Only if you would render one -and the same component twice it would behave differently. -
- --# File lib/wee/renderer.rb, line 50 - def render(component) - close - self.callbacks.unregister(component) - component.decoration.render_on(self) - nil - end --
-# File lib/wee/renderer.rb, line 57 - def render_decoration(decoration) - close - self.callbacks.unregister(decoration) - decoration.render_on(self) - nil - end --
-# File lib/wee/renderer.rb, line 23 - def with(component) - rclass = component.renderer_class - if rclass == self - # reuse renderer - old_component = @current_component - begin - @current_component = component - yield self - ensure - @current_component = old_component - end - else - close - r = rclass.new(@session, @request, @response, @callbacks, @document, component) - begin - yield r - ensure - r.close - end - end - end --
| Class | -Wee::Request | -
| In: | -
-
- lib/wee/request.rb
-
- - |
-
| Parent: | -- Rack::Request - | -
| fields | -[R] | -- |
| page_id | -[RW] | -- |
| session_id | -[RW] | -- |
-# File lib/wee/request.rb, line 15 - def initialize(env) - super(env) - @fields = self.params - @session_id = @fields.delete("_s") - @page_id = @fields.delete("_p") - end --
-# File lib/wee/request.rb, line 7 - def self.new(env) - env['wee.request'] ||= super - end --
-Is this an action request? -
- --# File lib/wee/request.rb, line 23 - def action? - not render? - end --
-# File lib/wee/request.rb, line 32 - def build_url(hash={}) - session_id = hash.has_key?(:session_id) ? hash[:session_id] : @session_id - page_id = hash.has_key?(:page_id) ? hash[:page_id] : @page_id - callback_id = hash[:callback_id] - info = hash.has_key?(:info) ? hash[:info] : @info - - raise ArgumentError if session_id.nil? and not page_id.nil? - raise ArgumentError if page_id.nil? and not callback_id.nil? - - q = {} - q['_s'] = session_id if session_id - q['_p'] = page_id if page_id - q[callback_id] = nil if callback_id - - path = script_name() + (info || path_info()) - path << "?" << Rack::Utils.build_query(q) unless q.empty? - - return path - end --
-Is this a render request? -
- --# File lib/wee/request.rb, line 28 - def render? - @fields.empty? - end --
| Class | -Wee::Response | -
| In: | -
-
- lib/wee/response.rb
-
- - |
-
| Parent: | -- Rack::Response - | -
| write | --> | -<< | -
| Class | -Wee::Session | -
| In: | -
-
- lib/wee/session.rb
-
- - |
-
| Parent: | -- - Object - - | -
| application | -[RW] | --Points to the Wee::Application object this -session belongs to. - - | -
| expire_after | -[RW] | -
-Expire the session after this number of seconds of inactivity. If this
-value is nil, the Session will never
-expire due to inactivity. (but still may expire for example due to
-max_lifetime).
-
- -Default: 1800 seconds (30 minutes) - - |
-
| id | -[RW] | --The (application-wide) unique id of this session. - - | -
| max_lifetime | -[RW] | -
-The maximum lifetime of this session in seconds. A value of nil
-means infinite lifetime.
-
- -Default: nil (infinite lifetime) - - |
-
| max_requests | -[RW] | -
-The maximum number of requests this session is allowed to serve. A value of
-nil means no limitation.
-
- -Default: nil (infinite number of requests) - - |
-
-Creates a new session. -
- --# File lib/wee/session.rb, line 100 - def initialize(root_component, serializer=nil, page_cache_capacity=20) - @root_component = root_component - @page_cache = Wee::LRUCache.new(page_cache_capacity) - @page_ids = Wee::IdGenerator::Sequential.new - @current_page = nil - - @running = true - - @expire_after = 30*60 - @max_lifetime = nil - @max_requests = nil - - @last_access = @creation_time = Time.now - @request_count = 0 - - @serializer = serializer || MutexSerializer.new - end --
-Queries whether the session is still alive. -
- --# File lib/wee/session.rb, line 131 - def alive? - now = Time.now - return false if not @running - return false if @expire_after and now - @last_access > @expire_after - return false if @max_lifetime and now - @creation_time > @max_lifetime - return false if @max_requests and @request_count >= @max_requests - return true - end --
-Handles a web request. -
- --# File lib/wee/session.rb, line 171 - def call(env) - if env['wee.session'] - # we are already serialized - raise if env['wee.session'] != self - begin - Thread.current[:wee_session] = self - @request_count += 1 - @last_access = Time.now - awake - response = handle(env) - sleep - return response - ensure - Thread.current[:wee_session] = nil - end - else - env['wee.session'] = self - @serializer.call(env) - end - end --
-Queries whether the session is dead. -
- --# File lib/wee/session.rb, line 143 - def dead? - not alive? - end --
-# File lib/wee/session.rb, line 257 - def render_ajax_proc(block, component) - proc { - r = component.renderer_class.new - r.session = self - r.request = @request - r.response = Wee::Response.new - r.document = Wee::HtmlDocument.new - r.callbacks = @page.callbacks - r.current_component = component - - begin - block.call(r) - ensure - r.close - end - - r.response << r.document.to_s - send_response(r.response) - } - end --
-Send a premature response -
- --# File lib/wee/session.rb, line 195 - def send_response(response) - raise AbortProcessing.new(response) - end --
-Returns some statistics -
- --# File lib/wee/session.rb, line 150 - def statistics - now = Time.now - { - :last_access => @last_access, # The time when this session was last accessed - :inactivity => now - @last_access, # The number of seconds of inactivity - :creation_time => @creation_time, # The time at which this session was created - :lifetime => now - @creation_time, # The lifetime of this session in seconds - :request_count => @request_count # The number of requests served by this session - } - end --
-# File lib/wee/session.rb, line 300 - def action(request, page) - @current_page = nil - - begin - @page = page # CONTINUATIONS! - action_callback = page.callbacks.with_triggered(request.fields) do - @root_component.decoration.process_callbacks(page.callbacks) - end - action_callback.call if action_callback - rescue AbortProcessing => abort - page = @page # CONTINUATIONS! - if abort.response - # - # replace the state of the current page - # - @current_page = page - page.state = take_snapshot() - @page_cache[page.id] = page - return abort.response - else - # pass on - this is a premature response from Component#call - end - end - request = @request # CONTINUATIONS! - - # - # create new page (state) - # - new_page = Page.new(@page_ids.next, take_snapshot(), nil) - @page_cache[new_page.id] = new_page - @current_page = new_page - - url = request.build_url(:page_id => new_page.id) - return Wee::RedirectResponse.new(url) - end --
-Is called before process_request is invoked. -
--Can be used e.g. to setup a database connection. -
- --# File lib/wee/session.rb, line 206 - def awake - end --
-The main routine where the request is processed. -
- --# File lib/wee/session.rb, line 220 - def handle(env) - request = Wee::Request.new(env) - @request = request # CONTINUATIONS! - page = @page_cache.fetch(request.page_id) - - if page - if page != @current_page - @current_page = nil - page.state.restore - @current_page = page - end - - if request.render? - return render(request, page).finish - else # request.action? - return action(request, page).finish - end - else - # - # either no or invalid page_id specified. reset to initial state (or - # create initial state if no such exists yet) - # - @initial_state ||= take_snapshot() - new_page = Page.new(@page_ids.next, @initial_state, nil) - @page_cache[new_page.id] = new_page - - url = request.build_url(:page_id => new_page.id) - if request.page_id - return Wee::RefreshResponse.new("Invalid or expired page", url).finish - else - return Wee::RedirectResponse.new(url).finish - end - end - ensure - @request = nil - end --
-# File lib/wee/session.rb, line 280 - def render(request, page) - r = Wee::Renderer.new - r.session = self - r.request = request - r.response = Wee::GenericResponse.new - r.document = Wee::HtmlDocument.new - r.callbacks = Wee::Callbacks.new - - begin - @root_component.decoration.render_on(r) - r.close - r.response << r.document.to_s - rescue AbortProcessing => abort - r.response = abort.response - end - - page.callbacks = r.callbacks - return r.response - end --
-Is called after process_request is run. -
--Can be used e.g. to release a database connection. -
- --# File lib/wee/session.rb, line 214 - def sleep - end --
| Class | -Wee::Session::AbortProcessing | -
| In: | -
-
- lib/wee/session.rb
-
- - |
-
| Parent: | -- Exception - | -
| response | -[R] | -- |
| Class | -Wee::Session::MutexSerializer | -
| In: | -
-
- lib/wee/session.rb
-
- - |
-
| Parent: | -- Mutex - | -
-The default serializer, when no continuation are going to be used. Ensures -that only one request of the same session is executed at the same time. -
- --# File lib/wee/session.rb, line 16 - def call(env) - synchronize { env['wee.session'].call(env) } - end --
| Class | -Wee::Session::Page | -
| In: | -
-
- lib/wee/session.rb
-
- - |
-
| Parent: | -- - Object - - | -
| callbacks | -[RW] | -- |
| id | -[RW] | -- |
| state | -[RW] | -- |
| Class | -Wee::Session::ThreadSerializer | -
| In: | -
-
- lib/wee/session.rb
-
- - |
-
| Parent: | -- - Object - - | -
-This serializer ensures that all requests of a session are executed within -the same thread. This is required if continuations are going to be used. -
--You can run multiple sessions within the same ThreadSerializer, or allocate one ThreadSerializer (and as such one Thread) -per session as you want. -
- --# File lib/wee/session.rb, line 31 - def initialize - @in, @out = Queue.new, Queue.new - @thread = Thread.new { - Thread.abort_on_exception = true - while true - env = @in.pop - @out.push(env['wee.session'].call(env)) - end - } - end --
-# File lib/wee/session.rb, line 42 - def call(env) - @in.push(env) - @out.pop - end --
| Class | -Wee::State | -
| In: | -
-
- lib/wee/state.rb
-
- - |
-
| Parent: | -- - Object - - | -
-This class is for backtracking the state of components (or -decorations/presenters). Components that want an undo-facility to be -implemented (triggered for example by a browsers back-button), have to -overwrite the Component#state method. -Class Wee::State simply represents a collection of -objects from which snapshots were taken via methods take_snapshot. -
- --# File lib/wee/state.rb, line 32 - def initialize - @objects = Hash.new - @objects_ivars = Hash.new - end --
-# File lib/wee/state.rb, line 37 - def add(object) - @objects[object.object_id] ||= Snapshot.new(object, object.take_snapshot) - end --
-# File lib/wee/state.rb, line 41 - def add_ivar(object, ivar, value) - (@objects_ivars[object.object_id] ||= SnapshotIVars.new(object, {})).add(ivar, value) - end --
-# File lib/wee/state.rb, line 47 - def restore - @objects.each_value {|s| s.object.restore_snapshot(s.snapshot) } - @objects_ivars.each_value {|s| s.restore } - end --
| Class | -Wee::State::Snapshot | -
| In: | -
-
- lib/wee/state.rb
-
- - |
-
| Parent: | -- - Object - - | -
| object | -[RW] | -- |
| snapshot | -[RW] | -- |
| Class | -Wee::State::SnapshotIVars | -
| In: | -
-
- lib/wee/state.rb
-
- - |
-
| Parent: | -- - Object - - | -
| ivars | -[RW] | -- |
| object | -[RW] | -- |
-# File lib/wee/state.rb, line 21 - def initialize(object, ivars) - @object, @ivars = object, ivars - end --
-# File lib/wee/state.rb, line 24 - def add(ivar, value) - @ivars[ivar] = value - end --
-# File lib/wee/state.rb, line 27 - def restore - @ivars.each_pair {|k,v| @object.instance_variable_set(k, v) } - end --
| Module | -Wee::StructSnapshotMixin | -
| In: | -
-
- lib/wee/state.rb
-
- - |
-
-# File lib/wee/state.rb, line 86 - def restore_snapshot(snap) - snap.each_pair {|k,v| send(k.to_s + "=", v)} - end --
| Class | -Wee::Task | -
| In: | -
-
- lib/wee/task.rb
-
- - |
-
| Parent: | -- - Component - - | -
-# File lib/wee/task.rb, line 10 - def render(r) - r.session.send_response(RedirectResponse.new(r.url_for_callback(method(:go)))) - end --
| Class | -Wee::WrapperDecoration | -
| In: | -
-
- lib/wee/decoration.rb
-
- - |
-
| Parent: | -- - Decoration - - | -
| render_presenter_on | --> | -render_on | -
-Overwrite this method, and call render_inner(r) where you want -the inner content to be drawn. -
- --# File lib/wee/decoration.rb, line 210 - def render(r) - render_inner(r) - end --
| Path: | -README.rdoc - | -
| Last Update: | -Fri Jan 01 15:06:06 +0100 2010 | -
-Copyright (c) 2004, 2005, 2009, 2010 by Michael Neumann -(mneumann@ntecs.de). -
--Released under the same terms of license as Ruby. -
--Wee is a light-weight, very high-level -and modern web-framework that makes Web engineering -easy. It mainly inherits many ideas and features from Seaside, but was written from scratch without -ever looking at the Seaside (or any other) sources. All code was developed -from ideas and lots of discussions with Avi Bryant. -
--Wee has real components, which -are like widgets in a GUI. Once written, you can use them everywhere. They -are completely independent and do not interfere with other components. -Components encapsulate state, a view and actions. Of course you can use an -external model or use templates for rendering. -
--See the What is backtracking? section below. In short, -backtracking lets the browser‘s back and forward-button play well -together with your application. -
--Wee is well thought out, is written in -and supports clean and concise code. Furthermore I think most parts -are now very well documented. -
--Wee does not depend on a special -templating-engine. You can use a different templating engine for each -component if you want. -
--Wee ships with an easy to use and very -powerful programmatic HTML-generation library. For example you can create a -select list easily with this piece of code: -
-
- # select an object from these items
- items = [1, 2, 3, 4]
-
- # the labels shown to the user
- labels = items.map {|i| i.to_s}
-
- # render it
- r.select_list(items).labels(labels).callback {|choosen| p choosen}
-
- # render a multi-select list, with objects 2 and 4 selected
- r.select_list(items).multi.labels(labels).selected([2,4])
-
--The callback is called with the selected objects from the items -array. Items can be any object, even whole components: -
-
- labels = ["msg1", "msg2"]
- items = labels.collect {|m| MessageBox.new(m)}
- r.select_list(items).labels(labels).callback {|choosen| call choosen.first}
-
--If you want, you can make the back-button of your browser work correctly -together with your web-application. Imagine you have a simple counter -application, which shows the current count and two links inc and -dec with which you can increase or decrease the current count. -Starting with an inital count of 0 you increase the counter up to 8, then -click three times the back button of your browser (now displays 5). Finally -you decrease by one and your counter shows what you‘d have expected: -4. In contrast, traditional web applications would have shown 7, because -the back button usually does not trigger a HTTP request and as such the -server-side state still has a value of 8 for the counter when the request -to decrease comes in. -
--The solution to this problem is to take snapshots of the components state -after an action is performed and restoring the state before peforming -actions. Each action generates a new state, which is indicated by a -so-called page-id within the URL. -
--Decorations are used to modify the look and behaviour of a component -without modifying the components tree itself. A component can have more -than one decoration. Decorations are implemented as a linked list -(Wee::Decoration#next points to the next decoration), starting at -Wee::Component#decoration, which either points to the next decoration in -the chain, or to itself. -
--The request/response cycle in Wee is -actually split into two separate phases. -
--The rendering phase is assumed to be side-effect free! So, you as a -programmer should take care to meet this assumption. Rendering is performed -by method Wee::Component#render_on. -
--Possible sources for callbacks are links (anchors) and all kinds of -form-elements like submit buttons, input-fields etc. There are two -different kinds of callbacks: -
--The distinction between input and action callbacks is important, as action -callbacks might depend on values of input-fields being assigned to instance -variables of the controlling component. Hence, Wee first invokes all input callbacks before -any action callback is triggered. Callback processing is performed by -method Wee::Component#process_callbacks. -
--The result of the action phase is an updated components state. As such, a -snapshot is taken of the new state and stored under a new page-id. Then, a -redirect requests is sent back to the client, including this new page-id. -The client automatically follows this redirect and triggers a render phase -of the new page. -
- -| Path: | -lib/wee/application.rb - | -
| Last Update: | -Sun Dec 06 09:13:46 +0100 2009 | -
| Path: | -lib/wee/call_answer.rb - | -
| Last Update: | -Thu Dec 17 15:09:56 +0100 2009 | -
| Path: | -lib/wee/callback.rb - | -
| Last Update: | -Thu Dec 17 14:46:27 +0100 2009 | -
| Path: | -lib/wee/component.rb - | -
| Last Update: | -Wed Dec 30 12:28:24 +0100 2009 | -
| Path: | -lib/wee/conversation.rb - | -
| Last Update: | -Sun Dec 06 09:13:46 +0100 2009 | -
| Path: | -lib/wee/decoration.rb - | -
| Last Update: | -Thu Dec 17 14:56:49 +0100 2009 | -
| Path: | -lib/wee/html_brushes.rb - | -
| Last Update: | -Sun Dec 06 09:13:46 +0100 2009 | -
| Path: | -lib/wee/html_canvas.rb - | -
| Last Update: | -Sun Dec 06 09:13:46 +0100 2009 | -
| Path: | -lib/wee/html_document.rb - | -
| Last Update: | -Sun Dec 06 09:13:46 +0100 2009 | -
| Path: | -lib/wee/html_writer.rb - | -
| Last Update: | -Sun Dec 06 09:13:46 +0100 2009 | -
| Path: | -lib/wee/id_generator.rb - | -
| Last Update: | -Sun Dec 06 09:13:46 +0100 2009 | -
| Path: | -lib/wee/jquery/jquery.rb - | -
| Last Update: | -Sun Dec 06 09:13:46 +0100 2009 | -
| Path: | -lib/wee/jquery.rb - | -
| Last Update: | -Sun Dec 06 09:13:46 +0100 2009 | -
| Path: | -lib/wee/lru_cache.rb - | -
| Last Update: | -Sun Dec 06 09:13:46 +0100 2009 | -
| Path: | -lib/wee/presenter.rb - | -
| Last Update: | -Thu Dec 17 14:57:10 +0100 2009 | -
| Path: | -lib/wee/renderer.rb - | -
| Last Update: | -Sun Dec 06 09:13:46 +0100 2009 | -
| Path: | -lib/wee/request.rb - | -
| Last Update: | -Sun Dec 06 09:13:46 +0100 2009 | -
| Path: | -lib/wee/response.rb - | -
| Last Update: | -Sun Dec 06 09:13:46 +0100 2009 | -
| Path: | -lib/wee/session.rb - | -
| Last Update: | -Thu Dec 17 15:24:21 +0100 2009 | -
| Path: | -lib/wee/state.rb - | -
| Last Update: | -Sun Dec 06 09:13:46 +0100 2009 | -
| Path: | -lib/wee/task.rb - | -
| Last Update: | -Sun Dec 06 09:13:46 +0100 2009 | -
| Path: | -lib/wee.rb - | -
| Last Update: | -Sun Dec 06 09:13:46 +0100 2009 | -
| DefaultRenderer | -= | -Wee::HtmlCanvas | -