This repository has been archived by the owner on Jul 10, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adding curl example * Adding curl snippet
- Loading branch information
Showing
12 changed files
with
133 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<pre>{{ contents }}</pre> |
11 changes: 11 additions & 0 deletions
11
src/app/_components/code-snippet/code-snippet.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,11 @@ | ||
pre { | ||
font-family: Consolas, 'Courier New', Courier, monospace; | ||
color: silver; | ||
background: black; | ||
max-width: 800px; | ||
padding: 5px; | ||
margin: 6px 0px; | ||
overflow: scroll; | ||
overflow-x: auto; | ||
overflow-y: auto; | ||
} |
27 changes: 27 additions & 0 deletions
27
src/app/_components/code-snippet/code-snippet.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,27 @@ | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { NO_ERRORS_SCHEMA } from '@angular/core'; | ||
|
||
import { CodeSnippetComponent } from './code-snippet.component'; | ||
|
||
describe('CodeSnippetComponent', () => { | ||
let component: CodeSnippetComponent; | ||
let fixture: ComponentFixture<CodeSnippetComponent>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [CodeSnippetComponent], | ||
schemas: [NO_ERRORS_SCHEMA], | ||
}) | ||
.compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(CodeSnippetComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
18 changes: 18 additions & 0 deletions
18
src/app/_components/code-snippet/code-snippet.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,18 @@ | ||
import { Component, OnInit, Input } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'app-code-snippet', | ||
templateUrl: './code-snippet.component.html', | ||
styleUrls: ['./code-snippet.component.scss'], | ||
}) | ||
export class CodeSnippetComponent implements OnInit { | ||
|
||
@Input() | ||
contents: string; | ||
|
||
constructor() { } | ||
|
||
ngOnInit() { | ||
} | ||
|
||
} |
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,26 @@ | ||
import { CurlCmdPipe } from './curl-cmd.pipe'; | ||
|
||
describe('CurlCmdPipe', () => { | ||
|
||
const pipe = new CurlCmdPipe(); | ||
|
||
it('create an instance', () => { | ||
expect(pipe).toBeTruthy(); | ||
}); | ||
|
||
it('should generate curl command', () => { | ||
expect(pipe.transform('2 lbs carrots', 'http://dummyurl.com')).toBe(` | ||
curl \\ | ||
--get \\ | ||
--data-urlencode 'q=2 lbs carrots' \\ | ||
"http://dummyurl.com/v1/parse"`.trim()); | ||
}); | ||
|
||
it('should escape single quotes', () => { | ||
expect(pipe.transform('2 cups tomatoes (don\'t chop them up; you won\'t like it)', 'http://dummyurl.com')).toBe(` | ||
curl \\ | ||
--get \\ | ||
--data-urlencode 'q=2 cups tomatoes (don\\\'t chop them up; you won\\\'t like it)' \\ | ||
"http://dummyurl.com/v1/parse"`.trim()); | ||
}); | ||
}); |
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,18 @@ | ||
import { Pipe, PipeTransform } from '@angular/core'; | ||
|
||
@Pipe({ | ||
name: 'curlCmd', | ||
}) | ||
export class CurlCmdPipe implements PipeTransform { | ||
|
||
transform(ingredientRaw: string, backendUrl: string): any { | ||
const ingredientEscaped = ingredientRaw.replace(/'/g, '\\\''); | ||
return ` | ||
curl \\ | ||
--get \\ | ||
--data-urlencode 'q=${ingredientEscaped}' \\ | ||
"${backendUrl}/v1/parse" | ||
`.trim(); | ||
} | ||
|
||
} |
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
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
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