Skip to content

Commit

Permalink
feat(showcase): use marked and prismjs to highlight the code
Browse files Browse the repository at this point in the history
  • Loading branch information
fpaul-1A committed Nov 14, 2024
1 parent dc80c32 commit acc9d88
Show file tree
Hide file tree
Showing 57 changed files with 1,698 additions and 236 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 5 additions & 2 deletions apps/showcase/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,17 @@
"ag-grid-angular": "~32.3.0",
"ag-grid-community": "~32.3.0",
"bootstrap": "5.3.3",
"highlight.js": "^11.8.0",
"clipboard": "^2.0.11",
"intl-messageformat": "~10.7.0",
"marked": "^12.0.0",
"monaco-editor": "~0.52.0",
"ngx-highlightjs": "^12.0.0",
"ngx-markdown": "^18.1.0",
"ngx-monaco-editor-v2": "^18.0.0",
"ngx-monaco-tree": "^18.1.0",
"pixelmatch": "^5.2.1",
"pngjs": "^7.0.0",
"prism-themes": "^1.9.0",
"prismjs": "^1.28.0",
"rxjs": "^7.8.1",
"sass-loader": "^14.0.0",
"tslib": "^2.6.2",
Expand Down
14 changes: 13 additions & 1 deletion apps/showcase/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
],
"styles": [
"apps/showcase/src/styles.scss",
"prism-themes/themes/prism-vsc-dark-plus.css",
{
"inject": false,
"input": "apps/showcase/src/style/dark-theme/dark-theme.scss",
Expand All @@ -88,7 +89,18 @@
"bundleName": "horizon-theme"
}
],
"scripts": []
"scripts": [
"clipboard",
"prismjs",
"prismjs/components/prism-bash",
"prismjs/components/prism-css",
"prismjs/components/prism-json",
"prismjs/components/prism-markdown",
"prismjs/components/prism-markup",
"prismjs/components/prism-regex",
"prismjs/components/prism-typescript",
"prismjs/components/prism-yaml"
]
},
"configurations": {
"production": {
Expand Down
33 changes: 16 additions & 17 deletions apps/showcase/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {PetApi} from '@o3r-training/showcase-sdk';
import { registerLocaleData } from '@angular/common';
import localeEN from '@angular/common/locales/en';
import localeFR from '@angular/common/locales/fr';
import { isDevMode, NgModule } from '@angular/core';
import { isDevMode, NgModule, SecurityContext } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { NgbOffcanvasModule } from '@ng-bootstrap/ng-bootstrap';
Expand All @@ -26,11 +26,12 @@ import {
import { ConsoleLogger, Logger, LOGGER_CLIENT_TOKEN, LoggerService } from '@o3r/logger';
import { OTTER_RULES_ENGINE_DEVTOOLS_OPTIONS, RulesEngineRunnerModule } from '@o3r/rules-engine';
import { OTTER_STYLING_DEVTOOLS_OPTIONS, StylingDevtoolsModule } from '@o3r/styling';
import { HIGHLIGHT_OPTIONS } from 'ngx-highlightjs';
import { ScrollBackTopPresComponent, SidenavPresComponent } from '../components/index';
import { CLIPBOARD_OPTIONS, provideMarkdown } from 'ngx-markdown';
import { ClipboardButtonPresComponent, ScrollBackTopPresComponent, SidenavPresComponent } from '../components/index';
import { DatePickerHebrewInputPresComponent } from '../components/utilities/date-picker-input-hebrew';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { markedAlert } from '../helpers/marked-alert-extension';


const runtimeChecks: Partial<RuntimeChecks> = {
Expand Down Expand Up @@ -113,27 +114,25 @@ export function registerCustomComponents(): Map<string, any> {
],
providers: [
{provide: MESSAGE_FORMAT_CONFIG, useValue: {}},
{
provide: HIGHLIGHT_OPTIONS,
useValue: {
coreLibraryLoader: () => import('highlight.js/lib/core'),
languages: {
bash: () => import('highlight.js/lib/languages/bash'),
css: () => import('highlight.js/lib/languages/css'),
json: () => import('highlight.js/lib/languages/json'),
typescript: () => import('highlight.js/lib/languages/typescript'),
xml: () => import('highlight.js/lib/languages/xml')
}
}
},
{provide: LOGGER_CLIENT_TOKEN, useValue: new ConsoleLogger()},
{provide: PetApi, useFactory: petApiFactory, deps: [LoggerService]},
{provide: OTTER_CONFIGURATION_DEVTOOLS_OPTIONS, useValue: {isActivatedOnBootstrap: true}},
{provide: OTTER_LOCALIZATION_DEVTOOLS_OPTIONS, useValue: {isActivatedOnBootstrap: true}},
{provide: OTTER_RULES_ENGINE_DEVTOOLS_OPTIONS, useValue: {isActivatedOnBootstrap: true}},
{provide: OTTER_COMPONENTS_DEVTOOLS_OPTIONS, useValue: {isActivatedOnBootstrap: true}},
{provide: OTTER_APPLICATION_DEVTOOLS_OPTIONS, useValue: {isActivatedOnBootstrap: true, appName: 'showcase'}},
{provide: OTTER_STYLING_DEVTOOLS_OPTIONS, useValue: {isActivatedOnBootstrap: true}}
{provide: OTTER_STYLING_DEVTOOLS_OPTIONS, useValue: {isActivatedOnBootstrap: true}},
provideMarkdown({
clipboardOptions: {
provide: CLIPBOARD_OPTIONS,
useValue: {
buttonComponent: ClipboardButtonPresComponent
}
},
markedExtensions: [markedAlert()],
/* Templates are only internal, no need to sanitize */
sanitize: SecurityContext.NONE
})
],
bootstrap: [AppComponent]
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { IN_PAGE_NAV_PRES_DIRECTIVES, InPageNavPresComponent } from '../../compo
import { AsyncPipe } from '@angular/common';
import { ComponentReplacementPresComponent } from '../../components/showcase/component-replacement/component-replacement-pres.component';
import { RouterModule } from '@angular/router';
import { CopyTextPresComponent } from '../../components/utilities/copy-text/copy-text-pres.component';
import { MarkdownModule } from 'ngx-markdown';

@O3rComponent({ componentType: 'Page' })
@Component({
Expand All @@ -15,7 +15,14 @@ import { CopyTextPresComponent } from '../../components/utilities/copy-text/copy
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
imports: [RouterModule, InPageNavPresComponent, AsyncPipe, IN_PAGE_NAV_PRES_DIRECTIVES, ComponentReplacementPresComponent, CopyTextPresComponent]
imports: [
RouterModule,
InPageNavPresComponent,
AsyncPipe,
IN_PAGE_NAV_PRES_DIRECTIVES,
ComponentReplacementPresComponent,
MarkdownModule
]
})
export class ComponentReplacementComponent implements AfterViewInit {
private readonly inPageNavPresService = inject(InPageNavPresService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentReplacementComponent } from './component-replacement.component';
import { RouterModule } from '@angular/router';
import { AsyncPipe } from '@angular/common';
import { provideMarkdown } from 'ngx-markdown';
import { ComponentReplacementPresComponent } from '../../components/showcase/component-replacement/component-replacement-pres.component';

describe('ComponentReplacementComponent', () => {
Expand All @@ -13,7 +14,8 @@ describe('ComponentReplacementComponent', () => {
await TestBed.configureTestingModule({
imports: [ComponentReplacementComponent,
RouterModule.forRoot([]),
AsyncPipe]
AsyncPipe],
providers: [provideMarkdown()]
}).overrideComponent(ComponentReplacementComponent, {
remove: { imports: [ComponentReplacementPresComponent] }
}).compileComponents();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ <h2 id="component-replacement-example">Example</h2>
<h2 id="comp-replacement-install">How to install</h2>
<p> To use the <i>component replacement mechanism</i> you'll need to install the <i>&#64;o3r/components</i> package.</p>
<div>
<o3r-copy-text-pres [wrap]="true" language="bash" text="ng add @o3r/components"></o3r-copy-text-pres>
<markdown clipboard ngPreserveWhitespaces>
```bash
ng add &#64;o3r/components
```
</markdown>
</div>

<h2 id="comp-replacement-references">References</h2>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { AfterViewInit, ChangeDetectionStrategy, Component, computed, inject, Qu
import { RouterModule } from '@angular/router';
import { ConfigurationBaseServiceModule } from '@o3r/configuration';
import { O3rComponent } from '@o3r/core';
import { ConfigurationPresComponent, CopyTextPresComponent, IN_PAGE_NAV_PRES_DIRECTIVES, InPageNavLink, InPageNavLinkDirective, InPageNavPresService } from '../../components/index';
import { MarkdownModule } from 'ngx-markdown';
import { ConfigurationPresComponent, IN_PAGE_NAV_PRES_DIRECTIVES, InPageNavLink, InPageNavLinkDirective, InPageNavPresService } from '../../components/index';
import { ConfigurationPresConfig } from '../../components/showcase/configuration/configuration-pres.config';

const CONFIG_OVERRIDE: ConfigurationPresConfig = {
Expand All @@ -24,9 +25,9 @@ const CONFIG_OVERRIDE: ConfigurationPresConfig = {
RouterModule,
ConfigurationPresComponent,
ConfigurationBaseServiceModule,
CopyTextPresComponent,
IN_PAGE_NAV_PRES_DIRECTIVES,
AsyncPipe
AsyncPipe,
MarkdownModule
],
templateUrl: './configuration.template.html',
styleUrls: ['./configuration.style.scss'],
Expand Down
4 changes: 3 additions & 1 deletion apps/showcase/src/app/configuration/configuration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
import { RouterModule } from '@angular/router';
import { StoreModule } from '@ngrx/store';
import { O3rElement } from '@o3r/testing/core';
import { provideMarkdown } from 'ngx-markdown';
import { ConfigurationComponent } from './configuration.component';
import { ConfigurationFixtureComponent } from './configuration.fixture';
let componentFixture: ConfigurationFixtureComponent;
Expand All @@ -18,7 +19,8 @@ describe('ConfigurationComponent', () => {
StoreModule.forRoot(),
RouterModule.forRoot([]),
AsyncPipe
]
],
providers: [provideMarkdown()]
});
fixture = TestBed.createComponent(ConfigurationComponent);
component = fixture.componentInstance;
Expand Down
32 changes: 26 additions & 6 deletions apps/showcase/src/app/configuration/configuration.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ <h2 id="configuration-examples">Examples</h2>
</p>
<o3r-configuration-pres [config]="config()"></o3r-configuration-pres>
<div class="row">
<o3r-copy-text-pres language="html" [text]="codeConfig()" class="col-12 col-md-8 col-lg-9"></o3r-copy-text-pres>
<markdown clipboard ngPreserveWhitespaces [data]="codeConfig() | language: 'html'" class="col-12 col-md-8 col-lg-9"></markdown>
<div class="d-flex gap-2 align-self-start mt-md-2 pb-3 col-12 col-md-4 col-lg-3">
<button type="button" class="btn btn-primary" id="btn-override-config" [disabled]="!!config()"
[class.disabled]="config()" (click)="toggleConfig()">Override</button>
Expand All @@ -43,19 +43,39 @@ <h2 id="configuration-examples">Examples</h2>
</div>
<h2 id="configuration-install">How to install</h2>
<div>
<o3r-copy-text-pres [wrap]="true" language="bash" text="ng add @o3r/configuration"></o3r-copy-text-pres>
<markdown clipboard ngPreserveWhitespaces>
```bash
ng add &#64;o3r/configuration
```
</markdown>
</div>
<h2 id="configuration-component-generation">How to generate a configurable component</h2>
<o3r-copy-text-pres [wrap]="true" language="bash" text="ng g component ComponentName --use-otter-config"></o3r-copy-text-pres>
<markdown clipboard ngPreserveWhitespaces>
```bash
ng g component ComponentName --use-otter-config
```
</markdown>
<h2 id="configuration-add-config-later">How to add configuration to a component</h2>
<o3r-copy-text-pres [wrap]="true" language="bash" text="ng g configuration-to-component --path='path/to/the/component/class/file'"></o3r-copy-text-pres>
<markdown clipboard ngPreserveWhitespaces>
```bash
ng g configuration-to-component --path='path/to/the/component/class/file'
```
</markdown>
<h2 id="configuration-metadata">Metadata</h2>
<div>
<h3>How to extract</h3>
<o3r-copy-text-pres [wrap]="true" language="bash" text="ng run project-name:extract-components"></o3r-copy-text-pres>
<markdown clipboard ngPreserveWhitespaces>
```bash
ng run project-name:extract-components
```
</markdown>
<p>It will extract components' configuration and generate the two following files: <code>component.config.metadata.json</code> and <code>component.class.metadata.json</code></p>
<p>Check the list of options available by running:</p>
<o3r-copy-text-pres [wrap]="true" language="bash" text="ng run project-name:extract-components --help"></o3r-copy-text-pres>
<markdown clipboard ngPreserveWhitespaces>
```bash
ng run project-name:extract-components --help
```
</markdown>
</div>
<h2 id="configuration-references">References</h2>
<div>
Expand Down
7 changes: 4 additions & 3 deletions apps/showcase/src/app/design-token/design-token.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ import { AsyncPipe } from '@angular/common';
import { AfterViewInit, ChangeDetectionStrategy, Component, inject, QueryList, ViewChildren, ViewEncapsulation } from '@angular/core';
import { RouterLink } from '@angular/router';
import { O3rComponent } from '@o3r/core';
import { CopyTextPresComponent, DesignTokenPresComponent, IN_PAGE_NAV_PRES_DIRECTIVES, InPageNavLink, InPageNavLinkDirective, InPageNavPresService } from '../../components';
import { MarkdownModule } from 'ngx-markdown';
import { DesignTokenPresComponent, IN_PAGE_NAV_PRES_DIRECTIVES, InPageNavLink, InPageNavLinkDirective, InPageNavPresService } from '../../components';

@O3rComponent({ componentType: 'Page' })
@Component({
selector: 'o3r-design-token',
standalone: true,
imports: [
AsyncPipe,
CopyTextPresComponent,
DesignTokenPresComponent,
RouterLink,
IN_PAGE_NAV_PRES_DIRECTIVES
IN_PAGE_NAV_PRES_DIRECTIVES,
MarkdownModule
],
templateUrl: './design-token.template.html',
styleUrl: './design-token.style.scss',
Expand Down
4 changes: 3 additions & 1 deletion apps/showcase/src/app/design-token/design-token.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { RouterModule } from '@angular/router';
import { provideMarkdown } from 'ngx-markdown';

import { DesignTokenComponent } from './design-token.component';

Expand All @@ -12,7 +13,8 @@ describe('DesignTokenComponent', () => {
imports: [
DesignTokenComponent,
RouterModule.forRoot([])
]
],
providers: [provideMarkdown()]
})
.compileComponents();

Expand Down
20 changes: 16 additions & 4 deletions apps/showcase/src/app/design-token/design-token.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,23 @@ <h2 id="design-token-examples">Examples</h2>
<a href="https://github.com/AmadeusITGroup/otter/blob/main/apps/showcase/src/components/showcase/design" target="_blank" rel="noopener">Source code</a>
</div>
<h2 id="design-token-install">How to install</h2>
<o3r-copy-text-pres [wrap]="true" language="bash" text="ng add @o3r/design"></o3r-copy-text-pres>
<markdown clipboard ngPreserveWhitespaces>
```bash
ng add &#64;o3r/design
```
</markdown>
<h2 id="configuration-add-config-later">How to add design-tokens to a component</h2>
<o3r-copy-text-pres [wrap]="true" language="bash" text="ng g design-token-to-component --path='path/to/the/component/class/file'"></o3r-copy-text-pres>
<h2 id="design-token-install">How to extract design-tokens from Sass files</h2>
<o3r-copy-text-pres [wrap]="true" language="bash" text="ng g extract-token --component-file-patterns='path/to/the/components/**/*.scss'"></o3r-copy-text-pres>
<markdown clipboard ngPreserveWhitespaces>
```bash
ng g design-token-to-component --path='path/to/the/component/class/file'
```
</markdown>
<h2 id="design-token-extract">How to extract design-tokens from Sass files</h2>
<markdown clipboard ngPreserveWhitespaces>
```bash
ng g extract-token --component-file-patterns='path/to/the/components/**/*.scss'
```
</markdown>
<h2 id="design-token-references">References</h2>
<div>
<ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { AfterViewInit, ChangeDetectionStrategy, Component, inject, QueryList, V
import { RouterModule } from '@angular/router';
import { O3rComponent } from '@o3r/core';
import { DynamicContentModule } from '@o3r/dynamic-content';
import { CopyTextPresComponent, DynamicContentPresComponent, IN_PAGE_NAV_PRES_DIRECTIVES, InPageNavLink, InPageNavLinkDirective, InPageNavPresService } from '../../components/index';
import { MarkdownModule } from 'ngx-markdown';
import { DynamicContentPresComponent, IN_PAGE_NAV_PRES_DIRECTIVES, InPageNavLink, InPageNavLinkDirective, InPageNavPresService } from '../../components/index';

@O3rComponent({ componentType: 'Page' })
@Component({
Expand All @@ -14,8 +15,8 @@ import { CopyTextPresComponent, DynamicContentPresComponent, IN_PAGE_NAV_PRES_DI
DynamicContentModule,
IN_PAGE_NAV_PRES_DIRECTIVES,
DynamicContentPresComponent,
CopyTextPresComponent,
AsyncPipe
AsyncPipe,
MarkdownModule
],
templateUrl: './dynamic-content.template.html',
styleUrls: ['./dynamic-content.style.scss'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { AsyncPipe } from '@angular/common';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { RouterModule } from '@angular/router';
import { O3rElement } from '@o3r/testing/core';
import { provideMarkdown } from 'ngx-markdown';
import { DynamicContentComponent } from './dynamic-content.component';
import { DynamicContentFixtureComponent } from './dynamic-content.fixture';
let componentFixture: DynamicContentFixtureComponent;
Expand All @@ -16,7 +17,8 @@ describe('DynamicContentComponent', () => {
DynamicContentComponent,
RouterModule.forRoot([]),
AsyncPipe
]
],
providers: [provideMarkdown()]
});
fixture = TestBed.createComponent(DynamicContentComponent);
component = fixture.componentInstance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ <h2 id="dynamic-content-example">Example</h2>
</p>
<o3r-dynamic-content-pres></o3r-dynamic-content-pres>
<div class="row">
<o3r-copy-text-pres class="col-12 col-md-8 col-lg-9" language="html" [text]="codeDataDynamicContentPath"></o3r-copy-text-pres>
<markdown clipboard [data]="codeDataDynamicContentPath | language: 'html'"></markdown>
<div class="d-flex gap-2 align-self-start mt-md-2 pb-3 col-12 col-md-4 col-lg-3">
<button type="button" class="btn btn-primary" id="btn-override-config" [disabled]="!!bodyDynamicContentPath"
[class.disabled]="bodyDynamicContentPath" (click)="setLocalStorage()">Override</button>
Expand All @@ -37,7 +37,11 @@ <h2 id="dynamic-content-example">Example</h2>
</div>
<h2 id="dynamic-content-install">How to install</h2>
<div>
<o3r-copy-text-pres [wrap]="true" language="bash" text="ng add @o3r/dynamic-content"></o3r-copy-text-pres>
<markdown clipboard ngPreserveWhitespaces>
```bash
ng add &#64;o3r/dynamic-content
```
</markdown>
</div>
<h2 id="dynamic-content-references">References</h2>
<div>
Expand Down
Loading

0 comments on commit acc9d88

Please sign in to comment.