Commit 5071a052 authored by Shashank Kumar's avatar Shashank Kumar

Tutorial Parser refactored to support uniform keys

parent c30ac502
......@@ -13,7 +13,8 @@ New Contributor Wizard v0.0.1
- How To Use module updated with a tutorial on how to get started with the application (Shashank Kumar - realslimshanky)
- Tutorial Parser refactored to validate invalid keys and prompt error message (Shashank Kumar - realslimshanky)
- Updated Tutorial Parser to support both Local and Online images (Shashank Kumar - realslimshanky)
- Tutorial Parser refactored to support both Local and Online images (Shashank Kumar - realslimshanky)
- Tutorial Parser refactored to support uniform JSON object with `type` and `content` keys. (Shashank Kumar - realslimshanky)
- Minor change in Tutorial Parser by changing `content` key to `lesson` for better context (Shashank Kumar - realslimshanky)
## July 30 2018
......
......@@ -106,25 +106,25 @@ Now try to `Open` `My Awesome Tutorial` from the Tutorial Menu as seen above. Wh
## Step 5 - Updating The Tutorial JSON
Each Tutorial JSON file is a array of `{}` obejcts. And each of those object must contain one and only one key i.e. `content` and value of this key should also be a `[]` object.
Each Tutorial JSON file is a array of `{}` obejcts. And each of those object must contain one and only one key i.e. `lesson` and value of this key should also be a `[]` object.
Each `{}` with a `content` represents a lesson in tutorial. Copy the code below and replace it with what you have in your Tutorial JSON file, restart the application and open your tutorial again.
Each `{}` with a `lesson` represents a lesson in tutorial. Copy the code below and replace it with what you have in your Tutorial JSON file, restart the application and open your tutorial again.
```json
[
{
"content": []
"lesson": []
},
{
"content": []
"lesson": []
},
{
"content": []
"lesson": []
}
]
```
We can see there are 3 different Lessons without any content and there's a handy navigation to switch between any of them. Cool right? Your first `content` becomes Lesson 1, second `content` becomes Lesson 2 and so on.
We can see there are 3 different Lessons without any content and there's a handy navigation to switch between any of them. Cool right? Your first `lesson` becomes Lesson 1, second `lesson` becomes Lesson 2 and so on.
Now when you are creating a Tutorial, you would like to add some content inside your Lesson, that's what we define in `[]`.
......@@ -139,10 +139,10 @@ A simple Text can be added to Lesson by using the following code
```json
[
{
"content": [
"lesson": [
{
"type": "text",
"text": "This is a text"
"content": "This is a text"
}
]
},
......@@ -153,7 +153,7 @@ This will result in
![Text Content](https://i.imgur.com/RtZECpK.png)
So, you have to add a `{}` object inside the `[]` of a Lesson. The compulsory key is `type` whose value should be `text`. Following this, add another key `text` whose value should contain the text you want to display in the lesson.
So, you have to add a `{}` object inside the `[]` of a Lesson. The compulsory key is `type` whose value should be `text`. Following this, add another key `content` whose value should contain the text you want to display in the lesson.
### 2. ** Image **
......@@ -162,10 +162,10 @@ Adding an image is just as simple like adding a text. Simply use below code to k
```json
[
{
"content": [
"lesson": [
{
"type": "image",
"url": "https://cdn.pixabay.com/photo/2018/07/28/19/57/lunar-eclipse-3568835_960_720.jpg"
"content": "https://cdn.pixabay.com/photo/2018/07/28/19/57/lunar-eclipse-3568835_960_720.jpg"
}
]
},
......@@ -176,7 +176,7 @@ This will result in
![Image Content](https://i.imgur.com/kAfFA05.png)
So this time, `type` key has value `image` and an additional key is `url` which should contain the url of the image you want to display. If the image doesn't load, try to host the image yourself online somewhere and replace the `url`.
So this time, `type` key has value `image` and an additional key is `content` which should contain the url of the image you want to display. If the image doesn't load, try to host the image yourself online somewhere and replace the url in `content`.
### 3. ** Code **
......@@ -185,10 +185,10 @@ Code snippets can also be added to Lesson which can be copied easily right from
```json
[
{
"content": [
"lesson": [
{
"type": "code",
"code": "man ls"
"content": "man ls"
}
]
},
......@@ -199,7 +199,7 @@ This will result in
![Code Content](https://i.imgur.com/qpwdZVy.png)
Now you might have guessed what `type` we are using. And similar to above convention, add additional key `code` and value should be whatever text you want the user to copy.
Now you might have guessed what `type` we are using. And similar to above convention, add additional key `content` and value should be whatever text you want the user to copy.
### 4. ** Question **
......@@ -208,12 +208,14 @@ Now this one is a little advance content type that the others. Let's first use t
```json
[
{
"content": [
"lesson": [
{
"type": "question",
"question": "Is Linux a Monolithic Kernal? Answer yes or no.",
"answer": "yes",
"hint": "do some research online"
"content": {
"question": "Is Linux a Monolithic Kernal? Answer yes or no.",
"answer": "yes",
"hint": "do some research online"
}
}
]
},
......@@ -233,44 +235,46 @@ Also, below is the example of how you can add multiple content to a single lesso
```json
[
{
"content": [
"lesson": [
{
"type": "text",
"text": "This is my AWESOME tutorial. Checkout the image below!"
"content": "This is my AWESOME tutorial. Checkout the image below!"
},
{
"type": "image",
"url": "https://cdn.pixabay.com/photo/2017/01/16/19/17/horses-1984977_960_720.jpg"
"content": "https://cdn.pixabay.com/photo/2017/01/16/19/17/horses-1984977_960_720.jpg"
}
]
},
{
"content": [
"lesson": [
{
"type": "text",
"text": "Another awesome lesson for you!"
"content": "Another awesome lesson for you!"
},
{
"type": "image",
"url": "https://cdn.pixabay.com/photo/2014/11/29/09/56/sleigh-ride-549727_960_720.jpg"
"content": "https://cdn.pixabay.com/photo/2014/11/29/09/56/sleigh-ride-549727_960_720.jpg"
}
]
},
{
"content": [
"lesson": [
{
"type": "text",
"text": "WOW! You made it to the end!"
"content": "WOW! You made it to the end!"
},
{
"type": "question",
"question": "How many horses did you see?",
"answer": "4",
"hint": "read the tutorial from the start"
"content": {
"question": "How many horses did you see?",
"answer": "4",
"hint": "read the tutorial from the start"
}
},
{
"type": "text",
"text": "Thank you for visiting my tutorial - Shashank"
"content": "Thank you for visiting my tutorial - Shashank"
}
]
}
......
......@@ -3,17 +3,19 @@
"lesson": [
{
"type": "image",
"url": "ui/assets/images/encryption_101_1.jpg"
"content": "ui/assets/images/encryption_101_1.jpg"
},
{
"type": "text",
"text": "Welcome to Encryption 101. This is just to get you started with what the term 'Encryption' means and how it is practiced in real life. Roughly speaking, encryption is the problem of how two parties can communicate in secret in the presence of an eavesdropper. The main goals of this chapter are to develop a meaningful and useful definition of what we are trying to achieve, and to take some first steps in actually achieving it. "
"content": "Welcome to Encryption 101. This is just to get you started with what the term 'Encryption' means and how it is practiced in real life. Roughly speaking, encryption is the problem of how two parties can communicate in secret in the presence of an eavesdropper. The main goals of this chapter are to develop a meaningful and useful definition of what we are trying to achieve, and to take some first steps in actually achieving it. "
},
{
"type": "question",
"question": "So, what can you secure using Encryption?",
"answer": "Communication",
"hint": "Read the above paragraph for answer"
"content": {
"question": "So, what can you secure using Encryption?",
"answer": "Communication",
"hint": "Read the above paragraph for answer"
}
}
]
},
......@@ -21,17 +23,19 @@
"lesson": [
{
"type": "text",
"text": "Now, let's take a real life example to understand where Encryption can be used."
"content": "Now, let's take a real life example to understand where Encryption can be used."
},
{
"type": "text",
"text": "Suppose Alice and Bob share a secret key k, and Alice wants to transmit a message m to Bob over a network while maintaining the secrecy of m in the presence of an eavesdropping adversary. This tutorial begins the development of basic techniques to solve this problem. Besides transmitting a message over a network, these same techniques allow Alice to store a file on a disk so that no one else with access to the disk can read the file, but Alice herself can read the file at a later time."
"content": "Suppose Alice and Bob share a secret key k, and Alice wants to transmit a message m to Bob over a network while maintaining the secrecy of m in the presence of an eavesdropping adversary. This tutorial begins the development of basic techniques to solve this problem. Besides transmitting a message over a network, these same techniques allow Alice to store a file on a disk so that no one else with access to the disk can read the file, but Alice herself can read the file at a later time."
},
{
"type": "question",
"question": "What Alice and Bob can use to secure message while transmission?",
"answer": "A secret key",
"hint": "Read the above paragraph for answer"
"content": {
"question": "What Alice and Bob can use to secure message while transmission?",
"answer": "A secret key",
"hint": "Read the above paragraph for answer"
}
}
]
}
......
......@@ -3,27 +3,27 @@
"lesson": [
{
"type": "text",
"text": "[size=40]Welcome to New Contributor Wizard[/size]"
"content": "[size=40]Welcome to New Contributor Wizard[/size]"
},
{
"type": "text",
"text": "This is 'How To Use', here you'll learn about how to use this application to get the best out of it. Let's first understand why you should use this application?"
"content": "This is 'How To Use', here you'll learn about how to use this application to get the best out of it. Let's first understand why you should use this application?"
},
{
"type": "text",
"text": "[size=25]Why you should use this application?[/size]"
"content": "[size=25]Why you should use this application?[/size]"
},
{
"type": "text",
"text": "New Contributor Wizard originated as a [ref=https://summerofcode.withgoogle.com/projects/#5056989357408256]Google Summer of Code 2018[/ref] project under Debian. It is a initiative to create an application which can provide all the resources to a person in order to help them out with Open Source contributions."
"content": "New Contributor Wizard originated as a [ref=https://summerofcode.withgoogle.com/projects/#5056989357408256]Google Summer of Code 2018[/ref] project under Debian. It is a initiative to create an application which can provide all the resources to a person in order to help them out with Open Source contributions."
},
{
"type": "text",
"text": "For more information regarding the project you can visit project repository on [ref=https://salsa.debian.org/new-contributor-wizard-team/new-contributor-wizard][color=0000ff]https://salsa.debian.org/new-contributor-wizard-team/new-contributor-wizard[/color][/ref]"
"content": "For more information regarding the project you can visit project repository on [ref=https://salsa.debian.org/new-contributor-wizard-team/new-contributor-wizard][color=0000ff]https://salsa.debian.org/new-contributor-wizard-team/new-contributor-wizard[/color][/ref]"
},
{
"type": "text",
"text": "Next. We'll look into what all we can learn from this application."
"content": "Next. We'll look into what all we can learn from this application."
}
]
},
......@@ -31,23 +31,23 @@
"lesson": [
{
"type": "text",
"text": "Now, let's have a look at different modules available for you. If you press the hamburger button available on the top-left corner of the application which looks something like the image below..."
"content": "Now, let's have a look at different modules available for you. If you press the hamburger button available on the top-left corner of the application which looks something like the image below..."
},
{
"type": "image",
"url": "ui/assets/images/how_to_use_1.png"
"content": "ui/assets/images/how_to_use_1.png"
},
{
"type": "text",
"text": "After clicking on it you will see a sidebar appear from the left which would look something like the image below..."
"content": "After clicking on it you will see a sidebar appear from the left which would look something like the image below..."
},
{
"type": "image",
"url": "ui/assets/images/how_to_use_2.png"
"content": "ui/assets/images/how_to_use_2.png"
},
{
"type": "text",
"text": "You might be overwhelmed by all these options. Next we'll understand what you'll find in all these options."
"content": "You might be overwhelmed by all these options. Next we'll understand what you'll find in all these options."
}
]
},
......@@ -55,39 +55,39 @@
"lesson": [
{
"type": "text",
"text": "Now let's take a look at what each option on the sidebar will teach you."
"content": "Now let's take a look at what each option on the sidebar will teach you."
},
{
"type": "text",
"text": "[size=25]How To Use[/size]\nThis module will help you understand, What this application is, How to use the application and How you can also contribute to the application."
"content": "[size=25]How To Use[/size]\nThis module will help you understand, What this application is, How to use the application and How you can also contribute to the application."
},
{
"type": "text",
"text": "[size=25]Communication[/size]\nThis module will help you understand, How to communicate with your mentors, How to communicate with an organization, What are the various ways of communication used in communities and What are the best practices you should follow while communicating."
"content": "[size=25]Communication[/size]\nThis module will help you understand, How to communicate with your mentors, How to communicate with an organization, What are the various ways of communication used in communities and What are the best practices you should follow while communicating."
},
{
"type": "text",
"text": "[size=25]CLI[/size]\nThis module will help you understand, What is Command Line Interface, Why we use CLI, What are the various ways in which CLI will help you in day to day work and more about CLI hacks."
"content": "[size=25]CLI[/size]\nThis module will help you understand, What is Command Line Interface, Why we use CLI, What are the various ways in which CLI will help you in day to day work and more about CLI hacks."
},
{
"type": "text",
"text": "[size=25]Blog[/size]\nThis module will help you understand, How to write blogs, Why blogging is important, Where to host blogs and more about efficiently bogging."
"content": "[size=25]Blog[/size]\nThis module will help you understand, How to write blogs, Why blogging is important, Where to host blogs and more about efficiently bogging."
},
{
"type": "text",
"text": "[size=25]VCS[/size]\nThis module will help you understand, What is Version Control System, How to manage projects efficiently with VCS and How VCS is used to collaborate with other contributors of a project."
"content": "[size=25]VCS[/size]\nThis module will help you understand, What is Version Control System, How to manage projects efficiently with VCS and How VCS is used to collaborate with other contributors of a project."
},
{
"type": "text",
"text": "[size=25]Encryption[/size]\nThis module will help you understand, What is encryption, Why encrypting your data is important, What are the various ways in which you can do encryption."
"content": "[size=25]Encryption[/size]\nThis module will help you understand, What is encryption, Why encrypting your data is important, What are the various ways in which you can do encryption."
},
{
"type": "text",
"text": "[size=25]Way Ahead[/size]\nThis module will help you understand, What are the various ways in which you can start getting involve with different communities, What are the various Open Source competitions which you can take part in like Google Summer of Code and much more."
"content": "[size=25]Way Ahead[/size]\nThis module will help you understand, What are the various ways in which you can start getting involve with different communities, What are the various Open Source competitions which you can take part in like Google Summer of Code and much more."
},
{
"type": "text",
"text": "In the next lesson, we'll look into what are Tools and Tutorials inside every course option on the sidebar."
"content": "In the next lesson, we'll look into what are Tools and Tutorials inside every course option on the sidebar."
}
]
},
......@@ -95,35 +95,35 @@
"lesson": [
{
"type": "text",
"text": "If you visit any of the option from the left sidebar (except How To Use), you'll find a bottom navigation like below."
"content": "If you visit any of the option from the left sidebar (except How To Use), you'll find a bottom navigation like below."
},
{
"type": "image",
"url": "ui/assets/images/how_to_use_3.png"
"content": "ui/assets/images/how_to_use_3.png"
},
{
"type": "text",
"text": "Tutorials and Tools! You can select either of them by simply clicking on them and a menu will appear just like the image below..."
"content": "Tutorials and Tools! You can select either of them by simply clicking on them and a menu will appear just like the image below..."
},
{
"type": "image",
"url": "ui/assets/images/how_to_use_4.png"
"content": "ui/assets/images/how_to_use_4.png"
},
{
"type": "text",
"text": "Tutorials are a manual about a particular topic which will help you understand the topic. Just like this tutorial which are reading right now which helps you understand how this application works."
"content": "Tutorials are a manual about a particular topic which will help you understand the topic. Just like this tutorial which are reading right now which helps you understand how this application works."
},
{
"type": "text",
"text": "Tools for a particular option would be simple tools provided to you in order to do simple tasks related to the option you select. For example, in the image above you can see 'Encryption Tools' menu. Here, all the tools are related to Encryption. Like, 'Enrypt a message' which will allow you to encrypt a message right from this application itself. Cool, right?"
"content": "Tools for a particular option would be simple tools provided to you in order to do simple tasks related to the option you select. For example, in the image above you can see 'Encryption Tools' menu. Here, all the tools are related to Encryption. Like, 'Enrypt a message' which will allow you to encrypt a message right from this application itself. Cool, right?"
},
{
"type": "text",
"text": "You might have also noticed that Each option in Tutorials or Tools menu has a specific difficulty attached to it. This will help you identify which Tutorials or Tools to start with. A difficulty can be 'Beginner', 'Intermediate' or 'Advance'. Menu items are also colored respectively for visual aid."
"content": "You might have also noticed that Each option in Tutorials or Tools menu has a specific difficulty attached to it. This will help you identify which Tutorials or Tools to start with. A difficulty can be 'Beginner', 'Intermediate' or 'Advance'. Menu items are also colored respectively for visual aid."
},
{
"type": "text",
"text": "That's all you needed to know in order to get started. If you have any more question or problem regarding the application please reach out to the maintainers at [ref=https://salsa.debian.org/new-contributor-wizard-team/new-contributor-wizard][color=0000ff]https://salsa.debian.org/new-contributor-wizard-team/new-contributor-wizard[/color][/ref]"
"content": "That's all you needed to know in order to get started. If you have any more question or problem regarding the application please reach out to the maintainers at [ref=https://salsa.debian.org/new-contributor-wizard-team/new-contributor-wizard][color=0000ff]https://salsa.debian.org/new-contributor-wizard-team/new-contributor-wizard[/color][/ref]"
}
]
}
......
......@@ -182,8 +182,8 @@ def get_text_widget(content_part):
get_text_widget will build a widget tree to display text type content
of the tutorial
'''
if 'text' in content_part:
text = content_part['text']
if 'content' in content_part:
text = content_part['content']
else:
text = '[color=d3d3d3]Empty Text Was Provided Here![/color]'
log_error_message('Empty Text Was Provided')
......@@ -212,15 +212,19 @@ def get_question_widget(content_part):
of the tutorial
'''
question_box = LessonQuestionBox()
if 'question' in content_part:
question = content_part['question']
if 'content' in content_part:
if 'question' in content_part['content']:
question = content_part['content']['question']
else:
question = '[color=d3d3d3]Empty Question Was Provided Here![/color]'
log_error_message('Empty Question Was Provided')
else:
question = '[color=d3d3d3]Empty Question Was Provided Here![/color]'
log_error_message('Empty Question Was Provided')
question_box.ids['lesson_question_label'].text = question
if 'hint' in content_part:
hint = content_part['hint']
if 'hint' in content_part['content']:
hint = content_part['content']['hint']
question_box.ids['lesson_question_input'].hint_text = hint
def on_answer_change(*_):
......@@ -236,8 +240,8 @@ def get_question_widget(content_part):
on_submit_answer is triggered when answer is submitted with and
validated accordingly
'''
if 'answer' in content_part:
answer = content_part['answer']
if 'answer' in content_part['content']:
answer = content_part['content']['answer']
else:
answer = ''
question_box_object = question_box.ids['lesson_answer_validation']
......@@ -257,9 +261,9 @@ def get_image_widget(content_part):
get_image_widget will build a widget tree to display image type content
of the tutorial
'''
if 'url' in content_part:
if content_part['url']:
content_url = content_part['url']
if 'content' in content_part:
if content_part['content']:
content_url = content_part['content']
lesson_image_box = LessonImageBox()
if content_url.lower().startswith('http'):
image_object = AsyncImage(source=content_url)
......@@ -311,8 +315,8 @@ def get_code_widget(content_part):
of the tutorial
'''
lesson_code_box = LessonCodeBox()
if 'code' in content_part:
code = content_part['code']
if 'content' in content_part:
code = content_part['content']
else:
code = '[color=d3d3d3]Invalid Code Provided Here![/color]'
log_error_message('Invalid Code Provided!')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment