<commit_before>###
# grunt-dust
# https://github.com/vtsvang/grunt-dust
#
# Copyright (c) 2013 <NAME>
# Licensed under the MIT license.
###

module.exports = ( grunt ) ->
	# Link to Underscore.js
	_ = grunt.util._

	dust = require "dustjs-linkedin"
	path = require "path"
	fs = require "fs"

	# ==========================================================================
	# HELPERS
	# ==========================================================================
	amdHelper = require( "../helpers/amd" ).init grunt
	commonjsHelper = require( "../helpers/commonjs" ).init grunt
	runtime = require( "../helpers/dustjs-runtime" ).init grunt

	# ==========================================================================
	# TASKS
	# ==========================================================================

	# Task to compile dustjs templates
	# ---
	grunt.registerMultiTask "dust", "Task to compile dustjs templates.", ->
		options = @options
			runtime: yes
			relative: no
			wrapper: "amd"
			wrapperOptions:
				packageName: null
				returning: "dust"
				deps: {}

		grunt.verbose.writeflags options, "Options"

		if options.amd
			grunt.log.error """Notice: option "amd" is deprecated and will be removed in next version.""".yellow
			if typeof options.amd is "object"
				options.wrapper = "amd"
				options.wrapperOptions = options.amd
				for key in options.amd.deps ? []
					options.wrapperOptions.deps[ key ] = key

		( options.wrapperOptions ?= {} ).deps ?= {}

		# add runtime if its specified
		if options.runtime and not options.wrapperOptions.deps is no
			if ( key for own key, dep of options.wrapperOptions.deps when key is "dust" ).length is 0
				options.wrapperOptions.deps.dust = runtime.amdName

		for file in @files

			output = []

			# array of compiled templates names
			tplNames = []

			for source in file.src
				# relative path to
				tplRelativePath = if file.orig.cwd? and options.relative then path.relative file.orig.cwd, source else source

				# remove extension from template name
				tplName = tplRelativePath.replace new RegExp( "\\#{ path.extname tplRelativePath }$" ), ""

				try
					output.push "// #{ tplRelativePath }\n" + dust.compile grunt.file.read( source ), tplName
					tplNames.push tplName
				catch e
					# Handle error and log it with Grunt.js API
					grunt.log.error().writeln e.toString()
					grunt.warn "DustJS found errors.", 10

			if output.length > 0
				joined = output.join( "\n ")

				if options.wrapper is "amd"
					# what should return AMD wrapper
					switch tplNames.length
						when 0
							returning = undefined
						when 1
							returning = _.last tplNames
						else
							returning = tplNames						<commit_msg>Added ability to define basePath in options<commit_after>###
# grunt-dust
# https://github.com/vtsvang/grunt-dust
#
# Copyright (c) 2013 <NAME>
# Licensed under the MIT license.
###

module.exports = ( grunt ) ->
	# Link to Underscore.js
	_ = grunt.util._

	dust = require "dustjs-linkedin"
	path = require "path"
	fs = require "fs"

	# ==========================================================================
	# HELPERS
	# ==========================================================================
	amdHelper = require( "../helpers/amd" ).init grunt
	commonjsHelper = require( "../helpers/commonjs" ).init grunt
	runtime = require( "../helpers/dustjs-runtime" ).init grunt

	# ==========================================================================
	# TASKS
	# ==========================================================================

	# Task to compile dustjs templates
	# ---
	grunt.registerMultiTask "dust", "Task to compile dustjs templates.", ->
		options = @options
			runtime: yes
			relative: no
			wrapper: "amd"
			wrapperOptions:
				packageName: null
				returning: "dust"
				deps: {}

		grunt.verbose.writeflags options, "Options"

		if options.amd
			grunt.log.error """Notice: option "amd" is deprecated and will be removed in next version.""".yellow
			if typeof options.amd is "object"
				options.wrapper = "amd"
				options.wrapperOptions = options.amd
				for key in options.amd.deps ? []
					options.wrapperOptions.deps[ key ] = key

		( options.wrapperOptions ?= {} ).deps ?= {}

		# add runtime if its specified
		if options.runtime and not options.wrapperOptions.deps is no
			if ( key for own key, dep of options.wrapperOptions.deps when key is "dust" ).length is 0
				options.wrapperOptions.deps.dust = runtime.amdName

		for file in @files

			output = []

			# array of compiled templates names
			tplNames = []

			for source in file.src
				# relative path to
				tplRelativePath = if file.orig.cwd? and options.relative then path.relative file.orig.cwd, source else
													if options.basePath? then path.relative options.basePath, source else source

				# remove extension from template name
				tplName = tplRelativePath.replace new RegExp( "\\#{ path.extname tplRelativePath }$" ), ""

				try
					output.push "// #{ tplRelativePath }\n" + dust.compile grunt.file.read( source ), tplName
					tplNames.push tplName
				catch e
					# Handle error and log it with Grunt.js API
					grunt.log.error().writeln e.toString()
					grunt.warn "DustJS found errors.", 10

			if output.length > 0
				joined = output.join( "\n ")

				if options.wrapper is "amd"
					# what should return AMD wrapper
					switch tplNames.length
						when 0
							returning = undefined
						when 1
							returning = _.last tplNames
						else
							returning = tplNames
{'fraction_non_alphanumeric': 0.2066266156926998, 'fraction_numerical': 0.0036409976333515383, 'mean_word_length': 3.2921875, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 2, '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': '315935', 'n_tokens_mistral': 1941, 'n_tokens_neox': 1537, 'n_words': 475}