## # Renderer for HTML with callbacks class Borges::HtmlRenderer < Borges::HtmlBuilder attr_accessor :action_url, :callbacks, :rendering_context ## # Creates a callback that sends +message+ to +object+ with zero # arguments. def action_callback(message, object) proc do object.send message end end ## # Creates a callback that sets +attr+ on +object+. def setter_callback(attr, object) proc do |val| object.send "#{attr}=", val end end ## # Creates a link with +anchor_text+ that executes a block when # clicked. def anchor(anchor_text, &block) open_anchor(&block) text(anchor_text) close end ## # Creates a link that calls +sym+ on +obj+ when clicked. +sym+ # is used as the title for the link. def anchor_on(sym, obj) element_id(sym) anchor(label_for(sym)) do obj.send(sym) end end ## # Creates a . +label+ sets the label for # the select. The option will be selected if +selected+ is # true. def option(label, selected = false, &callback) @attributes[:selected] if selected @attributes[:value] = @callbacks.register_callback(&callback) open_tag(:option) text(label) close end ## # Creates a radio button that is part of radio group +group+. # The radio button will be checked if +checked+ is true. # # +group+ must come from a previous #radio_group: # # group = r.radio_group # r.radio_button(group) do ... end def radio_button(group, checked = false, &block) @attributes[:checked] if checked input(:radio, group, @callbacks.register_callback(&block)) end ## # Creates a default action for a radio group. def radio_group return @callbacks.register_dispatch_callback end ## # Creates a