Skip to content

Commit

Permalink
init: publish initial version
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Hodges committed Jan 10, 2017
1 parent bef9ead commit 3854a31
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 0 deletions.
Empty file added .npmignore
Empty file.
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,40 @@
# ng2-gist
Angular 2 Component for embedding a gist within an Angular site

## Code Example

In order to use the component in your Angular 2 project after installation, follow these steps:

- Declare `ng2Gist` within app.module.ts

```@NgModule({
declarations: [
AppComponent,
ng2Gist
],
imports: [
BrowserModule,
FormsModule,
HttpModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
```
- Use the `ng2-gist` component in any template files by using the `ng2-gist` tag along with username and gistId
```html
<ng2-gist [gistId]="'{username}/{gistId}'"></ng2-gist>
```

## Motivation
This project was initiated after a search for an Angular 2 component of its kind returned no results.

## Installation

`npm i --save ng2-gist`

## Contributors

## License
MIT
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './lib/ng2-gist.component';
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exports.ng2Gist = require('./lib/ng2-gist.component').ng2Gist;
35 changes: 35 additions & 0 deletions src/ng2-gist.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import {Component, Input, ViewChild, ElementRef, AfterViewInit} from '@angular/core';

@Component({
selector: 'ng2-gist',
template:`
<iframe #iframe type="text/javascript" width="100%" frameborder="0"></iframe>
`,
styleUrls: []
})

export class ng2Gist implements AfterViewInit {
@ViewChild('iframe') iframe:ElementRef;
@Input() gistId;

constructor() { }

ngAfterViewInit() {
this.iframe.nativeElement.id = 'gist-' + this.gistId;
let doc = this.iframe.nativeElement.contentDocument || this.iframe.nativeElement.contentElement.contentWindow;
let content = `
<html>
<head>
<base target="_parent">
</head>
<body onload="parent.document.getElementById('${this.iframe.nativeElement.id}')
.style.height=document.body.scrollHeight + 'px'">
<script type="text/javascript" src="https://gist.github.com/${this.gistId}.js"></script>
</body>
</html>
`;
doc.open();
doc.write(content);
doc.close();
}
}
16 changes: 16 additions & 0 deletions src/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"compilerOptions": {
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es6",
"module": "commonjs",
"moduleResolution": "node",
"removeComments": true,
"sourceMap": true,
"outDir": "../lib",
"declaration": true
},
"exclude": [
"node_modules"
]
}

0 comments on commit 3854a31

Please sign in to comment.