Exemple #1
0
        /// <summary>
        /// Gets the selected section layout.
        /// </summary>
        /// <param name="placeholders">The placeholders.</param>
        /// <param name="sectionPlaceholder">The section placeholder.</param>
        /// <param name="defaultLayout">The default layout.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentException">Thrown if section placeholder does not contain a value</exception>
        public static string GetSelectedSectionLayout(PlaceholderCollection placeholders, string sectionPlaceholder, string defaultLayout)
        {
            if (placeholders == null)
            {
                throw new ArgumentNullException("placeholders");
            }

            // Make sure we know which usercontrol to load for the section
            string selectedLayout = String.Empty;

            // Hopefully the layout name was saved with the page in a placeholder
            if (placeholders.ContainsKey(sectionPlaceholder) && placeholders[sectionPlaceholder].Value != null)
            {
                selectedLayout = placeholders[sectionPlaceholder].Value.ToString();
            }

            // If not, the page probably hasn't been saved since this code was introduced, so default to
            // whichever layout was previously hard-coded into the template.
            // This is for published/unpublished mode. The default placeholder for edit mode is set earlier in SetDefaultSectionLayout, but it's done
            // in a way that only works when editing.
            if (selectedLayout.Length == 0)
            {
                selectedLayout = defaultLayout;
            }

            return(selectedLayout);
        }
        /// <summary>
        /// Sets the placeholder names and values and the layout used for a particular section.
        /// </summary>
        /// <param name="placeholders">The Umbraco fields</param>
        /// <param name="sectionPlaceholder">The section placeholder.</param>
        /// <param name="subtitlePlaceholder">The subtitle placeholder.</param>
        /// <param name="contentPlaceholder">The content placeholder.</param>
        /// <param name="imagePlaceholder1">The 1st image placeholder.</param>
        /// <param name="imagePlaceholder2">The 2nd image placeholder.</param>
        /// <param name="imagePlaceholder3">The 3rd image placeholder.</param>
        /// <param name="captionPlaceholder1">The 1st caption placeholder.</param>
        /// <param name="captionPlaceholder2">The 2nd caption placeholder.</param>
        /// <param name="captionPlaceholder3">The 3rd caption placeholder.</param>
        /// <param name="altAsCaptionPlaceholder1">The 1st alt as caption placeholder.</param>
        /// <param name="altAsCaptionPlaceholder2">The 2nd alt as caption placeholder.</param>
        /// <param name="altAsCaptionPlaceholder3">The 3rd alt as caption placeholder.</param>
        /// <param name="defaultLayout">The default layout.</param>
        private void SetupSections(PlaceholderCollection placeholders, string sectionPlaceholder, string subtitlePlaceholder, string contentPlaceholder, string imagePlaceholder1, string imagePlaceholder2, string imagePlaceholder3, string captionPlaceholder1, string captionPlaceholder2, string captionPlaceholder3, string altAsCaptionPlaceholder1, string altAsCaptionPlaceholder2, string altAsCaptionPlaceholder3, string defaultLayout)
        {
            // Load the usercontrol appropriate to the chosen layout, and pass in all the names of the placeholders it should use
            string selectedLayout = SectionLayoutManager.GetSelectedSectionLayout(placeholders, sectionPlaceholder, defaultLayout);

            try
            {
                Control      selectedControl = this.LoadControl(SectionLayoutManager.UserControlPath("Escc.EastSussexGovUK.Umbraco/TopicSectionLayouts", selectedLayout));
                TopicSection sectionControl  = selectedControl as TopicSection;

                if (sectionControl != null)
                {
                    sectionControl.PlaceholderToBindSection        = sectionPlaceholder;
                    sectionControl.PlaceholderToBindSubtitle       = subtitlePlaceholder;
                    sectionControl.PlaceholderToBindContent        = contentPlaceholder;
                    sectionControl.PlaceholderToBindImage01        = imagePlaceholder1;
                    sectionControl.PlaceholderToBindImage02        = imagePlaceholder2;
                    sectionControl.PlaceholderToBindImage03        = imagePlaceholder3;
                    sectionControl.PlaceholderToBindCaption01      = captionPlaceholder1;
                    sectionControl.PlaceholderToBindCaption02      = captionPlaceholder2;
                    sectionControl.PlaceholderToBindCaption03      = captionPlaceholder3;
                    sectionControl.PlaceholderToBindAltAsCaption01 = altAsCaptionPlaceholder1;
                    sectionControl.PlaceholderToBindAltAsCaption02 = altAsCaptionPlaceholder2;
                    sectionControl.PlaceholderToBindAltAsCaption03 = altAsCaptionPlaceholder3;
                }
                // Add the section to the page
                this.sections.Controls.Add(selectedControl);
            }
            catch (ArgumentException exception)
            {
                // Expected if an obsolete section has been removed from config, but is still referenced by the page
                exception.ToExceptionless().Submit();
            }
        }
