mirror of
				https://github.com/kbparagua/paloma
				synced 2023-03-27 23:21:17 -04:00 
			
		
		
		
	Remove old files
This commit is contained in:
		
							parent
							
								
									bf94d4cb92
								
							
						
					
					
						commit
						5f1f877e31
					
				
					 7 changed files with 23 additions and 529 deletions
				
			
		| 
						 | 
				
			
			@ -22,13 +22,9 @@ module Paloma
 | 
			
		|||
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
require 'action_controller/railtie'
 | 
			
		||||
require 'rails/generators'
 | 
			
		||||
 | 
			
		||||
# TODO: Rails version checking
 | 
			
		||||
 | 
			
		||||
require 'paloma/generators/add_generator'
 | 
			
		||||
require 'paloma/generators/setup_generator'
 | 
			
		||||
require 'action_controller/railtie'
 | 
			
		||||
 | 
			
		||||
require 'paloma/action_controller_extension'
 | 
			
		||||
require 'paloma/rails/controller_generator'
 | 
			
		||||
require 'paloma/rails/engine'
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,136 +0,0 @@
 | 
			
		|||
module Paloma
 | 
			
		||||
  #
 | 
			
		||||
  # Usage: 
 | 
			
		||||
  #   rails g paloma:add <controller_name>
 | 
			
		||||
  #     - Generates the following:
 | 
			
		||||
  #         - a folder under app/assets/javascripts/paloma named as <controller_name>
 | 
			
		||||
  #         - callbacks.js inside the folder just made
 | 
			
		||||
  #     - Updates index.js under the 'paloma' folder
 | 
			
		||||
  #         - adds a line in order to require the callbacks to be made under the recently made folder
 | 
			
		||||
  #
 | 
			
		||||
  #
 | 
			
		||||
  #   rails g paloma:add <controller_name>/<action_name>
 | 
			
		||||
  #     - Generates the following:
 | 
			
		||||
  #         - <action_name>.js file inside the <controller_name> folder
 | 
			
		||||
  #
 | 
			
		||||
  #
 | 
			
		||||
  # Generated Files:
 | 
			
		||||
  #  <controller_name>/callbacks.js
 | 
			
		||||
  #    - contains code for requiring all callbacks under the same folder <controller_name> 
 | 
			
		||||
  #
 | 
			
		||||
  #  <controller_name>/<action_name>.js
 | 
			
		||||
  #    - actual code to be executed when callback is called
 | 
			
		||||
  #
 | 
			
		||||
    
 | 
			
		||||
  class AddGenerator < ::Rails::Generators::NamedBase
 | 
			
		||||
    source_root Paloma.templates
 | 
			
		||||
    argument :actions, :type => :array, :required => false
 | 
			
		||||
    
 | 
			
		||||
    def create_callback_file
 | 
			
		||||
      initialize_arguments file_path
 | 
			
		||||
      
 | 
			
		||||
      generate_namespace_folder if @namespace.present?
 | 
			
		||||
      generate_controller_folder if @controller.present?
 | 
			
		||||
      generate_action_files(actions) if actions.present?
 | 
			
		||||
    end
 | 
			
		||||
    
 | 
			
		||||
    
 | 
			
		||||
    
 | 
			
		||||
  private
 | 
			
		||||
    
 | 
			
		||||
    
 | 
			
		||||
    def initialize_arguments args
 | 
			
		||||
      # split controller from actions
 | 
			
		||||
      arg = args.split(' ')
 | 
			
		||||
      @controller_path = arg[0]
 | 
			
		||||
      
 | 
			
		||||
      full_controller_path = @controller_path.split '/'
 | 
			
		||||
      @controller = full_controller_path.pop
 | 
			
		||||
      @namespace = full_controller_path.join '/'
 | 
			
		||||
      @namespace_folder = "#{Paloma.destination}/#{@namespace}" if @namespace 
 | 
			
		||||
      @controller_folder = "#{Paloma.destination}/#{@controller_path}"
 | 
			
		||||
    end
 | 
			
		||||
    
 | 
			
		||||
    
 | 
			
		||||
    def generate_namespace_folder
 | 
			
		||||
      return true if @namespace_folder.nil? || Dir.exists?(@namespace_folder)
 | 
			
		||||
      
 | 
			
		||||
      Dir.mkdir(@namespace_folder)
 | 
			
		||||
      
 | 
			
		||||
      generate_from_template :template => '/namespace/_locals.js',
 | 
			
		||||
        :filename => "#{@namespace_folder}/_locals.js",
 | 
			
		||||
        :replace => {':namespace' => @namespace}
 | 
			
		||||
        
 | 
			
		||||
      generate_from_template :template => '_filters.js',
 | 
			
		||||
        :filename => "#{@namespace_folder}/_filters.js",
 | 
			
		||||
        :replace => {':scope' => @namespace}
 | 
			
		||||
 | 
			
		||||
      generate_from_template :template => '/namespace/_manifest.js',
 | 
			
		||||
        :filename => "#{@namespace_folder}/_manifest.js",
 | 
			
		||||
        :replace => {':controller' => @controller}
 | 
			
		||||
      
 | 
			
		||||
      # Require _manifest.js to Paloma's main index file
 | 
			
		||||
      File.open(Paloma.index_js, 'a+'){ |f| 
 | 
			
		||||
        f << "\n//= require ./#{@namespace}/_manifest.js" 
 | 
			
		||||
      }
 | 
			
		||||
    end
 | 
			
		||||
    
 | 
			
		||||
    
 | 
			
		||||
    def generate_controller_folder
 | 
			
		||||
      return true if @controller_folder.nil? || Dir.exists?(@controller_folder)
 | 
			
		||||
      
 | 
			
		||||
      Dir.mkdir(@controller_folder)
 | 
			
		||||
      
 | 
			
		||||
      generate_from_template :template => '/controller/_locals.js', 
 | 
			
		||||
        :filename => "#{@controller_folder}/_locals.js",
 | 
			
		||||
        :replace => {
 | 
			
		||||
          ':controller_path' => @controller_path,
 | 
			
		||||
          ':parent' => (@namespace.present? ? @namespace : '/')}
 | 
			
		||||
 | 
			
		||||
      generate_from_template :template => '_filters.js',
 | 
			
		||||
        :filename => "#{@controller_folder}/_filters.js",
 | 
			
		||||
        :replace => {':scope' => @controller_path}
 | 
			
		||||
 | 
			
		||||
      generate_from_template :template => '/controller/_manifest.js', 
 | 
			
		||||
        :filename => "#{@controller_folder}/_manifest.js"
 | 
			
		||||
      
 | 
			
		||||
      if @namespace.present?
 | 
			
		||||
        # Require _manifest.js to namespace's _manifest.js file
 | 
			
		||||
        File.open("#{@namespace_folder}/_manifest.js", 'a+'){ |f| 
 | 
			
		||||
          f << "\n//= require ./#{@controller}/_manifest.js"}
 | 
			
		||||
      else
 | 
			
		||||
        # Require _manifest.js to Paloma's main index file
 | 
			
		||||
        File.open(Paloma.index_js, 'a+'){ |f| 
 | 
			
		||||
          f << "\n//= require ./#{@controller}/_manifest.js" }
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
    
 | 
			
		||||
    
 | 
			
		||||
    def generate_action_files actions
 | 
			
		||||
      actions.each do |action|
 | 
			
		||||
        action_js = "#{@controller_folder}/#{action}.js"
 | 
			
		||||
        next if action.nil? || File.exists?(action_js)
 | 
			
		||||
        
 | 
			
		||||
        content = File.read("#{Paloma.templates}/controller/action.js").
 | 
			
		||||
          gsub(':controller_path', @controller_path).
 | 
			
		||||
          gsub(':action', action)
 | 
			
		||||
          
 | 
			
		||||
        File.open(action_js, 'w'){ |f| f.write(content) }
 | 
			
		||||
        puts "create #{action_js}"  
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
    
 | 
			
		||||
    
 | 
			
		||||
    def generate_from_template options = {:template => nil, :filename => nil, :replace => {}}
 | 
			
		||||
      return true if File.exists?(options[:filename])
 | 
			
		||||
      
 | 
			
		||||
      content = File.read("#{Paloma.templates}/#{options[:template]}")
 | 
			
		||||
      options[:replace].each do |pattern, value| 
 | 
			
		||||
        content.gsub!(pattern, value)
 | 
			
		||||
      end if options[:replace].present?
 | 
			
		||||
      
 | 
			
		||||
      File.open(options[:filename], 'w'){ |f| f.write(content) }
 | 
			
		||||
      puts "create #{options[:filename]}"
 | 
			
		||||
    end 
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			@ -1,38 +0,0 @@
 | 
			
		|||
