/// <summary> /// Initializes a new instance of the <see cref="Slug"/> class. /// </summary> /// <param name="configuration"> /// Configuration from web.config /// </param> /// <exception cref="ArgumentNullException"> /// If configuration is null /// </exception> public Slug(ConfigurationManagerWrapper configuration) { if (configuration == null) { throw new ArgumentNullException("configuration"); } NameEditorElement nameEditorElement = configuration.Sections.Management.NameEditor; // start with empty collection this.replacementPatterns.Clear(); // first add any replacements from custom configuration, which will be applied first foreach (PatternValueElement element in nameEditorElement.Replacements.AllElements) { this.replacementPatterns.Add(element); } // then, add system replacements inserted from constructor foreach (PatternValueElement element in new PatternValueCollection()) { this.replacementPatterns.Add(element); } this.whitespaceReplacement = nameEditorElement.WhitespaceReplacement; this.toLower = nameEditorElement.ToLower; }
private Slug CreateCustomReplacementSlug() { PatternValueCollection patterns = new PatternValueCollection(); patterns.Clear(); // to remove all those added by constructor patterns.Add(new PatternValueElement("c1", "[@]", "at", true)); NameEditorElement nameEditorElement = new NameEditorElement { // WhitespaceReplacement = '-', Replacements = patterns //, // ToLower = true }; EditSection editSection = new EditSection { NameEditor = nameEditorElement }; ConfigurationManagerWrapper cmw = new ConfigurationManagerWrapper { Sections = new ConfigurationManagerWrapper.ContentSectionTable(null, null, null, editSection) }; return(new Slug(cmw)); }
private Slug CreateDefaultSlug() { NameEditorElement nameEditorElement = new NameEditorElement(); EditSection editSection = new EditSection { NameEditor = nameEditorElement }; ConfigurationManagerWrapper cmw = new ConfigurationManagerWrapper { Sections = new ConfigurationManagerWrapper.ContentSectionTable(null, null, null, editSection) }; return(new Slug(cmw)); }
private static NameEditorElement LoadConfiguration() { EditSection editSection = ConfigurationManager.GetSection("n2/edit") as EditSection; if (editSection != null) { return(editSection.NameEditor); } NameEditorElement config = new NameEditorElement(); config.WhitespaceReplacement = '-'; config.ShowKeepUpdated = true; config.ToLower = true; return(config); }
private Slug CreateLowercaseSlug() { NameEditorElement nameEditorElement = new NameEditorElement { WhitespaceReplacement = '-', Replacements = new PatternValueCollection(), ToLower = true }; EditSection editSection = new EditSection { NameEditor = nameEditorElement }; ConfigurationManagerWrapper cmw = new ConfigurationManagerWrapper { Sections = new ConfigurationManagerWrapper.ContentSectionTable(null, null, null, editSection) }; return(new Slug(cmw)); }