Skip to content

Commit 3e09448

Browse files
authored
LT-21761 & LT-21674: Handle Before, Between, After and more (#29)
* LT-21761 & LT-21674: Handle Before, Between, After and more Handle Before, Between, After, and DisplayInSeparateParagraphs. Remaining tasks: - Tables still need indenting. - The first line after a table is shifted to the left. A new ‘continuation’ style is needed when we start a new paragraph. - Before, Between, and After might need to use a different style.
1 parent 81f697a commit 3e09448

File tree

5 files changed

+181
-65
lines changed

5 files changed

+181
-65
lines changed

Src/xWorks/ConfiguredLcmGenerator.cs

Lines changed: 53 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,8 +1410,12 @@ private static IFragment GenerateContentForCollection(object collectionField, Co
14101410
Debug.Assert(config.DictionaryNodeOptions == null,
14111411
"double calls to GenerateContentForLexEntryRefsByType don't play nicely with ListOptions. Everything will be generated twice (if it doesn't crash)");
14121412
// Display typeless refs
1413+
bool first = true;
14131414
foreach (var entry in lerCollection.Where(item => !item.ComplexEntryTypesRS.Any() && !item.VariantEntryTypesRS.Any()))
1414-
bldr.Append(GenerateCollectionItemContent(config, pubDecorator, entry, collectionOwner, settings, lexEntryTypeNode));
1415+
{
1416+
bldr.Append(GenerateCollectionItemContent(config, pubDecorator, entry, collectionOwner, settings, first, lexEntryTypeNode));
1417+
first = false;
1418+
}
14151419
// Display refs of each type
14161420
GenerateContentForLexEntryRefsByType(config, lerCollection, collectionOwner, pubDecorator, settings, bldr, lexEntryTypeNode,
14171421
true); // complex
@@ -1421,8 +1425,12 @@ private static IFragment GenerateContentForCollection(object collectionField, Co
14211425
else
14221426
{
14231427
Debug.WriteLine("Unable to group " + config.FieldDescription + " by LexRefType; generating sequentially");
1428+
bool first = true;
14241429
foreach (var item in lerCollection)
1425-
bldr.Append(GenerateCollectionItemContent(config, pubDecorator, item, collectionOwner, settings));
1430+
{
1431+
bldr.Append(GenerateCollectionItemContent(config, pubDecorator, item, collectionOwner, settings, first));
1432+
first = false;
1433+
}
14261434
}
14271435
}
14281436
else if (config.FieldDescription.StartsWith("Subentries"))
@@ -1435,8 +1443,12 @@ private static IFragment GenerateContentForCollection(object collectionField, Co
14351443
}
14361444
else
14371445
{
1446+
bool first = true;
14381447
foreach (var item in collection)
1439-
bldr.Append(GenerateCollectionItemContent(config, pubDecorator, item, collectionOwner, settings));
1448+
{
1449+
bldr.Append(GenerateCollectionItemContent(config, pubDecorator, item, collectionOwner, settings, first));
1450+
first = false;
1451+
}
14401452
}
14411453
}
14421454

@@ -1528,16 +1540,24 @@ private static IFragment GenerateContentForEntryRefCollection(ConfigurableDictio
15281540
if (typeNode.IsEnabled && typeNode.ReferencedOrDirectChildren != null && typeNode.ReferencedOrDirectChildren.Any(y => y.IsEnabled))
15291541
{
15301542
// Display typeless refs
1543+
bool first = true;
15311544
foreach (var entry in lerCollection.Where(item => !item.ComplexEntryTypesRS.Any() && !item.VariantEntryTypesRS.Any()))
1532-
bldr.Append(GenerateCollectionItemContent(config, pubDecorator, entry, collectionOwner, settings, typeNode));
1545+
{
1546+
bldr.Append(GenerateCollectionItemContent(config, pubDecorator, entry, collectionOwner, settings, first, typeNode));
1547+
first = false;
1548+
}
15331549
// Display refs of each type
15341550
GenerateContentForLexEntryRefsByType(config, lerCollection, collectionOwner, pubDecorator, settings, bldr, typeNode, isComplex);
15351551
}
15361552
else
15371553
{
15381554
Debug.WriteLine("Unable to group " + config.FieldDescription + " by LexRefType; generating sequentially");
1555+
bool first = true;
15391556
foreach (var item in lerCollection)
1540-
bldr.Append(GenerateCollectionItemContent(config, pubDecorator, item, collectionOwner, settings));
1557+
{
1558+
bldr.Append(GenerateCollectionItemContent(config, pubDecorator, item, collectionOwner, settings, first));
1559+
first = false;
1560+
}
15411561
}
15421562
return bldr;
15431563
}
@@ -1561,11 +1581,13 @@ private static void GenerateContentForLexEntryRefsByType(ConfigurableDictionaryN
15611581
foreach (var typeGuid in lexEntryTypesFiltered)
15621582
{
15631583
var innerBldr = new StringBuilder();
1584+
bool first = true;
15641585
foreach (var lexEntRef in lerCollection)
15651586
{
15661587
if (isComplex ? lexEntRef.ComplexEntryTypesRS.Any(t => t.Guid == typeGuid) : lexEntRef.VariantEntryTypesRS.Any(t => t.Guid == typeGuid))
15671588
{
1568-
innerBldr.Append(GenerateCollectionItemContent(config, pubDecorator, lexEntRef, collectionOwner, settings, typeNode));
1589+
innerBldr.Append(GenerateCollectionItemContent(config, pubDecorator, lexEntRef, collectionOwner, settings, first, typeNode));
1590+
first = false;
15691591
}
15701592
}
15711593

@@ -1576,7 +1598,7 @@ private static void GenerateContentForLexEntryRefsByType(ConfigurableDictionaryN
15761598
var generateLexType = typeNode != null;
15771599
var lexTypeContent = generateLexType
15781600
? GenerateCollectionItemContent(typeNode, pubDecorator, lexEntryType,
1579-
lexEntryType.Owner, settings)
1601+
lexEntryType.Owner, settings, first)
15801602
: null;
15811603
var className = generateLexType ? settings.StylesGenerator.AddStyles(typeNode).Trim('.') : null;
15821604
var refsByType = settings.ContentGenerator.AddLexReferences(generateLexType,
@@ -1600,11 +1622,13 @@ private static void GenerateContentForSubentries(ConfigurableDictionaryNode conf
16001622
.Select(le => new Tuple<ILexEntryRef, ILexEntry>(EntryRefForSubentry(le, collectionOwner), le)).ToList();
16011623

16021624
// Generate any Subentries with no ComplexFormType
1625+
bool first = true;
16031626
for (var i = 0; i < subentries.Count; i++)
16041627
{
16051628
if (subentries[i].Item1 == null || !subentries[i].Item1.ComplexEntryTypesRS.Any())
16061629
{
1607-
bldr.Append(GenerateCollectionItemContent(config, pubDecorator, subentries[i].Item2, collectionOwner, settings));
1630+
bldr.Append(GenerateCollectionItemContent(config, pubDecorator, subentries[i].Item2, collectionOwner, settings, first));
1631+
first = false;
16081632
subentries.RemoveAt(i--);
16091633
}
16101634
}
@@ -1615,7 +1639,8 @@ private static void GenerateContentForSubentries(ConfigurableDictionaryNode conf
16151639
{
16161640
if (subentries[i].Item1.ComplexEntryTypesRS.Any(t => t.Guid == typeGuid))
16171641
{
1618-
bldr.Append(GenerateCollectionItemContent(config, pubDecorator, subentries[i].Item2, collectionOwner, settings));
1642+
bldr.Append(GenerateCollectionItemContent(config, pubDecorator, subentries[i].Item2, collectionOwner, settings, first));
1643+
first = false;
16191644
subentries.RemoveAt(i--);
16201645
}
16211646
}
@@ -1624,8 +1649,12 @@ private static void GenerateContentForSubentries(ConfigurableDictionaryNode conf
16241649
else
16251650
{
16261651
Debug.WriteLine("Unable to group " + config.FieldDescription + " by LexRefType; generating sequentially");
1652+
bool first = true;
16271653
foreach (var item in collection)
1628-
bldr.Append(GenerateCollectionItemContent(config, pubDecorator, item, collectionOwner, settings));
1654+
{
1655+
bldr.Append(GenerateCollectionItemContent(config, pubDecorator, item, collectionOwner, settings, first));
1656+
first = false;
1657+
}
16291658
}
16301659
}
16311660

@@ -1702,35 +1731,13 @@ private static IFragment GenerateContentForSenses(ConfigurableDictionaryNode con
17021731
var isThisSenseNumbered = ShouldThisSenseBeNumbered(filteredSenseCollection[0], config, filteredSenseCollection);
17031732
var bldr = settings.ContentGenerator.CreateFragment();
17041733

1705-
// TODO: Can handle separate sense paragraph styling here; likely will make the most sense to be handled wherever we deal with before/after content for senses.
1706-
// TODO: If handled here (or elsewhere w/in LcmGenerator), remove sense paragraph handling from the CssGenerator, otherwise sense paragraphs will be separated by two lines in the xhtml export.
1707-
/*// Only need to check once whether DisplayEachSenseInAParagraph is true -- value will be the same for each item in the loop
1708-
bool newParagraphPerSense;
1709-
if (senseNode?.DisplayEachSenseInAParagraph == true)
1710-
newParagraphPerSense = true;
1711-
else
1712-
newParagraphPerSense = false;
1713-
1714-
//If the first sense must be inline, we append the first sense without a preceding line break
1715-
int startSense = 0;
1716-
if (senseNode?.DisplayFirstSenseInline == true)
1717-
{
1718-
bldr.Append(GenerateSenseContent(config, publicationDecorator, filteredSenseCollection[startSense], isThisSenseNumbered, settings, isSameGrammaticalInfo, info));
1719-
startSense++;
1720-
}
1721-
1722-
for (int i = startSense; i < filteredSenseCollection.Count; i++)*/
1723-
1734+
bool first = true;
17241735
foreach (var item in filteredSenseCollection)
17251736
{
17261737
info.SenseCounter++;
1727-
1728-
// TODO: sense paragraphs
1729-
/*// If each sense belongs in a new paragraph, append a line break before the sense content.
1730-
if (newParagraphPerSense)
1731-
bldr.AppendBreak();*/
1732-
1733-
bldr.Append(GenerateSenseContent(config, publicationDecorator, item, isThisSenseNumbered, settings, isSameGrammaticalInfo, info));
1738+
bldr.Append(GenerateSenseContent(config, publicationDecorator, item, isThisSenseNumbered, settings,
1739+
isSameGrammaticalInfo, info, first));
1740+
first = false;
17341741
}
17351742
settings.StylesGenerator.AddStyles(config);
17361743
return bldr;
@@ -1876,7 +1883,7 @@ private static bool CheckIfAllGramInfoTheSame(ConfigurableDictionaryNode config,
18761883
}
18771884

18781885
private static IFragment GenerateSenseContent(ConfigurableDictionaryNode config, DictionaryPublicationDecorator publicationDecorator,
1879-
object item, bool isThisSenseNumbered, GeneratorSettings settings, bool isSameGrammaticalInfo, SenseInfo info)
1886+
object item, bool isThisSenseNumbered, GeneratorSettings settings, bool isSameGrammaticalInfo, SenseInfo info, bool first)
18801887
{
18811888
var senseNumberSpan = GenerateSenseNumberSpanIfNeeded(config, isThisSenseNumbered, ref info, settings);
18821889
var bldr = settings.ContentGenerator.CreateFragment();
@@ -1893,8 +1900,7 @@ private static IFragment GenerateSenseContent(ConfigurableDictionaryNode config,
18931900
if (bldr.Length() == 0)
18941901
return bldr;
18951902

1896-
return settings.ContentGenerator.AddSenseData(senseNumberSpan, IsBlockProperty(config), ((ICmObject)item).Owner.Guid,
1897-
bldr, GetCollectionItemClassAttribute(config));
1903+
return settings.ContentGenerator.AddSenseData(senseNumberSpan, ((ICmObject)item).Owner.Guid, config, bldr, first);
18981904
}
18991905

19001906
private static IFragment GeneratePictureContent(ConfigurableDictionaryNode config, DictionaryPublicationDecorator publicationDecorator,
@@ -1945,7 +1951,7 @@ private static IFragment GeneratePictureContent(ConfigurableDictionaryNode confi
19451951
}
19461952

19471953
private static IFragment GenerateCollectionItemContent(ConfigurableDictionaryNode config, DictionaryPublicationDecorator publicationDecorator,
1948-
object item, object collectionOwner, GeneratorSettings settings, ConfigurableDictionaryNode factoredTypeField = null)
1954+
object item, object collectionOwner, GeneratorSettings settings, bool first, ConfigurableDictionaryNode factoredTypeField = null)
19491955
{
19501956
if (item is IMultiStringAccessor)
19511957
return GenerateContentForStrings((IMultiStringAccessor)item, config, settings);
@@ -1979,7 +1985,7 @@ private static IFragment GenerateCollectionItemContent(ConfigurableDictionaryNod
19791985
if (bldr.Length() == 0)
19801986
return bldr;
19811987
var collectionContent = bldr;
1982-
return settings.ContentGenerator.AddCollectionItem(IsBlockProperty(config), GetCollectionItemClassAttribute(config), config, collectionContent);
1988+
return settings.ContentGenerator.AddCollectionItem(IsBlockProperty(config), GetCollectionItemClassAttribute(config), config, collectionContent, first);
19831989
}
19841990

19851991
private static void GenerateContentForLexRefCollection(ConfigurableDictionaryNode config,
@@ -2087,6 +2093,8 @@ private static IFragment GenerateCrossReferenceChildren(ConfigurableDictionaryNo
20872093
{
20882094
return settings.ContentGenerator.CreateFragment();
20892095
}
2096+
2097+
bool first = true;
20902098
foreach (var child in config.ReferencedOrDirectChildren.Where(c => c.IsEnabled))
20912099
{
20922100
switch (child.FieldDescription)
@@ -2097,7 +2105,8 @@ private static IFragment GenerateCrossReferenceChildren(ConfigurableDictionaryNo
20972105
{
20982106
var referenceItem = referenceListItem.Item2;
20992107
var targetItem = referenceListItem.Item1;
2100-
contentBldr.Append(GenerateCollectionItemContent(child, publicationDecorator, targetItem, referenceItem, settings));
2108+
contentBldr.Append(GenerateCollectionItemContent(child, publicationDecorator, targetItem, referenceItem, settings, first));
2109+
first = false;
21012110
}
21022111
if (contentBldr.Length > 0)
21032112
{
@@ -2252,7 +2261,7 @@ private static IFragment GenerateContentForICmObject(ICmObject propertyValue, Co
22522261
}
22532262

22542263
/// <summary>Write the class element in the span for an individual item in the collection</summary>
2255-
private static string GetCollectionItemClassAttribute(ConfigurableDictionaryNode config)
2264+
internal static string GetCollectionItemClassAttribute(ConfigurableDictionaryNode config)
22562265
{
22572266
var classAtt = CssGenerator.GetClassAttributeForCollectionItem(config);
22582267
if (config.ReferencedNode != null)
@@ -2487,8 +2496,7 @@ private static IFragment GenerateContentForValue(object field, object propertyVa
24872496
if (propertyValue is int)
24882497
{
24892498
var cssClassName = settings.StylesGenerator.AddStyles(config).Trim('.'); ;
2490-
return settings.ContentGenerator.AddProperty(cssClassName, false,
2491-
propertyValue.ToString());
2499+
return settings.ContentGenerator.AddProperty(cssClassName, false, propertyValue.ToString());
24922500
}
24932501
if (propertyValue is DateTime)
24942502
{

Src/xWorks/ILcmContentGenerator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ public interface ILcmContentGenerator
2222
IFragment GenerateGramInfoBeforeSensesContent(IFragment content, ConfigurableDictionaryNode config);
2323
IFragment GenerateGroupingNode(object field, string className, ConfigurableDictionaryNode config, DictionaryPublicationDecorator publicationDecorator, ConfiguredLcmGenerator.GeneratorSettings settings,
2424
Func<object, ConfigurableDictionaryNode, DictionaryPublicationDecorator, ConfiguredLcmGenerator.GeneratorSettings, IFragment> childContentGenerator);
25-
IFragment AddSenseData(IFragment senseNumberSpan, bool isBlockProperty, Guid ownerGuid, IFragment senseContent, string className);
26-
IFragment AddCollectionItem(bool isBlock, string collectionItemClass, ConfigurableDictionaryNode config,IFragment content);
25+
IFragment AddSenseData(IFragment senseNumberSpan, Guid ownerGuid, ConfigurableDictionaryNode config, IFragment senseContent, bool first);
26+
IFragment AddCollectionItem(bool isBlock, string collectionItemClass, ConfigurableDictionaryNode config, IFragment content, bool first);
2727
IFragment AddProperty(string className, bool isBlockProperty, string content);
2828
IFragment CreateFragment();
2929
IFragment CreateFragment(string str);

Src/xWorks/LcmJsonGenerator.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public IFragment GenerateGroupingNode(object field, string className, Configurab
117117
return new StringFragment();
118118
}
119119

120-
public IFragment AddCollectionItem(bool isBlock, string className, ConfigurableDictionaryNode config,IFragment content)
120+
public IFragment AddCollectionItem(bool isBlock, string className, ConfigurableDictionaryNode config,IFragment content, bool first)
121121
{
122122
var fragment = new StringFragment();
123123
fragment.StrBuilder.Append(content.IsNullOrEmpty() ? string.Empty : $"{{{content}}},");
@@ -431,8 +431,7 @@ public IFragment GenerateErrorContent(StringBuilder badStrBuilder)
431431
return new StringFragment($"\\u+0FFF\\u+0FFF\\u+0FFF{badStrBuilder}");
432432
}
433433

434-
public IFragment AddSenseData(IFragment senseNumberSpan, bool isBlock, Guid ownerGuid,
435-
IFragment senseContent, string className)
434+
public IFragment AddSenseData(IFragment senseNumberSpan, Guid ownerGuid, ConfigurableDictionaryNode config, IFragment senseContent, bool first)
436435
{
437436
var bldr = new StringBuilder();
438437
var fragment = new StringFragment(bldr);

0 commit comments

Comments
 (0)