Class: Goat::Page
Instance Attribute Summary collapse
-
#canvas ⇒ Object
readonly
Returns the value of attribute canvas.
-
#channel ⇒ Object
readonly
Returns the value of attribute channel.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#layout ⇒ Object
readonly
Returns the value of attribute layout.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
Class Method Summary collapse
- .disable_live_updates ⇒ Object
- .enable_live_updates ⇒ Object
- .handle_request(app) ⇒ Object
- .live_updates_enabled? ⇒ Boolean
Instance Method Summary collapse
- #_dom ⇒ Object
- #empty_response ⇒ Object
- #erb(name, opts = {}, &blk) ⇒ Object
-
#erb=(erb) ⇒ Object
TODO make it work properly, but not support embenned components.
- #halt ⇒ Object
- #html ⇒ Object
- #html_from_erb ⇒ Object
-
#initialize(app) ⇒ Page
constructor
A new instance of Page.
- #inject_html_from_dom(canvas) ⇒ Object
- #register_page(distiller) ⇒ Object
- #render_to_layout(canvas, layout) ⇒ Object
- #response ⇒ Object
- #title=(title) ⇒ Object
- #user ⇒ Object
Methods included from FlashHelper
Constructor Details
Instance Attribute Details
#canvas ⇒ Object (readonly)
Returns the value of attribute canvas.
768 769 770 |
# File 'lib/goat.rb', line 768 def canvas @canvas end |
#channel ⇒ Object (readonly)
Returns the value of attribute channel.
768 769 770 |
# File 'lib/goat.rb', line 768 def channel @channel end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
768 769 770 |
# File 'lib/goat.rb', line 768 def id @id end |
#layout ⇒ Object (readonly)
Returns the value of attribute layout.
768 769 770 |
# File 'lib/goat.rb', line 768 def layout @layout end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
768 769 770 |
# File 'lib/goat.rb', line 768 def params @params end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
768 769 770 |
# File 'lib/goat.rb', line 768 def request @request end |
Class Method Details
.disable_live_updates ⇒ Object
772 |
# File 'lib/goat.rb', line 772 def self.disable_live_updates; @live_updates = false; end |
.enable_live_updates ⇒ Object
773 |
# File 'lib/goat.rb', line 773 def self.enable_live_updates; @live_updates = true; end |
.handle_request(app) ⇒ Object
784 785 786 787 788 789 790 |
# File 'lib/goat.rb', line 784 def self.handle_request(app) pg = self.new(app) raise "Page #{pg} has no id: did you forget to call super()?" unless pg.id pg.response end |
.live_updates_enabled? ⇒ Boolean
774 |
# File 'lib/goat.rb', line 774 def self.live_updates_enabled?; @live_updates != false; end |
Instance Method Details
#_dom ⇒ Object
814 |
# File 'lib/goat.rb', line 814 def _dom; self.dom; end |
#empty_response ⇒ Object
799 800 801 |
# File 'lib/goat.rb', line 799 def empty_response Rack::Response.new end |
#erb(name, opts = {}, &blk) ⇒ Object
778 779 780 781 782 |
# File 'lib/goat.rb', line 778 def erb(name, opts={}, &blk) e = ERBRunner.new(@request, @response, @params) e.delegate = self e.erb(name, {:partial => false}.merge(opts), &blk) end |
#erb=(erb) ⇒ Object
TODO make it work properly, but not support embenned components
869 870 |
# File 'lib/goat.rb', line 869 def erb=(erb); @erb = erb; #TODO make it work properly, but not support embenned components end |
#halt ⇒ Object
803 804 805 |
# File 'lib/goat.rb', line 803 def halt raise Halt.new(empty_response) end |
#html ⇒ Object
839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 |
# File 'lib/goat.rb', line 839 def html layout = self.layout canvas = PageCanvas.new canvas.title = @title if @erb canvas.html = html_from_erb elsif methods.include?('dom') inject_html_from_dom(canvas) else raise "You should over-ride Page#dom or supply an erb template" end render_to_layout(canvas, layout) end |
#html_from_erb ⇒ Object
816 817 818 |
# File 'lib/goat.rb', line 816 def html_from_erb html = self.erb(@erb, :layout => false) end |
#inject_html_from_dom(canvas) ⇒ Object
820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 |
# File 'lib/goat.rb', line 820 def inject_html_from_dom(canvas) exp = nil helper = ExpansionHelper.new(@id) Dynamic.let(:expander => helper) do exp = DOMTools.(self._dom) end distiller = DOMDistiller.new(exp, helper.components) canvas.html = DOMTools::HTMLBuilder.new(exp).html canvas.style << distiller.style canvas.script << distiller.script distiller.all_component_classes.each {|c| canvas.script_files += c.script_files} EM.next_tick { register_page(distiller) } end |
#register_page(distiller) ⇒ Object
807 808 809 810 811 812 |
# File 'lib/goat.rb', line 807 def register_page(distiller) live = distiller.all_components.select(&:live_enabled?) pg_spec = live.map(&:skel) StateSrvClient.register_page(@id, self.user, pg_spec) end |
#render_to_layout(canvas, layout) ⇒ Object
860 861 862 863 864 865 866 867 |
# File 'lib/goat.rb', line 860 def render_to_layout(canvas, layout) layout ||= File.join(File.dirname(__FILE__), 'views/plain_layout.erb') erb(layout, :locals => {:page => self, :canvas => canvas}, # don't want a layout in our layout so we can layout while we layout :layout => false) { canvas.html } end |
#response ⇒ Object
856 857 858 |
# File 'lib/goat.rb', line 856 def response Rack::Response.new(self.html, 200, {}) end |
#title=(title) ⇒ Object
871 |
# File 'lib/goat.rb', line 871 def title=(title); @title = title; end |
#user ⇒ Object
873 |
# File 'lib/goat.rb', line 873 def user; end |