Module: SproutCore::PageHelper
- Defined in:
- lib/sproutcore/deprecated/view_helper.rb
Overview
The PageHelper is a singleton object that can render the Page javascript object.
Constant Summary collapse
- @@render_contexts =
[]
- @@outlets =
[]
- @@styles =
[]
- @@defines =
[]
Class Method Summary collapse
- .add_styles(styles) ⇒ Object
-
.current_render_context ⇒ Object
This is the current helper state used when rendering the HTML.
- .pop_render_context ⇒ Object
- .push_render_context(state) ⇒ Object
- .render_css ⇒ Object
-
.render_js(prefix = 'SC', bundle = nil) ⇒ Object
renders the page object for the current page.
-
.reset! ⇒ Object
reset the page helper.
- .set_define(key, opts = {}) ⇒ Object
- .set_outlet(key, opts = {}) ⇒ Object
Class Method Details
.add_styles(styles) ⇒ Object
49 50 51 |
# File 'lib/sproutcore/deprecated/view_helper.rb', line 49 def self.add_styles(styles) @@styles << styles end |
.current_render_context ⇒ Object
This is the current helper state used when rendering the HTML. When a view helper is rendered, it may add itself as an outlet to the current helper state instead of to the page helper.
21 22 23 |
# File 'lib/sproutcore/deprecated/view_helper.rb', line 21 def self.current_render_context @@render_contexts.last end |
.pop_render_context ⇒ Object
29 30 31 |
# File 'lib/sproutcore/deprecated/view_helper.rb', line 29 def self.pop_render_context @@render_contexts.pop end |
.push_render_context(state) ⇒ Object
25 26 27 |
# File 'lib/sproutcore/deprecated/view_helper.rb', line 25 def self.push_render_context(state) @@render_contexts.push(state) end |
.render_css ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/sproutcore/deprecated/view_helper.rb', line 74 def self.render_css if @@styles.size > 0 %(<style type="application/css">\n#{ @@styles * "\n" }\n</style>) else '' end end |
.render_js(prefix = 'SC', bundle = nil) ⇒ Object
renders the page object for the current page. If you include a prefix that will be used to create a separate page object. Otherwise, the object will live in the SC namespace. If you provide a bundle that is configured to minify sources the output will be compressed.
returns the text to insert into the HTML.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/sproutcore/deprecated/view_helper.rb', line 59 def self.render_js(prefix = 'SC', bundle = nil) outlets = [] @@outlets.each do | key, opts | outlet_path = opts[:outlet_path] || "##{opts[:id] || key}" outlets << %{ #{key}: #{opts[:class] || 'SC.View'}.extend({\n #{ opts[:properties].gsub("\n","\n ") }\n }).outletFor("#{outlet_path}") } end # defines let you define classes to include in your UI. ret = @@defines.each do | key, opts | %{#{key} = #{opts[:class] || 'SC.View'}.extend({\n #{ opts[:properties] }\n});} end ret << %{#{prefix}.page = SC.Page.create({\n#{ outlets * ",\n\n" }\n}); } bundle ? SproutCore::BuildTools::JavaScriptResourceBuilder.new(nil, nil, bundle, nil).join(ret) : ret*"\n" end |
.reset! ⇒ Object
reset the page helper.
34 35 36 37 38 39 |
# File 'lib/sproutcore/deprecated/view_helper.rb', line 34 def self.reset! @@render_contexts = [] @@outlets = [] @@styles = [] @@defines = [] end |
.set_define(key, opts = {}) ⇒ Object
41 42 43 |
# File 'lib/sproutcore/deprecated/view_helper.rb', line 41 def self.set_define(key, opts = {}) @@defines << [key, opts] end |
.set_outlet(key, opts = {}) ⇒ Object
45 46 47 |
# File 'lib/sproutcore/deprecated/view_helper.rb', line 45 def self.set_outlet(key,opts = {}) @@outlets << [key, opts] end |