<commit_before><commit_msg>Start work towards loading the decorator template.<commit_after>/*!
 * Thymeleaf Layout Dialect JS v0.1.0
 * https://github.com/ultraq/thymeleaf-layout-dialect
 * 
 * Copyright 2013, <NAME> (http://www.ultraq.net.nz/)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * Emulates what DecoratorProcessor in the Layout Dialect does in Thymeleaf, for
 * a prototyping environment, ie: in-browser only.
 *
 * @author <NAME>
 */
define(['domready', 'jquery'], function(domready, jquery) {
	'use strict';

	var ATTRIBUTE_LAYOUT_DECORATOR = 'layout:decorator';

	/**
	 * Recursive search for an element, returning when the test in the given
	 * function passes.
	 *
	 * @param element
	 * @param test
	 */
	function findElement(element, test) {

		if (test(element)) {
			return element;
		}
		for (var i = 0; i < element.children.length; i++) {
			var childElement = element.children[i];
			if (test(childElement)) {
				return childElement;
			}
		}
		return null;
	};

	var decorator = {

		/**
		 * Performs decoration of the document.
		 * 
		 * @param document
		 */
		decorate: function(document) {

			// Look for the layout:decorator attribute
			var decoratorElement = findElement(document.documentElement, function(element) {
				return element.hasAttribute(ATTRIBUTE_LAYOUT_DECORATOR);
			});
			if (decoratorElement) {
				var decoratorName = decoratorElement.getAttribute(ATTRIBUTE_LAYOUT_DECORATOR);
				if (!decoratorName.endsWith('.html')) {
					decoratorName += '.html';
				}

				// Load the document from the filesystem
				jquery.get(decoratorName)
					.done(function(data) {
						
					})
					.fail(function(data) {
						console.log('Unable to load ' + decoratorElement + ' from the file system');
					});
			}
		}
	};

	/**
	 * Run the decorator when the document has been loaded.
	 */
	domready(function() {
		decorator.decorate(document);
	});

	return decorator;
});
{'fraction_non_alphanumeric': 0.11407468198604842, 'fraction_numerical': 0.004924086992203529, 'mean_word_length': 3.4166666666666665, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 5, 'https://': 1, 'lorem ipsum': 0, 'www.': 2, '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': '6916471', 'n_tokens_mistral': 832, 'n_tokens_neox': 716, 'n_words': 225}