module Paloma
 | 
			
		||||
  #
 | 
			
		||||
  # rails g paloma:setup
 | 
			
		||||
  #   - Generates the following:
 | 
			
		||||
  #     - index.js and paloma.js under the 'paloma' folder
 | 
			
		||||
  #
 | 
			
		||||
  # Generated Files:
 | 
			
		||||
  # index.js
 | 
			
		||||
  #   - contains code for requiring all callbacks of all folders
 | 
			
		||||
  #   - always updated when new folders and callback.js files are created
 | 
			
		||||
  #
 | 
			
		||||
  # paloma.js
 | 
			
		||||
  #   - declaration of namespace used in all callbacks
 | 
			
		||||
  #
 | 
			
		||||
 | 
			
		||||
  class SetupGenerator < ::Rails::Generators::Base
 | 
			
		||||
    source_root Paloma.templates
 | 
			
		||||
    
 | 
			
		||||
    def setup_paloma
 | 
			
		||||
      locals_js = "#{Paloma.destination}/_locals.js"
 | 
			
		||||
      filters_js = "#{Paloma.destination}/_filters.js"
 | 
			
		||||
      index_js = "#{Paloma.destination}/index.js"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
      copy_file './application/_locals.js', locals_js unless File.exists?(locals_js)   
 | 
			
		||||
      copy_file './index.js', index_js unless File.exists?(index_js)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
      unless File.exists?(filters_js)
 | 
			
		||||
        content = File.read("#{Paloma.templates}/_filters.js")
 | 
			
		||||
        content.gsub!(':scope', '/')
 | 
			
		||||
 | 
			
		||||
        File.open(filters_js, 'w'){ |f| f.write(content) }
 | 
			
		||||
        puts "create #{filters_js}"
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			@ -1,11 +0,0 @@
 | 
			
		|||
