From 4918f3cff14f38653bd060fefbc46f5f130f5944 Mon Sep 17 00:00:00 2001 From: Byron Mayne Date: Mon, 11 Sep 2023 21:11:32 -0400 Subject: [PATCH] Updated the code examples to use remark-code-import This copies the source code from the solutions to make sure it compiles and does not go out of date. --- documentation/generic/ring_buffer.md | 37 +----------- .../generic/specialized/_category_.yml | 2 + .../generic/specialized/ordered_dictionary.md | 25 +-------- docusaurus/docusaurus.config.js | 6 ++ docusaurus/package.json | 4 +- docusaurus/yarn.lock | 56 ++++++++++++++++++- .../Generic/RingBufferSandbox.cs | 45 +++++++-------- .../Specialized/OrderedDictionarySandbox.cs | 33 +++++++++++ 8 files changed, 122 insertions(+), 86 deletions(-) create mode 100644 documentation/generic/specialized/_category_.yml create mode 100644 src/Extended.Collections.Playground/Generic/Specialized/OrderedDictionarySandbox.cs diff --git a/documentation/generic/ring_buffer.md b/documentation/generic/ring_buffer.md index a5af049..745bea9 100644 --- a/documentation/generic/ring_buffer.md +++ b/documentation/generic/ring_buffer.md @@ -3,39 +3,6 @@ A ring buffer is a data structure that efficiently manages a fixed-size, cyclically-referenced buffer, allowing for constant-time insertions and removals while overwriting the oldest data when full. -```csharp title=RingBufferSandbox.cs -using Extended.Collections.Generic; - -namespace Extended.Collections.Playground.Generic -{ - public class RingBufferSandbox : Sandbox - { - private readonly RingBuffer m_buffer; - - public RingBufferSandbox() - { - m_buffer = new RingBuffer(3); - } - - protected override void Run() - { - m_buffer.Add("A"); - m_buffer.Add("B"); - m_buffer.Add("C"); - Logger.Information("1. {Buffer}", m_buffer); // 1. [ "A", "B", "C" ] - - m_buffer.Add("D"); - Logger.Information("2. {Buffer}", m_buffer); // 2. [ "B", "C", "D" ] - - m_buffer.Remove("C"); - Logger.Information("3. {Buffer}", m_buffer); // 3. [ "B", "D" ] - - m_buffer.Add("E"); - Logger.Information("4. {Buffer}", m_buffer); // 4. [ "B", "D", "E" ] - - m_buffer.Clear(); - Logger.Information("5. {Buffer}", m_buffer); // [ ] - } - } -} +```csharp file=../../src/Extended.Collections.Playground\Generic\RingBufferSandbox.cs#L2- +// Imported ``` \ No newline at end of file diff --git a/documentation/generic/specialized/_category_.yml b/documentation/generic/specialized/_category_.yml new file mode 100644 index 0000000..76a60ab --- /dev/null +++ b/documentation/generic/specialized/_category_.yml @@ -0,0 +1,2 @@ +label: 'Specialized' +position: 1 \ No newline at end of file diff --git a/documentation/generic/specialized/ordered_dictionary.md b/documentation/generic/specialized/ordered_dictionary.md index 3b9f114..8e41379 100644 --- a/documentation/generic/specialized/ordered_dictionary.md +++ b/documentation/generic/specialized/ordered_dictionary.md @@ -13,28 +13,7 @@ Cons: ### Hypothetical Use Case: Suppose you are building a task management application, and you need to maintain a list of tasks for a project while preserving the order in which they were added. An OrderedDictionary can be useful in this scenario to store and manage tasks associated with a project. -```cs -using System; -using System.Collections.Specialized; -class Program -{ - static void Main() - { - // Create an OrderedDictionary to store tasks for a project. - OrderedDictionary projectTasks = new OrderedDictionary(); - - // Add tasks to the project in a specific order. - projectTasks.Add("Task1", "Complete research"); - projectTasks.Add("Task2", "Write documentation"); - projectTasks.Add("Task3", "Test functionality"); - - // Access tasks by their keys while maintaining their order. - Console.WriteLine("Project Tasks:"); - foreach (DictionaryEntry entry in projectTasks) - { - Console.WriteLine($"{entry.Key}: {entry.Value}"); - } - } -} +```csharp file=../../../src/Extended.Collections.Playground\Generic\Specialized\OrderedDictionarySandbox.cs#L2- +// Imported ``` \ No newline at end of file diff --git a/docusaurus/docusaurus.config.js b/docusaurus/docusaurus.config.js index e697a75..950fac8 100644 --- a/docusaurus/docusaurus.config.js +++ b/docusaurus/docusaurus.config.js @@ -1,4 +1,5 @@ // @ts-check +const path = require('path') const lightCodeTheme = require('prism-react-renderer/themes/github'); const darkCodeTheme = require('prism-react-renderer/themes/oceanicNext'); @@ -43,6 +44,11 @@ const config = { breadcrumbs: true, routeBasePath: '/', showLastUpdateTime: true, + remarkPlugins: [ + [require('remark-code-import'), { + removeRedundantIndentations: true, + }] + ], editUrl: ({docPath}) => `https://github.com/ByronMayne/Extended.Collections/edit/main/documentation/${docPath}`, diff --git a/docusaurus/package.json b/docusaurus/package.json index 919de1e..4897974 100644 --- a/docusaurus/package.json +++ b/docusaurus/package.json @@ -25,7 +25,9 @@ "clsx": "^1.2.1", "prism-react-renderer": "^1.3.5", "react": "^17.0.2", - "react-dom": "^17.0.2" + "react-dom": "^17.0.2", + "remark-code-import": "0.4.0", + "remark-jargon": "^2.22.2" }, "devDependencies": { "@docusaurus/module-type-aliases": "2.4.1", diff --git a/docusaurus/yarn.lock b/docusaurus/yarn.lock index 08b2518..82195c4 100644 --- a/docusaurus/yarn.lock +++ b/docusaurus/yarn.lock @@ -6338,6 +6338,14 @@ relateurl@^0.2.7: resolved "https://registry.yarnpkg.com/relateurl/-/relateurl-0.2.7.tgz#54dbf377e51440aca90a4cd274600d3ff2d888a9" integrity sha512-G08Dxvm4iDN3MLM0EsP62EDV9IuhXPR6blNz6Utcp7zyV3tr4HVNINt6MpaRWbxoOHT3Q7YN2P+jaHX8vUbgog== +remark-code-import@0.4.0: + version "0.4.0" + resolved "https://registry.yarnpkg.com/remark-code-import/-/remark-code-import-0.4.0.tgz#94cbfe74087c55a84e65f0a972c0977cac8fc7f6" + integrity sha512-3UHRIfr7+kRBGOy6Bzp4c1dl8BLCLv+saBTAgW4+lPfs56vV6yBhO038i6MJTEoyXX1zli7l8tMGIHbYANdtZg== + dependencies: + to-gatsby-remark-plugin "^0.1.0" + unist-util-visit "^2.0.1" + remark-emoji@^2.2.0: version "2.2.0" resolved "https://registry.yarnpkg.com/remark-emoji/-/remark-emoji-2.2.0.tgz#1c702090a1525da5b80e15a8f963ef2c8236cac7" @@ -6352,6 +6360,13 @@ remark-footnotes@2.0.0: resolved "https://registry.yarnpkg.com/remark-footnotes/-/remark-footnotes-2.0.0.tgz#9001c4c2ffebba55695d2dd80ffb8b82f7e6303f" integrity sha512-3Clt8ZMH75Ayjp9q4CorNeyjwIxHFcTkaektplKGl2A1jNGEUey8cKL0ZC5vJwfcD5GFGsNLImLG/NGzWIzoMQ== +remark-jargon@^2.22.2: + version "2.22.2" + resolved "https://registry.yarnpkg.com/remark-jargon/-/remark-jargon-2.22.2.tgz#d81cefe6ecd419488c7ac1936add4c6d9e958ea0" + integrity sha512-TRQozoCzaOt9dNlgdffWVujZP5FRO+SSDHAUDVqYZi110J7HbcCiYTvIOJdwH2roMtQGd0bnGWibDyRCjeXlZA== + dependencies: + unist-util-visit "^4.1.0" + remark-mdx@1.6.22: version "1.6.22" resolved "https://registry.yarnpkg.com/remark-mdx/-/remark-mdx-1.6.22.tgz#06a8dab07dcfdd57f3373af7f86bd0e992108bbd" @@ -7056,6 +7071,13 @@ to-fast-properties@^2.0.0: resolved "https://registry.yarnpkg.com/to-fast-properties/-/to-fast-properties-2.0.0.tgz#dc5e698cbd079265bc73e0377681a4e4e83f616e" integrity sha512-/OaKK0xYrs3DmxRYqL/yDc+FxFUVYhDlXMhRmv3z915w2HF1tnN1omB354j8VUGO/hbRzyD6Y3sA7v7GS/ceog== +to-gatsby-remark-plugin@^0.1.0: + version "0.1.0" + resolved "https://registry.yarnpkg.com/to-gatsby-remark-plugin/-/to-gatsby-remark-plugin-0.1.0.tgz#34167b2c3cf3209745cf97e5a488042586f9990d" + integrity sha512-blmhJ/gIrytWnWLgPSRCkhCPeki6UBK2daa3k9mGahN7GjwHu8KrS7F70MvwlsG7IE794JLgwAdCbi4hU4faFQ== + dependencies: + to-vfile "^6.1.0" + to-readable-stream@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/to-readable-stream/-/to-readable-stream-1.0.0.tgz#ce0aa0c2f3df6adf852efb404a783e77c0475771" @@ -7068,6 +7090,14 @@ to-regex-range@^5.0.1: dependencies: is-number "^7.0.0" +to-vfile@^6.1.0: + version "6.1.0" + resolved "https://registry.yarnpkg.com/to-vfile/-/to-vfile-6.1.0.tgz#5f7a3f65813c2c4e34ee1f7643a5646344627699" + integrity sha512-BxX8EkCxOAZe+D/ToHdDsJcVI4HqQfmw0tCkp31zf3dNP/XWIAjU4CmeuSwsSoOzOTqHPOL0KUzyZqJplkD0Qw== + dependencies: + is-buffer "^2.0.0" + vfile "^4.0.0" + toidentifier@1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/toidentifier/-/toidentifier-1.0.1.tgz#3be34321a88a820ed1bd80dfaa33e479fbb8dd35" @@ -7215,6 +7245,13 @@ unist-util-is@^4.0.0: resolved "https://registry.yarnpkg.com/unist-util-is/-/unist-util-is-4.1.0.tgz#976e5f462a7a5de73d94b706bac1b90671b57797" integrity sha512-ZOQSsnce92GrxSqlnEEseX0gi7GH9zTJZ0p9dtu87WRb/37mMPO2Ilx1s/t9vBHrFhbgweUwb+t7cIn5dxPhZg== +unist-util-is@^5.0.0: + version "5.2.1" + resolved "https://registry.yarnpkg.com/unist-util-is/-/unist-util-is-5.2.1.tgz#b74960e145c18dcb6226bc57933597f5486deae9" + integrity sha512-u9njyyfEh43npf1M+yGKDGVPbY/JWEemg5nH05ncKPfi+kBbKBJoTdsogMu33uhytuLlv9y0O7GH7fEdwLdLQw== + dependencies: + "@types/unist" "^2.0.0" + unist-util-position@^3.0.0: version "3.1.0" resolved "https://registry.yarnpkg.com/unist-util-position/-/unist-util-position-3.1.0.tgz#1c42ee6301f8d52f47d14f62bbdb796571fa2d47" @@ -7249,7 +7286,15 @@ unist-util-visit-parents@^3.0.0: "@types/unist" "^2.0.0" unist-util-is "^4.0.0" -unist-util-visit@2.0.3, unist-util-visit@^2.0.0, unist-util-visit@^2.0.3: +unist-util-visit-parents@^5.1.1: + version "5.1.3" + resolved "https://registry.yarnpkg.com/unist-util-visit-parents/-/unist-util-visit-parents-5.1.3.tgz#b4520811b0ca34285633785045df7a8d6776cfeb" + integrity sha512-x6+y8g7wWMyQhL1iZfhIPhDAs7Xwbn9nRosDXl7qoPTSCy0yNxnKc+hWokFifWQIDGi154rdUqKvbCa4+1kLhg== + dependencies: + "@types/unist" "^2.0.0" + unist-util-is "^5.0.0" + +unist-util-visit@2.0.3, unist-util-visit@^2.0.0, unist-util-visit@^2.0.1, unist-util-visit@^2.0.3: version "2.0.3" resolved "https://registry.yarnpkg.com/unist-util-visit/-/unist-util-visit-2.0.3.tgz#c3703893146df47203bb8a9795af47d7b971208c" integrity sha512-iJ4/RczbJMkD0712mGktuGpm/U4By4FfDonL7N/9tATGIF4imikjOuagyMY53tnZq3NP6BcmlrHhEKAfGWjh7Q== @@ -7258,6 +7303,15 @@ unist-util-visit@2.0.3, unist-util-visit@^2.0.0, unist-util-visit@^2.0.3: unist-util-is "^4.0.0" unist-util-visit-parents "^3.0.0" +unist-util-visit@^4.1.0: + version "4.1.2" + resolved "https://registry.yarnpkg.com/unist-util-visit/-/unist-util-visit-4.1.2.tgz#125a42d1eb876283715a3cb5cceaa531828c72e2" + integrity sha512-MSd8OUGISqHdVvfY9TPhyK2VdUrPgxkUtWSuMHF6XAAFuL4LokseigBnZtPnJMu+FbynTkFNnFlyjxpVKujMRg== + dependencies: + "@types/unist" "^2.0.0" + unist-util-is "^5.0.0" + unist-util-visit-parents "^5.1.1" + universalify@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/universalify/-/universalify-2.0.0.tgz#75a4984efedc4b08975c5aeb73f530d02df25717" diff --git a/src/Extended.Collections.Playground/Generic/RingBufferSandbox.cs b/src/Extended.Collections.Playground/Generic/RingBufferSandbox.cs index e18bb5b..34c16f5 100644 --- a/src/Extended.Collections.Playground/Generic/RingBufferSandbox.cs +++ b/src/Extended.Collections.Playground/Generic/RingBufferSandbox.cs @@ -1,34 +1,27 @@ -using Extended.Collections.Generic; +namespace Extended.Collections.Playground.Generic; +using Extended.Collections.Generic; -namespace Extended.Collections.Playground.Generic +public class RingBufferSandbox : Sandbox { - public class RingBufferSandbox : Sandbox - { - private readonly RingBuffer m_buffer; - - public RingBufferSandbox() - { - m_buffer = new RingBuffer(3); - } + private readonly RingBuffer m_buffer = new (3); - protected override void Run() - { - m_buffer.Add("A"); - m_buffer.Add("B"); - m_buffer.Add("C"); - Logger.Information("1. {Buffer}", m_buffer); // 1. [ "A", "B", "C" ] + protected override void Run() + { + m_buffer.Add("A"); + m_buffer.Add("B"); + m_buffer.Add("C"); + Logger.Information("1. {Buffer}", m_buffer); // 1. [ "A", "B", "C" ] - m_buffer.Add("D"); - Logger.Information("2. {Buffer}", m_buffer); // 2. [ "B", "C", "D" ] + m_buffer.Add("D"); + Logger.Information("2. {Buffer}", m_buffer); // 2. [ "B", "C", "D" ] - m_buffer.Remove("C"); - Logger.Information("3. {Buffer}", m_buffer); // 3. [ "B", "D" ] + m_buffer.Remove("C"); + Logger.Information("3. {Buffer}", m_buffer); // 3. [ "B", "D" ] - m_buffer.Add("E"); - Logger.Information("4. {Buffer}", m_buffer); // 4. [ "B", "D", "E" ] + m_buffer.Add("E"); + Logger.Information("4. {Buffer}", m_buffer); // 4. [ "B", "D", "E" ] - m_buffer.Clear(); - Logger.Information("5. {Buffer}", m_buffer); // [ ] - } + m_buffer.Clear(); + Logger.Information("5. {Buffer}", m_buffer); // [ ] } -} +} \ No newline at end of file diff --git a/src/Extended.Collections.Playground/Generic/Specialized/OrderedDictionarySandbox.cs b/src/Extended.Collections.Playground/Generic/Specialized/OrderedDictionarySandbox.cs new file mode 100644 index 0000000..f66a6b5 --- /dev/null +++ b/src/Extended.Collections.Playground/Generic/Specialized/OrderedDictionarySandbox.cs @@ -0,0 +1,33 @@ +using Extended.Collections.Generic.Specialized; +using System.Collections; + +namespace Extended.Collections.Playground.Generic.Specialized; + +public class OrderedDictionarySandbox : Sandbox +{ + private OrderedDictionary m_tasks = new (); + + protected override void Run() + { + // Add tasks to the project in a specific order. + m_tasks.Add("Task1", "Complete research"); + m_tasks.Add("Task2", "Write documentation"); + m_tasks.Add("Task3", "Test functionality"); + + // Access tasks by their keys while maintaining their order. + Console.WriteLine("Project Tasks:"); + foreach (KeyValuePair entry in m_tasks) + { + Console.WriteLine($"TaskId: {entry.Key}"); + Console.WriteLine($"Name:{entry.Value}"); + } + + // Remove + m_tasks.RemoveAt(1); // Remove by index + m_tasks.Remove("Task1"); // Remove by key + + Logger.Information("Value: {Value}", m_tasks); + // 1. [ 'Task2' ] = "Write documentation" + // 2. [ 'Task3' ] = "Test functionality" + } +} \ No newline at end of file