|
1 | 1 | <p align="center">
|
2 | 2 | <a href="https://www.ProAngular.com" target="_blank">
|
3 |
| - <img src="src/assets/images/pro-angular-logo.png" /> |
| 3 | + <img src="https://github.com/ProAngular/ngx-gist/raw/main/src/assets/images/pro-angular-logo.png" /> |
4 | 4 | </a>
|
5 | 5 | <h1 align="center">
|
6 | 6 | <a href="https://www.ProAngular.com" target="_blank">
|
7 | 7 | Pro Angular
|
8 |
| - </a>: GitHub gist Code Snippet Display |
| 8 | + </a>: GitHub gist Code Snippet Tabs |
9 | 9 | </h1>
|
10 | 10 | </p>
|
11 | 11 |
|
|
14 | 14 | [](https://gitter.im/ProAngular/community)
|
15 | 15 | [](https://github.com/ProAngular/ngx-gist/actions/workflows/on-merge-main-deploy-gpr.yml)
|
16 | 16 | [](https://github.com/ProAngular/ngx-gist/actions/workflows/on-merge-main-deploy-npmjs.yml)
|
| 17 | +[](https://www.npmjs.com/package/@proangular/ngx-gist) |
| 18 | +[](https://bundlephobia.com/result?p=ProAngular/ngx-gist) |
| 19 | +[](/LICENSE) |
17 | 20 |
|
18 | 21 | # Description
|
19 | 22 |
|
20 |
| -An Angular Material and HighlighJs styled display box for GitHub gist and local code snippets. |
| 23 | +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! |
21 | 24 |
|
22 | 25 | # Demo
|
23 | 26 |
|
24 |
| -TODO: Further documentation. |
| 27 | +TODO: Add demo here. |
| 28 | + |
| 29 | +# Requirements |
| 30 | + |
| 31 | +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. |
| 32 | + |
| 33 | +# Installation |
| 34 | + |
| 35 | +```bash |
| 36 | +ng add @proangular/ngx-gist@latest |
| 37 | +``` |
| 38 | +or |
| 39 | +```bash |
| 40 | +npm install @proangular/ngx-gist --save |
| 41 | +``` |
| 42 | + |
| 43 | +Import `NgxGistModule` where needed |
| 44 | +```diff |
| 45 | +... |
| 46 | ++ import { NgxGistModule } from '@proangular/ngx-gist'; |
| 47 | +... |
| 48 | + |
| 49 | +@NgModule({ |
| 50 | + imports: [ |
| 51 | + ... |
| 52 | ++ NgxGistModule |
| 53 | + ], |
| 54 | + ... |
| 55 | +}) |
| 56 | +export class AppModule { } |
| 57 | +``` |
| 58 | + |
| 59 | +# Usage |
| 60 | + |
| 61 | +### Default - fetched gist (auto cached for 24 hours) |
| 62 | + |
| 63 | +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. |
| 64 | +```html |
| 65 | +<ngx-gist gistId="gistId_123abc"></ngx-gist> |
| 66 | +``` |
| 67 | + |
| 68 | +### Fetched gist (forced no cache) |
| 69 | + |
| 70 | +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. |
| 71 | +```html |
| 72 | +<ngx-gist |
| 73 | + gistId="gistId_123abc" |
| 74 | + [useCache]="false" |
| 75 | +></ngx-gist> |
| 76 | +``` |
| 77 | + |
| 78 | +### Displaying one specific file |
| 79 | + |
| 80 | +Display only one specific file when your gist has many. |
| 81 | +```html |
| 82 | +<ngx-gist |
| 83 | + displayOnlyFileNames="super.js" |
| 84 | + gistId="gistId_123abc" |
| 85 | +></ngx-gist> |
| 86 | +``` |
| 87 | + |
| 88 | +### Displaying multiple, specific files |
| 89 | + |
| 90 | +Display only one specific file when your gist has many. |
| 91 | +```html |
| 92 | +<ngx-gist |
| 93 | + [displayOnlyFileNames]="['csstest.css', 'main.ts']" |
| 94 | + gistId="gistId_123abc" |
| 95 | +></ngx-gist> |
| 96 | +``` |
| 97 | + |
| 98 | +### Displaying a basic code snippet (without a remote gist) |
| 99 | + |
| 100 | +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. |
| 101 | +```html |
| 102 | +<ngx-gist [gist]="localGistObject"></ngx-gist> |
| 103 | +``` |
| 104 | + |
| 105 | +### Hiding line numbers |
| 106 | + |
| 107 | +Line numbers are enabled by default, but you can turn them off like so. |
| 108 | +```html |
| 109 | +<ngx-gist |
| 110 | + gistId="d55ea012b585a16a9970878d90106d74" |
| 111 | + [showLineNumbers]="false" |
| 112 | +></ngx-gist> |
| 113 | +``` |
| 114 | + |
| 115 | +# Component API |
| 116 | + |
| 117 | +| Input Name | Input Typing | Default Value | Description | |
| 118 | +| ------------------------ | ---------------------------------------- | ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | |
| 119 | +| **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. | |
| 120 | +| **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. | |
| 121 | +| **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. | |
| 122 | +| **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`. | |
| 123 | +| **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 | |
| 124 | +| **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` | |
| 125 | +| **showLineNumbers** | bool | `true` | Display or hide the line numbers in your gist code snippets. | |
| 126 | +| **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. | |
| 127 | + |
| 128 | +# Compatibility |
| 129 | + |
| 130 | +| Angular version | @proangular/ngx-gist | Install | |
| 131 | +| --------------- | -------------------------- | ------------------------------------ | |
| 132 | +| v14 | v1.x.x | `ng add @proangular/ngx-gist@latest` | |
| 133 | +| v13 | v1.x.x | `ng add @proangular/ngx-gist@latest` | |
| 134 | +| v12 | v1.x.x | `ng add @proangular/ngx-gist@latest` | |
| 135 | + |
| 136 | +# Development |
| 137 | + |
| 138 | +Please submit all issues, and feature requests here: [https://github.com/ProAngular/ngx-gist/issues](https://github.com/ProAngular/ngx-gist/issues) |
| 139 | + |
| 140 | +Contribution: |
| 141 | + |
| 142 | +1. Clone the repo and create a new branch: |
| 143 | + * `git clone https://github.com/ProAngular/ngx-gist.git` |
| 144 | + * `git checkout -b username/feature-or-bug-description` |
| 145 | +2. Bump up the version of package in `package.json` and `package-lock.json`, commit all changes, push. |
| 146 | + * `git add -A` |
| 147 | + * `git commit -m "My commit message"` |
| 148 | + * `git push origin username/feature-or-bug-description` |
| 149 | +3. Submit code in published PR for review and approval. Add a good description and link any possible user stories or bugs. |
| 150 | + * [Create a new pull request](https://github.com/ProAngular/ngx-gist/compare). |
| 151 | +4. Allow CI actions to completely run and verify files. |
| 152 | +5. Add/ping reviewers and await approval. |
| 153 | + |
| 154 | +Thank you for any and all contributions! |
| 155 | + |
| 156 | +# Donation |
| 157 | + |
| 158 | +As a husband and father of four children, your donations mean the world to me! Any donations are greatly appreciated and keep me going! |
| 159 | +* [https://www.paypal.me/CodyTolene](https://www.paypal.me/CodyTolene) |
| 160 | +* [https://github.com/sponsors/ProAngular](https://github.com/sponsors/ProAngular) |
| 161 | + |
| 162 | +# License |
| 163 | + |
| 164 | +Copyright © 2022 [Cody Tolene](https://www.CodyTolene.com) |
| 165 | + |
| 166 | +All content is licensed under the [MIT license]. |
| 167 | + |
| 168 | +[mit license]: LICENSE |
0 commit comments