Class: Nice::Logic
- Inherits:
-
Object
- Object
- Nice::Logic
- Defined in:
- lib/nice/logic.rb
Overview
> respond with JS which either first removes all elements of the current state and
later inserts new content OR directly replaces elements
Class Method Summary collapse
Class Method Details
.run(current_method, current_path, referer, doc, is_js) ⇒ Object
30 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 |
# File 'lib/nice/logic.rb', line 30 def self.run current_method, current_path, referer, doc, is_js current_state = current_method.downcase + current_path.gsub("/", "_") prev_state = referer.gsub("/","_") unless referer.nil? referenced_doc = Nice::HtmlParser.annotate_referencing_nodes doc cleaned_doc = Nice::HtmlParser.remove_elements_not_of_state current_state, referenced_doc # case 1 if !is_js then cleaned_doc.to_html # case 2 else js_stack = ["// remove elements not present in the following state"] js_stack << Nice::Js::Caller.generate_js_remove(current_state) js_stack << "// add new elements" js_stack += Nice::HtmlParser.add_elements_of_current_state(cleaned_doc,current_state).compact js_stack << "// add browser history scripts" js_stack << Nice::Js::Caller.move_to_url(current_path,"title") js_stack << Nice::Js::Caller.insert_or_update_back_listener(referer) js_stack << "// inform ui on state change" js_stack << Nice::Js::Caller.state_did_change(prev_state,current_state) js_stack.join("\n") end end |