module ::Rails::Generators
 | 
			
		||||
  class ControllerGenerator < NamedBase 
 | 
			
		||||
 | 
			
		||||
    class_option :paloma, :type => :boolean, :default => true
 | 
			
		||||
 | 
			
		||||
    def paloma
 | 
			
		||||
      invoke 'paloma:add', ([file_name] + actions) if options[:paloma]
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
							
								
								
									
										8
									
								
								test.js
									
										
									
									
									
								
							
							
						
						
									
										8
									
								
								test.js
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -7,12 +7,12 @@
 | 
			
		|||
//  Rails controller will be mapped to a corresponding Paloma controller with the same name.
 | 
			
		||||
//
 | 
			
		||||
//
 | 
			
		||||
Paloma.Route.resource('Users', {controller: 'Authors'});
 | 
			
		||||
Paloma.Route.redirect('Users#edit', {to: 'Authors#revise'});
 | 
			
		||||
Paloma.Routes.resource('Users', {controller: 'Authors'});
 | 
			
		||||
Paloma.Routes.redirect('Users#edit', {to: 'Authors#revise'});
 | 
			
		||||
 | 
			
		||||
// With namespace
 | 
			
		||||
Paloma.Route.resource('Admin.Users', {controller: 'Authors'});
 | 
			
		||||
Paloma.Rotue.resource('Users', {controller: 'Admin.Authors'});
 | 
			
		||||
Paloma.Routes.resource('Admin.Users', {controller: 'Authors'});
 | 
			
		||||
Paloma.Rotues.resource('Users', {controller: 'Admin.Authors'});
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										55
									
								
								vendor/assets/javascripts/paloma.js
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										55
									
								
								vendor/assets/javascripts/paloma.js
									
										
									
									
										vendored
									
									
								
							| 
						 | 
				
			
			@ -1,61 +1,40 @@
 | 
			
		|||
