Skip to content

Commit 5efa79b

Browse files
committed
Update layout and documentation
1 parent 7296333 commit 5efa79b

File tree

8 files changed

+238
-14
lines changed

8 files changed

+238
-14
lines changed

README.md

Lines changed: 144 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<h1 align="center">
66
<a href="https://www.ProAngular.com" target="_blank">
77
Pro Angular
8-
</a>: GitHub gist Code Snippet Display
8+
</a>: GitHub gist Code Snippet Tabs
99
</h1>
1010
</p>
1111

@@ -17,8 +17,149 @@
1717

1818
# Description
1919

20-
An Angular Material and HighlighJs styled display box for GitHub gist and local code snippets.
20+
An Angular Material and HighlighJs styled display box for GitHub gist and local code snippets. All files from the remote/local gist are displayed in separate tabs for users to easily navigate. Many optional features and themes are available. Enjoy!
2121

2222
# Demo
2323

24-
TODO: Further documentation.
24+
TODO: Add demo here.
25+
26+
# Requirements
27+
28+
This project uses Angular Material tabs so an Angular Material must be installed and available along with a theme. You can define a theme if you use this application outside of Angular using the public API `materialTheme` (see below for more information). See other peer dependancies in the package description.
29+
30+
# Installation
31+
32+
```bash
33+
ng add @proangular/ngx-gist@latest
34+
```
35+
or
36+
```bash
37+
npm install @proangular/ngx-gist --save
38+
```
39+
40+
Import `NgxGistModule` where needed
41+
```diff
42+
...
43+
+ import { NgxGistModule } from '@proangular/ngx-gist';
44+
...
45+
46+
@NgModule({
47+
imports: [
48+
...
49+
+ NgxGistModule
50+
],
51+
...
52+
})
53+
export class AppModule { }
54+
```
55+
56+
# Usage
57+
58+
### Default - fetched gist (auto cached for 24 hours)
59+
60+
ngx-gist will fetch the gist once and store it locally for 24 hours. In that timeframe, if the user returns or visits another page where this gist was previously loaded, it will reload the content without having to reach out to GitHub again.
61+
```html
62+
<ngx-gist gistId="gistId_123abc"></ngx-gist>
63+
```
64+
65+
### Fetched gist (forced no cache)
66+
67+
Force no cache. This will force ngx-gist to retrieve the content live from GitHub every time this content loads. This is disabled by default, but could be useful if your gists change frequently.
68+
```html
69+
<ngx-gist
70+
gistId="gistId_123abc"
71+
[useCache]="false"
72+
></ngx-gist>
73+
```
74+
75+
### Displaying one specific file
76+
77+
Display only one specific file when your gist has many.
78+
```html
79+
<ngx-gist
80+
displayOnlyFileNames="super.js"
81+
gistId="gistId_123abc"
82+
></ngx-gist>
83+
```
84+
85+
### Displaying multiple, specific files
86+
87+
Display only one specific file when your gist has many.
88+
```html
89+
<ngx-gist
90+
[displayOnlyFileNames]="['csstest.css', 'main.ts']"
91+
gistId="gistId_123abc"
92+
></ngx-gist>
93+
```
94+
95+
### Displaying a basic code snippet (without a remote gist)
96+
97+
These are not fetched from GitHub and are brought in elsewhere from your application (seperate HTTP request, or statically for example). With this method you can display code snippets without having to create a remote gist. Also, please notice here that no "Open Gist on GitHub" link is displayed here.
98+
```html
99+
<ngx-gist [gist]="localGistObject"></ngx-gist>
100+
```
101+
102+
### Hiding line numbers
103+
104+
Line numbers are enabled by default, but you can turn them off like so.
105+
```html
106+
<ngx-gist
107+
gistId="d55ea012b585a16a9970878d90106d74"
108+
[showLineNumbers]="false"
109+
></ngx-gist>
110+
```
111+
112+
# Component API
113+
114+
| Input Name | Input Typing | Default Value | Description |
115+
| ------------------------ | ---------------------------------------- | ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
116+
| **displayOnlyFileNames** | string \| readonly string[] \| undefined | `undefined` | Display in the DOM only the selected filename(s) from the gists files array. Can be either a string or string array. File names much match exactly, be sure to remove any leading or trailing whitespace in the provided strings. |
117+
| **hideGistLink** | bool | `false` | Optionally hide the gist link which opens the gist on GitHub. The gist links automatically dispaly for remote gists, but can be hidden with this feature. |
118+
| **gist** | NgxGist \| undefined | `undefined` | Provide a static gist model here directly which will be displayed if no `gistId` is provided for remote fetching. Also this model will be displayed should a fetch fail when retrieving `gistId`, or overwritten once the pertaining `gistId` data is fetched. |
119+
| **gistId** | string | `undefined` | Provide the GitHub gist id to be fetched and loaded. This can be found in URL of the gists you create. For example the id `TH1515th31DT0C0PY` in: https://gist.github.com/FakeUserName/TH1515th31DT0C0PY. Alternatively, provide a value directly in the sibling input `gist`. |
120+
| **languageName** | string \| undefined | `undefined` | When defined, override automatic language detection [and styling] and treat all gists as this lanuage. See supported language strings here: https://github.com/highlightjs/highlight.js/blob/main/SUPPORTED_LANGUAGES.md |
121+
| **materialTheme** | MaterialPrebuiltTheme \| undefined | `undefined` | Define a material core theme to apply. Ideally, you should already have your global material theme set at the root of your project so try to avoid using this if possible. Note: These are loaded from the CDN: `https://unpkg.com` |
122+
| **showLineNumbers** | bool | `true` | Display or hide the line numbers in your gist code snippets. |
123+
| **useCache** | bool | `true` | Cache the GitHub gist request in local memory for 24 hours. GitHub has a request limit, so this helps in reducing bandwidth. Loads previously fetched gist content from the users machine on refresh and page re-visits. |
124+
125+
# Compatibility
126+
127+
| Angular version | @proangular/ngx-gist | Install |
128+
| --------------- | -------------------------- | ------------------------------------ |
129+
| v14 | v1.x.x | `ng add @proangular/ngx-gist@latest` |
130+
| v13 | v1.x.x | `ng add @proangular/ngx-gist@latest` |
131+
| v12 | v1.x.x | `ng add @proangular/ngx-gist@latest` |
132+
133+
# Development
134+
135+
Please submit all issues, and feature requests here: [https://github.com/ProAngular/ngx-gist/issues](https://github.com/ProAngular/ngx-gist/issues)
136+
137+
Contribution:
138+
139+
1. Clone the repo and create a new branch:
140+
* `git clone https://github.com/ProAngular/ngx-gist.git`
141+
* `git checkout -b username/feature-or-bug-description`
142+
2. Bump up the version of package in `package.json` and `package-lock.json`, commit all changes, push.
143+
* `git add -A`
144+
* `git commit -m "My commit message"`
145+
* `git push origin username/feature-or-bug-description`
146+
3. Submit code in published PR for review and approval. Add a good description and link any possible user stories or bugs.
147+
* [Create a new pull request](https://github.com/ProAngular/ngx-gist/compare).
148+
4. Allow CI actions to completely run and verify files.
149+
5. Add/ping reviewers and await approval.
150+
151+
Thank you for any and all contributions!
152+
153+
# Donation
154+
155+
As a husband and father of four children, your donations mean the world to me! Any donations are greatly appreciated and keep me going!
156+
* [https://www.paypal.me/CodyTolene](https://www.paypal.me/CodyTolene)
157+
* [https://github.com/sponsors/ProAngular](https://github.com/sponsors/ProAngular)
158+
159+
# License
160+
161+
Copyright &copy; 2022 [Cody Tolene](https://www.CodyTolene.com)
162+
163+
All content is licensed under the [MIT license].
164+
165+
[mit license]: LICENSE

src/app/app.component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { Component } from '@angular/core';
1616
<h4>FETCHED GIST (AUTO CACHED FOR 24 HOURS)</h4>
1717
<p>
1818
ngx-gist will fetch the gist once and store it locally for 24 hours. In
19-
that timeframe if the user returns or visits another page where this
19+
that timeframe, if the user returns or visits another page where this
2020
gist was previously loaded, it will reload the content without having to
2121
reach out to GitHub again.
2222
</p>
@@ -50,8 +50,8 @@ import { Component } from '@angular/core';
5050
<h4>DISPLAYING A BASIC CODE SNIPPET (WITHOUT A REMOTE GIST)</h4>
5151
<p>
5252
These are not fetched from GitHub and are brought in elsewhere from your
53-
application (seperate HTTP request, or statically for example). With
54-
this method you can display code snippets without having to create a
53+
application (separate HTTP request, or statically, for example). With
54+
this method, you can display code snippets without having to create a
5555
remote gist. Also, please notice here that no "Open Gist on GitHub" link
5656
is displayed here.
5757
</p>

src/app/app.module.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@ import { NgxGistModule } from './public/ngx-gist.module';
55
import { BodyComponent, FooterComponent, HeaderComponent } from './layout';
66
import { HttpClientModule } from '@angular/common/http';
77
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
8+
import { MatToolbarModule } from '@angular/material/toolbar';
9+
import { MatButtonModule } from '@angular/material/button';
810

911
@NgModule({
1012
declarations: [AppComponent, BodyComponent, FooterComponent, HeaderComponent],
1113
imports: [
1214
BrowserAnimationsModule,
1315
BrowserModule,
1416
HttpClientModule,
17+
MatButtonModule,
18+
MatToolbarModule,
1519
NgxGistModule,
1620
],
1721
providers: [],

src/app/layout/body.component.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { Component } from '@angular/core';
1212
section {
1313
padding: 1rem;
1414
min-height: 90vh;
15+
margin-top: 64px;
1516
}
1617
`,
1718
],

src/app/layout/header.component.ts

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,55 @@ import { Component } from '@angular/core';
33
@Component({
44
selector: 'ngx-header',
55
template: `
6-
<header>
7-
<a href="https://www.ProAngular.com" target="_blank">
8-
<img src="assets/images/pro-angular-logo-full.png" />
9-
</a>
10-
</header>
6+
<mat-toolbar class="mat-elevation-z6">
7+
<mat-toolbar-row>
8+
<a class="logo" href="https://www.ProAngular.com" target="_blank">
9+
<img src="assets/images/pro-angular-logo-full.png" />
10+
</a>
11+
<div class="github-link-container">
12+
<a
13+
href="https://github.com/ProAngular/ngx-gist"
14+
aria-label="GitHub Repo"
15+
target="_blank"
16+
>
17+
<img class="git-hub" src="assets/images/git-hub.svg" />
18+
</a>
19+
</div>
20+
</mat-toolbar-row>
21+
</mat-toolbar>
1122
`,
1223
styles: [
1324
`
14-
header {
25+
:host,
26+
mat-toolbar {
27+
position: fixed;
1528
background-color: #1775d1;
16-
padding: 0.5rem 1rem;
29+
padding: 0;
30+
z-index: 1000;
31+
width: 100%;
32+
height: 64px;
33+
top: 0;
34+
}
35+
a.logo,
36+
img.git-hub {
37+
height: 40px;
38+
}
39+
.github-link-container {
40+
display: flex;
41+
justify-content: flex-end;
42+
align-items: center;
43+
width: 100%;
44+
min-width: 6.5rem;
45+
height: 100%;
46+
margin-right: 1rem;
47+
position: relative;
48+
margin: 0;
49+
50+
> a {
51+
background-color: transparent;
52+
border: none;
53+
cursor: pointer;
54+
}
1755
}
1856
`,
1957
],

src/app/public/ngx-gist.component.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ export class NgxGistComponent implements OnInit {
6161
private readonly ngxGistLineNumbersService: NgxGistLineNumbersService,
6262
private readonly ngxGistThemeService: NgxGistThemeService,
6363
) {}
64+
65+
// TODO: Apply HighlightJs code theme.
66+
// @Input() public codeTheme?: unknown;
67+
6468
/**
6569
* Display in the DOM only the selected filename(s) from the gists files array.
6670
*
@@ -132,7 +136,7 @@ export class NgxGistComponent implements OnInit {
132136
* Tip: See theming Angular Material: https://material.angular.io/guide/theming
133137
* if you need help applying a global material theme.
134138
*/
135-
@Input() public materialTheme: MaterialPrebuiltTheme | undefined = undefined;
139+
@Input() public materialTheme?: MaterialPrebuiltTheme;
136140
/**
137141
* Display or hide the line numbers in your gist code snippets.
138142
*

src/assets/images/git-hub.svg

Lines changed: 35 additions & 0 deletions
Loading

src/styles.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@
1515
body {
1616
padding: 0;
1717
margin: 0;
18+
background-color: #faf9f6;
1819
}

0 commit comments

Comments
 (0)