-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
XuanThuLab
committed
Aug 30, 2020
1 parent
a4a4257
commit 20cf28e
Showing
12 changed files
with
393 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"version": "2.0.0", | ||
"tasks": [ | ||
{ | ||
"label": "build", | ||
"command": "dotnet", | ||
"type": "process", | ||
"args": [ | ||
"build", | ||
"${workspaceFolder}/htmlhelper.csproj", | ||
"/property:GenerateFullPaths=true", | ||
"/consoleloggerparameters:NoSummary" | ||
], | ||
"problemMatcher": "$msCompile" | ||
}, | ||
{ | ||
"label": "publish", | ||
"command": "dotnet", | ||
"type": "process", | ||
"args": [ | ||
"publish", | ||
"${workspaceFolder}/htmlhelper.csproj", | ||
"/property:GenerateFullPaths=true", | ||
"/consoleloggerparameters:NoSummary" | ||
], | ||
"problemMatcher": "$msCompile" | ||
}, | ||
{ | ||
"label": "watch", | ||
"command": "dotnet", | ||
"type": "process", | ||
"args": [ | ||
"watch", | ||
"run", | ||
"${workspaceFolder}/htmlhelper.csproj", | ||
"/property:GenerateFullPaths=true", | ||
"/consoleloggerparameters:NoSummary" | ||
], | ||
"problemMatcher": "$msCompile" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using Microsoft.AspNetCore.Http; | ||
|
||
namespace XTLAB.HtmlHelper { | ||
|
||
public static class HtmlHelper { | ||
/// <summary> | ||
/// Phát sinh trang HTML | ||
/// </summary> | ||
/// <param name="title">Tiêu đề trang</param> | ||
/// <param name="content">Nội dung trong thẻ body</param> | ||
/// <returns>Trang HTML</returns> | ||
public static string HtmlDocument (string title, string content) { | ||
return $@" | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset=""UTF-8""> | ||
<title>{title}</title> | ||
<link rel=""stylesheet"" href=""/css/site.min.css"" /> | ||
<script src=""/js/jquery.min.js""> | ||
</script><script src=""/js/popper.min.js""> | ||
</script><script src=""/js/bootstrap.min.js""></script> | ||
</head> | ||
<body> | ||
{content} | ||
</body> | ||
</html>"; | ||
} | ||
|
||
/// <summary> | ||
/// Phát sinh HTML thanh menu trên, menu nào active phụ thuộc vào URL mà request gủi đến | ||
/// </summary> | ||
/// <param name="menus">Mảng các menu item, mỗi item có cấu trúc {url, lable}</param> | ||
/// <param name="request">HttpRequest</param> | ||
/// <returns></returns> | ||
|
||
public static string MenuTop (object[] menus, HttpRequest request) { | ||
|
||
var menubuilder = new StringBuilder (); | ||
menubuilder.Append ("<ul class=\"navbar-nav\">"); | ||
foreach (dynamic menu in menus) { | ||
string _class = "nav-item"; | ||
// Active khi request.PathBase giống url của menu | ||
if (request.PathBase == menu.url) _class += " active"; | ||
menubuilder.Append ($@" | ||
<li class=""{_class}""> | ||
<a class=""nav-link"" href=""{menu.url}"">{menu.label}</a> | ||
</li> | ||
"); | ||
} | ||
menubuilder.Append ("</ul>\n"); | ||
|
||
string menuhtml = $@" | ||
<div class=""container""> | ||
<nav class=""navbar navbar-expand-lg navbar-dark mainbackground""> | ||
<a class=""navbar-brand"" href=""/"">XTLAB</a> | ||
<button class=""navbar-toggler"" type=""button"" | ||
data-toggle=""collapse"" data-target=""#my-nav-bar"" | ||
aria-controls=""my-nav-bar"" aria-expanded=""false"" aria-label=""Toggle navigation""> | ||
<span class=""navbar-toggler-icon""></span> | ||
</button> | ||
<div class=""collapse navbar-collapse"" id=""my-nav-bar""> | ||
{menubuilder} | ||
</div> | ||
</nav></div>"; | ||
|
||
return menuhtml; | ||
} | ||
|
||
/// <summary> | ||
/// Những menu item mặc định cho trang | ||
/// </summary> | ||
/// <returns>Mảng các menuitem</returns> | ||
public static object[] DefaultMenuTopItems () { | ||
return new object[] { | ||
new { | ||
url = "/RequestInfo", | ||
label = "Request" | ||
}, | ||
new { | ||
url = "/Form", | ||
label = "Form" | ||
}, | ||
new { | ||
url = "/Encoding", | ||
label = "Encoding" | ||
}, | ||
new { | ||
url = "/Cookies", | ||
label = "Cookies" | ||
}, | ||
new { | ||
url = "/Json", | ||
label = "JSON" | ||
} | ||
}; | ||
} | ||
|
||
public static string HtmlTrangchu () { | ||
return $@" | ||
<div class=""container""> | ||
<div class=""jumbotron""> | ||
<h1 class=""display-4"">Đây là một trang Web .NET Core</h1> | ||
<p class=""lead"">Trang Web này xây dựng trên nền tảng <code>.NET Core</code>, | ||
chưa sử dụng kỹ thuật MVC - nhằm mục đích học tập. | ||
Mã nguồn trang này tại <a target=""_blank"" | ||
href=""https://github.com/xuanthulabnet/learn-cs-netcore/blob/master/ASP_NET_CORE/03.RequestResponse/""> | ||
Mã nguồn Ví dụ</a> | ||
</p> | ||
<hr class=""my-4""> | ||
<p><code>.NET Core</code> là một hệ thống chạy đa nền tảng (Windows, Linux, macOS)</p> | ||
<a class=""btn btn-danger btn-lg"" href=""https://xuanthulab.net/lap-trinh-c-co-ban/"" role=""button"">Xem thêm</a> | ||
</div> | ||
</div> | ||
"; | ||
|
||
} | ||
|
||
// Mở rộng String, phát sinh thẻ HTML với nội dụng là String | ||
// Ví dụ: | ||
// "content".HtmlTag() => <p>content</p> | ||
// "content".HtmlTag("div", "text-danger") => <div class="text-danger">content</div> | ||
public static string HtmlTag (this string content, string tag = "p", string _class = null) { | ||
string cls = (_class != null) ? $" class=\"{_class}\"" : null; | ||
return $"<{tag + cls}>{content}</{tag}>"; | ||
} | ||
public static string td (this string content, string _class = null) { | ||
return content.HtmlTag ("td", _class); | ||
} | ||
public static string tr (this string content, string _class = null) { | ||
return content.HtmlTag ("tr", _class); | ||
} | ||
public static string table (this string content, string _class = null) { | ||
return content.HtmlTag ("table", _class); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
<PackageId>XTL.HtmlHelper</PackageId> | ||
<Version>1.0.0</Version> | ||
<Authors>xuanthulab</Authors> | ||
<Company>XUANTHULAB.NET</Company> | ||
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" /> | ||
</ItemGroup> | ||
|
||
</Project> |
27 changes: 27 additions & 0 deletions
27
ASP_NET_CORE/htmlhelperlib/htmltestcode/.vscode/launch.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
// Use IntelliSense to find out which attributes exist for C# debugging | ||
// Use hover for the description of the existing attributes | ||
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": ".NET Core Launch (console)", | ||
"type": "coreclr", | ||
"request": "launch", | ||
"preLaunchTask": "build", | ||
// If you have changed target frameworks, make sure to update the program path. | ||
"program": "${workspaceFolder}/bin/Debug/netcoreapp3.1/htmltestcode.dll", | ||
"args": [], | ||
"cwd": "${workspaceFolder}", | ||
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console | ||
"console": "internalConsole", | ||
"stopAtEntry": false | ||
}, | ||
{ | ||
"name": ".NET Core Attach", | ||
"type": "coreclr", | ||
"request": "attach", | ||
"processId": "${command:pickProcess}" | ||
} | ||
] | ||
} |
42 changes: 42 additions & 0 deletions
42
ASP_NET_CORE/htmlhelperlib/htmltestcode/.vscode/tasks.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"version": "2.0.0", | ||
"tasks": [ | ||
{ | ||
"label": "build", | ||
"command": "dotnet", | ||
"type": "process", | ||
"args": [ | ||
"build", | ||
"${workspaceFolder}/htmltestcode.csproj", | ||
"/property:GenerateFullPaths=true", | ||
"/consoleloggerparameters:NoSummary" | ||
], | ||
"problemMatcher": "$msCompile" | ||
}, | ||
{ | ||
"label": "publish", | ||
"command": "dotnet", | ||
"type": "process", | ||
"args": [ | ||
"publish", | ||
"${workspaceFolder}/htmltestcode.csproj", | ||
"/property:GenerateFullPaths=true", | ||
"/consoleloggerparameters:NoSummary" | ||
], | ||
"problemMatcher": "$msCompile" | ||
}, | ||
{ | ||
"label": "watch", | ||
"command": "dotnet", | ||
"type": "process", | ||
"args": [ | ||
"watch", | ||
"run", | ||
"${workspaceFolder}/htmltestcode.csproj", | ||
"/property:GenerateFullPaths=true", | ||
"/consoleloggerparameters:NoSummary" | ||
], | ||
"problemMatcher": "$msCompile" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System; | ||
using XTLAB.HtmlHelper; | ||
|
||
namespace htmltestcode | ||
{ | ||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
String html = "Ví dụ sử dụng HtmlHelper".HtmlTag("div", "text-danger"); | ||
Console.WriteLine(html); | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
ASP_NET_CORE/htmlhelperlib/htmltestcode/htmltestcode.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\htmlhelper\htmlhelper.csproj" /> | ||
</ItemGroup> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
</PropertyGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Tạo thư viện C# NET Core và chia sẻ lên nuget.org | ||
|
||
https://xuanthulab.net/tao-thu-vien-c-net-core-va-chia-se-len-nuget-org.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
// Use IntelliSense to find out which attributes exist for C# debugging | ||
// Use hover for the description of the existing attributes | ||
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": ".NET Core Launch (console)", | ||
"type": "coreclr", | ||
"request": "launch", | ||
"preLaunchTask": "build", | ||
// If you have changed target frameworks, make sure to update the program path. | ||
"program": "${workspaceFolder}/bin/Debug/netcoreapp3.1/test.dll", | ||
"args": [], | ||
"cwd": "${workspaceFolder}", | ||
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console | ||
"console": "internalConsole", | ||
"stopAtEntry": false | ||
}, | ||
{ | ||
"name": ".NET Core Attach", | ||
"type": "coreclr", | ||
"request": "attach", | ||
"processId": "${command:pickProcess}" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"version": "2.0.0", | ||
"tasks": [ | ||
{ | ||
"label": "build", | ||
"command": "dotnet", | ||
"type": "process", | ||
"args": [ | ||
"build", | ||
"${workspaceFolder}/test.csproj", | ||
"/property:GenerateFullPaths=true", | ||
"/consoleloggerparameters:NoSummary" | ||
], | ||
"problemMatcher": "$msCompile" | ||
}, | ||
{ | ||
"label": "publish", | ||
"command": "dotnet", | ||
"type": "process", | ||
"args": [ | ||
"publish", | ||
"${workspaceFolder}/test.csproj", | ||
"/property:GenerateFullPaths=true", | ||
"/consoleloggerparameters:NoSummary" | ||
], | ||
"problemMatcher": "$msCompile" | ||
}, | ||
{ | ||
"label": "watch", | ||
"command": "dotnet", | ||
"type": "process", | ||
"args": [ | ||
"watch", | ||
"run", | ||
"${workspaceFolder}/test.csproj", | ||
"/property:GenerateFullPaths=true", | ||
"/consoleloggerparameters:NoSummary" | ||
], | ||
"problemMatcher": "$msCompile" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
using XTLAB; | ||
namespace test | ||
{ | ||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
"abc".HtmlTag("p"); | ||
Console.WriteLine("Hello World!"); | ||
} | ||
} | ||
} |
Oops, something went wrong.