/// <summary> /// Deletes the theme. /// </summary> /// <param name="themeName">Name of the theme.</param> /// <param name="messages">The messages.</param> /// <returns></returns> public static bool DeleteTheme(string themeName, out string messages) { messages = string.Empty; bool resultSucess = true; var theme = new RockTheme(themeName); if (!theme.IsSystem) { try { Directory.Delete(theme.AbsolutePath, true); } catch (Exception ex) { resultSucess = false; messages = ex.Message; } } else { resultSucess = false; messages = "Can not delete a system theme."; } return(resultSucess); }
/// <summary> /// Handles the Click event of the gCompileTheme control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RowEventArgs"/> instance containing the event data.</param> protected void gCompileTheme_Click( object sender, RowEventArgs e ) { var theme = new RockTheme( e.RowKeyValue.ToString() ); string messages = string.Empty; bool compileSuccess = theme.Compile( out messages ); if ( compileSuccess ) { mdThemeCompile.Show( "Theme was successfully compiled.", ModalAlertType.Information ); } else { nbMessages.NotificationBoxType = NotificationBoxType.Danger; nbMessages.Text = string.Format( "An error occurred while compiling the {0} them. Message: {1}", theme.Name, messages ); } }
/// <summary> /// Handles the Click event of the btnCompileTheme control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void btnCompileTheme_Click( object sender, EventArgs e ) { var rockContext = new RockContext(); SiteService siteService = new SiteService( rockContext ); Site site = siteService.Get( hfSiteId.Value.AsInteger() ); string messages = string.Empty; var theme = new RockTheme( site.Theme ); bool success = theme.Compile( out messages ); if ( success ) { mdThemeCompile.Show( "Theme was successfully compiled.", ModalAlertType.Information ); } else { mdThemeCompile.Show( string.Format("An error occurred compiling the theme {0}. Message: {1}.", site.Theme, messages), ModalAlertType.Warning ); } }
protected void btnSave_Click( object sender, EventArgs e ) { string variableFile = string.Format( @"{0}Themes/{1}/Styles/_variables.less", Request.PhysicalApplicationPath, _themeName ); string variableOverrideFile = string.Format( @"{0}Themes/{1}/Styles/_variable-overrides.less", Request.PhysicalApplicationPath, _themeName ); string cssOverrideFile = string.Format( @"{0}Themes/{1}/Styles/_css-overrides.less", Request.PhysicalApplicationPath, _themeName ); if ( File.Exists( cssOverrideFile ) ) { File.WriteAllText( cssOverrideFile, ceOverrides.Text ); } // get list of original values Dictionary<string, string> originalValues = GetVariables( variableFile ); StringBuilder overrideFile = new StringBuilder(); foreach (var control in phThemeControls.Controls ) { if ( control is TextBox ) { var textBoxControl = (TextBox)control; string variableName = textBoxControl.ID.Replace(" ", "-").ToLower(); // find original value if ( originalValues.ContainsKey( variableName )){ string originalValue = originalValues[variableName]; // color picker will convert #fff to #ffffff so take that into account string secondaryValue = string.Empty; if ( originalValue.Length == 4 && originalValue[0] == '#' ) { secondaryValue = originalValue + originalValue.Substring( 1, 3 ); } if ( originalValue != textBoxControl.Text && secondaryValue != textBoxControl.Text ) { overrideFile.Append( string.Format( "@{0}: {1};{2}", variableName, textBoxControl.Text, Environment.NewLine ) ); } } } } System.IO.StreamWriter file = new System.IO.StreamWriter( variableOverrideFile ); file.WriteLine( overrideFile ); file.Dispose(); // compile theme string messages = string.Empty; var theme = new RockTheme( _themeName ); theme.Compile(); NavigateToParentPage(); }
/// <summary> /// Deletes the theme. /// </summary> /// <param name="themeName">Name of the theme.</param> /// <param name="messages">The messages.</param> /// <returns></returns> public static bool DeleteTheme(string themeName, out string messages ) { messages = string.Empty; bool resultSucess = true; var theme = new RockTheme( themeName ); if ( !theme.IsSystem ) { try { Directory.Delete( theme.AbsolutePath, true ); } catch ( Exception ex ) { resultSucess = false; messages = ex.Message; } } else { resultSucess = false; messages = "Can not delete a system theme."; } return resultSucess; }