<commit_before>/**
 * Application
 * 
 * Base application class for client-side applications
 * 
 * @author		<NAME>
 */
conbo.Application = conbo.View.extend
({
	/**
	 * Default context class to use
	 * You'll normally want to override this with your own
	 */
	contextClass: conbo.Context,
	
	/**
	 * Constructor: DO NOT override! (Use initialize instead)
	 * @param options
	 */
	constructor: function(options)
	{
		options = conbo.clone(options) || {};
		
		var prefix = options.prefix || this.prefix || '';
		var namespace = options.namespace || this.namespace;
		
		_defineIncalculableProperty(this, 'prefix', prefix);
		_defineIncalculableProperty(this, 'namespace', namespace);
		
		options.app = this;
		options.context = new this.contextClass(options);
		options.el || (options.el = this._findAppElement());
		
		conbo.View.prototype.constructor.call(this, options);
		
		this.applyViews();
	},
	
	/**
	 * Apply View classes child DOM elements based on their cb-view attribute
	 */
	applyViews: function()
	{
		var selector = '[cb-view]';
		
		this.$(selector).not('.cb-view').each(this.bind(function(index, el)
		{
			var view = this.$(el).cbAttrs().view,
				viewClass;
			
			if (viewClass = this.getClass(view))
			{
				new viewClass(this.context.addTo({el:el}));
			}
			
		}));
		
		return this;
	},
	
	/**
	 * Attempt to convert string into a conbo.Class
	 * @param name
	 * @returns
	 */
	getClass: function(name)
	{
		if (!name) return;
		
		var viewClass = !!this.namespace
			? this.namespace[name]
			: eval(name);
		
		if (conbo.isClass(viewClass)) 
		{
			return viewClass;
		}		
	},
	
	toString: function()
	{
		return 'conbo.Application';
	},
	
	/**
	 * Find element with matching cb-app attribute, if it exists
	 */
	_findAppElement: function()
	{
		var $apps = $('[cb-app]');
		
		if (!$apps.length) return undefined;
		
		if (!this.namespace)
		{
			if (!!$apps.length)
			{
				console.warn('Application namespace not specified: unable to bind to cb-app element');
			}
			
			return undefined;
		}
		
		var appName;
		
		for (var a in this.namespace)
		{
			try
			{
				if (this instanceof this.namespace[a])
				{
					appName = a;
					break;
				}
			}
			catch(e) 
			{
				// Ignore
			}
		}
		
		if (!appName) return undefined;
		
		var selector = '[cb-app="'+this._addPrefix(appName)+'"]',
			el = $(selector)[0];
		
		return !!el ? el : undefined;
	},
	
	/**
	 * Returns prefixed class name
	 * @param 	name
	 * @returns
	 */
	_addPrefix: function(name)
	{
		name || (name = '');
		return !!this.prefix ? this.prefix+'.'+name : name;
	}

});

_denumerate(conbo.Application.prototype);
<commit_msg>Tidied up cb-app detection<commit_after>/**
 * Application
 * 
 * Base application class for client-side applications
 * 
 * @author		<NAME>
 */
conbo.Application = conbo.View.extend
({
	/**
	 * Default context class to use
	 * You'll normally want to override this with your own
	 */
	contextClass: conbo.Context,
	
	/**
	 * Constructor: DO NOT override! (Use initialize instead)
	 * @param options
	 */
	constructor: function(options)
	{
		options = conbo.clone(options) || {};
		
		var prefix = options.prefix || this.prefix || '';
		var namespace = options.namespace || this.namespace;
		
		_defineIncalculableProperty(this, 'prefix', prefix);
		_defineIncalculableProperty(this, 'namespace', namespace);
		
		options.app = this;
		options.context = new this.contextClass(options);
		options.el || (options.el = this._findAppElement());
		
		conbo.View.prototype.constructor.call(this, options);
		
		this.applyViews();
	},
	
	/**
	 * Apply View classes child DOM elements based on their cb-view attribute
	 */
	applyViews: function()
	{
		var selector = '[cb-view]';
		
		this.$(selector).not('.cb-view').each(this.bind(function(index, el)
		{
			var view = this.$(el).cbAttrs().view,
				viewClass;
			
			if (viewClass = this.getClass(view))
			{
				new viewClass(this.context.addTo({el:el}));
			}
			
		}));
		
		return this;
	},
	
	/**
	 * Attempt to convert string into a conbo.Class
	 * @param name
	 * @returns
	 */
	getClass: function(name)
	{
		if (!name) return;
		
		var viewClass = !!this.namespace
			? this.namespace[name]
			: eval(name);
		
		if (conbo.isClass(viewClass)) 
		{
			return viewClass;
		}		
	},
	
	toString: function()
	{
		return 'conbo.Application';
	},
	
	/**
	 * Find element with matching cb-app attribute, if it exists
	 */
	_findAppElement: function()
	{
		var $apps = $('[cb-app]');
		
		if (!$apps.length) return undefined;
		
		if (!this.namespace)
		{
			if (!!$apps.length)
			{
				console.warn('Application namespace not specified: unable to bind to cb-app element');
			}
			
			return undefined;
		}
		
		var appName;
		
		for (var a in this.namespace)
		{
			if (conbo.isClass(this.namespace[a]))
			{
				if (this instanceof this.namespace[a])
				{
					appName = a;
					break;
				}
			}
		}
		
		if (!appName) return undefined;
		
		var selector = '[cb-app="'+this._addPrefix(appName)+'"]',
			el = $(selector)[0];
		
		return !!el ? el : undefined;
	},
	
	/**
	 * Returns prefixed class name
	 * @param 	name
	 * @returns
	 */
	_addPrefix: function(name)
	{
		name || (name = '');
		return !!this.prefix ? this.prefix+'.'+name : name;
	}

});

_denumerate(conbo.Application.prototype);

{'fraction_non_alphanumeric': 0.15240439227565317, 'fraction_numerical': 0.0003786444528587656, 'mean_word_length': 2.9220489977728286, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6514066', 'n_tokens_mistral': 2080, 'n_tokens_neox': 1710, 'n_words': 408}