Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load yaml file data #16

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 0 additions & 1 deletion .gitignore
@@ -1,4 +1,3 @@
**/bin
**/obj
**/.vscode
portfolio/*
98 changes: 96 additions & 2 deletions Portfolio-generator-console/HtmlGenerator.cs
@@ -1,11 +1,18 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Threading.Tasks;
using YamlDotNet.RepresentationModel;

namespace Portfolio_generator_console {
public class HtmlGenerator {

public static string templateDir = Path.Combine (Directory.GetCurrentDirectory ().ToString (), "templates");
public static string targetDir = Path.Combine (Directory.GetCurrentDirectory ().ToString (), "portfolio");
// Please filled up your personal informations down below:

public static void SelectTemplate () {

Expand Down Expand Up @@ -108,6 +115,18 @@ public class HtmlGenerator {
public static void GenerateHtml () {

try {
string path = @"./Portfolio-generator-console/data.yml";

if (!File.Exists(path)){
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("++++++++++++++++++++++++++++++++++++++++");
Console.WriteLine("Error!!! Can not find the data.yml file.");
Console.WriteLine("++++++++++++++++++++++++++++++++++++++++");
Console.ResetColor();
}
// refrence: https://docs.microsoft.com/en-us/dotnet/api/system.io.file.readalltext?view=netframework-4.7.2


SelectTemplate ();

string templatePath = Path.Combine (Directory.GetCurrentDirectory ().ToString (), "templates", "template1", "index.html");
Expand All @@ -120,8 +139,82 @@ public class HtmlGenerator {
Console.Write ("Please enter your name : ");
var yourName = Console.ReadLine ();

string Document = File.ReadAllText(path);
var input = new StringReader(Document);

// Load the stream
var yaml = new YamlStream();
yaml.Load(input);


// Examine the stream
var mapping = (YamlMappingNode)yaml.Documents[0].RootNode;

foreach (var entry in mapping.Children){
Console.WriteLine(((YamlScalarNode)entry.Key).Value);
}

// List all the items
var skills = (YamlSequenceNode)mapping.Children[new YamlScalarNode("Skills")];
var educations = (YamlSequenceNode)mapping.Children[new YamlScalarNode("Education")];
var projects = (YamlSequenceNode)mapping.Children[new YamlScalarNode("Projects")];
var resume = (YamlSequenceNode)mapping.Children[new YamlScalarNode("Resume")];
var jobTitle = (YamlScalarNode)mapping.Children[new YamlScalarNode("Job title")];
var aboutMe = (YamlScalarNode)mapping.Children[new YamlScalarNode("Aboutme")];
var values = (YamlScalarNode)mapping.Children[new YamlScalarNode("Values")];
var goals = (YamlScalarNode)mapping.Children[new YamlScalarNode("Goals")];
var hobbies = (YamlScalarNode)mapping.Children[new YamlScalarNode("Hobbies")];

// var projects = (YamlScalarNode)mapping.Children[new YamlScalarNode("Projects")];
// var resume = (YamlScalarNode)mapping.Children[new YamlScalarNode("Resume")];


Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine(skills.ToString());
Console.WriteLine(Environment.NewLine);
Console.WriteLine(jobTitle.ToString());
Console.WriteLine(Environment.NewLine);
Console.WriteLine(aboutMe.ToString());
Console.WriteLine(Environment.NewLine);
Console.WriteLine(values.ToString());
Console.WriteLine(Environment.NewLine);
Console.WriteLine(goals.ToString());
Console.WriteLine(Environment.NewLine);
Console.WriteLine(educations.ToString());
Console.WriteLine(Environment.NewLine);
Console.WriteLine(resume.ToString());
Console.WriteLine(Environment.NewLine);
Console.WriteLine(projects.ToString());
Console.WriteLine(Environment.NewLine);
Console.WriteLine(hobbies.ToString());
Console.WriteLine(Environment.NewLine);
Console.ResetColor();

// foreach (YamlMappingNode skill in skills){
// Console.WriteLine(
// "{0}\t{1}",
// skill.Children[new YamlScalarNode("language")],
// skill.Children[new YamlScalarNode("descrip")]
// );
// }
// foreach (YamlMappingNode edu in educations){
// Console.WriteLine(
// "{0}\t{1}",
// edu.Children[new YamlScalarNode("language")],
// edu.Children[new YamlScalarNode("descrip")]
// );
// }


//Replace all values in the HTML
content = content.Replace ("{YOUR_NAME}", yourName);
content = content.Replace ("{YOUR_NAME}", yourName.ToString());
content = content.Replace ("{JOB_TITLE}", jobTitle.ToString());
content = content.Replace("{ABOUT_ME}",aboutMe.ToString());
content = content.Replace("{VALUES}",values.ToString());
content = content.Replace("{GOALS}",goals.ToString());
content = content.Replace("{HOBBIES}",hobbies.ToString());
content = content.Replace("{SKILLS}",skills.ToString());
content = content.Replace("{EDUCATION}",educations.ToString());

//Write new HTML string to file
File.WriteAllText (newFilePath, content);
Expand All @@ -132,4 +225,5 @@ public class HtmlGenerator {
}
}
}
}
}

Expand Up @@ -6,4 +6,8 @@
<RootNamespace>Portfolio_generator_console</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="YamlDotNet" Version="5.2.1" />
</ItemGroup>

</Project>
54 changes: 54 additions & 0 deletions Portfolio-generator-console/data.yml
@@ -0,0 +1,54 @@
---
Job title: Web Developer
date: 2018-10-15
Name:
given: Dorothy
family: Gale

Skills:
- language: C++
descrip: some descriptions_1
level: 99

- language: Java
descrip: some descriptions_2
level: 99

Projects:
- Project Name: test1
descrip: some descriptions_1
- Project Name: test2
descrip: some descriptions_2

Address:
street: |
123 Tornado Alley
Suite 16
city: East Westville
state: KS

Aboutme:
about meabout meabout meabout meabout meabout meabout meabout meabout meabout meabout me!!!
Values:
Values pLorem ipsum dolor sit amet, ea doming until epicuri iudicabit nam, te usu virtute placerat.
Purto brute disputando cu est.
Goals:
Goals pLorem ipsum dolor sit amet, ea doming until epicuri iudicabit nam, te usu virtute placerat.
Purto brute disputando cu est.
Hobbies:
hobbies pLorem ipsum dolor sit amet, ea doming until epicuri iudicabit nam, te usu virtute placerat.
Purto brute disputando cu est.
Resume:
- descrip: Resume pLorem ipsum dolor sit amet, ea doming until epicuri iudicabit nam, te usu virtute placerat.
Purto brute disputando cu est.
url: www.xiaochen.ca
Education:
- descrip: This this demo1 description
time period: March 2009 - December 2011
level: Major in Engineering, University B, Los Angeles, USA.
- descrip: This this demo2 description
time period: March 2009 - December 2011
level: Major in Engineering, MIT
- descrip: This this demo3 description
time period: March 2009 - December 2011
level: Major in Engineering, Seneca College.
1 change: 1 addition & 0 deletions node_modules/.bin/esparse

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/esvalidate

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/husky-upgrade

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/is-ci

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/js-yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/prettier

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/pretty-quick

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/run-node

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/semver

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/which

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

165 changes: 165 additions & 0 deletions node_modules/ansi-styles/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.