示例#1
0
        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>
        /// 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);
            }
        }
示例#3
0
        /// <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);
            }
        }
示例#4
0
        /// <summary>
        /// Handles the Click event of the btnSave 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 btnSave_Click(object sender, EventArgs e)
        {
            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();

            if (pnlFontAwesomeSettings.Visible)
            {
                overrideFile.AppendLine(FontAwesomeHelper.VariableOverridesTokens.StartRegion);

                var selectedPrimaryWeight = FontAwesomeHelper.FontAwesomeIconCssWeights.FirstOrDefault(a => a.WeightName == ddlFontAwesomeIconWeight.SelectedValue);

                overrideFile.AppendLine(string.Format("{0} {1};", FontAwesomeHelper.VariableOverridesTokens.FontWeightValueLineStart, selectedPrimaryWeight.WeightValue));
                overrideFile.AppendLine(string.Format("{0} '{1}';", FontAwesomeHelper.VariableOverridesTokens.FontWeightNameLineStart, selectedPrimaryWeight.WeightName));

                if (FontAwesomeHelper.HasFontAwesomeProKey())
                {
                    overrideFile.AppendLine("@fa-edition: 'pro';");
                }

                overrideFile.AppendLine();

                if (!selectedPrimaryWeight.IncludedInFree)
                {
                    overrideFile.AppendLine(string.Format("{0} {1};", FontAwesomeHelper.VariableOverridesTokens.FontEditionLineStart, FontAwesomeHelper.VariableOverridesTokens.FontEditionPro));
                }

                overrideFile.AppendLine("@import \"../../../Styles/FontAwesome/_rock-fa-mixins.less\";");

                foreach (var alternateFontWeightName in cblFontAwesomeAlternateFonts.Items.OfType <ListItem>().Where(a => a.Selected).Select(a => a.Value).ToList())
                {
                    var alternateFont = FontAwesomeHelper.FontAwesomeIconCssWeights.Where(a => a.WeightName == alternateFontWeightName).FirstOrDefault();
                    if (alternateFont != null)
                    {
                        string suffixParam = string.Empty;
                        overrideFile.AppendLine(
                            string.Format("{0} '{1}', 'pro' );",
                                          FontAwesomeHelper.VariableOverridesTokens.FontFaceLineStart,
                                          alternateFont.WeightName
                                          ));
                    }
                }

                overrideFile.AppendLine(FontAwesomeHelper.VariableOverridesTokens.EndRegion);
            }

            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.ToLower() != textBoxControl.Text.ToLower() && secondaryValue.ToLower() != textBoxControl.Text.ToLower())
                        {
                            overrideFile.Append(string.Format("@{0}: {1};{2}", variableName, textBoxControl.Text, Environment.NewLine));
                        }
                    }
                }
            }

            File.WriteAllText(_variableOverrideFile, overrideFile.ToString());

            // compile theme
            string messages = string.Empty;
            var    theme    = new RockTheme(_themeName);

            if (!theme.Compile(out messages))
            {
                nbMessages.NotificationBoxType = NotificationBoxType.Danger;
                nbMessages.Text    = string.Format("An error occurred while compiling the {0} theme.\nMessage: <pre>{1}</pre>", theme.Name, messages);;
                nbMessages.Visible = true;
            }
            else
            {
                NavigateToParentPage();
            }
        }