jekyll-theme-alta-docs 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/_includes/guidelines/rails/api_only_project_tree.md +90 -0
- data/_includes/guidelines/rails/api_only_project_tree_with_files.md +56 -0
- data/_includes/guidelines/rails/api_only_psql_no_admin_setup_instructions.md +236 -0
- data/_includes/guidelines/rails/rails_cheatsheet.md +275 -0
- data/_includes/guidelines/react/react_csr_setup_instructions.md +600 -0
- data/_includes/guidelines/react/react_guidelines.md +443 -0
- data/_includes/guidelines/react/react_project_tree.md +99 -0
- data/_includes/nav.html +24 -1
- data/_includes/templates/rails/rails_readme.md +52 -0
- data/_includes/templates/react/react_readme.md +54 -0
- data/_sass/jekyll-theme-alta-docs.scss +77 -3
- metadata +11 -2
@@ -0,0 +1,443 @@
|
|
1
|
+
|
2
|
+
### 1. Naming convention
|
3
|
+
|
4
|
+
Cases:
|
5
|
+
|
6
|
+
* PascalCase
|
7
|
+
* camelCase
|
8
|
+
* snake_case
|
9
|
+
* SCREAMING_SNAKE_CASE or CONSTANT_CASE
|
10
|
+
* dash-case
|
11
|
+
* flatcase
|
12
|
+
* TRAIN-CASE
|
13
|
+
* Train-Case
|
14
|
+
|
15
|
+
|
16
|
+
Basic rules:
|
17
|
+
|
18
|
+
* Use **PascalCase** in models, classes or any kind of "blueprint" (when it's not an particular instance).
|
19
|
+
* Use **camelCase** in functions, methods and variables (when it is an instance). Use it also to name files containing helper functions (exports only functions or set of functions).
|
20
|
+
* Use **CONSTANT_CASE** with constants.
|
21
|
+
|
22
|
+
```js
|
23
|
+
# PascalCase vs camelCase vs CONSTANT_CASE
|
24
|
+
|
25
|
+
const GOOGLE_API_KEY = 'xxxxxx'
|
26
|
+
|
27
|
+
class Product {
|
28
|
+
static resourceName = 'product'
|
29
|
+
|
30
|
+
getResourceName() {
|
31
|
+
return this.resourceName
|
32
|
+
}
|
33
|
+
}
|
34
|
+
|
35
|
+
const product = new Product()
|
36
|
+
|
37
|
+
```
|
38
|
+
|
39
|
+
#### Plural vs Singular
|
40
|
+
|
41
|
+
Class, models, components and containers names should be Singular. Variables and constants should be singular, unless they contains a list. Also file names can be plural, i.e. `routes.js` because file defines a **list** of routes.
|
42
|
+
|
43
|
+
|
44
|
+
#### Verb vs noun
|
45
|
+
|
46
|
+
Functions and methods should be composed with (commanding) verbs: `getName()`, `convertText()`, `calculatePrice()`. Variables and class names should be nouns: `Product`, `products`.
|
47
|
+
|
48
|
+
#### Name decorators
|
49
|
+
|
50
|
+
* `_` use with private functions / methods (`_getName()`)
|
51
|
+
|
52
|
+
|
53
|
+
#### Prefixes & suffixes
|
54
|
+
|
55
|
+
* Components - `Resource.jsx`
|
56
|
+
* Routes - `ResourceRoute.jsx`, `NewResourceRoute.jsx`
|
57
|
+
* Containers - `ResourceContainer.jsx`
|
58
|
+
* Layouts - `MainLayout.jsx`
|
59
|
+
|
60
|
+
|
61
|
+
### 2. REST naming
|
62
|
+
|
63
|
+
```
|
64
|
+
[GET] /resources/ - index, list of resources
|
65
|
+
[GET] /resources/new - displays a form to create a new resource
|
66
|
+
[GET] /resources/:id - show a resource
|
67
|
+
[GET] /resources/:id/edit - edit form
|
68
|
+
|
69
|
+
[POST] /resources/ - create a new resource
|
70
|
+
[PUT] /resources/:id - update a resource
|
71
|
+
[DELETE] /resources/:id - delete a resource
|
72
|
+
|
73
|
+
# Related resources:
|
74
|
+
[GET] /resources/:id/comments - list of "comments" related to the "resource"
|
75
|
+
[GET] /resources/:id/comments/new - displays a form to create a new comment related with the "resource"
|
76
|
+
( . . . )
|
77
|
+
|
78
|
+
```
|
79
|
+
|
80
|
+
|
81
|
+
### 3. Nest components and follow the context
|
82
|
+
|
83
|
+
1. Group components with similar purposes, for example: UI components:
|
84
|
+
|
85
|
+
|-- components
|
86
|
+
|-- UI
|
87
|
+
|-- Button
|
88
|
+
|-- List
|
89
|
+
|-- Tooltip
|
90
|
+
|
91
|
+
2. If components are strongly related to the specific component or they are used in the specific context, store them in particular component's folder:
|
92
|
+
|
93
|
+
|-- components
|
94
|
+
|-- Product
|
95
|
+
|-- components
|
96
|
+
| |-- ProductThumb
|
97
|
+
| | |-- ProductThumb.jsx
|
98
|
+
| | |-- ProductThumb.scss
|
99
|
+
| | |-- index.js
|
100
|
+
| |
|
101
|
+
| |-- ProductPrice
|
102
|
+
| |-- ProductPrice.jsx
|
103
|
+
| |-- ProductPrice.scss
|
104
|
+
| |-- index.js
|
105
|
+
|
|
106
|
+
|-- Product.jsx
|
107
|
+
|-- Product.scss
|
108
|
+
|-- index.js
|
109
|
+
|
110
|
+
### 4. Components vs containers vs routes vs layouts
|
111
|
+
|
112
|
+
**Components - HTML components**<br>
|
113
|
+
Components are used to build HTML code. Components can be stateless or stateful.
|
114
|
+
Components cannot be directly connected with Redux.
|
115
|
+
|
116
|
+
**Containers - Logic**<br>
|
117
|
+
Containers implement the logic, connect with Redux, import components and provide data to components.
|
118
|
+
The amount of HTML code should be minimal in containers. Containers are not pages!
|
119
|
+
|
120
|
+
**Routes - pages**<br>
|
121
|
+
Routes are defined with `react-router` (or other library). Each route is a subpage of the website. The route's page should compose the whole subpage by setting up layout and building other view elements with containers and/or plain components.
|
122
|
+
|
123
|
+
**Layouts - the page frame**<br>
|
124
|
+
Layouts sets up a page fram. Layouts are used in routes.
|
125
|
+
|
126
|
+
|
127
|
+
|
128
|
+
### 5. URL friendly routes
|
129
|
+
|
130
|
+
Routes are implemented in `src/routes/*` and they should follow REST naming convention:
|
131
|
+
|
132
|
+
```
|
133
|
+
|-- routes
|
134
|
+
|-- products
|
135
|
+
| |-- new
|
136
|
+
| | |-- NewProductRoute.jsx
|
137
|
+
| |
|
138
|
+
| |-- :id
|
139
|
+
| | |-- edit
|
140
|
+
| | | |-- EditProductRoute.jsx
|
141
|
+
| | |
|
142
|
+
| | |-- ShowProductRoute.jsx
|
143
|
+
| |
|
144
|
+
| |-- IndexProductRoute.jsx
|
145
|
+
|
|
146
|
+
|-- routes.js
|
147
|
+
```
|
148
|
+
|
149
|
+
|
150
|
+
### 6. Small components
|
151
|
+
|
152
|
+
Keep components small. It's easier to test, reuse and keep code DRY.
|
153
|
+
Choose wisely between stateless and stateful components.
|
154
|
+
Containers should keep logic and components should focus on rendering the view.
|
155
|
+
|
156
|
+
|
157
|
+
### 7. Configurability of components
|
158
|
+
|
159
|
+
Try to not hard-code any value in the components. Instead, give an option to pass in props and handle following cases:
|
160
|
+
|
161
|
+
1. the prop is not passed > display default value (it can be hardcoded)
|
162
|
+
2. the prop is passed > display the prop's value
|
163
|
+
3. the prop's turn-off flag passed > do not display it at all
|
164
|
+
|
165
|
+
```
|
166
|
+
const MyComponent = ({ title = null, titleOff = false }) => {
|
167
|
+
const defaultTitle = 'Hello World!'
|
168
|
+
|
169
|
+
return (
|
170
|
+
<div>
|
171
|
+
{ !titleOff &&
|
172
|
+
<h1>{ title ? title : defaultTitle }</h1>
|
173
|
+
}
|
174
|
+
</div>
|
175
|
+
)
|
176
|
+
}
|
177
|
+
|
178
|
+
|
179
|
+
<MyComponent /> // Display default: "Hello World!"
|
180
|
+
|
181
|
+
<MyComponent title="Good morning!" /> // Display prop: "Good morning!"
|
182
|
+
|
183
|
+
<MyComponent titleOff="Good morning!" /> // Display nothing
|
184
|
+
|
185
|
+
```
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
### 8. Configurability of the project
|
190
|
+
|
191
|
+
Use `src/config/*` to store configuration in multiple files:
|
192
|
+
|
193
|
+
```
|
194
|
+
|-- config
|
195
|
+
|-- app.js // Contains basic configuration
|
196
|
+
|-- aws.js // Contains AWS configuration
|
197
|
+
|-- resource.js // Contains "Resource" configuration
|
198
|
+
```
|
199
|
+
|
200
|
+
Instead of setting constants in components, containers and other files, define them in `src/config/*.js` file and import to other files.
|
201
|
+
|
202
|
+
|
203
|
+
|
204
|
+
### 9. Environment variables
|
205
|
+
|
206
|
+
In `src/config/*.js` use `process.env.NODE_ENV` to define the environment variables:
|
207
|
+
|
208
|
+
```
|
209
|
+
const prod = {
|
210
|
+
MY_VAR = 'xxx'
|
211
|
+
}
|
212
|
+
|
213
|
+
const dev = {
|
214
|
+
MY_VAR = 'yyy'
|
215
|
+
}
|
216
|
+
|
217
|
+
const config = process.env.NODE_ENV === 'production'
|
218
|
+
? prod
|
219
|
+
: dev
|
220
|
+
|
221
|
+
const GOOGLE_API_KEY = '1234567890'
|
222
|
+
|
223
|
+
export default {
|
224
|
+
...config,
|
225
|
+
GOOGLE_API_KEY
|
226
|
+
}
|
227
|
+
|
228
|
+
```
|
229
|
+
|
230
|
+
|
231
|
+
### 10. Conditional Rendering
|
232
|
+
|
233
|
+
```
|
234
|
+
// Wrong:
|
235
|
+
{
|
236
|
+
condition ?
|
237
|
+
<div>
|
238
|
+
// Do sth...
|
239
|
+
</div> :
|
240
|
+
null
|
241
|
+
}
|
242
|
+
|
243
|
+
// Good:
|
244
|
+
{condition &&
|
245
|
+
<div>
|
246
|
+
// Do sth...
|
247
|
+
</div>
|
248
|
+
}
|
249
|
+
```
|
250
|
+
|
251
|
+
### 9. Stylesheets
|
252
|
+
|
253
|
+
#### BEM
|
254
|
+
|
255
|
+
Follow BEM conventions:
|
256
|
+
|
257
|
+
* block - `.block`
|
258
|
+
* elements - `.block__element`
|
259
|
+
* modifier - `.block--modifier`, `.block__element--modifier`
|
260
|
+
|
261
|
+
Example:
|
262
|
+
|
263
|
+
```sass
|
264
|
+
|
265
|
+
.product { }
|
266
|
+
|
267
|
+
.product .product__header { }
|
268
|
+
|
269
|
+
.product .product--dark { }
|
270
|
+
|
271
|
+
.product .product__header--dark { }
|
272
|
+
|
273
|
+
```
|
274
|
+
|
275
|
+
#### SCSS
|
276
|
+
|
277
|
+
```scss
|
278
|
+
// 1. Variables
|
279
|
+
$primary-color: #23ab56;
|
280
|
+
|
281
|
+
h1 {
|
282
|
+
color: $primary-color;
|
283
|
+
}
|
284
|
+
|
285
|
+
|
286
|
+
// 2. Nesting
|
287
|
+
.navbar {
|
288
|
+
.brand { }
|
289
|
+
}
|
290
|
+
|
291
|
+
|
292
|
+
|
293
|
+
// 3. Import
|
294
|
+
@import '_some_styles'
|
295
|
+
|
296
|
+
|
297
|
+
|
298
|
+
|
299
|
+
// 4. Mixins
|
300
|
+
@mixin shadow($alpha) {
|
301
|
+
-webkit-box-shadow: 0px 0px 10px -2px rgba(20,34,51,$alpha);
|
302
|
+
-moz-box-shadow: 0px 0px 10px -2px rgba(20,34,51,$alpha);
|
303
|
+
box-shadow: 0px 0px 10px -2px rgba(20,34,51,$alpha);
|
304
|
+
}
|
305
|
+
|
306
|
+
.box { @include shadow(0.2); }
|
307
|
+
|
308
|
+
// Optional argument
|
309
|
+
@mixin shadow($alpha: 0.5) { ... }
|
310
|
+
|
311
|
+
// Keyword arguments and @if
|
312
|
+
@mixin square($size, $radius: 0) {
|
313
|
+
width: $size;
|
314
|
+
height: $size;
|
315
|
+
|
316
|
+
@if $radius != 0 {
|
317
|
+
border-radius: $radius;
|
318
|
+
}
|
319
|
+
}
|
320
|
+
|
321
|
+
.avatar {
|
322
|
+
@include square(100px, $radius: 4px);
|
323
|
+
}
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
// 5. Extend/Inheritance
|
328
|
+
%message-shared {
|
329
|
+
border: 1px solid #ccc;
|
330
|
+
padding: 10px;
|
331
|
+
color: #333;
|
332
|
+
}
|
333
|
+
|
334
|
+
.message {
|
335
|
+
@extend %message-shared;
|
336
|
+
}
|
337
|
+
|
338
|
+
.success {
|
339
|
+
@extend %message-shared;
|
340
|
+
border-color: green;
|
341
|
+
}
|
342
|
+
|
343
|
+
.error {
|
344
|
+
@extend %message-shared;
|
345
|
+
border-color: red;
|
346
|
+
}
|
347
|
+
|
348
|
+
.warning {
|
349
|
+
@extend %message-shared;
|
350
|
+
border-color: yellow;
|
351
|
+
}
|
352
|
+
|
353
|
+
// 6. Operators: +, -, *, /, %
|
354
|
+
article {
|
355
|
+
width: 600px / 960px * 100%;
|
356
|
+
}
|
357
|
+
|
358
|
+
|
359
|
+
|
360
|
+
// 7. Functions
|
361
|
+
@function pow($base, $exponent) {
|
362
|
+
$result: 1;
|
363
|
+
@for $_ from 1 through $exponent {
|
364
|
+
$result: $result * $base;
|
365
|
+
}
|
366
|
+
@return $result;
|
367
|
+
}
|
368
|
+
|
369
|
+
.sidebar {
|
370
|
+
float: left;
|
371
|
+
margin-left: pow(4, 3) * 1px;
|
372
|
+
}
|
373
|
+
|
374
|
+
```
|
375
|
+
|
376
|
+
|
377
|
+
#### Stylesheets in the project tree
|
378
|
+
|
379
|
+
Follow SASS 7-1 pattern:
|
380
|
+
|
381
|
+
```
|
382
|
+
stylesheets/
|
383
|
+
|
|
384
|
+
|– base/
|
385
|
+
| |– _reset.scss # Reset/normalize
|
386
|
+
| |– _typography.scss # Typography rules
|
387
|
+
| ... # Etc…
|
388
|
+
|
|
389
|
+
|– components/
|
390
|
+
| |– _buttons.scss # Buttons
|
391
|
+
| |– _carousel.scss # Carousel
|
392
|
+
| |– _cover.scss # Cover
|
393
|
+
| |– _dropdown.scss # Dropdown
|
394
|
+
| ... # Etc…
|
395
|
+
|
|
396
|
+
|– layout/
|
397
|
+
| |– _navigation.scss # Navigation
|
398
|
+
| |– _grid.scss # Grid system
|
399
|
+
| |– _header.scss # Header
|
400
|
+
| |– _footer.scss # Footer
|
401
|
+
| |– _sidebar.scss # Sidebar
|
402
|
+
| |– _forms.scss # Forms
|
403
|
+
| ... # Etc…
|
404
|
+
|
|
405
|
+
|– pages/
|
406
|
+
| |– _home.scss # Home specific styles
|
407
|
+
| |– _contact.scss # Contact specific styles
|
408
|
+
| ... # Etc…
|
409
|
+
|
|
410
|
+
|– themes/
|
411
|
+
| |– _theme.scss # Default theme
|
412
|
+
| |– _admin.scss # Admin theme
|
413
|
+
| ... # Etc…
|
414
|
+
|
|
415
|
+
|– utils/
|
416
|
+
| |– _variables.scss # Sass Variables
|
417
|
+
| |– _functions.scss # Sass Functions
|
418
|
+
| |– _mixins.scss # Sass Mixins
|
419
|
+
| |– _helpers.scss # Class & placeholders helpers
|
420
|
+
|
|
421
|
+
|– vendors/
|
422
|
+
| |– _bootstrap.scss # Bootstrap
|
423
|
+
| |– _jquery-ui.scss # jQuery UI
|
424
|
+
| ... # Etc…
|
425
|
+
|
|
426
|
+
|
|
427
|
+
|– main.scss # Main Sass file
|
428
|
+
```
|
429
|
+
|
430
|
+
|
431
|
+
#### Project's stylesheets vs component's stylesheets
|
432
|
+
|
433
|
+
In the `src/stylesheets`, build general project styles. Styles which are limited to a specific components, implement in the component's folder:
|
434
|
+
|
435
|
+
```
|
436
|
+
|-- Product
|
437
|
+
|-- Product.jsx
|
438
|
+
|-- Product.scss
|
439
|
+
```
|
440
|
+
|
441
|
+
### 10. Linter
|
442
|
+
|
443
|
+
Use Linter to keep the same coding style with other team members.
|
@@ -0,0 +1,99 @@
|
|
1
|
+
```
|
2
|
+
|
3
|
+
build // The build artifact
|
4
|
+
node_modules // Installed Node modules
|
5
|
+
public
|
6
|
+
|-- favicon
|
7
|
+
|-- index.html
|
8
|
+
|-- manifest.json
|
9
|
+
|-- robots.txt
|
10
|
+
src
|
11
|
+
|-- actions // Redux actions
|
12
|
+
| |-- app.js
|
13
|
+
| |-- products.js
|
14
|
+
|
|
15
|
+
|-- assets
|
16
|
+
| |-- images
|
17
|
+
|
|
18
|
+
|-- components // Components should not fetch
|
19
|
+
| |-- Products // data by itself (neither from Redux,
|
20
|
+
| | |-- ProductThumb // neither from API)
|
21
|
+
| | | |-- ProductThumb.jsx
|
22
|
+
| | | |-- ProductThumb.scss
|
23
|
+
| | | |-- index.js
|
24
|
+
| | |
|
25
|
+
| | |-- ProductTable
|
26
|
+
| | |-- ProductTable.jsx
|
27
|
+
| | |-- ProductTable.scss
|
28
|
+
| | |-- index.js
|
29
|
+
| |
|
30
|
+
| |-- UI // Reusable UI components grouped
|
31
|
+
| |-- Button // together in one folder
|
32
|
+
| |-- Tooltip
|
33
|
+
|
|
34
|
+
|--containers // Containers implement the logic
|
35
|
+
| |-- Products // and provide data to components
|
36
|
+
| |-- IndexProduct
|
37
|
+
| | |-- ProductIndexContainer.jsx
|
38
|
+
| | |-- index.js
|
39
|
+
| |
|
40
|
+
| |-- NewProduct
|
41
|
+
| |-- NewProductContainer.jsx
|
42
|
+
| |-- index.js
|
43
|
+
|
|
44
|
+
|-- config // Extract all configurable values
|
45
|
+
| |-- app.js // from components and containers
|
46
|
+
| |-- products.js // to config files.
|
47
|
+
|
|
48
|
+
|-- helpers // Reusable functions
|
49
|
+
|
|
50
|
+
|-- layouts // Layouts
|
51
|
+
| |-- MainLayout
|
52
|
+
| |-- MainLayout.jsx
|
53
|
+
| |-- MainLayout.scss
|
54
|
+
| |-- index.js
|
55
|
+
|
|
56
|
+
|-- locales // I18n
|
57
|
+
|
|
58
|
+
|-- models // Models provide a better
|
59
|
+
| |-- Product.js // representation of objects
|
60
|
+
|
|
61
|
+
|-- modules // Here you can import or build
|
62
|
+
| // modules that should be easily moved
|
63
|
+
| // to other projects
|
64
|
+
|
|
65
|
+
|-- reducers // Redux reducers
|
66
|
+
| |-- appReducer.js
|
67
|
+
| |-- productReducer.js
|
68
|
+
| |-- index.js
|
69
|
+
|
|
70
|
+
|-- routes // Routing
|
71
|
+
| |-- home
|
72
|
+
| | |-- HomeRoute.jsx
|
73
|
+
| |
|
74
|
+
| |-- products
|
75
|
+
| | |-- [id]
|
76
|
+
| | | |-- ProductRoute.jsx
|
77
|
+
| | |
|
78
|
+
| | |-- ProductsRoute.jsx
|
79
|
+
| |
|
80
|
+
| |-- routes.jsx
|
81
|
+
|
|
82
|
+
|-- services // Services
|
83
|
+
| |-- APIService.js
|
84
|
+
| |-- PayPalService.js
|
85
|
+
|
|
86
|
+
|-- App.jsx // Imports routes and connects with Redux
|
87
|
+
|-- index.jsx // Entrypoint of the app. Imports App.jsx
|
88
|
+
|-- init.js // Used in the app initialization stage
|
89
|
+
|-- serviceWorker
|
90
|
+
|-- store.js // Redux store
|
91
|
+
|
92
|
+
.eslintignore
|
93
|
+
.eslintrc.js
|
94
|
+
.eslintrc.json
|
95
|
+
.gitignore
|
96
|
+
package.json
|
97
|
+
README.md
|
98
|
+
|
99
|
+
```
|