is it possible to have subfolders setup under the Dynamic Stylesheet/Scripts root vs having to have all the CSS/script files in the main folder? i.e., we have lots of SASS files but have them organized in subfolders. would prefer to keep the natural subfolder structure if possible. is this an option? many thanks!
Tim - I believe I have this working correctly. I ended up updating the following files: BaseDynamicFileTree.cs, CreateScript.ascx.cs, CreateStyleSheet.ascx.cs (I'll post those updates in next post). Below are some BackOffice snapshots of these changes made..
Mind submitting this as a pull request on github or if you don't know how to do that, send me the updated files tg at umbraco dot com since copying from this forum...
Dynamic Stylesheets/Scripts Subfolders
is it possible to have subfolders setup under the Dynamic Stylesheet/Scripts root vs having to have all the CSS/script files in the main folder? i.e., we have lots of SASS files but have them organized in subfolders. would prefer to keep the natural subfolder structure if possible. is this an option? many thanks!
Not at this point but would be a nice feature :)
If you are up for the tasks the sourcecode is public so you can commit a pull request https://github.com/TimGeyssens/BundlingAndMinificationForTheMasses
Tim - I believe I have this working correctly. I ended up updating the following files: BaseDynamicFileTree.cs, CreateScript.ascx.cs, CreateStyleSheet.ascx.cs (I'll post those updates in next post). Below are some BackOffice snapshots of these changes made..
Below are the code changes for BaseDynamicFileTree.cs, CreateScript.ascx.cs, CreateStyleSheet.ascx.cs:
BaseDynamicFileTree.cs
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Web; using umbraco.cms.presentation.Trees; using Umbraco.Core.IO; using Optimus.Extensions; using umbraco.interfaces; using umbraco.BusinessLogic.Actions; using Optimus.Enums; namespace Optimus.Umbraco.Trees { public abstract class BaseDynamicFileTree : BaseTree { public abstract TranslatorType TranslatorType { get; } public BaseDynamicFileTree(string application) : base(application) { } public override void RenderJS(ref StringBuilder Javascript) { Javascript.Append( TranslatorType == TranslatorType.StyleSheet ? @" function openDyanmicCSSFileEditor(fileName, compiled) { UmbClientMgr.contentFrame('../App_Plugins/Optimus/Pages/FileEditor.aspx?file='+ fileName + '&path=/css/&compiled=' + compiled); }" : @" function openDyanmicScriptFileEditor(fileName, compiled) { UmbClientMgr.contentFrame('../App_Plugins/Optimus/Pages/FileEditor.aspx?file='+ fileName + '&path=/scripts/&compiled=' + compiled); }" ); } public override void Render(ref XmlTree tree) { string FilePath = TranslatorType == Enums.TranslatorType.StyleSheet ? "/css/" : "/scripts/"; string orgPath = String.Empty; string path = String.Empty; if (!string.IsNullOrEmpty(this.NodeKey)) { orgPath = this.NodeKey; path = IOHelper.MapPath(FilePath + orgPath); orgPath += "/"; } else { path = IOHelper.MapPath(FilePath); } DirectoryInfo dirInfo = new DirectoryInfo(path); DirectoryInfo[] dirInfos = dirInfo.GetDirectories(); var allowedExts = new Translation.Core().GetPossibleExtensions(TranslatorType).ToArray(); var args = new TreeEventArgs(tree); OnBeforeTreeRender(dirInfo, args); foreach (DirectoryInfo dir in dirInfos) { if ((dir.Attributes & FileAttributes.Hidden) == 0) { XmlTreeNode xDirNode = XmlTreeNode.Create(this); xDirNode.NodeID = orgPath + dir.Name; xDirNode.NodeType = TranslatorType == Enums.TranslatorType.StyleSheet ? "initstylesheetsNew" : "initscriptsNew"; xDirNode.Menu = new List(new IAction[] { ActionDelete.Instance, ContextMenuSeperator.Instance, ActionNew.Instance, ContextMenuSeperator.Instance, ActionRefresh.Instance }); xDirNode.Text = dir.Name; xDirNode.Source = GetTreeServiceUrl(orgPath + dir.Name); xDirNode.Icon = FolderIcon; xDirNode.OpenIcon = FolderIconOpen; xDirNode.HasChildren = dir.GetFiles().Length > 0 || dir.GetDirectories().Length > 0; OnRenderFolderNode(ref xDirNode); OnBeforeNodeRender(ref tree, ref xDirNode, EventArgs.Empty); if (xDirNode != null) { tree.Add(xDirNode); OnAfterNodeRender(ref tree, ref xDirNode, EventArgs.Empty); } } } FileInfo[] fileInfo = dirInfo.GetFiles("*.*"); foreach (FileInfo file in fileInfo) { if ((file.Attributes & FileAttributes.Hidden) == 0 && allowedExts.Contains(file.Extension)) { XmlTreeNode xFileNode = XmlTreeNode.Create(this); xFileNode.NodeID = orgPath + file.Name; xFileNode.Text = file.Name; xFileNode.Icon = new Optimus.Translation.Core().GetTranslatorTreeIconPath(file.Name); xFileNode.OpenIcon = "doc.gif"; xFileNode.Menu = new List { ActionDelete.Instance }; xFileNode.NodeType = TranslatorType == Enums.TranslatorType.StyleSheet ? "initstylesheetsNew" : "initscriptsNew"; if (string.IsNullOrEmpty(xFileNode.Action)) { if (orgPath != string.Empty) { xFileNode.Action = TranslatorType == Enums.TranslatorType.StyleSheet ? "javascript:openDyanmicCSSFileEditor('" + orgPath + file.Name + "', 'false');" : "javascript:openDyanmicScriptFileEditor('" + orgPath + file.Name + "', 'false');"; } else { xFileNode.Action = TranslatorType == Enums.TranslatorType.StyleSheet ? "javascript:openDyanmicCSSFileEditor('" + file.Name + "', 'false');" : "javascript:openDyanmicScriptFileEditor('" + file.Name + "', 'false');"; } } OnRenderFileNode(ref xFileNode); OnBeforeNodeRender(ref tree, ref xFileNode, EventArgs.Empty); if (xFileNode != null) { tree.Add(xFileNode); OnAfterNodeRender(ref tree, ref xFileNode, EventArgs.Empty); } } } OnAfterTreeRender(dirInfo, args); } /// /// Inheritors can override this method to modify the file node that is created. /// /// protected virtual void OnRenderFileNode(ref XmlTreeNode xNode) { } /// /// Inheritors can override this method to modify the folder node that is created. /// /// protected virtual void OnRenderFolderNode(ref XmlTreeNode xNode) { } protected override void CreateRootNode(ref XmlTreeNode rootNode) { rootNode.Icon = ".sprTreeFolder"; rootNode.OpenIcon = ".sprTreeFolder_o"; rootNode.NodeID = "init"; rootNode.NodeType = rootNode.NodeID + TreeAlias; rootNode.Menu = new List { ActionNew.Instance, ActionRefresh.Instance }; } } }CreateScript.ascx.cs
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using umbraco; using umbraco.BasePages; using System.IO; namespace Optimus.Umbraco.Dialogs { public partial class CreateScript : System.Web.UI.UserControl { protected void Page_Load(object sender, EventArgs e) { sbmt.Text = ui.Text("create"); if (!Page.IsPostBack) { //scriptType.Items.Add(new ListItem("Plain script", "js")); scriptType.Items.Add(new ListItem(ui.Text("folder"), "")); scriptType.Items.FindByText(ui.Text("folder")).Selected = true; foreach (var trans in new Translation.Core().GetScriptTranslators()) { scriptType.Items.Add(new ListItem(trans.Name, trans.FileExtension)); } } } protected void sbmt_Click(object sender, EventArgs e) { if (Page.IsValid) { //get file new path info var fileName = !String.IsNullOrEmpty(scriptType.SelectedValue) ? rename.Text + "." + scriptType.SelectedValue : rename.Text; var helperPath = helper.Request("nodeID") == "init" ? String.Empty : helper.Request("nodeID"); var cmsPath = !String.IsNullOrEmpty(helperPath) ? ("/scripts/" + helperPath + "/") : "/scripts/"; var fullFilePath = Server.MapPath(cmsPath) + fileName; //make sure not create folder if (!String.IsNullOrEmpty(scriptType.SelectedValue)) { //create new file File.Create(fullFilePath).Close(); //redirect to new file edit mode BasePage.Current.ClientTools .ChangeContentFrameUrl(".." + Config.EditFilePagePath + "?file=" + fileName + "&path=" + cmsPath) .ChildNodeCreated() .CloseModalWindow(); } else { //create new directory if not already exists if (!Directory.Exists(fullFilePath)) Directory.CreateDirectory(fullFilePath); //redirect to new file edit mode BasePage.Current.ClientTools .ChildNodeCreated() .CloseModalWindow(); } } } } }CreateStyleSheet.ascx.cs
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using umbraco; using umbraco.BasePages; using umbraco.cms.helpers; using umbraco.BasePages; using umbraco.IO; namespace Optimus.Umbraco.Dialogs { public partial class CreateStyleSheet : System.Web.UI.UserControl { protected void Page_Load(object sender, EventArgs e) { sbmt.Text = ui.Text("create"); if (!Page.IsPostBack) { //styleSheetType.Items.Add(new ListItem("Plain stylesheet", "css")); styleSheetType.Items.Add(new ListItem(ui.Text("folder"), "")); styleSheetType.Items.FindByText(ui.Text("folder")).Selected = true; foreach (var trans in new Translation.Core().GetStyleSheetTranslators()) { styleSheetType.Items.Add(new ListItem(trans.Name, trans.FileExtension)); } } } protected void sbmt_Click(object sender, EventArgs e) { if (Page.IsValid) { //get file new path info var fileName = !String.IsNullOrEmpty(styleSheetType.SelectedValue) ? rename.Text + "." + styleSheetType.SelectedValue : rename.Text; var helperPath = helper.Request("nodeID") == "init" ? String.Empty : helper.Request("nodeID"); var cmsPath = !String.IsNullOrEmpty(helperPath) ? ("/css/" + helperPath + "/") : "/css/"; var fullFilePath = Server.MapPath(cmsPath) + fileName; //make sure not create folder if (!String.IsNullOrEmpty(styleSheetType.SelectedValue)) { //create new file File.Create(fullFilePath).Close(); //redirect to new file edit mode BasePage.Current.ClientTools .ChangeContentFrameUrl(".." + Config.EditFilePagePath + "?file=" + fileName + "&path=" + cmsPath) .ChildNodeCreated() .CloseModalWindow(); } else { //create new directory if not already exists if (!Directory.Exists(fullFilePath)) Directory.CreateDirectory(fullFilePath); //redirect to new file edit mode BasePage.Current.ClientTools .ChildNodeCreated() .CloseModalWindow(); } } } } }Wow that's awesome :)
Mind submitting this as a pull request on github or if you don't know how to do that, send me the updated files tg at umbraco dot com since copying from this forum...
Code has been added :) will release new version shortly (working on v7 compat)
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.