This repository has been archived by the owner on Feb 2, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(examples): highlight code examples in component readme files
- Loading branch information
1 parent
9c377fa
commit 4033074
Showing
25 changed files
with
427 additions
and
216 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
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 |
---|---|---|
@@ -1,5 +1,11 @@ | ||
<p class="examples-intro" *ngIf="value.readme" [innerHtml]="value.readme"></p> | ||
<p class="examples-intro example-readme" *ngIf="value.readme" [innerHtml]="value.readme"></p> | ||
|
||
<h1 class="examples-title">Examples</h1> | ||
|
||
<docs-example *ngFor="let demo of value.examples" [model]="demo"></docs-example> | ||
|
||
<docs-highlight-container | ||
class="examples-intro" | ||
*ngIf="value.documentation" | ||
selector="pre > code" [innerHtml]="value.documentation"> | ||
</docs-highlight-container> |
50 changes: 44 additions & 6 deletions
50
modules/docs/src/app/+components/components.component.scss
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 |
---|---|---|
@@ -1,10 +1,48 @@ | ||
@import "core/style/mixins"; | ||
@import "core/style/variables"; | ||
@import "core/style/default-theme"; | ||
|
||
:host { | ||
.examples-intro { | ||
pre { | ||
padding: 12px; | ||
border: 1px solid lightgray; | ||
background-color: white; | ||
|
||
.example-readme { | ||
pre { | ||
padding: 12px; | ||
border: 1px solid lightgray; | ||
background-color: white; | ||
} | ||
} | ||
.examples-intro { | ||
|
||
&:not(:first-child) { | ||
margin-top: 2em; | ||
} | ||
|
||
h1 { | ||
margin-top: 3em; | ||
color: md-color($md-primary); | ||
} | ||
h2 { | ||
margin-top: 2em; | ||
margin-bottom: 1.5em; | ||
> code { | ||
color: md-color($md-primary); | ||
} | ||
} | ||
table { | ||
background-color: white; | ||
border-collapse: collapse; | ||
width: 100%; | ||
font-size: 0.8em; | ||
th, td { | ||
padding: 4px 12px; | ||
border: 1px solid #ddd; | ||
} | ||
tr { | ||
background-color: #fff; | ||
border-top: 1px solid #ccc; | ||
} | ||
} | ||
|
||
} | ||
} | ||
|
||
} |
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
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
|
||
``` | ||
These components are a work in progress. | ||
This component is experimental. | ||
``` |
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
14 changes: 14 additions & 0 deletions
14
modules/docs/src/app/shared/highlight/highlight-container.component.scss
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 @@ | ||
@import "./highlight"; | ||
|
||
:host { | ||
pre { | ||
@extend .highlight-block; | ||
@extend .higlight-pre; | ||
> code.highlight { | ||
margin-bottom: 0 !important; | ||
font-size: 0.9em; | ||
border: 1px solid lightgrey; | ||
} | ||
} | ||
} | ||
|
46 changes: 46 additions & 0 deletions
46
modules/docs/src/app/shared/highlight/highlight-container.component.spec.ts
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,46 @@ | ||
import { | ||
beforeEach, | ||
beforeEachProviders, | ||
describe, | ||
expect, | ||
it, | ||
inject, | ||
} from '@angular/core/testing'; | ||
import { ComponentFixture, TestComponentBuilder } from '@angular/compiler/testing'; | ||
import { Component } from '@angular/core'; | ||
import { By } from '@angular/platform-browser'; | ||
import { HighlightContainerComponent } from './highlight-container.component.ts'; | ||
|
||
describe('Component: HighlightContainer', () => { | ||
let builder: TestComponentBuilder; | ||
|
||
beforeEachProviders(() => [HighlightContainerComponent]); | ||
beforeEach(inject([TestComponentBuilder], function (tcb: TestComponentBuilder) { | ||
builder = tcb; | ||
})); | ||
|
||
it('should inject the component', inject([HighlightContainerComponent], | ||
(component: HighlightContainerComponent) => { | ||
expect(component).toBeTruthy(); | ||
})); | ||
|
||
it('should create the component', inject([], () => { | ||
return builder.createAsync(HighlightContainerComponentTestController) | ||
.then((fixture: ComponentFixture<any>) => { | ||
let query = fixture.debugElement.query(By.directive(HighlightContainerComponent)); | ||
expect(query).toBeTruthy(); | ||
expect(query.componentInstance).toBeTruthy(); | ||
}); | ||
})); | ||
}); | ||
|
||
@Component({ | ||
selector: 'test', | ||
template: ` | ||
<docs-highlight-container></docs-highlight-container> | ||
`, | ||
directives: [HighlightContainerComponent] | ||
}) | ||
class HighlightContainerComponentTestController { | ||
} | ||
|
36 changes: 36 additions & 0 deletions
36
modules/docs/src/app/shared/highlight/highlight-container.component.ts
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,36 @@ | ||
import {ElementRef, Component, AfterViewInit, Input} from '@angular/core'; | ||
import {HighlightComponent} from './highlight.component'; | ||
|
||
@Component({ | ||
moduleId: module.id, | ||
selector: 'docs-highlight-container', | ||
template: `<ng-content></ng-content>`, | ||
styleUrls: ['highlight-container.component.css'] | ||
}) | ||
export class HighlightContainerComponent implements AfterViewInit { | ||
|
||
@Input() selector: string = ''; | ||
|
||
constructor(private elementRef: ElementRef) { | ||
|
||
} | ||
|
||
ngAfterViewInit() { | ||
// Find children and highlight them in place | ||
if (this.selector !== '' && this.elementRef) { | ||
const blocks = this.elementRef.nativeElement.querySelectorAll(this.selector); | ||
for (var i = 0; i < blocks.length; i++) { | ||
const codeBlock = blocks[i] as HTMLElement; | ||
const inputCode = codeBlock.innerText; | ||
const hasType = codeBlock.className.indexOf('lang-') === 0; | ||
const language = hasType ? codeBlock.className.replace('lang-', '') : 'html'; | ||
|
||
const code = HighlightComponent.highlight(language, inputCode); | ||
codeBlock.classList.add('highlight'); | ||
codeBlock.innerHTML = code; | ||
} | ||
|
||
} | ||
} | ||
|
||
} |
Oops, something went wrong.