Module: RightRails::JavaScriptGenerator::Methods
- Included in:
- RightRails::JavaScriptGenerator
- Defined in:
- lib/right_rails/java_script_generator.rb
Overview
This module contains the predefined methods collection
Instance Method Summary collapse
-
#<<(code) ⇒ Object
just pushes a line of code into the thread.
-
#[](record_or_id) ⇒ Object
referring an element by an id or a record.
-
#find(css_rule) ⇒ Object
builds a css-select block.
-
#get(name) ⇒ Object
access to the javascript variables.
-
#insert(record, position = nil) ⇒ Object
builds the record HTML code and then insterts it in place.
-
#insert_and_care(record, position = nil) ⇒ Object
generates a script that inserts the record partial, then updates the form and the flashes block.
-
#redirect_to(location) ⇒ Object
generates the redirection script.
-
#reload ⇒ Object
generates the page reload script.
-
#remove(record) ⇒ Object
removes the record element from the page.
-
#replace(record) ⇒ Object
replaces the record element on the page.
-
#replace_and_care(record) ⇒ Object
replaces the record partial and updates the flash.
-
#replace_form_for(record) ⇒ Object
renders and updates a form for the record.
-
#set(name, value) ⇒ Object
variables initializing method.
-
#show_form_for(record) ⇒ Object
renders and shows a form for the record.
-
#update_flash(content = nil) ⇒ Object
updates the flashes block.
Instance Method Details
#<<(code) ⇒ Object
just pushes a line of code into the thread
41 42 43 44 |
# File 'lib/right_rails/java_script_generator.rb', line 41 def << (code) @util.write(code) self end |
#[](record_or_id) ⇒ Object
referring an element by an id or a record
36 37 38 |
# File 'lib/right_rails/java_script_generator.rb', line 36 def [](record_or_id) @util.record("#{RightRails::Helpers.prefix}$(\"#{@util.dom_id(record_or_id)}\")") end |
#find(css_rule) ⇒ Object
builds a css-select block
47 48 49 |
# File 'lib/right_rails/java_script_generator.rb', line 47 def find(css_rule) @util.record("#{RightRails::Helpers.prefix}$$(\"#{css_rule}\")") end |
#get(name) ⇒ Object
access to the javascript variables
52 53 54 |
# File 'lib/right_rails/java_script_generator.rb', line 52 def get(name) @util.record(name) end |
#insert(record, position = nil) ⇒ Object
builds the record HTML code and then insterts it in place
74 75 76 |
# File 'lib/right_rails/java_script_generator.rb', line 74 def insert(record, position=nil) self.RR.insert(*[record.class.table_name, @util.render(record), position].compact) end |
#insert_and_care(record, position = nil) ⇒ Object
generates a script that inserts the record partial, then updates the form and the flashes block
79 80 81 82 83 84 |
# File 'lib/right_rails/java_script_generator.rb', line 79 def insert_and_care(record, position=nil) insert(record, position) @util.template.instance_variable_set("@#{record.class.table_name.singularize}", record.class.new) replace_form_for(record.class.new) update_flash end |
#redirect_to(location) ⇒ Object
generates the redirection script
62 63 64 65 |
# File 'lib/right_rails/java_script_generator.rb', line 62 def redirect_to(location) self.document[:location].href = (location.is_a?(String) ? location : @util.template.url_for(location)) self end |
#reload ⇒ Object
generates the page reload script
68 69 70 71 |
# File 'lib/right_rails/java_script_generator.rb', line 68 def reload self.document[:location].reload self end |
#remove(record) ⇒ Object
removes the record element from the page
98 99 100 |
# File 'lib/right_rails/java_script_generator.rb', line 98 def remove(record) self.RR.remove(@util.dom_id(record)) end |
#replace(record) ⇒ Object
replaces the record element on the page
87 88 89 |
# File 'lib/right_rails/java_script_generator.rb', line 87 def replace(record) self.RR.replace(@util.dom_id(record), @util.render(record)) end |
#replace_and_care(record) ⇒ Object
replaces the record partial and updates the flash
92 93 94 95 |
# File 'lib/right_rails/java_script_generator.rb', line 92 def replace_and_care(record) replace(record) update_flash end |
#replace_form_for(record) ⇒ Object
renders and updates a form for the record
108 109 110 |
# File 'lib/right_rails/java_script_generator.rb', line 108 def replace_form_for(record) self.RR.replace_form(@util.form_id_for(record), @util.render('form')) end |
#set(name, value) ⇒ Object
variables initializing method
57 58 59 |
# File 'lib/right_rails/java_script_generator.rb', line 57 def set(name, value) @util.record("var #{name}=#{@util.to_js_type(value)}") end |
#show_form_for(record) ⇒ Object
renders and shows a form for the record
103 104 105 |
# File 'lib/right_rails/java_script_generator.rb', line 103 def show_form_for(record) self.RR.show_form_for(@util.dom_id(record), @util.render('form')) end |
#update_flash(content = nil) ⇒ Object
updates the flashes block
113 114 115 116 |
# File 'lib/right_rails/java_script_generator.rb', line 113 def update_flash(content=nil) self.RR.update_flash(content || @util.template.flashes) @util.template.flash.clear end |