Skip to content

Conversation

@VerzatileDev
Copy link
Contributor

@VerzatileDev VerzatileDev commented Dec 29, 2023

++ PLEASE Read the changes carefully and comments specified under the post ++

[ADDRESSING] - @JDSherbert

Discussion in Issue " #25 ":

In this issue, it was discussed that while the current "Concepts" folder contains examples, there's a need to enhance it by including examples in different languages instead of defaulting to the easiest option. This is particularly relevant where certain languages do not utilize specific concepts, like Object-Oriented Programming (OOP).

Key points of discussion in Issue " #25 " include:

  1. Default Language for Examples:

    • There is a need to deliberate on establishing a default language for examples. This decision could impact the initial user experience and comprehension.
  2. Folder Structure and Organization:

    • Consideration should be given to the organization of the folder structure. The question of whether to duplicate pages with language-specific examples or adopt an alternative approach is raised. This involves a strategic decision about the balance between simplicity and specificity.
  3. Implementation of Multiple Language Examples on the Same Page:

    • Exploring the possibility of incorporating examples from multiple languages on a single page was discussed. The suggestion involves a potential solution of utilizing a dropdown to allow users to switch between different languages. This approach aims to provide a more versatile and inclusive learning experience.

The following example implementation aims to address the aforementioned points:

  • Utilizes Javascript eventListener to initially store a user's preference locally when they first request the site, selecting the default "Cpp."
  • Upon page load or refresh, the content displayed is checked locally for defined preferences.
  • If the user clicks "csharp" and it's not set at the time, the local value is rewritten to the local storage.
  • This allows the user to view the same content after refreshing or reloading the page (for example, changing the page and returning).

Please note:

  • This requires a setup of a "JavaScript" file that handles these globally, rather than being page-specific, as the latter would significantly degrade user and developer load times.
  • Currently, all listed languages and their content should be included under the same file, specified with the div and an ID. Please note that this could change in the future, but currently, there are no solutions to address it as far as I'm aware.

Has Been fully addressed in
#68 (comment)

Programming language specific toggle example on the OOP file.

- Does not include:
Listener to remember the selected after page refresh

Javascript has to be changed to its own specific file rather than on the .md itself.
Additionally added a feature that adds an event listener and saves the current language to the users local storage, if not defiend previously.

If it is defined it loads the selected language from this example Cpp or Csharp.

Which will be asked each time a refresh is called or page is reloaded.

Additionally Pressing the Button either cpp or Csharp will rewrite the Language Preference and store it to locally.

Note:

This Requires that the JavaScript would be made globally not for each instance where possible.

Make sure that only specified buttons are called so make cases if there are less or more languages.

" in the future figure out where to store these as all in the same file would be an overkill potentially ".
@VerzatileDev VerzatileDev added 📖 Type: Content Edits to documentation/content. 🌈 Type: Cosmetic Edits to layout or looks. 🌟 Type: Feature New feature or repository request. 🆘 Help Needed! Help is required on this issue. 🚫 Review: DO NOT MERGE PR should not be merged yet. ⚠️ Priority: Minor Should be addressed where possible, if there are resources to spare. labels Dec 29, 2023
@VerzatileDev
Copy link
Contributor Author

VerzatileDev commented Dec 29, 2023

With the following the layout of the page is as follows:

image

The Current has two available

markers with defined ID and content, which by the button is either hidden or updated on the page to show that part of the discussion.

Though note with this both of these will be available if enabled by inspector, but for the default user it would display it as one, which is enabled locally otherwise uses the default first value as to what is displayed.

image

Which is modified to enable or disable by the following Script

image

Now the Content has a saved value based on the Path of the URL and the ID selected.  When page is refreshed or loaded it would load the value if defined by default it should be on " cpp "

Wrote comments to be more clear  and understandable what each section actually does.

Made an " asset " folder to hold the js file. Additionally in the next commit will include Images and CSS into that specified location.

Currently Using " OOP and Memory " as placeholders for these examples.
@VerzatileDev
Copy link
Contributor Author

VerzatileDev commented Jan 5, 2024

Script has been listed for global use under "asssets/js/script.. " can be called by using the command include_programming_language_switch_script: true

Within the .md file file as an example:

---
layout: default
title: OOP
nav_order: 1
parent: Concepts
has_children: false
include_programming_language_switch_script: true
---

Other dependencies of the page is a requirement to select the following buttons:

<button onclick="setLanguageAndShowContent('cpp')">C++</button>
<button onclick="setLanguageAndShowContent('csharp')">C#</button>
<button onclick="setLanguageAndShowContent('python')">Python</button>

Which must include a "

" to be used as an example here are the three specified:

<div id="cppContent">
<!-- Your default C++ content goes here -->
This is C++ content for Object-Oriented Programming.
</div>

<div id="csharpContent" style="display:none;">
<!-- Your C# content goes here -->
This is C# content for Object-Oriented Programming.
</div>

<div id="pythonContent" style="display:none;">
<!-- Your C# content goes here -->
This is python content for Object-Oriented Programming.
</div>

NOTE:


You can specify any amount from 0 to 3
If the button is not added with the div ID then it will display none;
if there is content added and it is currently active it will display as block;

As for example you can use:
Only python, or only cpp, or only csharp, or neither of them all even when the script it enabled.


<div id="pythonContent" style="display:none;">

The specified must be listed with these exact words for ID

As these specifications are defined within the -> programmingLanguageSwitch.js

with the following

var contentMap = {
'cpp': 'cppContent',
'csharp': 'csharpContent',
'python': 'pythonContent'
};

Functionality of the feature:

  • Content selected is saved locally to the users storage when buttons are pressed, if non are pressed and the Saved is " Null " it will default to " cpp " content or which ever is first defined by default.
  • When content button is pressed it saves that value to the page based on the URL path specific to the page and contentMap ID
  • Adding the path and ID will make a unique "Storage ID " which is used to load the correct preview when the page is Refreshed or changed to and back. (Making sure that if " Csharp " has been selected and page is changed and then changed back it would then display the saved value of " Csharp " and its content.

@VerzatileDev VerzatileDev added 👁️ Review: Required This PR is ready for review. and removed 🆘 Help Needed! Help is required on this issue. 🚫 Review: DO NOT MERGE PR should not be merged yet. labels Jan 5, 2024
Copy link
Collaborator

@JDSherbert JDSherbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, raised a question but otherwise fine to go in.

@JDSherbert JDSherbert added ✅ Review: Approved PR is approved and ready for merge. and removed 👁️ Review: Required This PR is ready for review. labels Jan 9, 2024
@JDSherbert JDSherbert merged commit e5fbca8 into VerzatileDevOrg:main Jan 9, 2024
@VerzatileDev VerzatileDev deleted the language-specific-Examples branch January 9, 2024 23:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

⚠️ Priority: Minor Should be addressed where possible, if there are resources to spare. ✅ Review: Approved PR is approved and ready for merge. 📖 Type: Content Edits to documentation/content. 🌈 Type: Cosmetic Edits to layout or looks. 🌟 Type: Feature New feature or repository request.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Discussion]: Add + Organize language specific Examples and Implementations

2 participants