Class: Page
Instance Attribute Summary collapse
-
#page ⇒ Object
readonly
Returns the value of attribute page.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#render_queue ⇒ Object
readonly
Returns the value of attribute render_queue.
-
#routes ⇒ Object
readonly
Returns the value of attribute routes.
-
#store ⇒ Object
readonly
Returns the value of attribute store.
-
#templates ⇒ Object
readonly
Returns the value of attribute templates.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #add_model(model_name) ⇒ Object
- #add_routes(&block) ⇒ Object
- #add_template(name, template, bindings) ⇒ Object
-
#binding_name ⇒ Object
We provide a binding_name, so we can bind events on the document.
- #channel ⇒ Object
- #events ⇒ Object
-
#initialize ⇒ Page
constructor
A new instance of Page.
- #launch_console ⇒ Object
- #link_clicked(url) ⇒ Object
- #start ⇒ Object
- #tasks ⇒ Object
Constructor Details
#initialize ⇒ Page
Returns a new instance of Page.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/volt/page/page.rb', line 38 def initialize # debugger puts "------ Page Loaded -------" @model_classes = {} # Run the code to setup the page @page = ReactiveValue.new(Model.new)#({}, nil, 'page', @model_classes)) @store = ReactiveValue.new(Store.new(tasks))#({}, nil, 'store', @model_classes)) @url = ReactiveValue.new(URL.new) @params = @url.params @url_tracker = UrlTracker.new(self) @events = DocumentEvents.new @render_queue = RenderQueue.new if RUBY_PLATFORM == 'opal' # Setup escape binding for console %x{ $(document).keyup(function(e) { if (e.keyCode == 27) { Opal.gvars.page.$launch_console(); } }); $(document).on('click', 'a', function(event) { Opal.gvars.page.$link_clicked($(this).attr('href')); event.stopPropagation(); return false; }); } end end |
Instance Attribute Details
#page ⇒ Object (readonly)
Returns the value of attribute page.
36 37 38 |
# File 'lib/volt/page/page.rb', line 36 def page @page end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
36 37 38 |
# File 'lib/volt/page/page.rb', line 36 def params @params end |
#render_queue ⇒ Object (readonly)
Returns the value of attribute render_queue.
36 37 38 |
# File 'lib/volt/page/page.rb', line 36 def render_queue @render_queue end |
#routes ⇒ Object (readonly)
Returns the value of attribute routes.
36 37 38 |
# File 'lib/volt/page/page.rb', line 36 def routes @routes end |
#store ⇒ Object (readonly)
Returns the value of attribute store.
36 37 38 |
# File 'lib/volt/page/page.rb', line 36 def store @store end |
#templates ⇒ Object (readonly)
Returns the value of attribute templates.
36 37 38 |
# File 'lib/volt/page/page.rb', line 36 def templates @templates end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
36 37 38 |
# File 'lib/volt/page/page.rb', line 36 def url @url end |
Instance Method Details
#add_model(model_name) ⇒ Object
112 113 114 115 116 |
# File 'lib/volt/page/page.rb', line 112 def add_model(model_name) # puts "ADD MODEL: #{model_name.inspect} - #{model_name.camelize.inspect}" @model_classes[["*", "_#{model_name}"]] = Object.const_get(model_name.camelize) end |
#add_routes(&block) ⇒ Object
125 126 127 128 |
# File 'lib/volt/page/page.rb', line 125 def add_routes(&block) @routes = Routes.new.define(&block) @url.cur.router = @routes end |
#add_template(name, template, bindings) ⇒ Object
118 119 120 121 122 123 |
# File 'lib/volt/page/page.rb', line 118 def add_template(name, template, bindings) # puts "Add Template: #{name}\n#{template.inspect}\n#{bindings.inspect}" @templates ||= {} @templates[name] = {'html' => template, 'bindings' => bindings} # puts "Add Template: #{name}" end |
#binding_name ⇒ Object
We provide a binding_name, so we can bind events on the document
90 91 92 |
# File 'lib/volt/page/page.rb', line 90 def binding_name 'page' end |
#channel ⇒ Object
98 99 100 101 102 103 104 105 106 |
# File 'lib/volt/page/page.rb', line 98 def channel @channel ||= begin if Volt.client? ReactiveValue.new(Channel.new) else ReactiveValue.new(ChannelStub.new) end end end |
#events ⇒ Object
108 109 110 |
# File 'lib/volt/page/page.rb', line 108 def events @events end |
#launch_console ⇒ Object
94 95 96 |
# File 'lib/volt/page/page.rb', line 94 def launch_console puts "Launch Console" end |
#link_clicked(url) ⇒ Object
78 79 80 81 82 83 84 85 86 87 |
# File 'lib/volt/page/page.rb', line 78 def link_clicked(url) # Skip when href == '' return if url.blank? # Normalize url Benchmark.bm(1) do host = `document.location.host` @url.parse("http://#{host}" + url) end end |
#start ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/volt/page/page.rb', line 130 def start # Setup to render template Element.find('body').html = "<!-- $CONTENT --><!-- $/CONTENT -->" main_controller = IndexController.new # Setup main page template TemplateRenderer.new(DomTarget.new, main_controller, 'CONTENT', 'home/index/index/body') # Setup title listener template title_target = AttributeTarget.new title_target.on('changed') do title = title_target.to_html `document.title = title;` end TemplateRenderer.new(title_target, main_controller, "main", "home/index/index/title") @url_tracker.url_updated(true) end |