Skip to content

Ct/wrap up todos #2

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

Merged
merged 10 commits into from
Jul 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
152 changes: 148 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<p align="center">
<a href="https://www.ProAngular.com" target="_blank">
<img src="src/assets/images/pro-angular-logo.png" />
<img src="https://github.com/ProAngular/ngx-gist/raw/main/src/assets/images/pro-angular-logo.png" />
</a>
<h1 align="center">
<a href="https://www.ProAngular.com" target="_blank">
Pro Angular
</a>: GitHub gist Code Snippet Display
</a>: GitHub gist Code Snippet Tabs
</h1>
</p>

Expand All @@ -14,11 +14,155 @@
[![Join the chat at https://gitter.im/ProAngular/community](https://badges.gitter.im/ProAngular/lobby.svg)](https://gitter.im/ProAngular/community)
[![Verify and Deploy to GitHub Packages](https://github.com/ProAngular/ngx-gist/actions/workflows/on-merge-main-deploy-gpr.yml/badge.svg)](https://github.com/ProAngular/ngx-gist/actions/workflows/on-merge-main-deploy-gpr.yml)
[![Verify and Deploy to npmjs](https://github.com/ProAngular/ngx-gist/actions/workflows/on-merge-main-deploy-npmjs.yml/badge.svg)](https://github.com/ProAngular/ngx-gist/actions/workflows/on-merge-main-deploy-npmjs.yml)
[![Monthly Downloads](https://img.shields.io/npm/dm/@ProAngular/ngx-gist.svg)](https://www.npmjs.com/package/@proangular/ngx-gist)
[![npm bundle size (minified + gzip)](https://img.shields.io/bundlephobia/minzip/ProAngular/ngx-gist.svg)](https://bundlephobia.com/result?p=ProAngular/ngx-gist)
[![License](https://img.shields.io/npm/l/express.svg?maxAge=2592000)](/LICENSE)

# Description

An Angular Material and HighlighJs styled display box for GitHub gist and local code snippets.
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!

# Demo

TODO: Further documentation.
TODO: Add demo here.

# Requirements

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.

# Installation

```bash
ng add @proangular/ngx-gist@latest
```
or
```bash
npm install @proangular/ngx-gist --save
```

Import `NgxGistModule` where needed
```diff
...
+ import { NgxGistModule } from '@proangular/ngx-gist';
...

@NgModule({
imports: [
...
+ NgxGistModule
],
...
})
export class AppModule { }
```

# Usage

### Default - fetched gist (auto cached for 24 hours)

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.
```html
<ngx-gist gistId="gistId_123abc"></ngx-gist>
```

### Fetched gist (forced no cache)

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.
```html
<ngx-gist
gistId="gistId_123abc"
[useCache]="false"
></ngx-gist>
```

### Displaying one specific file

Display only one specific file when your gist has many.
```html
<ngx-gist
displayOnlyFileNames="super.js"
gistId="gistId_123abc"
></ngx-gist>
```

### Displaying multiple, specific files

Display only one specific file when your gist has many.
```html
<ngx-gist
[displayOnlyFileNames]="['csstest.css', 'main.ts']"
gistId="gistId_123abc"
></ngx-gist>
```

### Displaying a basic code snippet (without a remote gist)

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.
```html
<ngx-gist [gist]="localGistObject"></ngx-gist>
```

### Hiding line numbers

Line numbers are enabled by default, but you can turn them off like so.
```html
<ngx-gist
gistId="d55ea012b585a16a9970878d90106d74"
[showLineNumbers]="false"
></ngx-gist>
```

# Component API

| Input Name | Input Typing | Default Value | Description |
| ------------------------ | ---------------------------------------- | ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| **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. |
| **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. |
| **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. |
| **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`. |
| **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 |
| **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` |
| **showLineNumbers** | bool | `true` | Display or hide the line numbers in your gist code snippets. |
| **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. |

# Compatibility

| Angular version | @proangular/ngx-gist | Install |
| --------------- | -------------------------- | ------------------------------------ |
| v14 | v1.x.x | `ng add @proangular/ngx-gist@latest` |
| v13 | v1.x.x | `ng add @proangular/ngx-gist@latest` |
| v12 | v1.x.x | `ng add @proangular/ngx-gist@latest` |

# Development

Please submit all issues, and feature requests here: [https://github.com/ProAngular/ngx-gist/issues](https://github.com/ProAngular/ngx-gist/issues)

Contribution:

1. Clone the repo and create a new branch:
* `git clone https://github.com/ProAngular/ngx-gist.git`
* `git checkout -b username/feature-or-bug-description`
2. Bump up the version of package in `package.json` and `package-lock.json`, commit all changes, push.
* `git add -A`
* `git commit -m "My commit message"`
* `git push origin username/feature-or-bug-description`
3. Submit code in published PR for review and approval. Add a good description and link any possible user stories or bugs.
* [Create a new pull request](https://github.com/ProAngular/ngx-gist/compare).
4. Allow CI actions to completely run and verify files.
5. Add/ping reviewers and await approval.

Thank you for any and all contributions!

# Donation

As a husband and father of four children, your donations mean the world to me! Any donations are greatly appreciated and keep me going!
* [https://www.paypal.me/CodyTolene](https://www.paypal.me/CodyTolene)
* [https://github.com/sponsors/ProAngular](https://github.com/sponsors/ProAngular)

# License

Copyright &copy; 2022 [Cody Tolene](https://www.CodyTolene.com)

All content is licensed under the [MIT license].

[mit license]: LICENSE
17 changes: 15 additions & 2 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@proangular/ngx-gist",
"version": "1.0.2",
"version": "1.0.3",
"description": "An Angular Material and HighlighJs styled display box for GitHub gist and local code snippets.",
"author": "Pro Angular <webmaster@proangular.com>",
"homepage": "https://www.proangular.com",
Expand Down Expand Up @@ -32,6 +32,7 @@
"@angular/platform-browser": ">=12 <15",
"@ngneat/until-destroy": "^9.2.1",
"highlight.js": "^11.6.0",
"highlightjs-line-numbers.js": "^2.8.0",
"io-ts": "^2.2.17",
"io-ts-types": "^0.5.16"
},
Expand Down
99 changes: 88 additions & 11 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { NgxGist } from './public/ngx-gist.model';
import { Component } from '@angular/core';

@Component({
Expand All @@ -9,26 +10,102 @@ import { Component } from '@angular/core';
<h3 align="center">
Examples of displaying local and GitHub gists and code snippets.
</h3>
<!-- EXAMPLE: FETCH _NEW_ GIST FROM GITHUB (NOT-SAVED) -->

<hr />

<h4>FETCHED GIST (AUTO CACHED FOR 24 HOURS)</h4>
<p>
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.
</p>
<ngx-gist gistId="d55ea012b585a16a9970878d90106d74"></ngx-gist>
<!-- EXAMPLE: FETCH _CACHED_ GIST FROM MEMORY (ON SUBSEQUENT REQUESTS) -->

<h4>FETCHED GIST (FORCED NO CACHE)</h4>
<p>
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.
</p>
<ngx-gist
gistId="d55ea012b585a16a9970878d90106d74"
[useCache]="false"
></ngx-gist>

<h4>DISPLAYING ONE SPECIFIC FILE</h4>
<p>Display only one specific file when your gist has many.</p>
<ngx-gist
displayOnlyFileNames="super.js"
gistId="d55ea012b585a16a9970878d90106d74"
[useCache]="true"
></ngx-gist>
<!-- EXAMPLE: DISPLAYING A SPECIFIC FILE -->

<h4>DISPLAYING MULTIPLE, SPECIFIC FILES</h4>
<p>You can also display any number of specific files by name.</p>
<ngx-gist
displayOnlyFileName="super.js"
[displayOnlyFileNames]="['csstest.css', 'main.ts']"
gistId="d55ea012b585a16a9970878d90106d74"
[useCache]="true"
></ngx-gist>
<!-- TODO: SUPPORT LOCAL GIST -->
<!--

<h4>DISPLAYING A BASIC CODE SNIPPET (WITHOUT A REMOTE GIST)</h4>
<p>
These are not fetched from GitHub and are brought in elsewhere from your
application (separate 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.
</p>
<ngx-gist [gist]="localGistObject"></ngx-gist>
-->

<h4>HIDING LINE NUMBERS</h4>
<p>
Line numbers are enabled by default, but you can turn them off like so.
</p>
<ngx-gist
gistId="d55ea012b585a16a9970878d90106d74"
[showLineNumbers]="false"
></ngx-gist>
</ngx-body>
<ngx-footer #footer></ngx-footer>
`,
styles: [],
styles: [
`
h2 {
margin-top: 2rem;
}
h3 {
margin-bottom: 3rem;
}
`,
],
})
export class AppComponent {}
export class AppComponent {
public readonly localGistObject = NgxGist.create({
// Required
files: [
{
content: getTimeSnippet,
filename: 'get-time.ts',
},
{
content: printHelloWorldSnippet,
filename: 'print-hello-world.js',
},
],
// Optional
created_at: undefined,
languageOverride: undefined,
});
}

const getTimeSnippet = `
function getTime(): number {
return new Date().getTime();
}
`.trimStart();

const printHelloWorldSnippet = `
function printHelloWorld() {
console.log('Hello world!');
}
`.trimStart();
4 changes: 4 additions & 0 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ import { NgxGistModule } from './public/ngx-gist.module';
import { BodyComponent, FooterComponent, HeaderComponent } from './layout';
import { HttpClientModule } from '@angular/common/http';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { MatToolbarModule } from '@angular/material/toolbar';
import { MatButtonModule } from '@angular/material/button';

@NgModule({
declarations: [AppComponent, BodyComponent, FooterComponent, HeaderComponent],
imports: [
BrowserAnimationsModule,
BrowserModule,
HttpClientModule,
MatButtonModule,
MatToolbarModule,
NgxGistModule,
],
providers: [],
Expand Down
1 change: 1 addition & 0 deletions src/app/layout/body.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { Component } from '@angular/core';
section {
padding: 1rem;
min-height: 90vh;
margin-top: 64px;
}
`,
],
Expand Down
Loading