<commit_before>/* global bowlineApp, moment, io */
bowlineApp.directive('dockersyntax', function(){

	return {
		restrict: 'E',
		scope: {
			dockerfile: '=dockerfile', // an array of lines of a dockerfile.
		},
		templateUrl: 'views/dockersyntax.html',
		controller: ['$scope','$http','$attrs','$location','ENV', 'loginModule', function ($scope,$http,$attrs,$location,ENV,login) {

			var dockercmds = [
				'FROM',
				'MAINTAINER',
				'RUN',
				'CMD',
				'EXPOSE',
				'ENV',
				'ADD',
				'COPY',
				'ENTRYPOINT',
				'VOLUME',
				'USER',
				'WORKDIR',
				'ONBUILD',
			];

			$scope.init = function() {

				console.log("!trace dockersyntax.... init");

				$scope.syntax = [];

				// Ok, cycle the lines of the dockerfile, and make add chunked stylized portions per line.
				for (var i = 0; i < $scope.dockerfile.length; i++) {
					var line = $scope.dockerfile[i];

					$scope.syntax.push($scope.syntaxHighlight(line));

				}

				// console.log("!trace syntax pack ",$scope.syntax);

			};

			$scope.syntaxHighlight = function(dockerline) {

				if (/^[\s]*#/.test(dockerline)) {
					// Is it a bowline specific tag?
					if (/^#bowline/.test(dockerline)) {
						return [{ text: dockerline, style: "coded-bowlinedefine" }];
					} else {
						// That's a remark
						return [{ text: dockerline, style: "coded-comment" }];
					}

				} else {

					var collection = [];

					for (var i = 0; i < dockercmds.length; i++) {
						if (dockerline.indexOf(dockercmds[i]) > -1) {
							// ok it matches that command,
							// we need to put that part
							var dockerline_eachtext = dockerline.replace(new RegExp(dockercmds[i], 'g'),'');
							collection.push({ text: dockercmds[i], style: "coded-highlight"});
							collection.push({ text: dockerline_eachtext, style: "coded"});
						}
					}

					if (dockerline.indexOf('AUTOBUILD_UNIXTIME') > -1) {
						var useline = dockerline;
						if (collection.length > 0) {
							var end = collection.pop();
							useline = end.text;
						}

						var eachtext = useline.replace(new RegExp('AUTOBUILD_UNIXTIME', 'g'),'');

						collection.push({ text: ' AUTOBUILD_UNIXTIME' + " ", style: "coded-autobuild"});
						collection.push({ text: eachtext, style: "coded"});
						
					}

					return collection;
				}

			};

			$scope.init();

		}]
	};

});<commit_msg>[bugfix] dockerfile syntax shows lines that aren't preceeded by a docker command, e.g. for multi-line commands hacks in line breaks at 80 chars for dockerfile<commit_after>/* global bowlineApp, moment, io */
bowlineApp.directive('dockersyntax', function(){

	return {
		restrict: 'E',
		scope: {
			dockerfile: '=dockerfile', // an array of lines of a dockerfile.
		},
		templateUrl: 'views/dockersyntax.html',
		controller: ['$scope','$http','$attrs','$location','ENV', 'loginModule', function ($scope,$http,$attrs,$location,ENV,login) {

			var dockercmds = [
				'FROM',
				'MAINTAINER',
				'RUN',
				'CMD',
				'LABEL',
				'EXPOSE',
				'ENV',
				'ADD',
				'COPY',
				'ENTRYPOINT',
				'VOLUME',
				'USER',
				'WORKDIR',
				'ARG',
				'ONBUILD',
				'STOPSIGNAL',
				'HEALTHCHECK',
				'SHELL',
			];


			function stringDivider(str, width, spaceReplacer) {
		    if (str.length>width) {
	        var p=width;
	        for (;p>0 && str[p]!=' ';p--) {
	        }
	        if (p>0) {
	            var left = str.substring(0, p);
	            var right = str.substring(p+1);
	            return left + spaceReplacer + stringDivider(right, width, spaceReplacer);
	        }
		    }
		    return str;
			}

			$scope.init = function() {

				// console.log("!trace dockersyntax.... init");

				$scope.syntax = [];

				// Ok, cycle the lines of the dockerfile, and make add chunked stylized portions per line.
				for (var i = 0; i < $scope.dockerfile.length; i++) {
					var line = $scope.dockerfile[i];

					$scope.syntax.push($scope.syntaxHighlight(line));

				}

				// console.log("!trace syntax pack ",$scope.syntax);

			};

			$scope.syntaxHighlight = function(dockerline) {

				if (/^[\s]*#/.test(dockerline)) {
					// Is it a bowline specific tag?
					if (/^#bowline/.test(dockerline)) {
						return [{ text: dockerline, style: "coded-bowlinedefine" }];
					} else {
						// That's a remark
						return [{ text: dockerline, style: "coded-comment" }];
					}

				} else {

					var collection = [];
					var is_raw = true;

					for (var i = 0; i < dockercmds.length; i++) {
						if (dockerline.indexOf(dockercmds[i]) > -1) {
							// ok it matches that command,
							// we need to put that part
							var dockerline_eachtext = dockerline.replace(new RegExp(dockercmds[i], 'g'),'');
							collection.push({ text: dockercmds[i], style: "coded-highlight"});
							collection.push({ text: stringDivider(dockerline_eachtext,80,"\n"), style: "coded"});
							is_raw = false;
						}
					}

					if (dockerline.indexOf('AUTOBUILD_UNIXTIME') > -1) {
						var useline = dockerline;
						if (collection.length > 0) {
							var end = collection.pop();
							useline = end.text;
						}

						var eachtext = useline.replace(new RegExp('AUTOBUILD_UNIXTIME', 'g'),'');

						collection.push({ text: ' AUTOBUILD_UNIXTIME' + " ", style: "coded-autobuild"});
						collection.push({ text: eachtext, style: "coded"});
						is_raw = false;
					}

					if (is_raw) {
						collection.push({ text: stringDivider(dockerline,80,"\n"), style: "coded"});
					}

					return collection;
				}

			};

			$scope.init();

		}]
	};

});
{'fraction_non_alphanumeric': 0.17015468607825296, 'fraction_numerical': 0.003639672429481347, 'mean_word_length': 2.5851272015655575, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 12, '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': '4225046', 'n_tokens_mistral': 2499, 'n_tokens_neox': 1817, 'n_words': 422}