Skip to content

Commit a9fd16f

Browse files
committed
added features
1 parent 0add231 commit a9fd16f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+961
-36
lines changed

DescribeCompiler/DescribeCompiler.cs

Lines changed: 411 additions & 3 deletions
Large diffs are not rendered by default.

DescribeCompiler/DescribeCompiler.csproj

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@
6060
</ItemGroup>
6161
<ItemGroup>
6262
<Content Include="describe.ico" />
63+
<EmbeddedResource Include="Translations\Item.html" />
64+
<EmbeddedResource Include="Translations\ItemColored.html" />
65+
<EmbeddedResource Include="Translations\ItemComment.html" />
66+
<EmbeddedResource Include="Translations\ItemEmpty.html" />
67+
<EmbeddedResource Include="Translations\Page.html" />
68+
<EmbeddedResource Include="Translations\Production.html" />
69+
<EmbeddedResource Include="Translations\Root.html" />
6370
<EmbeddedResource Include="Translations\Link.html" />
64-
<EmbeddedResource Include="Translations\NotSpacedItemColored.html" />
65-
<EmbeddedResource Include="Translations\NotSpacedItemComment.html" />
66-
<EmbeddedResource Include="Translations\NotSpacedItemEmpty.html" />
67-
<EmbeddedResource Include="Translations\NotSpacedItem.html" />
68-
<EmbeddedResource Include="Translations\NotSpacedPage.html" />
69-
<EmbeddedResource Include="Translations\NotSpacedProduction.html" />
70-
<EmbeddedResource Include="Translations\NotSpacedRoot.html" />
7171
</ItemGroup>
7272
<ItemGroup>
7373
<ProjectReference Include="..\GoldParserEngine\GoldParserEngine\GoldParserEngine.csproj">

DescribeCompiler/ResourceUtil.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,51 @@ public static string ExtractResource_String(string filename)
5555
}
5656
}
5757
}
58+
59+
/// <summary>
60+
/// Retrieve a string that is an embedded resource
61+
/// </summary>
62+
/// <param name="filename">The name of the string resource, without extention</param>
63+
/// <returns>The retrieved string</returns>
64+
public static string ExtractResourceByName_String(string filename)
65+
{
66+
System.Reflection.Assembly a = System.Reflection.Assembly.GetExecutingAssembly();
67+
68+
string[] resNames = a.GetManifestResourceNames();
69+
string resourceName = null;
70+
foreach (string s in resNames)
71+
{
72+
string[] sep = s.Split('.');
73+
if (sep.Length < 1) continue;
74+
if (sep.Length >= 2 && sep[sep.Length - 2] == filename)
75+
{
76+
resourceName = s;
77+
break;
78+
}
79+
}
80+
if(resourceName == null)
81+
{
82+
foreach (string s in resNames)
83+
{
84+
string[] sep = s.Split('.');
85+
if (sep.Length < 1) continue;
86+
if (sep.Length >= 2 && sep[sep.Length - 2] == filename)
87+
{
88+
resourceName = s;
89+
break;
90+
}
91+
}
92+
}
93+
94+
using (Stream resFilestream = a.GetManifestResourceStream(resourceName))
95+
{
96+
if (resFilestream == null) return null;
97+
using (StreamReader reader = new StreamReader(resFilestream))
98+
{
99+
string result = reader.ReadToEnd();
100+
return result;
101+
}
102+
}
103+
}
58104
}
59105
}

DescribeCompiler/Translations.cs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77

