<commit_before>/*
 * Copyright 2015 Concept
 *
 * 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.
 */
/*****************************************************************************/
/* Client App Namespace  */
/*****************************************************************************/

_.extend(App, {
});

/**
 * UI helper methods
 */

App.helpers = {

  /**
   * Returns a substring of length n.
   *
   * @str: string to cut
   * @n: where to cut
   * @m: optional left cut
   */
	'$cutText': function (str, n, m) {

    // swap n and m if m is present
    if(arguments.length > 3) {
      var tmp = n;

      n = m;
      m = tmp;
    }

		if(str) {
      // only cut and append '...' if the length of the string is
      // greater than the given cut-length.
			if(str.length > n) {
				str = str.substring(m, n);
				str = str + '...';
			}
			return str;
		}
		return '';
	},

  '$convertLineBreaks': function(text) {
    if (text != null) {
      text = text.replace(/^[\r\n]+|[\r\n]+$/g,'').replace(/(?:\r\n|\r|\n)/g, '<br />');
      return text.trim();
    }
    return null;
  },

  /**
   * Returns true if the current visiting route is equal to the
   * route given.
   *
   * @route: route to compare against
   */
	'$currentRouteIs': function(route) {
		var currentRoute = Router.current();
		if (!currentRoute) return '';

		return route === currentRoute.route.getName() ? true : false;
	},

  /**
   * Returns a 'active' or the second param if the current visiting
   * route is equal to the route specified as the first parameter.
   *
   * @route: route to compare against
   */
	'$activeIfRouteIs': function(route, rValue) {
    var returnValue = 'active';

    if(arguments.length > 2) {
      returnValue = rValue;
    }

		var curRoute = Router.current();
    	if (!curRoute) return '';

		return curRoute && route === curRoute.route.getName() ? returnValue : '';
  },

  /**
   * Returns an id on the form: name + _id. Used with nested documents.
   *
   * @name: name of field
   * @_id: element id
   */
  '$generateId': function (name, _id, options) {
    return _.extend(options.hash, { id: name + '-' + _id});
	},

  /**
   * Returns true if a radio button is checked.
   *
   * @num: current value in the scope.
   * @val: this radio button value
   */
	'$checked': function (num, val) {
		if (num === undefined && parseInt(val) == 1)
			return true;
		return (parseInt(val)) == num ? true : false;
	},
<commit_msg>Fixes an error if the user is on the not found page.<commit_after>/*
 * Copyright 2015 Concept
 *
 * 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.
 */
/*****************************************************************************/
/* Client App Namespace  */
/*****************************************************************************/

_.extend(App, {
});

/**
 * UI helper methods
 */

App.helpers = {

  /**
   * Returns a substring of length n.
   *
   * @str: string to cut
   * @n: where to cut
   * @m: optional left cut
   */
	'$cutText': function (str, n, m) {

    // swap n and m if m is present
    if(arguments.length > 3) {
      var tmp = n;

      n = m;
      m = tmp;
    }

		if(str) {
      // only cut and append '...' if the length of the string is
      // greater than the given cut-length.
			if(str.length > n) {
				str = str.substring(m, n);
				str = str + '...';
			}
			return str;
		}
		return '';
	},

  '$convertLineBreaks': function(text) {
    if (text != null) {
      text = text.replace(/^[\r\n]+|[\r\n]+$/g,'').replace(/(?:\r\n|\r|\n)/g, '<br />');
      return text.trim();
    }
    return null;
  },

  /**
   * Returns true if the current visiting route is equal to the
   * route given.
   *
   * @route: route to compare against
   */
	'$currentRouteIs': function(route) {
		var currentRoute = Router.current();
		if (!currentRoute) return '';

		return route === currentRoute.route.getName() ? true : false;
	},

  /**
   * Returns a 'active' or the second param if the current visiting
   * route is equal to the route specified as the first parameter.
   *
   * @route: route to compare against
   */
	'$activeIfRouteIs': function(route, rValue) {
    var returnValue = 'active';

    if(arguments.length > 2) {
      returnValue = rValue;
    }

		var curRoute = Router.current();
    	if (!curRoute || !curRoute.route) return '';

		return curRoute && ((route === curRoute.route.getName()) ? returnValue : '');
  },

  /**
   * Returns an id on the form: name + _id. Used with nested documents.
   *
   * @name: name of field
   * @_id: element id
   */
  '$generateId': function (name, _id, options) {
    return _.extend(options.hash, { id: name + '-' + _id});
	},

  /**
   * Returns true if a radio button is checked.
   *
   * @num: current value in the scope.
   * @val: this radio button value
   */
	'$checked': function (num, val) {
		if (num === undefined && parseInt(val) == 1)
			return true;
		return (parseInt(val)) == num ? true : false;
	},

{'fraction_non_alphanumeric': 0.1886317907444668, 'fraction_numerical': 0.003688799463447351, 'mean_word_length': 2.751572327044025, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, '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': '3772262', 'n_tokens_mistral': 1879, 'n_tokens_neox': 1776, 'n_words': 636}