Skip to content

Commit ef4ae43

Browse files
committed
Initial commit
0 parents  commit ef4ae43

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+13799
-0
lines changed

.babelrc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"presets": [["env", { "modules": false }], "react", "stage-2"],
3+
"env": {
4+
"test": {
5+
"plugins": [
6+
"transform-es2015-modules-commonjs"
7+
]
8+
}
9+
}
10+
}

.circleci/config.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
defaults: &defaults
2+
working_directory: ~/react-github-renderer
3+
docker:
4+
- image: circleci/node:8.9.0
5+
6+
version: 2
7+
8+
jobs:
9+
checkout:
10+
<<: *defaults
11+
steps:
12+
- checkout
13+
- save_cache:
14+
key: repository-{{ .Environment.CIRCLE_SHA1 }}
15+
paths:
16+
- ~/react-github-renderer
17+
18+
dependency:
19+
<<: *defaults
20+
steps:
21+
- restore_cache:
22+
key: repository-{{ .Environment.CIRCLE_SHA1 }}
23+
- restore_cache:
24+
key: dependency-{{ .Branch }}-{{ checksum "yarn.lock" }}
25+
- run:
26+
name: Install Root Dependency
27+
command: yarn install
28+
- save_cache:
29+
key: dependency-{{ .Branch }}-{{ checksum "yarn.lock" }}
30+
paths:
31+
- ./node_modules
32+
- ~/.yarn-cache
33+
34+
test:
35+
<<: *defaults
36+
steps:
37+
- restore_cache:
38+
key: repository-{{ .Environment.CIRCLE_SHA1 }}
39+
- restore_cache:
40+
key: dependency-{{ .Branch }}-{{ checksum "yarn.lock" }}
41+
- run:
42+
name: Test
43+
command: yarn test:coverage --maxWorkers=2
44+
- store_artifacts:
45+
path: coverage
46+
destination: coverage
47+
48+
workflows:
49+
version: 2
50+
checkout-and-dependency-test:
51+
jobs:
52+
- checkout:
53+
filters:
54+
tags:
55+
only: /.*/
56+
- dependency:
57+
requires:
58+
- checkout
59+
filters:
60+
tags:
61+
only: /.*/
62+
- test:
63+
requires:
64+
- dependency
65+
filters:
66+
tags:
67+
only: /.*/

.eslintrc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"extends": "eslint:recommended",
3+
"plugins": ["react"],
4+
"env": {
5+
"node": true
6+
},
7+
"parser": "babel-eslint",
8+
"overrides": [
9+
{
10+
"files": ["*.spec.js"],
11+
"rules": {
12+
"no-unused-vars": 0
13+
},
14+
"env": {
15+
"jest": true
16+
},
17+
}
18+
]
19+
}

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
*.log
2+
.env
3+
.idea
4+
coverage
5+
node_modules
6+
7+
dist

.npmignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
examples
2+
src
3+
tests
4+
rollup.config.js
5+
yarn.lock
6+
.*
7+
*.log

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
8.9.0

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2017 Taehwan, No
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# react-github-renderer
2+
3+
> A react custom renderer for Github :octocat:
4+
5+
**Table of contents**
6+
7+
- [Installation](#installation)
8+
- [Motivation](#motivation)
9+
- [API](#api)
10+
- [Renderer](#renderer)
11+
- `ReactGithub.render(element)`
12+
- [Components](#components)
13+
- [Gists](#gists)
14+
- `<Gist description isPublic children />`
15+
- `<File name children />`
16+
- [Releases](#releases)
17+
- `<Release tagName targetCommitish name draft prerelease children />`
18+
- [Examples](#examples)
19+
20+
# Installation
21+
22+
```bash
23+
$ npm install --save react-github-renderer
24+
```
25+
26+
Alternatively, using yarn.
27+
28+
```bash
29+
$ yarn add react-github-renderer
30+
```
31+
32+
# Motivation
33+
34+
Just for fun. I have wanted to look into react implementation (renderer, reconciler).
35+
36+
# API
37+
38+
## Renderer
39+
40+
- `ReactGithub.render(element)`
41+
42+
## Components
43+
44+
- ### Gists
45+
46+
```jsx
47+
<Gist description isPublic>
48+
<File name children />
49+
</Gist>
50+
```
51+
52+
```jsx
53+
<Gist description isPublic children />
54+
```
55+
56+
- `description` (*String*): a description of the gist (Default: `''`)
57+
- `isPublic` (*Boolean*): indicates whether the gist is public. (Default: `false`)
58+
59+
```jsx
60+
<File name children />
61+
```
62+
63+
- `name` (*String*, **Required**): name of file
64+
- `children` (*String*, **Required**): contents of file
65+
66+
- ### Releases
67+
68+
```jsx
69+
<Release tagName targetCommitish name draft prerelease children />
70+
```
71+
72+
- `tagName` (*String*, **Required**): the name of the tag
73+
- `targetCommitish` (*String*): the commitish value that determines where the Git tag is created from (Default: `master`)
74+
- `name` (*String*): the name of the release
75+
- `draft` (*Boolean*): `true` to create a draft (unpublished) release, `false` to create a published one. (Default: `false`)
76+
- `prerelease` (*Boolean*): `true` to identify the release as a prerelease. `false` to identify the release as a full release. (Default: `false`)
77+
- `children` (*String*): text describing the contents of the tag
78+
79+
# Examples
80+
81+
- ## [Gists](./examples/Gists/README.md)
82+
83+
```jsx
84+
import React from 'react';
85+
import ReactGithub, { Gist, File } from 'react-github-renderer';
86+
import GithubClient from './GithubClient';
87+
88+
const gist = ReactGithub.render(
89+
<Gist description="gist created by react-github-renderer" isPublic={false}>
90+
<File name="file.js">
91+
function fn() {}
92+
</File>
93+
<File name="file2.txt">
94+
contents of file2.txt
95+
</File>
96+
</Gist>
97+
);
98+
99+
GithubClient.createGist(gist);
100+
```
101+
102+
- ## [Releases](./examples/Releases/README.md)
103+
104+
```jsx
105+
import React from 'react';
106+
import ReactGithub, { Release } from 'react-github-renderer';
107+
import GithubClient from './GithubClient';
108+
109+
const release = ReactGithub.render(
110+
<Release
111+
tagName="v1.0.0"
112+
targetCommitish="master"
113+
name="v1.0.0"
114+
draft
115+
prerelease={false}
116+
>
117+
- Update dependencies version (#15)
118+
</Release>
119+
);
120+
121+
GithubClient.createRelease(release);
122+
```
123+
124+
# Thanks
125+
126+
- [@nitin42](https://github.com/nitin42): for [helpful tutorial](https://github.com/nitin42/Making-a-custom-React-renderer)
127+
- [@iamdustan](https://github.com/iamdustan): for [tiny-react-renderer](https://github.com/iamdustan/tiny-react-renderer) with a brief implementation
128+
- [@CentaurWarchief](https://github.com/CentaurWarchief): for inspiration from [react-slack-renderer](https://github.com/CentaurWarchief/react-slack-renderer)
129+
130+
# License
131+
132+
MIT © [Taehwan, No (taehwanno)](https://github.com/taehwanno)

examples/Gists/.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["env", "react", "stage-2"]
3+
}

examples/Gists/.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
TOKEN=

examples/Gists/App.jsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/* eslint-disable no-unused-vars */
2+
3+
import React from 'react';
4+
import ReactGithub, { Gist, File } from 'react-github-renderer';
5+
6+
const render = () => ReactGithub.render(
7+
<Gist description="gist created by react-github-renderer" isPublic={false}>
8+
<File name="file.js">
9+
function fn() {}
10+
</File>
11+
<File name="file2.txt">
12+
contents of file2.txt
13+
</File>
14+
</Gist>
15+
);
16+
17+
export default render;

examples/Gists/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# ReactGithubRenderer Gists Example
2+
3+
> This example create secret gist.
4+
5+
# Steps
6+
7+
1. `git clone https://github.com/taehwanno/react-github-renderer.git`
8+
2. `cd react-github-renderer/examples/Gists`
9+
3. `npm install`
10+
4. `cp .env.example .env`
11+
5. Insert `TOKEN` with your [OAuth token](https://developer.github.com/apps/building-integrations/setting-up-and-registering-oauth-apps/about-scopes-for-oauth-apps/) with gist access (create at [`Settings > Developer settings`](https://github.com/settings/tokens)) to `.env`
12+
6. `npm start`
13+
7. Then, simple gist will be created. Check out https://gist.github.com

examples/Gists/index.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
7+
<title>ReactGithubRenderer Gists</title>
8+
</head>
9+
<body>
10+
<h1>Gists example</h1>
11+
</body>
12+
</html>

examples/Gists/index.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* eslint-disable no-console */
2+
3+
require('babel-register');
4+
require('dotenv-safe').load();
5+
const render = require('./App.jsx').default;
6+
const r2 = require('r2');
7+
8+
const app = {
9+
async createGist(body) {
10+
try {
11+
const res = await r2.post('https://api.github.com/gists', {
12+
headers: { Authorization: `token ${process.env.TOKEN}` },
13+
json: body,
14+
}).response;
15+
console.log(`${res.status}: ${res.statusText}`);
16+
} catch (error) {
17+
console.error(error);
18+
}
19+
},
20+
};
21+
22+
app.createGist(render());

examples/Gists/index.web.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/* eslint-disable no-console */
2+
3+
import render from './App';
4+
5+
const app = {
6+
createGist(body) {
7+
console.log(body);
8+
}
9+
};
10+
11+
app.createGist(render());

examples/Gists/package.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "react-github-renderer-gists-example",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"private": true,
6+
"license": "MIT",
7+
"scripts": {
8+
"start": "babel-node index.js",
9+
"serve": "webpack-dev-server"
10+
},
11+
"dependencies": {
12+
"r2": "^2.0.0",
13+
"react": "^16.1.1",
14+
"react-github-renderer": "^0.1.0"
15+
},
16+
"devDependencies": {
17+
"babel-cli": "^6.26.0",
18+
"babel-loader": "^7.1.2",
19+
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.0",
20+
"babel-preset-env": "^1.6.1",
21+
"babel-preset-react": "^6.24.1",
22+
"babel-preset-stage-2": "^6.24.1",
23+
"babel-register": "^6.26.0",
24+
"dotenv-safe": "^4.0.4",
25+
"html-webpack-plugin": "^2.30.1",
26+
"webpack": "^3.8.1",
27+
"webpack-dev-server": "^2.9.4"
28+
}
29+
}

0 commit comments

Comments
 (0)