Exemple #1
0
        /// <summary>
        ///     Compile a model for JavaScript.
        /// </summary>
        protected static void CompileJavaScript(ConversionKernel kernel,
                                                JavaScriptVersion version,
                                                Func <ClassDescriptor, bool> predicate = null,
                                                string fileName = "ecmascript",
                                                bool minify     = false,
                                                Wrap wrap       = Wrap.None)
        {
            var converter = kernel.CreateConverterForJavaScript(version, wrap);
            var converted = converter.Convert(predicate);

            fileName += $".{version.ToString().ToLowerInvariant()}";

            if (wrap != Wrap.None)
            {
                fileName += "." + wrap;
            }

            if (minify)
            {
                fileName += ".min";
            }

            converter.WriteToFile(converted, FilePath, fileName, minify);
        }
Exemple #2
0
        /// <summary>
        ///     Initialize a <see cref="ModelConverter"/> to work with ECMAScript with a specific <paramref name="version"/>.
        /// </summary>
        /// <param name="this">The <see cref="ConversionKernel"/> to use.</param>
        /// <param name="version">The ECMAScript <paramref name="version"/>.</param>
        /// <param name="wrap">If a specific <see cref="Wrap"/> should be used for the generated script model(s).</param>
        /// <returns></returns>
        public static ModelConverter CreateConverterForJavaScript(this ConversionKernel @this, JavaScriptVersion version, Wrap wrap = Wrap.None)
        {
            ILanguageSpecification language;

            switch (version)
            {
            case JavaScriptVersion.V6:
                language = new JavaScriptSpecification("JavaScript", new Version(6, 0)).UseTemplate(Resources.V6);
                break;

            case JavaScriptVersion.V5:
                language = new JavaScriptSpecification("JavaScript", new Version(5, 0)).UseTemplate(Resources.V5);
                break;

            default:
                throw Errors.LanguageNotFound();
            }

            switch (wrap)
            {
            case Wrap.AMD:
                language = language.UseWrapTemplate(Resources.dependency_injection, WrapTemplateUsage.Global);
                break;

            case Wrap.SIAF:
                language = language.UseWrapTemplate(Resources.isolated_self_invokation, WrapTemplateUsage.Global);
                break;

            case Wrap.None:
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(wrap), wrap, null);
            }

            var converter = @this.CreateConverterForTemplate(language);

            return(converter);
        }