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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e66de8ee1a3d8de337c6ab2214b84461339547390700443763ec32669f12e1ac
4
- data.tar.gz: 407c33116e63d462aab77409f8161c614e189141565b4d6d690c2bf03581f007
3
+ metadata.gz: 594c6b0c645f5d4f641908e5348ba0a2a4cee23594d8b9c7d01dcaf3510b3d90
4
+ data.tar.gz: 4502b626ddf5cf2f4c1ae951eb80708eeae09a26cd23873d1b7047aaef89aca5
5
5
  SHA512:
6
- metadata.gz: 68c991d1a43d1a76c4ed7d4a616f28b7e3efb10e45958d3c361aabf41768b831986bd4a4b9d26fe6840521ad04e5574749d4668bdd9b1455006e3a26537c2b04
7
- data.tar.gz: b2e2567c5d572a406700f28e9fa91902ad5d60b15a1c98a3f18824aad5ffb1f50c9dc0da6d309c891b99fde090d3cf4e8fcc4ebb1af122e533e838800ea38710
6
+ metadata.gz: 37ee64aebf1b94aea5885f93792db8fc93c7df82ae2613e9759a6a7b0a00ca04aba7ac323b13a3f437d80e25076f7fdb4ec10e84fc060162adcaf9a67b458824
7
+ data.tar.gz: 35f9070c24010178cc30a0d755f0293f731cb72729b0854faee7bd9c2074fac22f07d43a005b0bde65ae465638629f97a7b29b30efca9df27980503824573e09
@@ -0,0 +1,90 @@
1
+ ```
2
+ |-- app
3
+ | |-- assets
4
+ | | |-- (...)
5
+ | |
6
+ | |-- channels
7
+ | | |-- (...)
8
+ | |
9
+ | |-- controllers
10
+ | | |-- api
11
+ | | | |-- v1
12
+ | | | | |-- base_controller.rb
13
+ | | | |-- api_controller.rb
14
+ | | |-- concerns
15
+ | | | |-- .keep
16
+ | | |-- application_controller.rb
17
+ | |
18
+ | |-- exceptions
19
+ | | |-- .keep
20
+ | |
21
+ | |-- helpers
22
+ | | |-- application_helper.rb
23
+ | |
24
+ | |-- jobs
25
+ | | |-- application_job.rb
26
+ | |
27
+ | |-- lib
28
+ | | |-- .keep
29
+ | |
30
+ | |-- mailers
31
+ | | |-- application_mailer.rb
32
+ | |
33
+ | |-- models
34
+ | | |-- (...)
35
+ | |
36
+ | |-- queries
37
+ | | |-- .keep
38
+ | |
39
+ | |-- serializers
40
+ | | |-- .keep
41
+ | |
42
+ | |-- services
43
+ | | |-- .keep
44
+ | |
45
+ | |-- views
46
+ | |-- (...)
47
+ |
48
+ |-- bin
49
+ | |-- (...)
50
+ |
51
+ |-- config
52
+ | |-- (...)
53
+ |
54
+ |-- db
55
+ | |-- (...)
56
+ |
57
+ |-- lib
58
+ | |-- (...)
59
+ |
60
+ |-- log
61
+ | |-- (...)
62
+ |
63
+ |-- public
64
+ | |-- (...)
65
+ |
66
+ |-- storage
67
+ | |-- (...)
68
+ |
69
+ |-- storage
70
+ | |-- (...)
71
+ |
72
+ |-- test
73
+ | |-- (...)
74
+ |
75
+ |-- tmp
76
+ | |-- (...)
77
+ |
78
+ |-- vendor
79
+ | |-- (...)
80
+ |
81
+ |-- .env
82
+ |-- .env.template
83
+ |-- .gitignore
84
+ |-- .rubocop.yml
85
+ |-- .ruby-version
86
+ |-- config.ru
87
+ |-- Gemfile
88
+ |-- Rakefile
89
+ |-- README.md
90
+ ```
@@ -0,0 +1,56 @@
1
+ {% include guidelines/rails/api_only_project_tree.md %}
2
+
3
+
4
+ **app/controllers/api/api_controller.rb**
5
+ ```ruby
6
+ module Api
7
+ class ApiController < ActionController::API
8
+ end
9
+ end
10
+ ```
11
+
12
+ **app/controllers/api/v1/base_controller.rb**
13
+ ```ruby
14
+ module Api
15
+ module V1
16
+ # Base API controller. It is used by other controllers in API/V1 directory.
17
+ class BaseController < Api::ApiController
18
+ # before_action :set_current_user
19
+ # before_action :check_blocked_user
20
+
21
+ # def send_response(status, message, code, data)
22
+ # response = {
23
+ # status: status,
24
+ # message: message
25
+ # }
26
+ # response['data'] = data if data
27
+ # response['code'] = code if code
28
+ # render json: response, status: status
29
+ # end
30
+ #
31
+ # rescue_from Apipie::Error do |e|
32
+ # send_response(
33
+ # 422,
34
+ # e.message,
35
+ # "ERR_#{controller_name}##{action_name}_INVALID_PARAM_#{e.param}".upcase,
36
+ # nil
37
+ # )
38
+ # end
39
+
40
+ # def set_current_user
41
+ # @current_user_cognito = AwsCognitoService.new.get_current_user(request.headers['Authorization'])
42
+ # @current_user = UserIdentity
43
+ # .includes(user_account: [:organization])
44
+ # .find_by(identity_id: @current_user_cognito.username)
45
+ # .user_account
46
+ # rescue StandardError => e
47
+ # send_response(401, 'User unauthorized', 'ERR_USER_UNAUTHORIZED', { error: e })
48
+ # end
49
+ #
50
+ # def check_blocked_user
51
+ # send_response(403, 'User unauthorized', 'ERR_USER_BLOCKED', nil) if @current_user.blocked?
52
+ # end
53
+ end
54
+ end
55
+ end
56
+ ```
@@ -0,0 +1,236 @@
1
+ {% assign project_name = 'project-name' %}
2
+ {% if include.project_name %}
3
+ {% assign project_name = include.project_name %}
4
+ {% endif %}
5
+
6
+ *Ruby: 2.6.5, Rails: 6.0.3*
7
+
8
+ **Purpose:** Ruby on Rails API-only + PostgreSQL
9
+
10
+ ### Prerequisites
11
+
12
+ * Ruby installed
13
+ * Rails installed
14
+ * Selected database installed (PostgreSQL, MySQL, etc.)
15
+
16
+ ### A) Set up Ruby on Rails project
17
+
18
+ 1. Create a project folder:
19
+
20
+ $ mkdir {{ project_name }}-api && cd {{ project_name }}-api
21
+
22
+ 2. Create Rails API-only project with PostgreSQL database:
23
+
24
+ $ rails new . --api --database postgresql
25
+
26
+ 3. Add gems:
27
+
28
+ ```ruby
29
+ # Gemfile
30
+
31
+ # Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible
32
+ gem 'rack-cors'
33
+
34
+ # API documentation
35
+ gem 'apipie-rails'
36
+
37
+ # Serializer
38
+ gem 'active_model_serializers', '~> 0.10.0'
39
+
40
+ # .ENV
41
+ gem 'dotenv-rails'
42
+
43
+ group :development, :test do
44
+ # Call 'byebug' anywhere in the code to stop execution and get a debugger console
45
+ gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
46
+ # Tests fixtures
47
+ gem 'factory_bot_rails'
48
+ # Tests coverage
49
+ gem 'simplecov', require: false
50
+ # Code analyzers
51
+ gem 'rails_best_practices'
52
+ gem 'rubocop-rails', require: false
53
+ gem 'rubycritic', require: false
54
+
55
+ gem 'minitest-hooks'
56
+ end
57
+
58
+ group :development do
59
+ # Catch security vulnerabilities
60
+ gem 'brakeman'
61
+ # Catch N+1 queries and unused eager loading
62
+ gem 'bullet'
63
+ end
64
+ ```
65
+
66
+ Other optional gems:
67
+
68
+ ```ruby
69
+ # Gemfile
70
+
71
+ # AWS SDK
72
+ gem 'aws-sdk', '~> 3'
73
+ gem 'aws-sdk-rails'
74
+
75
+ # HTTP requests
76
+ gem 'httparty'
77
+
78
+ # Support PostGIS
79
+ gem 'activerecord-postgis-adapter'
80
+
81
+ # UI
82
+ gem 'jquery-rails'
83
+ gem 'select2-rails'
84
+
85
+ ```
86
+
87
+ <div>
88
+ 4. Run:
89
+ </div>
90
+
91
+ $ bundle install
92
+
93
+
94
+ ### B) Set up environment variables with .ENV
95
+
96
+ 1. Generate secret key:
97
+
98
+ $ rake secret
99
+
100
+ 2. Create `.env` file and add configuration:
101
+
102
+ APP_DB_USERNAME=db_username
103
+ APP_DB_PASSWORD=db_password
104
+ APP_DB_HOSTNAME=127.0.0.1
105
+ APP_DB_PORT=5432
106
+ SECRET_KEY_BASE=<paste here secret generate in the previous step>
107
+
108
+ 3. Create `.env` file template:
109
+
110
+ $ dotenv -t .env
111
+
112
+ 4. Add to `.gitignore`:
113
+
114
+ # Environment variables
115
+ .env
116
+ .env.prod
117
+ .env.dev
118
+
119
+ # Ignore Simplecov tests coverage results
120
+ coverage
121
+
122
+ # Ignore RDoc
123
+ doc
124
+
125
+ # Ignore Breakman output
126
+ brakeman_output.html
127
+
128
+ ### C) Set up database and run project
129
+
130
+ 1. Edit `config/database.yml`
131
+
132
+ pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
133
+ username: <%= ENV['APP_DB_USERNAME'] %>
134
+ password: <%= ENV['APP_DB_PASSWORD'] %>
135
+ port: <%= ENV['APP_DB_PORT'] %>
136
+ host: <%= ENV['APP_DB_HOSTNAME'] %>
137
+
138
+ 2. Create database and run migrations
139
+
140
+ $ rake db:create
141
+ $ rake db:migrate
142
+
143
+ 3. Run project
144
+
145
+ $ rails s
146
+ # OR
147
+ $ rails s -b xxx.xx.xxx.xx -p 4001
148
+
149
+ 4. Open website in the web browser.
150
+
151
+ ### D) Repository
152
+
153
+ 1. Create a new project and/or repository on Bitbucket, GitHub, etc.
154
+
155
+ 2. Run:
156
+
157
+ $ git add .
158
+ $ git commit -m "Ruby on Rails project setup."
159
+ $ git remote add origin <add repository URL>
160
+ $ git push -u origin master
161
+
162
+
163
+
164
+ ### E) Edit README.md file
165
+
166
+ ```markdown
167
+ {% include templates/rails/rails_readme.md project_name=project_name %}
168
+ ```
169
+
170
+
171
+
172
+ ### F) Set up project tree
173
+
174
+ Create folders and files in the project tree. Add empty `.keep` file to empty folders.
175
+
176
+ {% include guidelines/rails/api_only_project_tree_with_files.md %}
177
+
178
+
179
+ ### G) Set up Gems and other
180
+
181
+
182
+ #### UUID
183
+
184
+ Add `config/initializers/generators.rb` file to set up database to use `uuid` as a primary key (ID):
185
+
186
+ ```ruby
187
+ Rails.application.config.generators do |g|
188
+ g.orm :active_record, primary_key_type: :uuid
189
+ end
190
+ ```
191
+
192
+
193
+ #### Apipie
194
+
195
+ Run:
196
+
197
+ ```
198
+ $ rails g apipie:install
199
+ ```
200
+
201
+ Edit `config/initializers/apipie.rb` file:
202
+
203
+ ```ruby
204
+ Apipie.configure do |config|
205
+ config.app_name = '{{ project_name }}'
206
+ config.api_base_url = '/api/v1'
207
+ config.doc_base_url = '/api/docs'
208
+ config.translate = false
209
+ config.default_locale = 'en'
210
+ config.languages = ['en']
211
+ config.layout = 'apipie'
212
+ # where is your API defined?
213
+ config.api_controllers_matcher = File.join(Rails.root, 'app', 'controllers', '**', '*.rb') # rubocop:disable Rails/FilePath
214
+ end
215
+ ```
216
+
217
+ #### CORS
218
+
219
+ Add/edit `config/initializers/cors.rb` file:
220
+
221
+ ```ruby
222
+ Rails.application.config.middleware.insert_before 0, Rack::Cors do
223
+ allow do
224
+ origins '*'
225
+
226
+ resource '*',
227
+ headers: :any,
228
+ methods: %i[get post put patch delete options head]
229
+ end
230
+ end
231
+ ```
232
+
233
+
234
+ ***
235
+
236
+ After all, commit changes to the repository.
@@ -0,0 +1,275 @@
1
+ ### Basic commands
2
+ ---
3
+
4
+ #### Run project
5
+
6
+ ``` bash
7
+ $ rails s
8
+ # OR
9
+ $ rails s -b xxx.xxx.xx.xx -p yyyy
10
+ ```
11
+
12
+
13
+ #### Database
14
+
15
+ ```bash
16
+ $ rake db:create
17
+ $ rake db:migrate
18
+ $ rake db:rollback
19
+ $ rake db:seed
20
+ ```
21
+
22
+ #### Tests
23
+
24
+ TODO
25
+
26
+ #### Common tools, commands & scripts
27
+
28
+ ```bash
29
+ # Rubocop
30
+ $ rubocop --require rubocop-rails
31
+ $ rubocop --require rubocop-rails -a # with auto-correct
32
+ $ rubocop --auto-correct --only FrozenStringLiteralComment # To fix frozen_string_literal
33
+
34
+
35
+ # Rails best practices
36
+ $ rails_best_practices .
37
+
38
+ # Rubycritic
39
+ $ bundle exec rubycritic --no-browser -f console
40
+
41
+ # Breakman
42
+ $ brakeman -o brakeman_output.html
43
+
44
+
45
+ # Check also Bullet and code coverage with simplecov.
46
+ ```
47
+
48
+
49
+ ### Fixing issues
50
+ ---
51
+
52
+ Some issues can be resolved by clearing the cache:
53
+
54
+ ```bash
55
+ $ rake tmp:clear
56
+ ```
57
+
58
+ ... or restarting the spring:
59
+
60
+ ```bash
61
+ $ spring stop
62
+ ```
63
+
64
+
65
+ ### Database login
66
+ ---
67
+
68
+ ```bash
69
+ # PostgreSQL
70
+ $ psql -U <user> -d <db_name> -h 127.0.0.1 -W
71
+
72
+ # MySQL
73
+ $ mysql -u <user> -h 127.0.0.1 -p <db_name>
74
+
75
+ ```
76
+
77
+
78
+ ### frozen_string_literal
79
+ ---
80
+
81
+ Run following command to add `# frozen_string_literal: true` to all files:
82
+
83
+ ```bash
84
+ $ bundle exec rubocop --auto-correct --only FrozenStringLiteralComment
85
+ ```
86
+
87
+ ### Gems
88
+ ---
89
+
90
+ #### Apipie
91
+
92
+ [Learn more](https://github.com/Apipie/apipie-rails)
93
+
94
+ Apipie-rails is a DSL and Rails engine for documenting your RESTful API.
95
+
96
+ *Setup*
97
+
98
+ Run:
99
+
100
+ ```bash
101
+ $ rails g apipie:install
102
+ ```
103
+
104
+ Edit initializer: `config/initializers/apipie.rb`:
105
+
106
+ ```ruby
107
+ Apipie.configure do |config|
108
+ config.app_name = 'project-name'
109
+ config.api_base_url = '/api/v1'
110
+ config.doc_base_url = '/api/docs'
111
+ config.translate = false
112
+ config.default_locale = 'en'
113
+ config.languages = ['en']
114
+ config.layout = 'apipie'
115
+ # where is your API defined?
116
+ config.api_controllers_matcher = File.join(Rails.root, 'app', 'controllers', '**', '*.rb') # rubocop:disable Rails/FilePath
117
+ end
118
+ ```
119
+
120
+ *Usage*
121
+
122
+ Add Apipie comments to controllers' actions:
123
+
124
+ ```ruby
125
+ api :GET, '/user', 'Get user data'
126
+ error code: 401, desc: 'ERR_USER_UNAUTHORIZED: User is not authorized.'
127
+ returns code: 200, desc: 'User data' do
128
+ property :status, String, desc: '200'
129
+ property :message, String, desc: 'User data'
130
+ property :data, Hash, desc: 'User data' do
131
+ property :id, String
132
+ property :email, String
133
+ property :organization, Hash do
134
+ property :id, String
135
+ property :name, String
136
+ end
137
+ end
138
+ end
139
+ def show
140
+ (...)
141
+ end
142
+ ```
143
+
144
+ Then, open in the web browser: `/api/docs`.
145
+
146
+
147
+
148
+ #### Bullet
149
+
150
+ [Learn more](https://github.com/flyerhzm/bullet)
151
+
152
+ Helps to kill N+1 queries and unused eager loading
153
+
154
+ *Usage*
155
+
156
+ Bullet works by itself when server runs in development mode, logging warnings to the terminal and `/log/bullet.log`.
157
+
158
+
159
+ #### Byebug
160
+
161
+ [Learn more](https://github.com/deivid-rodriguez/byebug)
162
+
163
+ Ruby debugger.
164
+
165
+ *Usage*
166
+
167
+ Add `byebug` to the code:
168
+
169
+ ```ruby
170
+ def index
171
+ byebug
172
+ @articles = Article.find_recent
173
+ end
174
+ ```
175
+
176
+ **Basic commands**
177
+
178
+ |Command|Description|
179
+ |-------|-----------|
180
+ |c|Continue|
181
+ |q|Exit byebug|
182
+ |n|Next breakpoint|
183
+ |s|Next step (instruction)|
184
+
185
+
186
+
187
+ #### Serializers
188
+
189
+ [Learn more](https://github.com/rails-api/active_model_serializers)
190
+
191
+ Serializes the data in responses.
192
+
193
+ *Usage*
194
+
195
+ Create a file for a resource in `app/serializers/<my_resource>_serializer.rb`:
196
+
197
+ ```ruby
198
+ # MyResource serializer
199
+ class MyResourceSerializer < ActiveModel::Serializer
200
+ attributes :id, :name, :color
201
+ end
202
+ ```
203
+
204
+ You can serialize data manually:
205
+
206
+ ```ruby
207
+ MyResourceSerializer.new(@resource)
208
+ ```
209
+
210
+
211
+ #### SimpleCov
212
+
213
+ [Learn more](https://github.com/colszowka/simplecov)
214
+
215
+ SimpleCov is a code coverage analysis tool for Ruby.
216
+
217
+ *Usage*
218
+
219
+ Run `RAILS_ENV='test' rake tests:run` and check coverage statistics.
220
+
221
+ #### rails_best_practices
222
+
223
+ [Learn more](https://github.com/flyerhzm/rails_best_practices)
224
+
225
+ It is a code metric tool to check the quality of Rails code.
226
+
227
+ *Usage*
228
+
229
+ ```
230
+ rails_best_practices .
231
+ ```
232
+
233
+ #### Rubycritic
234
+
235
+ [Learn more](https://github.com/whitesmith/rubycritic)
236
+
237
+ A Ruby code quality reporter.
238
+
239
+ *Usage*
240
+
241
+ ```
242
+ $ rubycritic
243
+ $ rubycritic --no-browser
244
+ $ rubycritic --no-browser -f console
245
+
246
+ $ bundle exec rubycritic --no-browser -f console
247
+ ```
248
+
249
+ #### Rubocop
250
+
251
+ [Learn more](https://github.com/rubocop-hq/rubocop)
252
+
253
+ A Ruby static code analyzer and code formatter.
254
+
255
+ *Usage*
256
+
257
+ ```
258
+ $ rubocop --require rubocop-rails
259
+
260
+ $ rubocop --require rubocop-rails -a # with auto-correct
261
+ ```
262
+
263
+ #### Breakman
264
+
265
+ [Learn more](https://github.com/presidentbeef/brakeman)
266
+
267
+ Brakeman is a static analysis tool which checks Ruby on Rails applications for security vulnerabilities.
268
+
269
+ *Usage*
270
+
271
+ ```
272
+ $ brakeman
273
+
274
+ $ brakeman -o brakeman_output.html
275
+ ```