Пример #1
0
        public override void Render(ExtensionHtmlRenderer renderer, GitHistory gitHistory, IFormatState formatState)
        {
            var repo = new Repository(@"c:\users\ruudp\desktop\markdig");
            //var commits = repo.Commits.QueryBy("README.md").ToList();
            var sb = new StringBuilder();

            sb.AppendLine("<table>");
            sb.AppendLine("<thead>");
            sb.AppendLine("<tr>");
            foreach (var field in gitHistory.Fields)
            {
                sb.AppendLine($@"<td>{field.Name}</td>");
            }
            sb.AppendLine("</tr>");

            sb.AppendLine("</thead>");

            foreach (var tag in repo.Tags)
            {
                sb.AppendLine("<tr>");
                Commit commit = tag.Target as Commit;
                foreach (var field in gitHistory.Fields)
                {
                    var text = field.GetTagText(tag);
                    sb.AppendLine($@"<td>{text}</td>");
                }
                var sha = new string(commit.Sha.Take(7).ToArray());
                sb.AppendLine("</tr>");
            }
            sb.AppendLine("</table>");
            renderer.Write(sb.ToString());
        }
        public override void Render(ExtensionHtmlRenderer renderer, MsSqlTable msSqlTable, IFormatState formatState)
        {
            var table = GetTable(msSqlTable.Name);
            var sb    = new StringBuilder();

            sb.AppendLine($@"<table class='sql-table'>");

            sb.AppendLine($@"<thead>");
            sb.AppendLine($@"<tr><th colspan='2'>{msSqlTable.Name}</th></tr>");
            sb.AppendLine($@"</thead>");

            sb.AppendLine($@"<tbody class='sql-fields'>");
            foreach (var field in table.Fields)
            {
                sb.AppendLine($@"<tr>");
                if (field.IsNullable || field.IsPrimaryKey)
                {
                    string nullable   = field.IsNullable ? "*" : "";
                    string primaryKey = field.IsPrimaryKey ? "PK" : "";
                    sb.AppendLine($@"<td>{nullable}{primaryKey}</td>");
                }
                else
                {
                    sb.AppendLine($@"<td></td>");
                }
                sb.AppendLine($@"<td>{field.ToText()}</td></tr>");
            }
            sb.AppendLine($@"</tbody>");

            sb.AppendLine($@"<tbody class='sql-foreign-keys-header'>");
            sb.AppendLine($@"<tr><td colspan='2'>Foreign keys</td></tr>");
            sb.AppendLine($@"</tbody'>");
            sb.AppendLine($@"<tbody class='sql-foreign-keys'>");
            foreach (var fk in table.ForeignKeys)
            {
                sb.AppendLine($@"<tr><td></td><td>{fk.Name} {fk.Table}.{fk.Column} ↔ {fk.ReferencedTable}.{fk.ReferencedColumn}</td></tr>");
            }
            sb.AppendLine($@"</tbody>");

            sb.AppendLine($@"<tbody class='sql-indexes-header'>");
            sb.AppendLine($@"<tr><td colspan='2'>Indexes</td></tr>");
            sb.AppendLine($@"</tbody'>");
            sb.AppendLine($@"<tbody class='sql-indexes'>");
            foreach (var index in table.Indexes)
            {
                sb.AppendLine($@"<tr><td></td><td>{index.Name}({index.IndexType})</td></tr>");
            }
            sb.AppendLine($@"</tbody>");

            //sb.AppendLine($@"<tbody>");
            //sb.AppendLine($@"<tr><td>{table.PrimaryKey.Name}({table.PrimaryKey.Type})</td></tr>");
            //sb.AppendLine($@"</tbody>");
            sb.AppendLine("</table>");
            renderer.Write(sb.ToString());
        }
Пример #3
0
        public override void Render(ExtensionHtmlRenderer renderer, RequirementsTableName table, IFormatState formatState)
        {
            var package = _provider.GetElementsByPackage(new Path(table.Name));

            if (package != null)
            {
                var sb = new StringBuilder();
                Format(package, sb, formatState.HeadingLevel);
                renderer.Write(sb.ToString());
            }
        }
        private void RenderDiagram(Path diagramPath, ExtensionHtmlRenderer renderer)
        {
            var  folder = _renderSettings.ImageFolder;
            File file   = _provider.GetDiagramFile(diagramPath, folder);

            if (IO.File.Exists(file.AbsolutePath))
            {
                if (_renderSettings.EmbedImages)
                {
                    var bytes  = IO.File.ReadAllBytes(file.AbsolutePath);
                    var base64 = Convert.ToBase64String(bytes);
                    renderer.Write($@"<img src='data:image/png;base64,{base64}' />");
                }
                else
                {
                    renderer.Write($@"<img src='{file.RelativePath}' />");
                }
            }
            else
            {
                renderer.Write($@"<p>something went wrong retrieving the image [{diagramPath}]</p>");
            }
        }
