Beispiel #1
0
        private static void _compile(ImulessModel imulessModel, IEnumerable <string> domainList, string outputDirectory, string workingDirectory)
        {
            Debugger("Begin compile method...");

            var context = HttpContext.Current;

            if (context == null || imulessModel == null || !domainList.Any())
            {
                return;
            }

            //go thru each hostname for this tree
            foreach (var domain in domainList)
            {
                Debugger("Handling: " + domain);

                //figure selected theme path
                var themeFilePath = context.Server.MapPath(workingDirectory + "/" + imulessModel.Theme + "/" + rootLessFile);

                //write an override file
                var overrideFilePath = context.Server.MapPath(workingDirectory + "/" + varsDirectory + "/" + domain + ".less");

                File.WriteAllText(overrideFilePath, GetOverrideVariables(imulessModel), Encoding.UTF8);

                //get selected theme application.less file

                if (File.Exists(themeFilePath))
                {
                    //add import to the selected theme
                    var fileLines = File.ReadAllLines(themeFilePath);

                    if (fileLines.Last().Contains(varsDirectory))
                    {
                        var cleanedFile = fileLines.ToList().GetRange(0, fileLines.Length - 2);
                        cleanedFile.Add("");
                        cleanedFile.Add(string.Format("@import '../{0}/{1}.less';", varsDirectory, domain));

                        File.WriteAllLines(themeFilePath, cleanedFile);
                    }
                    else
                    {
                        File.AppendAllText(themeFilePath, string.Format("@import '../{0}/{1}.less';", varsDirectory, domain));
                    }

                    //run compile
                    var outputFilePath = context.Server.MapPath(outputDirectory + "/" + domain + ".css");

                    RunCommand(themeFilePath, outputFilePath);
                }
                else
                {
                    Debugger("Could not find theme: " + themeFilePath);
                    return;
                }
            }
        }
Beispiel #2
0
        void CompileCss(global::Umbraco.Core.Events.PublishEventArgs <IContent> e)
        {
            LogHelper.Info <ImulessEvents>("Begin Imuless Publish Event...");

            foreach (var content in e.PublishedEntities)
            {
                if (content.ContentType.Alias == ConfigurationManager.AppSettings["imuless:doctypeAlias"])
                {
                    LogHelper.Info <ImulessEvents>("Begin compile: " + content.Id);
                    var model = ImulessModel.Deserialize(content, ConfigurationManager.AppSettings["imuless:propertyAlias"]);

                    LogHelper.Info <ImulessEvents>(model.Theme);

                    ImulessCore.Compile(model, content.GetDomains());
                }
            }
        }
Beispiel #3
0
        private static string GetOverrideVariables(ImulessModel model)
        {
            if (model == null)
            {
                return("");
            }

            if (!model.Vars.Any())
            {
                return("");
            }

            var sb = new StringBuilder();

            foreach (var _var in model.Vars)
            {
                if (_var != null && !string.IsNullOrWhiteSpace(_var.Alias) && !string.IsNullOrWhiteSpace(_var.Value))
                {
                    sb.AppendFormat(@"@{0}: {1};" + Environment.NewLine, _var.Alias, _var.Value);
                }
            }

            return(sb.ToString());
        }
Beispiel #4
0
 public static void Compile(ImulessModel imulessModel, IEnumerable <string> domainList, string outputDirectory, string workingDirectory)
 {
     _compile(imulessModel, domainList, outputDirectory, workingDirectory);
 }