コード例 #1
0
    List<EngineResult> IEngine.Process(string contents, string filename)
    {
      var result = new EngineResult { FileName = filename, Extension = "min.js" };
      var properties = new Dictionary<string, object>();
      properties["js"] = contents;

      const string script = @"
var uglify = require('https://raw.github.com/mishoo/UglifyJS/master/uglify-js.js');
var js = external.Get('js');
var result = uglify(js);
external.Set('result', result);
";

			try 
      {
        var javascriptResult = JavascriptRunner.Execute(script, properties);
        result.Contents = javascriptResult.Get("result") as string;
        result.Exceptions.AddRange(javascriptResult.Messages);

      } catch (ChirpyException cex) {
        result.Exceptions.Add(cex);
      }

      return new List<EngineResult> { result };
    }
コード例 #2
0
		public List<EngineResult> Process(string contents, string filename)
		{
			var result = new EngineResult {FileName = filename};
			var properties = new Dictionary<string, object>();

			properties["css"] = contents;

			const string script = @"
var exports = require('http://csslint.net/js/csslint.js', null, 'exports.CSSLint = CSSLint;');
var CSSLint = exports.CSSLint;

var css = external.Get('css');

var result = CSSLint.verify(css);

for(var i = 0; i < result.messages.length; i++)
{
	var message = result.messages[i];
	var messageText = message.message + ': ' + message.evidence;

	external.LogMessage(messageText, message.line, message.col);
}
";

			var javascriptResult = JavascriptRunner.Execute(script, properties);

			result.Exceptions.AddRange(javascriptResult.Messages);

			return new List<EngineResult> {result};
		}
コード例 #3
0
		public List<EngineResult> Process(string contents, string filename)
		{
			var result = new EngineResult {FileName = filename};
			var properties = new Dictionary<string, object>();

			properties["js"] = contents;

			const string script = @"
var exports = require('https://raw.github.com/jshint/jshint/master/jshint.js', null, '');
var JSHINT = exports.JSHINT;

var js = external.Get('js');
var result = JSHINT(js);
var errors = JSHINT.errors;
 
external.Set('result', result);
external.Set('errors', errors.length);
if (!result) 
{
	for (var i = 0; i < errors.length; i++) 
	{
		external.LogWarning((errors[i].reason || '') + ': ' + (errors[i].evidence || ''), errors[i].line || 0, errors[i].character || 0);
	}
}
";

			var javascriptResult = JavascriptRunner.Execute(script, properties);

			result.Exceptions.AddRange(javascriptResult.Messages);

			return new List<EngineResult> {result};
		}
コード例 #4
0
        List <EngineResult> IEngine.Process(string contents, string filename)
        {
            var engineResult = new EngineResult();
            var result       = new List <EngineResult> {
                engineResult
            };

            try
            {
                string outputExtension;

                var output = Process(contents, filename, out outputExtension);

                engineResult.Contents  = output;
                engineResult.Extension = outputExtension;
            }
            catch (ChirpyException cex)
            {
                engineResult.Exceptions.Add(cex);
            }

            return(result);
        }
コード例 #5
0
ファイル: Chirp.cs プロジェクト: jamesfoster/ChirpyMEF
		string GetOutputFileName(EngineResult result, string filename, EngineContainer engine)
		{
			var baseFileName = filename;

			if (!string.IsNullOrEmpty(result.FileName))
				baseFileName = result.FileName;

			var inputExtension = ExtensionResolver.GetExtensionFromCategory(engine.Category);

			if (baseFileName.EndsWith(inputExtension))
				baseFileName = filename.Substring(0, filename.Length - inputExtension.Length);
			else
				baseFileName = FileHandler.GetBaseFileName(baseFileName);

			return string.Format("{0}.{1}", baseFileName, result.Extension);
		}