From 7508613d1361474aaf5bb9536d140ff27c2fd866 Mon Sep 17 00:00:00 2001 From: antoine Date: Thu, 22 May 2014 22:20:13 +0200 Subject: [PATCH] First approach --- src/Umbraco.Web.UI/Umbraco/js/tuning.front.js | 2 +- src/Umbraco.Web.UI/Umbraco/js/tuning.panel.js | 214 ++++++++++++++---- .../Views/Partials/Grid/bootstrap3.cshtml | 68 +++--- src/Umbraco.Web/Editors/TuningController.cs | 178 +++++++++++++-- src/Umbraco.Web/UmbracoHelper.cs | 29 ++- 5 files changed, 390 insertions(+), 101 deletions(-) diff --git a/src/Umbraco.Web.UI/Umbraco/js/tuning.front.js b/src/Umbraco.Web.UI/Umbraco/js/tuning.front.js index d5328b0627..4352f80f21 100644 --- a/src/Umbraco.Web.UI/Umbraco/js/tuning.front.js +++ b/src/Umbraco.Web.UI/Umbraco/js/tuning.front.js @@ -121,7 +121,7 @@ var initTuningPanel = function () { // Init panel if (parent.setFrameIsLoaded) { - parent.setFrameIsLoaded(tuningParameterUrl); + parent.setFrameIsLoaded(tuningParameterUrl, tuningGridStyleUrl); } } diff --git a/src/Umbraco.Web.UI/Umbraco/js/tuning.panel.js b/src/Umbraco.Web.UI/Umbraco/js/tuning.panel.js index 618a3b3a81..80c40d0e22 100644 --- a/src/Umbraco.Web.UI/Umbraco/js/tuning.panel.js +++ b/src/Umbraco.Web.UI/Umbraco/js/tuning.panel.js @@ -40,10 +40,11 @@ var refrechIntelTuning = function (schema) { } -var setFrameIsLoaded = function (tuningParameterUrl) { - console.info("iframe id loaded " + tuningParameterUrl); +var setFrameIsLoaded = function (tuningParameterUrl, tuningGridStyleUrl) { + console.info("iframe id loaded " + tuningParameterUrl + " " + tuningGridStyleUrl); var scope = angular.element($("#tuningPanel")).scope(); scope.tuningParameterUrl = tuningParameterUrl; + scope.tuningGridStyleUrl = tuningGridStyleUrl; scope.frameLoaded++; scope.frameFirstLoaded = true; scope.$apply(); @@ -63,6 +64,7 @@ angular.module("umbraco.tuning", ['ui.bootstrap', 'spectrumcolorpicker', 'ui.sli $scope.frameLoaded = 0; $scope.frameFirstLoaded = false; $scope.tuningParameterUrl = ""; + $scope.tuningGridStyleUrl = ""; $scope.schemaFocus = "body"; $scope.settingIsOpen = 'previewDevice'; $scope.BackgroundPositions = ['center', 'left', 'right', 'bottom center', 'bottom left', 'bottom right', 'top center', 'top left', 'top right']; @@ -83,12 +85,107 @@ angular.module("umbraco.tuning", ['ui.bootstrap', 'spectrumcolorpicker', 'ui.sli ]; $scope.previewDevice = $scope.devices[0]; + + + + + + + + + + //***************************************************************************** + // Grid row model + //***************************************************************************** + + var rows = ['grid-row-0', 'grid-row-1']; + + var rowModel = { + name: "Grid", + sections: [{ + name: "Main", + subSections: [] + }] + }; + + $.each(rows, function (index, row) { + var newIndex = rowModel.sections[0].subSections.length + 1; + + var rowFieldModel = { + name: "Row", + schema: "", + fields: [ + { + name: "Background color", + alias: "backgroundRowColor", + description: "Background body color", + type: "colorPicker", + value: "", + colorPaletteProperty: "colorBodyBackground" + }, + { + name: "Image/Pattern", + alias: "backgroundRowImageOrPattern", + description: "Use an image for the background instead of a solid colour/gradient", + type: "bgImagePicker", + value: "" + }, + { + name: "Image position", + alias: "backgroundRowPosition", + description: "Background body position", + type: "bgPositionPicker", + value: "" + }, + { + name: "Stretch background", + alias: "backgroundRowCover", + description: "Checked: stretches the chosen image to fill the.\nUnchecked: the image is tiled according to the Repeat setting below", + type: "checkbox", + value: "" + }, + { + name: "Background tiling", + alias: "backgroundRowRepeat", + description: "How to tile the background image", + type: "bgRepeatPicker", + value: "" + }, + { + name: "Background scrolling behaviour", + alias: "backgroundRowAttachment", + description: "When fixed the background doesn't scroll with the content", + type: "bgAttachmentPicker", + value: "" + } + ] + }; + + rowModel.sections[0].subSections.splice(newIndex, 0, rowFieldModel); + rowModel.sections[0].subSections[newIndex - 1].schema = "." + row; + $.each(rowModel.sections[0].subSections[newIndex - 1].fields, function (indexField, field) { + field.alias = field.alias + "__" + row; + }); + + }) + + tuningConfig.categories.splice(tuningConfig.categories.length + 1, 0, rowModel); + + //***************************************************************************** + + + + + + + + + + // Load parameters from GetLessParameters and init data of the tuning config var initTuning = function () { - - console.info("url " + $scope.tuningParameterUrl); - - $http.get('/Umbraco/Api/tuning/Load', { params: { param: $scope.tuningParameterUrl } }) + + $http.get('/Umbraco/Api/tuning/Load', { params: { tuningStyleUrl: $scope.tuningParameterUrl, tuningGridStyleUrl: $scope.tuningGridStyleUrl } }) .success(function (data) { $.each(tuningConfig.categories, function (indexCategory, category) { @@ -96,18 +193,24 @@ angular.module("umbraco.tuning", ['ui.bootstrap', 'spectrumcolorpicker', 'ui.sli $.each(section.subSections, function (indexSubSection, subSection) { $.each(subSection.fields, function (indexField, field) { - // value - field.value = eval("data." + field.alias.replace("@", "")); - if (field.value == "''") { field.value = ""; } + try { - // special init for font family picker - if (field.type == "fontFamilyPicker") { - field.fontWeight = eval("data." + field.alias.replace("@", "") + "_weight"); - field.fontStyle = eval("data." + field.alias.replace("@", "") + "_style"); - field.fontType = eval("data." + field.alias.replace("@", "") + "_type"); - if (field.fontWeight == "''") { field.fontWeight = ""; } - if (field.fontStyle == "''") { field.fontStyle = ""; } - if (field.fontType == "''") { field.fontType = ""; } + // value + field.value = eval("data." + field.alias.replace("@", "")); + if (field.value == "''") { field.value = ""; } + + // special init for font family picker + if (field.type == "fontFamilyPicker") { + field.fontWeight = eval("data." + field.alias.replace("@", "") + "_weight"); + field.fontStyle = eval("data." + field.alias.replace("@", "") + "_style"); + field.fontType = eval("data." + field.alias.replace("@", "") + "_type"); + if (field.fontWeight == "''") { field.fontWeight = ""; } + if (field.fontStyle == "''") { field.fontStyle = ""; } + if (field.fontType == "''") { field.fontType = ""; } + } + } + catch (err) { + console.info("Style parameter not found " + field.alias); } }) @@ -123,33 +226,35 @@ angular.module("umbraco.tuning", ['ui.bootstrap', 'spectrumcolorpicker', 'ui.sli } }); + } // Refresh all less parameters for every changes watching tuningModel var refreshtuning = function () { var parameters = []; - $.each($scope.tuningModel.categories, function (indexCategory, category) { - $.each(category.sections, function (indexSection, section) { - $.each(section.subSections, function (indexSubSection, subSection) { - $.each(subSection.fields, function (indexField, field) { + if ($scope.tuningModel) { + $.each($scope.tuningModel.categories, function (indexCategory, category) { + $.each(category.sections, function (indexSection, section) { + $.each(section.subSections, function (indexSubSection, subSection) { + $.each(subSection.fields, function (indexField, field) { - // value - parameters.splice(parameters.length + 1, 0, "'@" + field.alias + "':'" + field.value + "'"); + // value + parameters.splice(parameters.length + 1, 0, "'@" + field.alias + "':'" + field.value + "'"); - // special init for font family picker - if (field.type == "fontFamilyPicker") { - parameters.splice(parameters.length + 1, 0, "'@" + field.alias + "_weight':'" + field.fontWeight + "'"); - parameters.splice(parameters.length + 1, 0, "'@" + field.alias + "_Style':'" + field.fontStyle + "'"); - } + // special init for font family picker + if (field.type == "fontFamilyPicker") { + parameters.splice(parameters.length + 1, 0, "'@" + field.alias + "_weight':'" + field.fontWeight + "'"); + parameters.splice(parameters.length + 1, 0, "'@" + field.alias + "_Style':'" + field.fontStyle + "'"); + } + }) }) }) - }) - }); - - // Refrech page style - document.getElementById("resultFrame").contentWindow.refrechLayout(parameters); + }); + // Refrech page style + document.getElementById("resultFrame").contentWindow.refrechLayout(parameters); + } } var openIntelTuning = function () { @@ -192,30 +297,39 @@ angular.module("umbraco.tuning", ['ui.bootstrap', 'spectrumcolorpicker', 'ui.sli $scope.saveLessParameters = function () { var parameters = []; + var parametersGrid = []; $.each($scope.tuningModel.categories, function (indexCategory, category) { $.each(category.sections, function (indexSection, section) { $.each(section.subSections, function (indexSubSection, subSection) { $.each(subSection.fields, function (indexField, field) { - // value - var value = (field.value != 0 && (field.value == undefined || field.value == "")) ? "''" : field.value; - parameters.splice(parameters.length + 1, 0, "@" + field.alias + ":" + value + ";"); + if (subSection.schema && subSection.schema.indexOf("grid-row-") >= 0) + { + var value = (field.value != 0 && (field.value == undefined || field.value == "")) ? "''" : field.value; + parametersGrid.splice(parametersGrid.length + 1, 0, "@" + field.alias + ":" + value + ";"); + } + else + { + // value + var value = (field.value != 0 && (field.value == undefined || field.value == "")) ? "''" : field.value; + parameters.splice(parameters.length + 1, 0, "@" + field.alias + ":" + value + ";"); - // special init for font family picker - if (field.type == "fontFamilyPicker") { - if (field.fontType == "google" && value != "''") { - var variant = field.fontWeight != "" || field.fontStyle != "" ? ":" + field.fontWeight + field.fontStyle : ""; - var gimport = "@import url('http://fonts.googleapis.com/css?family=" + value + variant + "');"; - if ($.inArray(gimport, parameters) < 0) { - parameters.splice(0, 0, gimport); + // special init for font family picker + if (field.type == "fontFamilyPicker") { + if (field.fontType == "google" && value != "''") { + var variant = field.fontWeight != "" || field.fontStyle != "" ? ":" + field.fontWeight + field.fontStyle : ""; + var gimport = "@import url('http://fonts.googleapis.com/css?family=" + value + variant + "');"; + if ($.inArray(gimport, parameters) < 0) { + parameters.splice(0, 0, gimport); + } } + var fontWeight = (field.fontWeight != 0 && (field.fontWeight == undefined || field.fontWeight == "")) ? "''" : field.fontWeight; + var fontStyle = (field.fontStyle != 0 && (field.fontStyle == undefined || field.fontStyle == "")) ? "''" : field.fontStyle; + var fontType = (field.fontType != 0 && (field.fontType == undefined || field.fontType == "")) ? "''" : field.fontType; + parameters.splice(parameters.length + 1, 0, "@" + field.alias + "_weight:" + fontWeight + ";"); + parameters.splice(parameters.length + 1, 0, "@" + field.alias + "_style:" + fontStyle + ";"); + parameters.splice(parameters.length + 1, 0, "@" + field.alias + "_type:" + fontType + ";"); } - var fontWeight = (field.fontWeight != 0 && (field.fontWeight == undefined || field.fontWeight == "")) ? "''" : field.fontWeight; - var fontStyle = (field.fontStyle != 0 && (field.fontStyle == undefined || field.fontStyle == "")) ? "''" : field.fontStyle; - var fontType = (field.fontType != 0 && (field.fontType == undefined || field.fontType == "")) ? "''" : field.fontType; - parameters.splice(parameters.length + 1, 0, "@" + field.alias + "_weight:" + fontWeight + ";"); - parameters.splice(parameters.length + 1, 0, "@" + field.alias + "_style:" + fontStyle + ";"); - parameters.splice(parameters.length + 1, 0, "@" + field.alias + "_type:" + fontType + ";"); } }) @@ -223,7 +337,7 @@ angular.module("umbraco.tuning", ['ui.bootstrap', 'spectrumcolorpicker', 'ui.sli }) }); - var resultParameters = { result: parameters.join(""), pageId: $location.search().id }; + var resultParameters = { parameters: parameters.join(""), parametersGrid: parametersGrid.join(""), pageId: $location.search().id }; var transform = function (result) { return $.param(result); } diff --git a/src/Umbraco.Web.UI/Views/Partials/Grid/bootstrap3.cshtml b/src/Umbraco.Web.UI/Views/Partials/Grid/bootstrap3.cshtml index 91aaf305af..96ca7b8284 100644 --- a/src/Umbraco.Web.UI/Views/Partials/Grid/bootstrap3.cshtml +++ b/src/Umbraco.Web.UI/Views/Partials/Grid/bootstrap3.cshtml @@ -12,53 +12,53 @@
@foreach (var row in column.rows) { -
-
-
+
+
+
- @foreach (var cell in row.cells) - { -
-
+ @foreach (var cell in row.cells) + { +
+
- @foreach (var control in cell.controls) + @foreach (var control in cell.controls) + { + if (control != null && control.macro != null) { - if (control != null && control.macro != null) + string macroAlias = control.macro.macroAlias.ToString(); + ViewDataDictionary parameters = new ViewDataDictionary(); + foreach (dynamic mpd in control.macro.marcoParamsDictionary) { - string macroAlias = control.macro.macroAlias.ToString(); - ViewDataDictionary parameters = new ViewDataDictionary(); - foreach (dynamic mpd in control.macro.marcoParamsDictionary) - { - parameters.Add(mpd.Name, mpd.Value); - } - - @Umbraco.RenderMacro(macroAlias, parameters) + parameters.Add(mpd.Name, mpd.Value); } - if (control != null && control.tinyMCE != null) - { + @Umbraco.RenderMacro(macroAlias, parameters) + } + + if (control != null && control.tinyMCE != null) + {
@Html.Raw(TemplateUtilities.ParseInternalLinks(control.tinyMCE.value.ToString()))
- } - - if (control != null && control.media != null) - { - - } - - if (control != null && control.embed != null) - { - @Html.Raw(control.embed.content) - } } -
+ + if (control != null && control.media != null) + { + + } + + if (control != null && control.embed != null) + { + @Html.Raw(control.embed.content) + } + }
- } -
+
+ }
- } +
+}
}
diff --git a/src/Umbraco.Web/Editors/TuningController.cs b/src/Umbraco.Web/Editors/TuningController.cs index 61840fecde..a443e180db 100644 --- a/src/Umbraco.Web/Editors/TuningController.cs +++ b/src/Umbraco.Web/Editors/TuningController.cs @@ -12,6 +12,7 @@ using System; using System.Net.Http.Headers; using System.Web; using System.IO; +using Umbraco.Core.Models; namespace Umbraco.Web.Editors { @@ -23,6 +24,8 @@ namespace Umbraco.Web.Editors static string frontBasePath = HttpContext.Current.Server.MapPath(@"\Css\tuning\"); static string resultCssPath = @"\Css\tuning\{0}.css"; static string resultLessPath = @"\Css\tuning\{0}.less"; + static string resultGridLessPath = @"\Css\tuning\grid_{0}.less"; + static string resultGridCssPath = @"\Css\tuning\grid_{0}.css"; static string tuningStylePath = basePath + @"tuning.defaultStyle.less"; [HttpGet] @@ -54,19 +57,30 @@ namespace Umbraco.Web.Editors public HttpResponseMessage Load() { - var tuningParametersPath = HttpContext.Current.Request["param"]; + // Get style less url + var tuningStyleUrl = HttpContext.Current.Request["tuningStyleUrl"]; + var tuningGridStyleUrl = HttpContext.Current.Request["tuningGridStyleUrl"]; - if (string.IsNullOrEmpty(tuningParametersPath)) - tuningParametersPath = tuningStylePath; + if (string.IsNullOrEmpty(tuningStyleUrl)) + tuningStyleUrl = tuningStylePath; else - tuningParametersPath = HttpContext.Current.Server.MapPath(tuningParametersPath); + tuningStyleUrl = HttpContext.Current.Server.MapPath(tuningStyleUrl); + // Get all parameters string paramBlock = string.Empty; - using (System.IO.StreamReader sr = new System.IO.StreamReader(tuningParametersPath)) + using (System.IO.StreamReader sr = new System.IO.StreamReader(tuningStyleUrl)) { paramBlock = GetStyleBloque("lessParam", sr.ReadToEnd()); } - + if (!string.IsNullOrEmpty(tuningGridStyleUrl)) + { + using (System.IO.StreamReader sr = new System.IO.StreamReader(HttpContext.Current.Server.MapPath(tuningGridStyleUrl))) + { + paramBlock += GetStyleBloque("lessParam", sr.ReadToEnd()); + } + } + + // Prepare string parameter result string[] paramLines = paramBlock.Trim().Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); IList parameters = new List(); foreach (var line in paramLines) @@ -75,6 +89,7 @@ namespace Umbraco.Web.Editors parameters.Add("\"" + line.Replace(":", "\":\"").Replace(";", "\"").Replace("@", "").Replace(";", "")); } + // Response var resp = new HttpResponseMessage() { Content = new StringContent("{" + String.Join(",", parameters) + "}") @@ -87,9 +102,55 @@ namespace Umbraco.Web.Editors public HttpResponseMessage Save() { - var result = HttpContext.Current.Request["result"]; + // Get parameters + var parameters = HttpContext.Current.Request["parameters"]; + var parametersGrid = HttpContext.Current.Request["parametersGrid"]; var pageId = HttpContext.Current.Request["pageId"]; + /*********************************************/ + /* Grid parameters */ + /*********************************************/ + + // Path to the new grid less + string newResultGridLessPath = HttpContext.Current.Server.MapPath(string.Format(resultGridLessPath, pageId)); + string newResultGridCssPath = HttpContext.Current.Server.MapPath(string.Format(resultGridCssPath, pageId)); + + // Load current grid Less + string gridLessContent = string.Empty; + using (System.IO.StreamReader sr = new System.IO.StreamReader(newResultGridLessPath)) + { + gridLessContent = sr.ReadToEnd(); + } + + // Prepare grid parameters + string newGridParamBlock = string.Empty; + foreach (string parameter in parametersGrid.Trim().Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries)) + { + newGridParamBlock += (parameter + ";").Replace(":;", ":'';") + Environment.NewLine; + } + gridLessContent = gridLessContent.Replace(GetStyleBloque("lessParam", gridLessContent), Environment.NewLine + newGridParamBlock); + + // Save Grid less file + using (System.IO.StreamWriter file = new System.IO.StreamWriter(newResultGridLessPath)) + { + file.Write(gridLessContent); + } + + // Compile the Grid Less file + string compiledGridStyle = GetCssFromLessString(gridLessContent, false, true, true); + + // Save compiled file + using (System.IO.StreamWriter file = new System.IO.StreamWriter(newResultGridCssPath)) + { + file.Write(compiledGridStyle); + } + + + + /*********************************************/ + /* Main parameters */ + /*********************************************/ + // Path to the new less and css files string newResultLessPath = HttpContext.Current.Server.MapPath(string.Format(resultLessPath, pageId)); string newResultCssPath = HttpContext.Current.Server.MapPath(string.Format(resultCssPath, pageId)); @@ -101,22 +162,22 @@ namespace Umbraco.Web.Editors lessContent = sr.ReadToEnd(); } - // Create font directory + // Create front directory if (!Directory.Exists(frontBasePath)) Directory.CreateDirectory(frontBasePath); // Prepare parameters and gf block string newParamBlock = string.Empty; string newGfBlock = string.Empty; - foreach (string parameters in result.Trim().Split(new string[] {";"}, StringSplitOptions.RemoveEmptyEntries)) + foreach (string parameter in parameters.Trim().Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries)) { - if (parameters.IndexOf("@import") < 0) + if (parameter.IndexOf("@import") < 0) { - newParamBlock += (parameters + ";").Replace(":;", ":'';") + Environment.NewLine; + newParamBlock += (parameter + ";").Replace(":;", ":'';") + Environment.NewLine; } else { - newGfBlock += parameters + ";" + Environment.NewLine; + newGfBlock += parameter + ";" + Environment.NewLine; } } lessContent = lessContent.Replace(GetStyleBloque("lessParam", lessContent), Environment.NewLine + newParamBlock); @@ -166,7 +227,98 @@ namespace Umbraco.Web.Editors resp.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); return resp; - } + } + + [HttpGet] + public HttpResponseMessage GridStyle() { + + // Load current content + int pageId = int.TryParse(HttpContext.Current.Request["pageId"], out pageId) ? pageId : -1; + var contentService = Services.ContentService; + IContent content = contentService.GetById(pageId); + + // Path to the new grid less + string newResultGridLessPath = HttpContext.Current.Server.MapPath(string.Format(resultGridLessPath, pageId)); + + // Load current grid Less + string gridLessContent = string.Empty; + using (System.IO.StreamReader sr = new System.IO.StreamReader(newResultGridLessPath)) + { + gridLessContent = sr.ReadToEnd(); + } + + //Get parameter block + string lessParam = GetStyleBloque("lessParam", gridLessContent); + + //Get style block + string gridStyle = GetStyleBloque("gridStyle", gridLessContent); + + // Look after grid properies + foreach (var property in content.Properties) + { + + if (property.PropertyType.PropertyEditorAlias == "Umbraco.Grid") + { + dynamic grid = Newtonsoft.Json.Linq.JObject.Parse(property.Value.ToString()); + foreach (var column in grid.columns) + { + foreach (var row in column.rows) + { + + string newTag = "grid-row-" + column.rows.IndexOf(row); + + if (gridStyle.IndexOf(newTag + " ") < 0) + { + lessParam += string.Format("@backgroundRowColor__{0}:;\r\n" + + "@backgroundRowImageOrPattern__{0}:;\r\n" + + "@backgroundRowGradientColor__{0}:;\r\n" + + "@backgroundRowPosition__{0}:;\r\n" + + "@backgroundRowCover__{0}:;\r\n" + + "@backgroundRowRepeat__{0}:;\r\n" + + "@backgroundRowAttachment__{0}:;\r\n", newTag); + + gridStyle += string.Format("\r\n\r\n.Row-cover__{0} () when (@backgroundRowCover__{0} = true) {{ \r\n" + + "-webkit-background-size: cover; \r\n" + + "-moz-background-size: cover; \r\n" + + "-o-background-size: cover; \r\n" + + "background-size: cover; \r\n" + + "}} \r\n\r\n" + + ".{0} {{ \r\n" + + "background-color:@backgroundRowColor__{0}; \r\n" + + "background: -moz-linear-gradient(top, @backgroundRowColor__{0} 41%,@backgroundRowGradientColor__{0} 100%); \r\n" + + "background: -webkit-gradient(linear, left top, left bottom, color-stop(41%,@backgroundRowColor__{0}), color-stop(100%,@backgroundRowGradientColor__{0})); \r\n" + + "background: -webkit-linear-gradient(top, @backgroundRowColor__{0} 41%,@backgroundRowGradientColor__{0} 100%); \r\n" + + "background: -o-linear-gradient(top, @backgroundRowColor__{0} 41%,@backgroundRowGradientColor__{0} 100%); \r\n" + + "background: -ms-linear-gradient(top, @backgroundRowColor__{0} 41%,@backgroundRowGradientColor__{0} 100%); \r\n" + + "background: linear-gradient(to bottom, @backgroundRowColor__{0} 41%,@backgroundRowGradientColor__{0} 100%); \r\n" + + "background-image: @backgroundRowImageOrPattern__{0}; \r\n" + + "background-position: @backgroundRowPosition__{0}; \r\n" + + "background-repeat: @backgroundRowRepeat__{0}; \r\n" + + "background-attachment: @backgroundRowAttachment__{0}; \r\n" + + ".Row-cover__{0};}}", newTag); + } + } + } + } + + } + + string result = "/***start-lessParam***/\r\n{0}/***end-lessParam***/\r\n\r\n/***start-gridStyle***/{1}/***end-gridStyle***/"; + result = string.Format(result, lessParam, gridStyle); + + // Save compiled file + using (System.IO.StreamWriter file = new System.IO.StreamWriter(newResultGridLessPath)) + { + file.Write(result); + } + + + return new HttpResponseMessage(HttpStatusCode.OK) + { + Content = new StringContent(result, Encoding.UTF8, "text/css") + }; + + } private static string GetCssFromLessString(string css, Boolean cacheEnabled, Boolean minifyOutput, Boolean disableVariableRedefines) { diff --git a/src/Umbraco.Web/UmbracoHelper.cs b/src/Umbraco.Web/UmbracoHelper.cs index 629bdf2bf3..167994fe0f 100644 --- a/src/Umbraco.Web/UmbracoHelper.cs +++ b/src/Umbraco.Web/UmbracoHelper.cs @@ -1308,10 +1308,11 @@ namespace Umbraco.Web string previewLink = @"" + @"" + + @"" + @"" + @"" + @"" + - @"" + + @"" + @""; string noPreviewLinks = @"" + @@ -1327,6 +1328,8 @@ namespace Umbraco.Web int pageId = UmbracoContext.PublishedContentRequest.UmbracoPage.PageID; string[] path = UmbracoContext.PublishedContentRequest.UmbracoPage.SplitPath; + + // Looking for style folder string linkResult = string.Empty; foreach (var page in path.OrderByDescending(r => path.IndexOf(r))) @@ -1339,13 +1342,33 @@ namespace Umbraco.Web } } + + string result = string.Empty; if (UmbracoContext.Current.InPreviewMode) { - result = string.IsNullOrEmpty(linkResult) ? string.Format(previewLink, defaultLessStyle) : string.Format(previewLink, linkResult); + result = string.IsNullOrEmpty(linkResult) ? string.Format(previewLink, defaultLessStyle, pageId) : string.Format(previewLink, linkResult, pageId); } else { - result = string.IsNullOrEmpty(linkResult) ? string.Format(noPreviewLinks, defaultCssStyle) : string.Format(noPreviewLinks, linkResult); + result = string.IsNullOrEmpty(linkResult) ? string.Format(noPreviewLinks, defaultCssStyle, pageId) : string.Format(noPreviewLinks, linkResult, pageId); } + + + //// Grid Styles + //var previewGridStyleLink = "/Umbraco/Api/Tuning/GridStyle?pageId={0}"; + + //if + + //var gridStyleLink = string.Empty; + //string styleGridPath = HttpContext.Current.Server.MapPath(string.Format(gridStyleLink, pageId)); + //if (System.IO.File.Exists(styleGridPath)) + //{ + // gridStyleLink = UmbracoContext.Current.InPreviewMode ? @"" : + // @""; + // gridStyleLink = string.Format(gridStyleLink, pageId); + //} + + + return new HtmlString(result); }