88
namespace DescribeCompiler
99
{
10-
public static class Translations
10+
public interface IUnfoldTranslator
11+
{
12+
string TranslateUnfold(DescribeUnfold u);
13+
}
14+
public class UnfoldTranslator : IUnfoldTranslator
1115
{
1216
static string pageTemplate;
1317
static string rootTemplate;
@@ -18,18 +22,18 @@ public static class Translations
1822
static string prodTemplate;
1923
static string linkTemplate;
2024

21-
static Translations()
25+
static UnfoldTranslator()
2226
{
23-
pageTemplate = ResourceUtil.ExtractResource_String(@"NotSpacedPage.html");
24-
rootTemplate = ResourceUtil.ExtractResource_String(@"NotSpacedRoot.html");
25-
prodTemplate = ResourceUtil.ExtractResource_String(@"NotSpacedProduction.html");
27+
pageTemplate = ResourceUtil.ExtractResourceByName_String(@"Page");
28+
rootTemplate = ResourceUtil.ExtractResourceByName_String(@"Root");
29+
prodTemplate = ResourceUtil.ExtractResourceByName_String(@"Production");
2630

27-
itemTemplate = ResourceUtil.ExtractResource_String(@"NotSpacedItem.html");
28-
emptyItemTemplate = ResourceUtil.ExtractResource_String(@"NotSpacedItemEmpty.html");
29-
commentItemTemplate = ResourceUtil.ExtractResource_String(@"NotSpacedItemComment.html");
30-
coloredItemTemplate = ResourceUtil.ExtractResource_String(@"NotSpacedItemColored.html");
31+
itemTemplate = ResourceUtil.ExtractResourceByName_String(@"Item");
32+
emptyItemTemplate = ResourceUtil.ExtractResourceByName_String(@"ItemEmpty");
33+
commentItemTemplate = ResourceUtil.ExtractResourceByName_String(@"ItemComment");
34+
coloredItemTemplate = ResourceUtil.ExtractResourceByName_String(@"ItemColored");
3135

32-
linkTemplate = ResourceUtil.ExtractResource_String(@"Link.html");
36+
linkTemplate = ResourceUtil.ExtractResourceByName_String(@"Link");
3337
}
3438

3539
//http://xahlee.info/comp/unicode_circled_numbers.html
@@ -233,7 +237,7 @@ static Translations()
233237
/// </summary>
234238
/// <param name="u">The unfold to be translated</param>
235239
/// <returns>The generated html code</returns>
236-
public static string TranslateUnfold(DescribeUnfold u)
240+
public string TranslateUnfold(DescribeUnfold u)
237241
{
238242
string data = "";
239243
foreach (string key in u.PrimaryProductions)
@@ -247,12 +251,12 @@ public static string TranslateUnfold(DescribeUnfold u)
247251
return pt;
248252
}
249253

250-
static string TranslateProductionOrItem(DescribeUnfold u, string id)
254+
string TranslateProductionOrItem(DescribeUnfold u, string id)
251255
{
252256
if (u.Productions.ContainsKey(id)) return TranslateProduction(u, id);
253257
else return TranslateItem(u, id);
254258
}
255-
static string TranslateProduction(DescribeUnfold u, string id)
259+
string TranslateProduction(DescribeUnfold u, string id)
256260
{
257261
List<string> li = new List<string>();
258262
if (u.Productions.ContainsKey(id)) li = u.Productions[id];
@@ -291,7 +295,7 @@ static string TranslateProduction(DescribeUnfold u, string id)
291295
pt = pt.Replace("{ITEMS}", items);
292296
return pt;
293297
}
294-
static string TranslateItem(DescribeUnfold u, string id)
298+
string TranslateItem(DescribeUnfold u, string id)
295299
{
296300
//do links
297301
//we are assuming there would be no backslashes in links
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<li>{ITEM}</li>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<li style="color: {COLOR};">{ITEM}</li>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<li style="color: green; font-style: italic;">{ITEM}</li>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<li>&nbsp;</li>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<!DOCTYPE html><html lang="en"><head><meta name="description" content="Created by #Describe TestGadget v 8.0"><meta charset="utf-8"><title>World in lists - Describe Compiler v0.9</title><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="author" content=""><style>.listree-submenu-heading{cursor:pointer}ul.listree{list-style:none}ul.listree-submenu-items{list-style:none;border-left:1px dashed #000;white-space:nowrap;margin-right:4px;padding-left:20px}div.listree-submenu-heading.collapsed:before{content:"+";margin-right:4px}div.listree-submenu-heading.expanded:before{content:"-";margin-right:4px}.scrollable-menu{height:auto;max-width:800px;overflow-y:hidden}</style></head><body>{DATA}<script>!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).listree=t()}(this,(function(){"use strict";return function(){const e=document.getElementsByClassName("listree-submenu-heading");Array.from(e).forEach((function(e){e.classList.add("collapsed"),e.nextElementSibling.style.display="none",e.addEventListener("click",(function(t){t.preventDefault();const n=t.target.nextElementSibling;"none"==n.style.display?(e.classList.remove("collapsed"),e.classList.add("expanded"),n.style.display="block"):(e.classList.remove("expanded"),e.classList.add("collapsed"),n.style.display="none"),t.stopPropagation()}))}))}}));listree();</script></body></html>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<li><div class="listree-submenu-heading">{TITLE}</div><ul class="listree-submenu-items"><br />{ITEMS}<br /></ul></li>

0 commit comments

Comments
 (0)