Пример #5
0
        public override void Render(ExtensionHtmlRenderer renderer, PanZoomImage panZoomImage, IFormatState formatState)
        {
            var    bytes  = System.IO.File.ReadAllBytes(panZoomImage.Uri);
            var    base64 = Convert.ToBase64String(bytes);
            string html   = $@"
				<div>
					<img src='data:image/png;base64,{base64}' id='{_id}'>
				</div>
                <script>
					var panzoomEl{_id} = document.getElementById('{_id}');
					var panzoom{_id} = panzoom(panzoomEl{_id}, {{ bounds: true }});
				</script>"                ;

            _id++;
            renderer.Write(html);
        }
        public override void Render(ExtensionHtmlRenderer renderer, ExcelTableSelection excelSelection, IFormatState formatState)
        {
            var excelTable = new ExcelTable {
                Rows = new List <Row>()
            };

            using (var stream = IO.File.Open(excelSelection.FileName, IO.FileMode.Open, IO.FileAccess.Read))
            {
                using (var reader = ExcelReaderFactory.CreateReader(stream))
                {
                    DataSet       result = reader.AsDataSet();
                    DataTable     sheet  = result.Tables[excelSelection.Sheet];
                    CellReference from   = CellReference.Parse(excelSelection.CellsFrom);
                    CellReference to     = CellReference.Parse(excelSelection.CellsTo);
                    for (int i = from.Row - 1; i <= to.Row - 1; i++)
                    {
                        //var row = sheet.Rows[i];
                        var row = new Row {
                            Cells = new List <string>()
                        };
                        for (int j = from.Column; j <= to.Column; j++)
                        {
                            var value = sheet.Rows[i].ItemArray[j].ToString();
                            row.Cells.Add(value);
                        }
                        excelTable.Rows.Add(row);
                    }
                    // The result of each spreadsheet is in result.Tables
                }
            }
            var sb = new StringBuilder();

            sb.AppendLine("<table class='excel-table'>");
            foreach (var row in excelTable.Rows)
            {
                sb.AppendLine("<tr>");
                foreach (var column in row.Cells)
                {
                    sb.AppendLine($@"<td>{column}</td>");
                }
                sb.AppendLine("</tr>");
            }
            sb.AppendLine("</table>");
            renderer.Write(sb.ToString());
        }
        public override void Render(ExtensionHtmlRenderer renderer, Diagram diagram, IFormatState formatState)
        {
            var(element, elementsEnumerable) = _provider.GetBpmnElements(new Path(diagram.Name));
            var elements = elementsEnumerable.ToList();

            elements.Sort(new BpmnElement.AliasComparer());
            var sb = new StringBuilder();

            sb.AppendLine($@"<h1>{element.Name}</h1>");
            foreach (var e in elements)
            {
                string name = string.IsNullOrEmpty(e.Name) ? e.Alias : e.Name;
                sb.AppendLine($@"<h2>{name}</h2>");
                sb.AppendLine($@"<p>Lane: {e.Lane}</p>");
                sb.AppendLine($@"<p>Description:<br>");
                sb.AppendLine($@"{e.Notes}</p>");
            }
            renderer.Write(sb.ToString());
        }
        public override void Render(ExtensionHtmlRenderer renderer, TableOfContent model, IFormatState formatState)
        {
            List <Heading> headings = renderer.ContainerBlock.GetHeadings();
            var            sb       = new StringBuilder();

            sb.AppendLine("<nav>");
            sb.AppendLine("<div class='title'>Contents</div>");
            foreach (var heading in headings)
            {
                var id = HtmlHelper.Unescape(heading.HeadingBlock.GetAttributes().Id);
                sb.AppendLine($@"<a href='#{id}' class='nav-level-{heading.Level}'>{heading.Title}</a>");
            }
            sb.AppendLine("</nav>");
            renderer.Write(sb.ToString());

            var dynamicCss = GenerateCss(model);

            if (dynamicCss != null)
            {
                renderer.RegisterDynamicCss(dynamicCss);
            }
        }