Exemple #3
0
 private static int FindMinIndex(Literal literal, PlaceholderCollection placeholders)
 {
     return(placeholders
            .Where(placeholder => placeholder.Identifier == literal.Identifier)
            .Select(placeholder => placeholder.Index)
            .Min());
 }
        protected override void Execute(ExecutionContext context, Snippet snippet)
        {
            snippet.SuffixShortcut("x");
            snippet.SuffixTitle(" definition");
            snippet.SuffixDescription(" definition");
            snippet.SnippetTypes |= SnippetTypes.SurroundsWith;
            snippet.SuffixFileName("Definition");
            snippet.AddTag(KnownTags.ExcludeFromReadme);

            PlaceholderCollection placeholders = snippet.Code.Placeholders;

            if (placeholders.Contains("_definition"))
            {
                snippet.CodeText = snippet.Code.ReplacePlaceholders("_definition", @" {
	$selected$$end$
}");
            }
        }
Exemple #5
0
        protected override void Execute(ExecutionContext context, Snippet snippet)
        {
            snippet.SuffixTitle(" declaration");
            snippet.SuffixDescription(" declaration");
            snippet.SuffixFileName("Declaration");

            PlaceholderCollection placeholders = snippet.Code.Placeholders;

            if (placeholders.Contains("_definitionStart"))
            {
                int index    = placeholders.Find("_definitionStart").Index - 1;
                int endIndex = placeholders.Find("_definitionEnd").EndIndex + 1;

                string s = snippet.CodeText;

                s = s.Insert(endIndex, ";");
                s = s.Remove(index, endIndex - index);

                snippet.CodeText = s;
            }

            snippet.AppendCode(snippet.Delimiter + Placeholder.EndIdentifier + snippet.Delimiter);
        }
Exemple #6
0
        private static string GetTextMateBody(Snippet snippet)
        {
            snippet = (Snippet)snippet.Clone();

            snippet.RemoveLiteralAndReplacePlaceholders(XmlSnippetGenerator.CDataIdentifier, "]]>");

            LiteralCollection literals = snippet.Literals;

            string s = snippet.CodeText;

            var sb = new StringBuilder(s.Length);

            int pos = 0;

            PlaceholderCollection placeholders = snippet.Code.Placeholders;

            Dictionary <Literal, int> literalIndexes = literals
                                                       .OrderBy(f => FindMinIndex(f, placeholders))
                                                       .Select((literal, i) => new { Literal = literal, Index = i })
                                                       .ToDictionary(f => f.Literal, f => f.Index + 1);

            var processedIds = new List <string>();

            foreach (Placeholder placeholder in placeholders.OrderBy(f => f.Index))
            {
                sb.Append(s, pos, placeholder.Index - 1 - pos);

                if (placeholder.IsEndPlaceholder)
                {
                    sb.Append("${0}");
                }
                else if (placeholder.IsSelectedPlaceholder)
                {
                    sb.Append("${TM_SELECTED_TEXT}");
                }
                else
                {
                    string id = placeholder.Identifier;

                    Literal literal = literals[id];

                    sb.Append("${");
                    sb.Append(literalIndexes[literal]);

                    if (!processedIds.Contains(id))
                    {
                        sb.Append(":");
                        sb.Append(literal.DefaultValue);
                        processedIds.Add(id);
                    }

                    sb.Append("}");
                }

                pos = placeholder.EndIndex + 1;
            }

            sb.Append(s, pos, s.Length - pos);

            return(sb.ToString());
        }
        private void Parse()
        {
            _startIndex = -1;
            _indexes = new Dictionary<int, Placeholder>();
            var placeholders = new List<Placeholder>();

            for (int i = 0; i < Text.Length; i++)
            {
                if (Text[i] == Delimiter)
                {
                    if (_startIndex == -1)
                    {
                        _startIndex = i + 1;
                    }
                    else
                    {
                        if (i > _startIndex)
                        {
                            var placeholder = new Placeholder(_startIndex, Text.Substring(_startIndex, i - _startIndex), Delimiter);
                            _indexes.Add(_startIndex, placeholder);
                            placeholders.Add(placeholder);
                        }
                        else
                        {
                            _indexes.Add(_startIndex, null);
                        }

                        _startIndex = -1;
                    }
                }
            }

            _placeholders = new PlaceholderCollection(placeholders);
        }