├── .babelrc
├── .eslintrc
├── .github
└── workflows
│ └── semgrep.yml
├── .gitignore
├── LICENSE
├── README.md
├── components
├── app.js
├── constraints.js
├── definition.js
├── endpoint.js
├── exampleObject.js
├── head.js
├── helpers.js
├── objectDefinitionTable.js
├── schema.js
└── sidebar.js
├── index.js
├── package.json
└── styles
├── .gitkeep
└── styles.css
/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": ["es2015", "react"],
3 | "plugins": ["transform-runtime", "transform-class-properties"]
4 | }
5 |
--------------------------------------------------------------------------------
/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "parser" : "babel-eslint",
3 | "extends" : ["airbnb"],
4 | "rules": {
5 | "react/prefer-stateless-function": 0
6 | },
7 | "globals": {
8 | "IS_JAVASCRIPT": false,
9 | "LAST_MODIFIED": false,
10 | "process.env": false
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/.github/workflows/semgrep.yml:
--------------------------------------------------------------------------------
1 |
2 | on:
3 | pull_request: {}
4 | workflow_dispatch: {}
5 | push:
6 | branches:
7 | - main
8 | - master
9 | schedule:
10 | - cron: '0 0 * * *'
11 | name: Semgrep config
12 | jobs:
13 | semgrep:
14 | name: semgrep/ci
15 | runs-on: ubuntu-20.04
16 | env:
17 | SEMGREP_APP_TOKEN: ${{ secrets.SEMGREP_APP_TOKEN }}
18 | SEMGREP_URL: https://cloudflare.semgrep.dev
19 | SEMGREP_APP_URL: https://cloudflare.semgrep.dev
20 | SEMGREP_VERSION_CHECK_URL: https://cloudflare.semgrep.dev/api/check-version
21 | container:
22 | image: returntocorp/semgrep
23 | steps:
24 | - uses: actions/checkout@v3
25 | - run: semgrep ci
26 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | node_modules
3 | npm-debug.log
4 | build
5 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2016, CloudFlare.
2 | All rights reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5 |
6 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7 |
8 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9 |
10 | 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
11 |
12 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
13 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # doca-bootstrap-theme (DEPRECATED)
2 |
3 | The `doca` package for which this was written has been depreacted in favor of `@cloudflare/doca`,
4 | in the [json-schema-tools](https://github.com/cloudflare/json-schema-tools) repository.
5 | While `@cloudflare/doca` is conceptually the same, the back-end tools use a different
6 | format that retains compatibility with JSON Schema, so the theme requirements are different
7 |
8 | Also in that repository you will find a new `@cloudflare/doca-default-theme`, which is
9 | currently only a bare-bones debugging display for the back end tools. We will be expanding
10 | it into a fully functional new theme, and feature requests will be handled there from now on.
11 |
12 | ----
13 |
14 | The new `@cloudflare/doca` does not yet have a fully functioning theme, so this package
15 | is still the produciton-ready one. But we will be implementing feature requests on the new
16 | code, and moving most open issues to the new repo whenever it makes sense.
17 |
18 | Simple [Twitter Boostrap 3](http://getbootstrap.com/) based theme for [doca](https://github.com/cloudflare/doca).
19 |
20 | It's supposed to be used in combination with [doca](https://github.com/cloudflare/doca) - a tool that scaffolds API documentation based on JSON HyperSchemas.
21 |
22 | Please file any issues at the [doca](https://github.com/cloudflare/doca/issues) repository.
23 |
24 | ## Usage
25 |
26 | ```
27 | npm install -g doca
28 | doca init -t bootstrap
29 | ```
30 |
31 | This creates a new API documentation with `doca-bootstrap-theme` as a dependency.
32 |
33 | # How to create your own theme
34 |
35 | **The best way is to fork and modify this repository.** The integration with doca is pretty loose and it makes just a few assumptions about your theme.
36 |
37 |
38 | ## React Components
39 |
40 | Doca expects to import **two React components** from your theme (otherwise it fails):
41 |
42 | - **`App`** - main root component that gets all schemas through the props
43 | - **`Head`** - `
` part of the final documentation
44 |
45 | ### App component
46 |
47 | [App component](https://github.com/cloudflare/doca-bootstrap-theme/blob/master/components/app.js) can expect to receive two props:
48 |
49 | - **`this.props.schemas`** : *Immutable.List* - an array of all imported schemas, the schema format can be found [here](https://github.com/cloudflare/json-schema-example-loader) - it's the ouput of [json-schema-example-loader](https://github.com/cloudflare/json-schema-example-loader). However, the whole data structure is additionally turned into immutable one by [Immutable.js](https://facebook.github.io/immutable-js) library and `Immutable.fromJS()` function. It deeply converts all arrays into [Immutable.List](https://facebook.github.io/immutable-js/docs/#/List) and all objects into [Immutable.Map](https://facebook.github.io/immutable-js/docs/#/Map). Thus, you have to use slightly different methods for iteration or prop access.
50 | - **`this.props.config`** : *object* - a plain object exported by users from `config.js`, it should always have the key `title`.
51 |
52 | ### Head component
53 |
54 | [Head component](https://github.com/cloudflare/doca-bootstrap-theme/blob/master/components/head.js) can expect to receive two props:
55 |
56 | - **`this.props.title`** : *string* - the title specified in `config.js`
57 | - **`this.props.cssBundle`** : *string* - you should put this code into your Head component:
58 |
59 | ```jsx
60 | {this.props.cssBundle && }
61 | ```
62 |
63 | ### State
64 |
65 | - You should just use native `this.state` and keep the state in your components. It's perfect for things like toggling.
66 | - **Advanced:** If your theme is getting bigger (a lot of state everywhere), you can consider using [Redux](http://redux.js.org/). Doca is already using Redux for handling schemas. Your theme can export a reducer ([check this pattern](https://github.com/cloudflare/cf-ui/tree/master/packages/cf-builder-card/src) in our cf-ui components). However, it's up to you to modify the scaffolded application and import your reducer in `/src/client/reducers/index.js`. Doca app currently doesn't do any assumptions about this (it could auto-import the theme reducer in future though). So if you want to make your theme useful out-of-the-box, try to use native `this.state` instead.
67 |
68 | ## Global variables
69 |
70 | You can use these three global variables (provided by webpack):
71 |
72 | - **`IS_JAVASCRIPT`** : *bool* - doca provides `npm run build:nojs` script. You can ship your API docs without JS bundle. This variable is `true` when `nojs` flag is used. It gives you opportunity to do some changes in your components (show/hide sections should be visible by default etc.)
73 | - **`LAST_MODIFIED`** : *number* - `Date.now()` value, in case you want to display "last modified" information somewhere
74 | - **`process.env.NODE_ENV`** : *enum* - can be `development` or `production`
75 |
76 | ## Styles
77 |
78 | You have three options how to style your React components:
79 |
80 | - [React inline styles](https://facebook.github.io/react/tips/inline-styles.html).
81 | - Link directly your external stylesheet in the Head component.
82 | - Doca's webpack **expects to find folder `/styles` in your theme**. It [dynamically imports](https://webpack.github.io/docs/context.html) and processes all css, less and scss files from this folder. **Magic!** Then, it bundles them into a single css file and passes `this.props.cssBundle` to your Head component. You can leave this folder empty, then `this.props.cssBundle` is going to be empty.
83 |
84 | Unfortunately, you can't directly import styles from your React components since webpack can't resolve such requires in `node_modules`.
85 |
86 | ## Publishing
87 |
88 | We would be happy to see more open source doca themes! Let us know if you publish some. It should follow this name convention:
89 |
90 | ```
91 | doca-XXXXXXXX-theme
92 | ```
93 |
94 | ## Tips
95 |
96 | - **Immutable.js** is used because resulting app (page) can be pretty big and we want to keep re-rendering fast. All your components should implement `shouldComponentUpdate()` method, so it prevents unnecessary re-renders. Or you can simply extend your components from [react-pure-render](https://github.com/gaearon/react-pure-render).
97 |
98 | - When you're developing a new theme, you can streamline the process by copy&pasting your components into Doca app. That will give you hot-reloading! Otherwise, you can use [npm link](https://docs.npmjs.com/cli/link). With every change, you have to call `npm link` again, so it triggers `npm prepublish` and rebuilds your components (babel/JSX -> ES5).
99 |
100 | - `npm run lint` (use node v4+)
101 |
102 |
--------------------------------------------------------------------------------
/components/app.js:
--------------------------------------------------------------------------------
1 | const React = require('react');
2 | const ImmutablePropTypes = require('react-immutable-proptypes');
3 | const Component = require('react-pure-render/component');
4 | const Sidebar = require('./sidebar');
5 | const Schema = require('./schema');
6 |
7 | class App extends Component {
8 |
9 | static propTypes = {
10 | schemas: ImmutablePropTypes.list.isRequired,
11 | config: React.PropTypes.object,
12 | };
13 |
14 | render() {
15 | const { schemas, config } = this.props;
16 |
17 | return (
18 |