Пример #9
0
        public override void Render(ExtensionHtmlRenderer renderer, BpmnGraph bpmnGraph, IFormatState formatState)
        {
            var sb      = new StringBuilder();
            var bpmnXml = IO.File.ReadAllText(bpmnGraph.FileUri);

            // Loading BPMN xml from filesystem results in a CORS error
            sb.AppendLine($@"
				<div class='box' style='height: {bpmnGraph.Height};'>
				  <div class='row content' id='canvas' ></div>
				</div>
				<script>
					var nav = document.getElementById('nav');
					var bpmnViewer = new BpmnJS({{ container: '#canvas' }});
					bpmnViewer.importXML(`{bpmnXml}`, function(err) {{
						if (err) {{
							return console.error('could not import BPMN 2.0 diagram', err);
						}}
						//var canvas = bpmnViewer.get('canvas');
						//canvas.zoom('fit-height');
					}});
				</script>"                );
            renderer.Write(sb.ToString());
        }
Пример #10
0
        public override void Render(ExtensionHtmlRenderer renderer, FM.Folder model, IFormatState formatState)
        {
            void write(string value) => renderer.Write(value);

            Output(model, 1, write);
        }
Пример #11
0
        public override void Render(ExtensionHtmlRenderer renderer, DatamodelApi model, IFormatState formatState)
        {
            var file = new File(_renderSettings.SourceFolder, model.FileName ?? "schema.json");

            //if (file.Exists() && !_renderSettings.ForceRefreshData)
            //{
            //	return;
            //}
            bool IncludeTable(Element e)
            {
                if (e.Stereotype != "table" && e.Type != "Enumeration")
                {
                    return(false);
                }
                return(e.TaggedValue("IsMigrationApi"));
            }

            bool IncludeEnum(Element e)
            {
                return(e.Type == "Enumeration" && e.TaggedValue("IsMigrationApi"));
            }

            var path   = new Path(model.PackagePath);
            var tables = _eaProvider
                         .GetElements(path, IncludeTable, "DataModelApiTables", true);

            var schema = new JSchema
            {
                SchemaVersion = new Uri("http://json-schema.org/draft-07/schema#"),
                Type          = JSchemaType.Object,
                Title         = "SOSPES Permit datamodel migration API",
            };
            var enums          = new Dictionary <string, IList <JToken> >();
            var requiredTables = new List <string>();
            IEnumerable <Element> enumElements = null;

            if (model.EnumsPackagePath != null)
            {
                var enumPath = new Path(model.EnumsPackagePath);
                enumElements = _eaProvider.GetElements(enumPath, IncludeEnum, "DataModelApiEnums", true);
            }
            else
            {
                enumElements = tables.Where(t => t.Type == "Enumeration");
            }

            foreach (var table in enumElements)
            {
                var values = new List <JToken>();
                foreach (var enumValue in table.Attributes)
                {
                    values.Add(enumValue.Name);
                }
                foreach (var enumValue in table.Attributes)
                {
                    values.Add(enumValue.DefaultValue);
                }
                enums.Add(table.Name, values);
            }
            foreach (var table in tables.Where(t => t.Type != "Enumeration"))
            {
                var tableArraySchema = new JSchema
                {
                    Type = JSchemaType.Array
                };
                void transform(MarkdownDocument md)
                {
                    md.IncreaseHeadingLevel(3);
                }

                var sanitizedNotes = table.Notes.Replace("\\r\\n", "\n");
                var notes          = Helper.Converter2(table.Notes, transform, renderer.Pipeline);
                var tableSchema    = new JSchema
                {
                    Description = notes,
                    Title       = table.Name,
                    Type        = JSchemaType.Object,
                    Format      = "Date-time",
                };
                tableArraySchema.Items.Add(tableSchema);
                var required = new List <string>();
                //
                foreach (var attribute in table.Attributes)
                {
                    if (!attribute.TaggedValue("IsMigrationApi"))
                    {
                        continue;
                    }

                    bool isEnum = attribute.Name.EndsWith("EnumId");
                    var(schemaType, format) = ToJsonType(attribute);
                    var columnSchema = new JSchema
                    {
                        Type        = isEnum ? JSchemaType.Integer | JSchemaType.String : schemaType,
                        Description = attribute.Notes,
                        Format      = format
                    };
                    if (isEnum)
                    {
                        string         enumName = attribute.Name.Replace("EnumId", string.Empty);
                        IList <JToken> @enum    = enums[enumName];
                        foreach (var enumValue in @enum)
                        {
                            columnSchema.Enum.Add(enumValue);
                        }
                        //var enumValueComments = new JSchema
                        //{

                        //};
                        //JToken derpy = "";
                        //enumValueComments.Properties.Add("enumValueName", (JToken)"");
                        //columnSchema.Properties.Add("meta:enum", enumValueComments);
                    }
                    if (attribute.Length != 0)
                    {
                        columnSchema.MaximumLength = attribute.Length;
                    }
                    if (!attribute.Nullable)
                    {
                        required.Add(attribute.Name);
                    }
                    tableSchema.Properties.Add(attribute.Name, columnSchema);
                }
                if (table.TaggedValue("IncludeCreatedDateTimeInMigrationApi"))
                {
                    var createdDateTime = new JSchema
                    {
                        Type        = JSchemaType.String,
                        Description = "Creation DateTime"
                    };
                    tableSchema.Properties.Add("CreatedDateTime", createdDateTime);
                }
                required.ForEach(r => tableSchema.Required.Add(r));
                schema.Properties.Add(table.Name + "List", tableArraySchema);
                requiredTables.Add(table.Name);
            }
            requiredTables.ForEach(rt => schema.Required.Add(rt));
            renderer.Write(schema.ToString());
            using (System.IO.StreamWriter textWriter = System.IO.File.CreateText(file.AbsolutePath))
                using (var jsonWriter = new JsonTextWriter(textWriter))
                {
                    jsonWriter.Formatting = Formatting.Indented;
                    schema.WriteTo(jsonWriter);
                    jsonWriter.Flush();
                }
        }
Пример #12
0
        public override void Render(ExtensionHtmlRenderer renderer, GitGraph gitGraph, IFormatState formatState)
        {
            // first commit should have a branch name
            var    script        = new StringBuilder();
            var    branches      = new HashSet <BranchName>();
            string currentBranch = null;

            foreach (var commit in gitGraph.Commits)
            {
                if (!branches.Contains(commit.BranchName))
                {
                    branches.Add(commit.BranchName);
                    var branch = commit.BranchName.Name;
                    currentBranch = branch;
                    script.AppendLine($"const {branch} = gitGraph.branch('{branch}');");
                }
                if (commit.Branch != null && !branches.Contains(commit.Branch))
                {
                    branches.Add(commit.Branch);
                    var branch = commit.Branch.Name;
                    currentBranch = branch;
                    script.AppendLine($"const {branch} = gitGraph.branch('{branch}');");
                }
                string authorText = null;
                if (commit.Author == null)
                {
                    authorText = "null";
                }
                else if (commit.Author != null && commit.Author.Email == null)
                {
                    authorText = $@"'{commit.Author.Name}'";
                }
                else if (commit.Author != null && commit.Author.Email == null)
                {
                    authorText = $@"'{commit.Author.Name} <{commit.Author.Email}>'";
                }
                string author = null;
                if (!string.IsNullOrEmpty(authorText))
                {
                    author = $@"author: {authorText}";
                }

                string tag = null;
                if (commit.Tag != null)
                {
                    script.AppendLine($@"{currentBranch}.tag('{commit.Tag.Name}')");
                }
                var    subject    = $@"subject: '{commit.Title}'";
                string commitArgs = null;
                if (author != null)
                {
                    commitArgs = $@"{{{subject}, {author}}}";
                }
                else
                {
                    commitArgs = $@"{{{subject}}}";
                }
                script.AppendLine($"{commit.BranchName.Name}.commit({commitArgs});");
                if (commit.Merge != null)
                {
                    script.AppendLine($"{commit.Merge.Name}.merge('{commit.BranchName.Name}');");
                }
            }
            var sb = new StringBuilder();

            sb.Append($@"
                <div>
                    <div id='derpy'></div>
                    <script type='text/javascript'>
                        const graphContainer = document.getElementById('derpy');
                        const gitGraph = GitgraphJS.createGitgraph(graphContainer);
                        {script.ToString()}
                    </script>
                </div>");
            renderer.Write(sb.ToString());
        }
        public override void Render(ExtensionHtmlRenderer renderer, KeyboardKeys keyboardKeys, IFormatState formatState)
        {
            var html = string.Join(string.Empty, keyboardKeys.Keys.Select(k => $@"<kbd>{k}</kbd>"));

            renderer.Write(html);
        }