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
def render_component© canvas.components << c c.html end.
- #title=(title) ⇒ Object
- #user ⇒ Object
Methods included from FlashHelper
Constructor Details
Instance Attribute Details
#canvas ⇒ Object (readonly)
Returns the value of attribute canvas.
756 757 758 |
# File 'lib/goat.rb', line 756 def canvas @canvas end |
#channel ⇒ Object (readonly)
Returns the value of attribute channel.
756 757 758 |
# File 'lib/goat.rb', line 756 def channel @channel end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
756 757 758 |
# File 'lib/goat.rb', line 756 def id @id end |
#layout ⇒ Object (readonly)
Returns the value of attribute layout.
756 757 758 |
# File 'lib/goat.rb', line 756 def layout @layout end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
756 757 758 |
# File 'lib/goat.rb', line 756 def params @params end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
756 757 758 |
# File 'lib/goat.rb', line 756 def request @request end |
Class Method Details
.disable_live_updates ⇒ Object
760 |
# File 'lib/goat.rb', line 760 def self.disable_live_updates; @live_updates = false; end |
.enable_live_updates ⇒ Object
761 |
# File 'lib/goat.rb', line 761 def self.enable_live_updates; @live_updates = true; end |
.handle_request(app) ⇒ Object
772 773 774 775 776 777 778 |
# File 'lib/goat.rb', line 772 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
762 |
# File 'lib/goat.rb', line 762 def self.live_updates_enabled?; @live_updates != false; end |
Instance Method Details
#_dom ⇒ Object
805 |
# File 'lib/goat.rb', line 805 def _dom; self.dom; end |
#empty_response ⇒ Object
787 788 789 |
# File 'lib/goat.rb', line 787 def empty_response Rack::Response.new end |
#erb(name, opts = {}, &blk) ⇒ Object
766 767 768 769 770 |
# File 'lib/goat.rb', line 766 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
863 864 |
# File 'lib/goat.rb', line 863 def erb=(erb); @erb = erb; #TODO make it work properly, but not support embenned components end |
#halt ⇒ Object
791 792 793 |
# File 'lib/goat.rb', line 791 def halt raise Halt.new(empty_response) end |
#html ⇒ Object
828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 |
# File 'lib/goat.rb', line 828 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
807 808 809 |
# File 'lib/goat.rb', line 807 def html_from_erb html = self.erb(@erb, :layout => false) end |
#inject_html_from_dom(canvas) ⇒ Object
811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 |
# File 'lib/goat.rb', line 811 def inject_html_from_dom(canvas) exp = nil helper = ExpansionHelper.new 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 EM.next_tick { register_page(distiller) } end |
#register_page(distiller) ⇒ Object
795 796 797 798 799 800 801 802 803 |
# File 'lib/goat.rb', line 795 def register_page(distiller) live = distiller.all_components.select(&:live_enabled?) pg_spec = live.map do |c| c.pgid = @id c.skel end StateSrvClient.register_page(@id, self.user, pg_spec) end |
#render_to_layout(canvas, layout) ⇒ Object
854 855 856 857 858 859 860 861 |
# File 'lib/goat.rb', line 854 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
def render_component©
canvas.components << c
c.html
end
850 851 852 |
# File 'lib/goat.rb', line 850 def response Rack::Response.new(self.html, 200, {}) end |
#title=(title) ⇒ Object
865 |
# File 'lib/goat.rb', line 865 def title=(title); @title = title; end |
#user ⇒ Object
867 |
# File 'lib/goat.rb', line 867 def user; end |