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.
769 770 771 |
# File 'lib/goat.rb', line 769 def canvas @canvas end |
#channel ⇒ Object (readonly)
Returns the value of attribute channel.
769 770 771 |
# File 'lib/goat.rb', line 769 def channel @channel end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
769 770 771 |
# File 'lib/goat.rb', line 769 def id @id end |
#layout ⇒ Object (readonly)
Returns the value of attribute layout.
769 770 771 |
# File 'lib/goat.rb', line 769 def layout @layout end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
769 770 771 |
# File 'lib/goat.rb', line 769 def params @params end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
769 770 771 |
# File 'lib/goat.rb', line 769 def request @request end |
Class Method Details
.disable_live_updates ⇒ Object
773 |
# File 'lib/goat.rb', line 773 def self.disable_live_updates; @live_updates = false; end |
.enable_live_updates ⇒ Object
774 |
# File 'lib/goat.rb', line 774 def self.enable_live_updates; @live_updates = true; end |
.handle_request(app) ⇒ Object
785 786 787 788 789 790 791 |
# File 'lib/goat.rb', line 785 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
775 |
# File 'lib/goat.rb', line 775 def self.live_updates_enabled?; @live_updates != false; end |
Instance Method Details
#_dom ⇒ Object
815 |
# File 'lib/goat.rb', line 815 def _dom; self.dom; end |
#empty_response ⇒ Object
800 801 802 |
# File 'lib/goat.rb', line 800 def empty_response Rack::Response.new end |
#erb(name, opts = {}, &blk) ⇒ Object
779 780 781 782 783 |
# File 'lib/goat.rb', line 779 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
870 871 |
# File 'lib/goat.rb', line 870 def erb=(erb); @erb = erb; #TODO make it work properly, but not support embenned components end |
#halt ⇒ Object
804 805 806 |
# File 'lib/goat.rb', line 804 def halt raise Halt.new(empty_response) end |
#html ⇒ Object
840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 |
# File 'lib/goat.rb', line 840 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
817 818 819 |
# File 'lib/goat.rb', line 817 def html_from_erb html = self.erb(@erb, :layout => false) end |
#inject_html_from_dom(canvas) ⇒ Object
821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 |
# File 'lib/goat.rb', line 821 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
808 809 810 811 812 813 |
# File 'lib/goat.rb', line 808 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
861 862 863 864 865 866 867 868 |
# File 'lib/goat.rb', line 861 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
857 858 859 |
# File 'lib/goat.rb', line 857 def response Rack::Response.new(self.html, 200, {}) end |
#title=(title) ⇒ Object
872 |
# File 'lib/goat.rb', line 872 def title=(title); @title = title; end |
#user ⇒ Object
874 |
# File 'lib/goat.rb', line 874 def user; end |