Module: Gon::Base
- Defined in:
- lib/gon/base.rb
Constant Summary collapse
- ENV_CONTROLLER_KEY =
'action_controller.instance'
Class Method Summary collapse
- .get_controller(options = {}) ⇒ Object
- .get_template_path(options, extension) ⇒ Object
- .render_data(options) ⇒ Object
- .render_data_amd(options) ⇒ Object
Class Method Details
.get_controller(options = {}) ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/gon/base.rb', line 31 def get_controller( = {}) [:controller] || ( current_gon && current_gon.env[Gon::Base::ENV_CONTROLLER_KEY] || current_gon.env['action_controller.rescue.response']. instance_variable_get('@template'). instance_variable_get('@controller') ) end |
.get_template_path(options, extension) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/gon/base.rb', line 42 def get_template_path(, extension) if [:template] if right_extension?(extension, [:template]) [:template] else [[:template], extension].join('.') end else controller = get_controller().controller_path action = get_controller().action_name "app/views/#{controller}/#{action}.json.#{extension}" end end |
.render_data(options) ⇒ Object
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/gon/base.rb', line 7 def render_data() namespace, tag, cameled, camel_depth, watch, type, cdata, global_root, namespace_check = () script = namespace_check ? "window.#{namespace}=window.#{namespace}||{};" : "window.#{namespace}={};" script << formatted_data(namespace, cameled, camel_depth, watch, global_root) script = Gon::Escaper.escape_unicode(script) script = Gon::Escaper.javascript_tag(script, type, cdata) if tag script.html_safe end |
.render_data_amd(options) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/gon/base.rb', line 18 def render_data_amd() namespace, tag, cameled, camel_depth, watch, type, cdata, global_root = () script = "define('#{namespace}',[],function(){" script << amd_formatted_data(namespace, cameled, camel_depth, watch, global_root) script << 'return gon;});' script = Gon::Escaper.escape_unicode(script) script = Gon::Escaper.javascript_tag(script, type, cdata) if tag script.html_safe end |