Sha256: 7e1101a7e4d21374b53baa8b4bf48e3aa8aabd0c9d9992fe7f3fcd0a55b15dfa

Contents?: true

Size: 1.43 KB

Versions: 4

Compression:

Stored size: 1.43 KB

Contents

class NetzkeController < ApplicationController
  
  # Collect javascripts from all plugins that registered it in Netzke::Base.config[:javascripts]
  # TODO: caching
  # caches_action :netzke
  def netzke
    respond_to do |format|
      format.js {
        res = ""
        Netzke::Base.config[:javascripts].each do |path|
          f = File.new(path)
          res << f.read
        end
        render :text => res.strip_js_comments
      }
      
      format.css {
        res = ""
        Netzke::Base.config[:stylesheets].each do |path|
          f = File.new(path)
          res << f.read
        end
        render :text => res
      }
    end
  end
  
  # Main dispatcher of the HTTP requests. The URL contains the name of the widget, 
  # as well as the method of this widget to be called, according to the double underscore notation. 
  # E.g.: some_grid__post_grid_data.
  def method_missing(method_name)
    widget_name, *action = method_name.to_s.split('__')
    widget_name = widget_name.to_sym
    action = !action.empty? && action.join("__").to_sym
  
    if action
      w_instance = Netzke::Base.instance_by_config(Netzke::Base.session[:netzke_widgets][widget_name])
      # only widget's actions starting with "api_" are accessible from outside (security)
      api_action = action.to_s.index('__') ? action : "api_#{action}"
      render :text => w_instance.send(api_action, params), :layout => false
    else
      super
    end
  end
  
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
netzke-core-0.5.5 lib/app/controllers/netzke_controller.rb
netzke-core-0.5.4 lib/app/controllers/netzke_controller.rb
netzke-core-0.5.3 lib/app/controllers/netzke_controller.rb
netzke-core-0.5.2 lib/app/controllers/netzke_controller.rb