module SproutCore::ViewHelperSupport
Public Class Methods
find_helper(helper_name)
click to toggle source
# File lib/sproutcore/deprecated/view_helper.rb, line 87 def self.find_helper(helper_name) @@helpers[helper_name.to_sym] || @@helpers[:view] end
render_view(view_helper_id, item_id, opts={}, client_builder=nil, render_source=nil, &block)
click to toggle source
:outlet => define if you want this to be used as an outlet. :prototype => define if you want this to be used as a prototype.
# File lib/sproutcore/deprecated/view_helper.rb, line 538 def self.render_view(view_helper_id, item_id, opts={}, client_builder=nil, render_source=nil, &block) # item_id is optional. If it is not a symbol or string, then generate # an item_id if item_id.instance_of?(Hash) opts = item_id; item_id = nil end item_id = render_source.dom_id! if item_id.nil? # create the new render context and set it. client_builder = opts[:client] if opts[:client] rc = RenderContext.new(view_helper_id, item_id, opts, client_builder, render_source) hs = find_helper(view_helper_id) # render the inner_html using the block, if one is given. SproutCore::PageHelper.push_render_context(rc) rc.options[:inner_html] = render_source.capture(&block) if block_given? # now, use the helper state to prepare the render context. This will # extract the properties from the options and setup the render procs. hs.prepare_context(rc) unless hs.nil? # now have the render context render the HTML content. This may also # make changes to the other items to render. ret = rc.render_content SproutCore::PageHelper.pop_render_context # get the JS. Save as an outlet or in the page. cur_rc = opts[:current_context] || SproutCore::PageHelper.current_render_context view_class = opts[:view] || rc.view_class unless view_class.nil? view_settings = { :id => item_id, :class => view_class, :properties => rc.render_view, :lazy => opts[:lazy], :outlet_path => opts[:outlet_path] } # if an outlet item is passed, then register this as an outlet. outlet = opts[:outlet] if outlet.nil? outlet = opts[:field].nil? ? !cur_rc.nil? : [opts[:field].to_s, 'field'].join('_').to_sym end define = opts[:define] if outlet && cur_rc outlet = item_id if outlet == true cur_rc.set_outlet(outlet, view_settings) elsif define define = define.to_s.camelize.gsub('::','.') SproutCore::PageHelper.set_define(define, view_settings) # otherwise, add it to the page-wide setting. else prop = item_id.to_s.camelize(:lower) SproutCore::PageHelper.set_outlet(prop, view_settings) end end # get the styles, if any styles = rc.render_styles SproutCore::PageHelper.add_styles(styles) if styles && styles.size > 0 # done. return the generated HTML render_source.concat(ret,block) if block_given? return ret end
set_helper(helper_name,obj)
click to toggle source
# File lib/sproutcore/deprecated/view_helper.rb, line 91 def self.set_helper(helper_name,obj) @@helpers[helper_name.to_sym] = obj end