'use strict';

/*
 * A set of functions that manipulate and read files and filepaths
 */

module.exports = {
  read: read,
  find_closest_match: find_closest_match,
  is_markdown: is_markdown,
  is_dot: is_dot,
  has_extension: has_extension
};

var grunt = require('grunt');

function read (filename, folder) {
  console.log("Reading " + filename + " from " + folder);
  if (folder) filename = find_closest_match(folder, filename);
  return grunt.file.read(filename);
}

function find_closest_match (folder, filename) {
  if (!grunt.file.isDir(folder)) grunt.warn.log("The folder " + folder + " does not exist.");

  var pattern = build_pattern(folder, filename);
  var file = grunt.file.expand(pattern);

  // Warn again if the resulting file doesn't exist
  if (!file.length) grunt.warn.log("The file " + pattern + " cannot be found.");

  return file[0];
};

function build_pattern (folder, filename) {
  var separator = '';
  if (folder) {
    separator = folder.length ? '/' : '';
  }
  var extension = has_extension(filename) ? '' : '.*';
  return folder + separator + filename + extension;
}

function is_markdown (file) {
  return /\.md$|\.md\..*$/.test(file);
};

function is_dot (file) {
  return /\.dot.html$/.test(file.toString());
};

function has_extension (file) {
  return file.toString().match(/\.[0-9a-z]+$/i);
};
@@ -309,66 +309,8 @@
 ) %7B%0A
-  console.log(%22Reading %22 + filename + %22 from %22 + folder);%0A
   if
@@ -368,16 +368,16 @@
 ename);%0A
+
   return
@@ -716,32 +716,33 @@
 ngth) grunt.
+fail.
 warn
-.log
 (%22The file %22
@@ -1154,13 +1154,19 @@
 .dot
-.html
+$%7C%5C.dot%5C..*
 $/.t

Correct use of grunt warn. More comprehensive test for dot extension