Ejemplo n.º 1
0
        /// <summary>
        /// Processes a single item.
        /// </summary>
        /// <param name="input">The input to process.</param>
        /// <returns>The output of the process.</returns>
        public override IAssetFile Process(IAssetFile input)
        {
            try
            {
                // Get the content
                var content = input.Content.AsString();

                // Attempt to extract headers, if none simply return the input
                int endOffset;
                var header = AssetHeader.FromString(content, out endOffset);
                if (header == null)
                {
                    return(input);
                }

                //dynamic head = header;
                //Console.WriteLine("layout: " + (string)head.layout);
                //Console.WriteLine("title: " + (string)head.title);

                // Return processed output
                return(AssetOutputFile.Create(
                           from: input,
                           content: content.Remove(0, endOffset).TrimStart(),
                           meta: header
                           ));
            }
            catch (Exception ex)
            {
                // We didn't manage to create anything
                Tracing.Error("Header", ex);
                return(null);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Processes a single item.
        /// </summary>
        /// <param name="input">The input to process.</param>
        /// <returns>The output of the process.</returns>
        public override IAssetFile Process(IAssetFile input)
        {
            try
            {
                // Do we have some metadata?
                if (input.Meta == null)
                {
                    return(input);
                }

                // Get the headers
                var headers = (dynamic)input.Meta;
                var layout  = (string)headers.layout;
                if (String.IsNullOrWhiteSpace(layout))
                {
                    return(input);
                }


                // Minified successfully
                Tracing.Info("Layout", "Render " + input.RelativeName);

                // Return processed output
                return(AssetOutputFile.Create(input,
                                              input.Project.ViewEngine.RenderPage(input, layout).AsBytes()
                                              ));
            }
            catch (Exception ex)
            {
                // We didn't manage to create anything
                Tracing.Error("Layout", ex);
                return(null);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Processes a single item.
        /// </summary>
        /// <param name="input">The input to process.</param>
        /// <returns>The output of the process.</returns>
        public override IAssetFile Process(IAssetFile input)
        {
            try
            {
                // Minify css
                var quantizer = new WuQuantizer();
                using (var bitmap = new Bitmap(Bitmap.FromStream(input.Content.AsStream())))
                {
                    using (var quantized = quantizer.QuantizeImage(bitmap, 10, 70))
                        using (var output = new MemoryStream())
                        {
                            // Save to the output stream
                            quantized.Save(output, ImageFormat.Png);

                            // Minified successfully
                            Tracing.Info("PNG", "Optimized " + input.RelativeName);

                            // Return processed output
                            return(AssetOutputFile.Create(input, output));
                        }
                }
            }
            catch (Exception ex)
            {
                // We didn't manage to create anything
                Tracing.Error("PNG", ex);
                return(null);
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Processes a single item.
 /// </summary>
 /// <param name="input">The input to process.</param>
 /// <returns>The output of the process.</returns>
 public override IAssetFile Process(IAssetFile input)
 {
     try
     {
         // Simply copy the file
         return(AssetOutputFile.Create(input, input.Content.AsBytes()));
     }
     catch (Exception ex)
     {
         // We didn't manage to create anything
         Tracing.Error("File", ex);
         return(null);
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Processes a single item.
        /// </summary>
        /// <param name="input">The input to process.</param>
        /// <returns>The output of the process.</returns>
        public override IAssetFile Process(IAssetFile input)
        {
            try
            {
                // Select the files we should compile
                var compile = input.Project.Configuration.Less;
                if (compile == null || compile.Count == 0 || !compile.Any(c => input.RelativeName.EndsWith(c)))
                {
                    // Return processed output
                    return(AssetOutputFile.Create(
                               from: input,
                               content: String.Empty,
                               extension: "css"
                               ));
                }

                // Get the content
                var content = input.Content.AsString();

                // Get the LESS engine
                var engine   = new LessEngine();
                var importer = (Importer)engine.Parser.Importer;
                var freader  = (FileReader)importer.FileReader;
                freader.PathResolver = new LessPathResolver(input.FullName);

                // Transform to CSS
                var output = engine.TransformToCss(content, input.FullName);

                // Return processed output
                return(AssetOutputFile.Create(
                           from: input,
                           content: output,
                           extension: "css"
                           ));
            }
            catch (Exception ex)
            {
                // We didn't manage to create anything
                Tracing.Error("Less", ex);
                return(null);
            }
        }
        /// <summary>
        /// Processes a single item.
        /// </summary>
        /// <param name="input">The input to process.</param>
        /// <returns>The output of the process.</returns>
        public override IAssetFile Process(IAssetFile input)
        {
            try
            {
                // !!!!!!!!
                // NOT USED
                // !!!!!!!!

                // Only processes .ts files
                if (input.Extension != ".ts")
                {
                    return(input);
                }

                // Measure
                var watch = new Stopwatch();
                watch.Start();

                // compiles a TS file
                var output = TypeScriptCompiler.Compile(input.Content.AsString());

                // We've compiled
                watch.Stop();

                // Compiled successfully
                Tracing.Info("TypeScript", "Compiled " + input.RelativeName + ", " + watch.ElapsedMilliseconds + " ms.");

                // Return processed output
                return(AssetOutputFile.Create(
                           from: input,
                           content: output,
                           extension: "js"
                           ));
            }
            catch (Exception ex)
            {
                // We didn't manage to create anything
                Tracing.Error("TypeScript", ex);
                return(null);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Processes a single item.
        /// </summary>
        /// <param name="input">The input to process.</param>
        /// <returns>The output of the process.</returns>
        public override IAssetFile Process(IAssetFile input)
        {
            try
            {
                // Minify javascript
                var minifier = new Minifier();
                var content  = minifier.MinifyJavaScript(input.Content.AsString());

                // Compiled successfully
                Tracing.Info("JS", "Minified " + input.RelativeName);

                // Return processed output
                return(AssetOutputFile.Create(input, content));
            }
            catch (Exception ex)
            {
                // We didn't manage to create anything
                Tracing.Error("JS", ex);
                return(null);
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Processes a single item.
        /// </summary>
        /// <param name="input">The input to process.</param>
        /// <returns>The output of the process.</returns>
        public override IAssetFile Process(IAssetFile input)
        {
            try
            {
                // Get the original content
                var content = input.Content.AsString();

                // Get all translation matches
                var matches = Pattern.Matches(content);
                foreach (var match in matches)
                {
                    // Get the key for the entry
                    var key = match.ToString().Substring(1);

                    // Get the text for the translation
                    var text = input.Project.Translations.Get(key);
                    if (text != null)
                    {
                        // If we have found a translation, replace it in the content
                        content = content.Replace(match.ToString(), text);
                    }
                }

                // Return the output
                return(AssetOutputFile.Create(
                           from: input,
                           content: content
                           ));
            }
            catch (Exception ex)
            {
                // We didn't manage to create anything
                Tracing.Error("Locale", ex);
                return(null);
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Processes a single item.
        /// </summary>
        /// <param name="input">The input to process.</param>
        /// <returns>The output of the process.</returns>
        public override IAssetFile Process(IAssetFile input)
        {
            try
            {
                var engine  = new Markdown();
                var content = engine.Transform(input.Content.AsString());

                // Compiled successfully
                Tracing.Info("Markdown", "Compiled " + input.RelativeName);

                // Return the output
                return(AssetOutputFile.Create(
                           from: input,
                           content: content,
                           extension: "html"
                           ));
            }
            catch (Exception ex)
            {
                // We didn't manage to create anything
                Tracing.Error("Markdown", ex);
                return(null);
            }
        }