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
Constructor Details
#initialize ⇒ Page
Returns a new instance of Page.
31 32 33 34 35 36 37 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/templates/page.rb', line 31 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(Model.new)#({}, nil, 'store', @model_classes)) @url = ReactiveValue.new(URL.new) @params = @url.params @url_tracker = UrlTracker.new(self) @events = DocumentEvents.new @render_queue = RenderQueue.new # Add event for link clicks to handle all a onclick # EventBinding.new(self, ) # 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; }); } # channel # channel.on('message') do |message| # # puts "GOT: #{message}" # # `console.log('got: ', message);` # end end |
Instance Attribute Details
#page ⇒ Object (readonly)
Returns the value of attribute page.
29 30 31 |
# File 'lib/volt/templates/page.rb', line 29 def page @page end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
29 30 31 |
# File 'lib/volt/templates/page.rb', line 29 def params @params end |
#render_queue ⇒ Object (readonly)
Returns the value of attribute render_queue.
29 30 31 |
# File 'lib/volt/templates/page.rb', line 29 def render_queue @render_queue end |
#routes ⇒ Object (readonly)
Returns the value of attribute routes.
29 30 31 |
# File 'lib/volt/templates/page.rb', line 29 def routes @routes end |
#store ⇒ Object (readonly)
Returns the value of attribute store.
29 30 31 |
# File 'lib/volt/templates/page.rb', line 29 def store @store end |
#templates ⇒ Object (readonly)
Returns the value of attribute templates.
29 30 31 |
# File 'lib/volt/templates/page.rb', line 29 def templates @templates end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
29 30 31 |
# File 'lib/volt/templates/page.rb', line 29 def url @url end |
Instance Method Details
#add_model(model_name) ⇒ Object
102 103 104 105 106 |
# File 'lib/volt/templates/page.rb', line 102 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
115 116 117 118 |
# File 'lib/volt/templates/page.rb', line 115 def add_routes(&block) @routes = Routes.new.define(&block) @url.cur.router = @routes end |
#add_template(name, template, bindings) ⇒ Object
108 109 110 111 112 113 |
# File 'lib/volt/templates/page.rb', line 108 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
86 87 88 |
# File 'lib/volt/templates/page.rb', line 86 def binding_name 'page' end |
#channel ⇒ Object
94 95 96 |
# File 'lib/volt/templates/page.rb', line 94 def channel @channel ||= Channel.new end |
#events ⇒ Object
98 99 100 |
# File 'lib/volt/templates/page.rb', line 98 def events @events end |
#launch_console ⇒ Object
90 91 92 |
# File 'lib/volt/templates/page.rb', line 90 def launch_console puts "Launch Console" end |
#link_clicked(url) ⇒ Object
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/volt/templates/page.rb', line 74 def link_clicked(url) puts "Link Clicked to: #{url}" # Skip when href == '' return if url.blank? # Normalize url # Benchmark.bm(1) do @url.parse("http://localhost:3000" + url) # end end |
#start ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/volt/templates/page.rb', line 120 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 |