window.Paloma = window.Paloma || {};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
(function(P){
 | 
			
		||||
 | 
			
		||||
  // Initialize Containers
 | 
			
		||||
  P.Resources = {};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
  P.execute = function(callback){
 | 
			
		||||
    var resource = P.Resources[ callback['resource'] ];
 | 
			
		||||
    if (resource == undefined){ return false; }
 | 
			
		||||
 | 
			
		||||
    var instance = new resource(),
 | 
			
		||||
        action = callback['action'];
 | 
			
		||||
 | 
			
		||||
    if (instance[action] != null){ instance[action](callback['params']); }
 | 
			
		||||
  var ControllerBuilder = function(){
 | 
			
		||||
    this.instances = {};
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
  ControllerBuilder.prototype.register = function(name){
 | 
			
		||||
 | 
			
		||||
  P.Resource = function(options){};
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
  P.Resource.create = function(name, options){
 | 
			
		||||
    options = defaultOptions(options);
 | 
			
		||||
  ControllerBuilder.prototype._parse = function(name){
 | 
			
		||||
    var parts = {},
 | 
			
		||||
        namespacedName = name.split('/');
 | 
			
		||||
 | 
			
		||||
    var path = name.split('.'),
 | 
			
		||||
        resource = path.pop(),
 | 
			
		||||
        namespace = path.pop();
 | 
			
		||||
    if (namespacedName.length > 1){
 | 
			
		||||
      // The last part of the namespacedName will be the controller name.
 | 
			
		||||
      for (var i = 0, lastIndex = namespacedName.length - 1; i < lastIndex; i++){
 | 
			
		||||
        namespace = namespacedName[i];
 | 
			
		||||
 | 
			
		||||
    var Resource = function(){};
 | 
			
		||||
 | 
			
		||||
    if (namespace != null){
 | 
			
		||||
      P.Resources[namespace] = P.Resource[namespace] || {};
 | 
			
		||||
      return P.Resources[namespace][resource] = Resource;
 | 
			
		||||
    }
 | 
			
		||||
    else {
 | 
			
		||||
      return P.Resources[resource] = Resource;
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
  P.Controller = new ControllerBuilder();
 | 
			
		||||
 | 
			
		||||
  // Filters
 | 
			
		||||
  P.Resource.prototype.perform = function(){
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
  var Controller = function(){
 | 
			
		||||
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
  var defaultOptions = function(options){
 | 
			
		||||
    options = options || {};
 | 
			
		||||
 | 
			
		||||
    var values = {};
 | 
			
		||||
    values['extend'] = options['extend'] != null ? options['extend'] : null;
 | 
			
		||||
 | 
			
		||||
    return values;
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
})(window.Paloma);
 | 
			
		||||
							
								
								
									
										296
									
								
								vendor/assets/javascripts/paloma_core.old.js
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										296
									
								
								vendor/assets/javascripts/paloma_core.old.js
									
										
									
									
										vendored
									
									
								
							| 
						 | 
				
			
			@ -1,296 +0,0 @@
 | 
			
		|||
/*(function(){
 | 
			
		||||
window.Paloma = {
 | 
			
		||||
  callbacks : {},
 | 
			
		||||
  filterScopes : {},
 | 
			
		||||
  locals : {},
 | 
			
		||||
  variableContainer : {}
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
var FILTER_TYPES = {},
 | 
			
		||||
  FILTER_TYPE_NAMES = ['BEFORE', 'AFTER', 'AROUND'],
 | 
			
		||||
  INCLUSION_TYPES = {},
 | 
			
		||||
  INCLUSION_TYPE_NAMES = ['ALL', 'ONLY', 'EXCEPT'];
 | 
			
		||||
 | 
			
		||||
FILTER_TYPES.BEFORE = 0;
 | 
			
		||||
FILTER_TYPES.AFTER = 1;
 | 
			
		||||
FILTER_TYPES.AROUND = 2;
 | 
			
		||||
 | 
			
		||||
INCLUSION_TYPES.ALL = 3;
 | 
			
		||||
INCLUSION_TYPES.ONLY = 4;
 | 
			
		||||
INCLUSION_TYPES.EXCEPT = 5;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
Paloma.inheritLocals = function(options){
 | 
			
		||||
  var from = Paloma.locals[options['from']],
 | 
			
		||||
    to = Paloma.locals[options['to']];
 | 
			
		||||
 | 
			
		||||
  for (var local in from){
 | 
			
		||||
    // Overriding is allowed.
 | 
			
		||||
    if ( to.hasOwnProperty(local) ){ continue; }
 | 
			
		||||
 | 
			
		||||
    to[local] = from[local];
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
Paloma.FilterScope = function(name){
 | 
			
		||||
  this.name = name;
 | 
			
		||||
 | 
			
		||||
  this.filters = {};
 | 
			
		||||
  this.skippers = {};
 | 
			
		||||
 | 
			
		||||
  for (var i = 0, n = FILTER_TYPE_NAMES.length; i < n; i++){
 | 
			
		||||
    var type = FILTER_TYPE_NAMES[i].toUpperCase();
 | 
			
		||||
    this.filters[ FILTER_TYPES[type] ] = [];
 | 
			
		||||
    this.skippers[ FILTER_TYPES[type] ] = [];
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  Paloma.filterScopes[name] = this;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// Creates a new Filter instance registered under this FilterScope.
 | 
			
		||||
Paloma.FilterScope.prototype.as = function(filterName){
 | 
			
		||||
  return (new Paloma.Filter(this, filterName));
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// skip_*_filter/s methods
 | 
			
		||||
(function(){
 | 
			
		||||
  for (var i = 0, n = FILTER_TYPE_NAMES.length; i < n; i++){
 | 
			
		||||
    var type = FILTER_TYPE_NAMES[i],
 | 
			
		||||
      singular = 'skip_' + type.toLowerCase() + '_filter',
 | 
			
		||||
      plural = singular + 's',
 | 
			
		||||
      method = function(skipperType){
 | 
			
		||||
        return function(){
 | 
			
		||||
          return (new Paloma.Skipper(this, FILTER_TYPES[skipperType], arguments));
 | 
			
		||||
        };
 | 
			
		||||
      };
 | 
			
		||||
 | 
			
		||||
    Paloma.FilterScope.prototype[singular] = new method(type);
 | 
			
		||||
    Paloma.FilterScope.prototype[plural] = Paloma.FilterScope.prototype[singular];
 | 
			
		||||
  }
 | 
			
		||||
})();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// Skipper class
 | 
			
		||||
Paloma.Skipper = function(scope, type, filters){
 | 
			
		||||
  this.scope = scope;
 | 
			
		||||
  this.type = type;
 | 
			
		||||
  this.filters = Array.prototype.slice.call(filters);
 | 
			
		||||
  this.inclusionType = INCLUSION_TYPES.ALL;
 | 
			
		||||
  this.actions = [];
 | 
			
		||||
 | 
			
		||||
  // Register this skipper on its scope.
 | 
			
		||||
  this.scope.skippers[this.type].push(this);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
Paloma.Skipper.prototype.skip = function(filter, action){
 | 
			
		||||
  if (this.filters.indexOf(filter.name) == -1){ return false; }
 | 
			
		||||
 | 
			
		||||
  var actionIsListed = this.actions.indexOf(action) != -1,
 | 
			
		||||
    isAllActions = this.inclusionType == INCLUSION_TYPES.ALL,
 | 
			
		||||
    isQualified = this.inclusionType == INCLUSION_TYPES.ONLY && actionIsListed,
 | 
			
		||||
    isNotExcepted = this.inclusionType == INCLUSION_TYPES.EXCEPT && !actionIsListed;
 | 
			
		||||
 | 
			
		||||
  return (isAllActions || isQualified || isNotExcepted);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
Paloma.Skipper.prototype.only = function(){
 | 
			
		||||
  this.inclusionType = INCLUSION_TYPES.ONLY;
 | 
			
		||||
  this.actions = Array.prototype.slice.call(arguments);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
Paloma.Skipper.prototype.except = function(){
 | 
			
		||||
  this.inclusionType = INCLUSION_TYPES.EXCEPT;
 | 
			
		||||
  this.actions = Array.prototype.slice.call(arguments);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// Filter class
 | 
			
		||||
Paloma.Filter = function(scope, name){
 | 
			
		||||
  this.scope = scope;
 | 
			
		||||
  this.name = name;
 | 
			
		||||
 | 
			
		||||
  this.type = undefined;
 | 
			
		||||
  this.inclusionType = INCLUSION_TYPES.ONLY;
 | 
			
		||||
 | 
			
		||||
  this.actions = [];
 | 
			
		||||
  this.method = undefined;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// Create Methods:
 | 
			
		||||
//  - before, after, around, *_all, except_*
 | 
			
		||||
(function(){
 | 
			
		||||
var Basic = function(type){
 | 
			
		||||
  return function(){
 | 
			
		||||
    return this.setProperties(type, INCLUSION_TYPES.ONLY, arguments);
 | 
			
		||||
  };
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
var All = function(type){
 | 
			
		||||
  return function(){
 | 
			
		||||
    return this.setProperties(type, INCLUSION_TYPES.ALL, []);
 | 
			
		||||
  };
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
var Except = function(type){
 | 
			
		||||
  return function(){
 | 
			
		||||
    return this.setProperties(type, INCLUSION_TYPES.EXCEPT, arguments);
 | 
			
		||||
  };
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
for (var i = 0, n = FILTER_TYPE_NAMES.length; i < n; i++){
 | 
			
		||||
  var name = FILTER_TYPE_NAMES[i].toLowerCase(),
 | 
			
		||||
    type = FILTER_TYPES[name.toUpperCase()];
 | 
			
		||||
 | 
			
		||||
  Paloma.Filter.prototype[name] = new Basic(type);
 | 
			
		||||
  Paloma.Filter.prototype[name + '_all'] = new All(type);
 | 
			
		||||
  Paloma.Filter.prototype['except_' + name] = new Except(type);
 | 
			
		||||
}
 | 
			
		||||
})();
 | 
			
		||||
// End of creating methods.
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// This will be the last method to be invoked when declaring a filter.
 | 
			
		||||
// This will set what method/function will be executed when the filter is called.
 | 
			
		||||
Paloma.Filter.prototype.perform = function(method){
 | 
			
		||||
  this.method = method;
 | 
			
		||||
 | 
			
		||||
  // This is the only time the filter is registered to its owner scope.
 | 
			
		||||
  this.scope.filters[this.type].push(this);
 | 
			
		||||
  return this;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
Paloma.Filter.prototype.isApplicable = function(action){
 | 
			
		||||
  var actionIsListed = this.actions.indexOf(action) != -1,
 | 
			
		||||
    isAllActions = this.inclusionType == INCLUSION_TYPES.ALL,
 | 
			
		||||
    isQualified = this.inclusionType == INCLUSION_TYPES.ONLY && actionIsListed,
 | 
			
		||||
    isNotExcepted = this.inclusionType == INCLUSION_TYPES.EXCEPT && !actionIsListed;
 | 
			
		||||
 | 
			
		||||
  return (isAllActions || isQualified || isNotExcepted);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
Paloma.Filter.prototype.setProperties = function(type, inclusion, actions){
 | 
			
		||||
  this.type = type;
 | 
			
		||||
  this.inclusionType = inclusion;
 | 
			
		||||
  this.actions = Array.prototype.slice.call(actions);
 | 
			
		||||
  return this;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// Execute callback that corresponds to the controller and action passed.
 | 
			
		||||
Paloma.execute = function(controller, action, params){
 | 
			
		||||
  var callbackFound = true;
 | 
			
		||||
 | 
			
		||||
  var callback = Paloma.callbacks[controller];
 | 
			
		||||
  callbackFound = callback != undefined;
 | 
			
		||||
 | 
			
		||||
  if (callbackFound){
 | 
			
		||||
    callback = callback[action];
 | 
			
		||||
    callbackFound = callback != undefined;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // Parse parameters
 | 
			
		||||
  params = params || {};
 | 
			
		||||
 | 
			
		||||
  // Request details
 | 
			
		||||
  var requestControllerPath = params['controller_path'].split('/');
 | 
			
		||||
  params['controller'] = requestControllerPath.pop();
 | 
			
		||||
  params['namespace'] = requestControllerPath.join('/');
 | 
			
		||||
 | 
			
		||||
  // Callback details
 | 
			
		||||
  var callbackControllerPath = controller.split('/');
 | 
			
		||||
  params['callback_controller'] = callbackControllerPath.pop();
 | 
			
		||||
  params['callback_namespace'] = callbackControllerPath.join('/');
 | 
			
		||||
  params['callback_controller_path'] = controller;
 | 
			
		||||
  params['callback_action'] = action;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
  var beforeFilters = getOrderedFilters(
 | 
			
		||||
    FILTER_TYPES.BEFORE,
 | 
			
		||||
    params['callback_namespace'],
 | 
			
		||||
    controller,
 | 
			
		||||
    action);
 | 
			
		||||
 | 
			
		||||
  var afterFilters = getOrderedFilters(
 | 
			
		||||
    FILTER_TYPES.AFTER,
 | 
			
		||||
    params['callback_namespace'],
 | 
			
		||||
    controller,
 | 
			
		||||
    action);
 | 
			
		||||
 | 
			
		||||
  // Start filter and callback executions
 | 
			
		||||
  performFilters(beforeFilters, params);
 | 
			
		||||
  if (callbackFound){ callback(params); }
 | 
			
		||||
  performFilters(afterFilters, params);
 | 
			
		||||
 | 
			
		||||
  // variableContainer is used to share variable between filters and callbacks.
 | 
			
		||||
  // It will be cleared after it is used.
 | 
			
		||||
  Paloma.variableContainer = [];
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
var getOrderedFilters = function(beforeOrAfter, namespace, controller, action){
 | 
			
		||||
  var filters = [],
 | 
			
		||||
    applicableFilters = [],
 | 
			
		||||
    skippers = [],
 | 
			
		||||
    scopes = [
 | 
			
		||||
      Paloma.filterScopes['/'],
 | 
			
		||||
      Paloma.filterScopes[namespace],
 | 
			
		||||
      Paloma.filterScopes[controller]];
 | 
			
		||||
 | 
			
		||||
  for (var i = 0, n = scopes.length; i < n; i++){
 | 
			
		||||
    var scope = scopes[i];
 | 
			
		||||
    if (scope == undefined){ continue; }
 | 
			
		||||
 | 
			
		||||
    var mainFilters = scope.filters[beforeOrAfter],
 | 
			
		||||
      aroundFilters = scope.filters[FILTER_TYPES.AROUND];
 | 
			
		||||
 | 
			
		||||
    // Around Filters have lower precedence than before or after filters.
 | 
			
		||||
    if (mainFilters != undefined){ filters = filters.concat(mainFilters); }
 | 
			
		||||
    if (aroundFilters != undefined){ filters = filters.concat(aroundFilters); }
 | 
			
		||||
 | 
			
		||||
    skippers = skippers.concat(
 | 
			
		||||
        scope.skippers[beforeOrAfter],
 | 
			
		||||
        scope.skippers[FILTER_TYPES.AROUND]);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
  // Select only applicable filters for the passed action.
 | 
			
		||||
  for (var i = 0, n = filters.length; i < n; i++){
 | 
			
		||||
    var filter = filters[i],
 | 
			
		||||
      isApplicable = filter.isApplicable(action),
 | 
			
		||||
      isNotSkipped = true;
 | 
			
		||||
 | 
			
		||||
    for (var k = 0, len = skippers.length; k < len; k++){
 | 
			
		||||
      if ( skippers[k].skip(filter, action) ){ isNotSkipped = false; break;}
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (isApplicable && isNotSkipped){ applicableFilters.push(filter); }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return applicableFilters;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
var performFilters = function(filters, params){
 | 
			
		||||
  for (var i = 0, n = filters.length; i < n; i++){
 | 
			
		||||
    filters[i].method(params);
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
})();*/
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue