Skip to content

Commit 83cb897

Browse files
authored
Merge pull request #13 from contentstack/next
Next
2 parents 8ffbfec + a15ba29 commit 83cb897

File tree

6 files changed

+112
-5
lines changed

6 files changed

+112
-5
lines changed

.github/workflows/sca-scan.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@ jobs:
66
security-sca:
77
runs-on: ubuntu-latest
88
steps:
9-
- uses: actions/checkout@master
9+
- name: Checkout repository
10+
uses: actions/checkout@master
11+
- uses: snyk/actions/setup@master
12+
- name: Setup .NET
13+
uses: actions/[email protected]
14+
- name: Restore dependencies
15+
run: dotnet restore ./Contentstack.Utils.sln
1016
- name: Run Snyk to check for vulnerabilities
11-
uses: snyk/actions/dotnet@master
17+
run: cd Contentstack.Utils && snyk test --fail-on=all
1218
env:
1319
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
14-
with:
15-
args: --fail-on=all

.talismanrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
fileignoreconfig:
22
- filename: Contentstack.Utils/Models/Options.cs
33
checksum: 3dc51f0de02429ef9a43b66e666ac4dbde41195e245f8ecc0094548ca8603245
4+
- filename: Contentstack.Utils/Utils.cs
5+
checksum: dfcfa04bedf8e5f9e74f68d02a9f8cb4e35de399e272da015453c6bc4c481e3f
46
version: ""

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11

2+
### Version: 1.0.3
3+
#### Date: Jul-10-2024
4+
- Editable tags added
5+
26
### Version: 1.0.2
37
#### Date: Mar-14-2024
48
- Style attributes supported in converted HTML.

Contentstack.Utils/Interfaces/IEmbeddedObject.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ string Title
2424
}
2525
}
2626

27+
public interface EditableEntry: IEmbeddedEntry
28+
{
29+
30+
string Locale { get; set; }
31+
32+
object this[string key] { get; set; }
33+
}
34+
2735
public interface IEmbeddedAsset: IEmbeddedObject
2836
{
2937
string Title

Contentstack.Utils/Utils.cs

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,5 +193,94 @@ private static IEmbeddedObject findEmbedded(Metadata metadata, List<IEmbeddedObj
193193
}
194194
return null;
195195
}
196+
197+
public static void addEditableTags(EditableEntry entry, string contentTypeUid, bool tagsAsObject, string locale = "en-us")
198+
{
199+
if (entry != null)
200+
entry["$"] = GetTag(entry, $"{contentTypeUid}.{entry.Uid}.{locale}", tagsAsObject, locale);
201+
}
202+
203+
private static Dictionary<string, object> GetTag(object content, string prefix, bool tagsAsObject, string locale)
204+
{
205+
var tags = new Dictionary<string, object>();
206+
foreach (var property in (Dictionary<string, object>)content)
207+
{
208+
var key = property.Key;
209+
var value = property.Value;
210+
211+
if (key == "$")
212+
continue;
213+
214+
switch (value)
215+
{
216+
case object obj when obj is object[] array:
217+
for (int index = 0; index < array.Length; index++)
218+
{
219+
object objValue = array[index];
220+
string childKey = $"{key}__{index}";
221+
string parentKey = $"{key}__parent";
222+
223+
tags[childKey] = GetTagsValue($"{prefix}.{key}.{index}", tagsAsObject);
224+
tags[parentKey] = GetParentTagsValue($"{prefix}.{key}", tagsAsObject);
225+
226+
if (objValue != null &&
227+
objValue.GetType().GetProperty("_content_type_uid") != null &&
228+
objValue.GetType().GetProperty("Uid") != null)
229+
{
230+
var typedObj = (EditableEntry)objValue;
231+
string locale_ = Convert.ToString(typedObj.GetType().GetProperty("locale").GetValue(typedObj));
232+
string ctUid = Convert.ToString(typedObj.GetType().GetProperty("_content_type_uid").GetValue(typedObj));
233+
string uid = Convert.ToString(typedObj.GetType().GetProperty("uid").GetValue(typedObj));
234+
string localeStr = "";
235+
if (locale_ != null)
236+
{
237+
localeStr = locale_;
238+
} else
239+
{
240+
localeStr = locale;
241+
}
242+
typedObj["$"] = GetTag(typedObj, $"{ctUid}.{uid}.{localeStr}", tagsAsObject, locale);
243+
}
244+
else if (value is object)
245+
{
246+
((EditableEntry)value)["$"] = GetTag(value, $"{prefix}.{key}.{index}", tagsAsObject, locale);
247+
}
248+
}
249+
tags[key] = GetTagsValue($"{prefix}.{key}", tagsAsObject);
250+
break;
251+
case object obj when obj != null:
252+
if (value != null)
253+
{
254+
((EditableEntry)value)["$"] = GetTag(value, $"{prefix}.{key}", tagsAsObject, locale);
255+
}
256+
break;
257+
}
258+
}
259+
return tags;
260+
}
261+
262+
private static object GetTagsValue(string dataValue, bool tagsAsObject)
263+
{
264+
if (tagsAsObject)
265+
{
266+
return new Dictionary<string, object> { { "data-cslp", dataValue } };
267+
}
268+
else
269+
{
270+
return $"data-cslp={dataValue}";
271+
}
272+
}
273+
274+
private static object GetParentTagsValue(string dataValue, bool tagsAsObject)
275+
{
276+
if (tagsAsObject)
277+
{
278+
return new Dictionary<string, object> { { "data-cslp-parent-field", dataValue } };
279+
}
280+
else
281+
{
282+
return $"data-cslp-parent-field={dataValue}";
283+
}
284+
}
196285
}
197286
}

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<Project>
22
<PropertyGroup>
3-
<Version>1.0.2</Version>
3+
<Version>1.0.3</Version>
44
</PropertyGroup>
55
</Project>

0 commit comments

Comments
 (0)