Skip to content

Commit

Permalink
Migrate/add an API documentation site based on MkDocs
Browse files Browse the repository at this point in the history
Includes version selector and auto-deployment to GitHub Pages
  • Loading branch information
oprypin committed Mar 2, 2021
1 parent bd45602 commit e3e8da5
Show file tree
Hide file tree
Showing 9 changed files with 249 additions and 2 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/deploy-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Deploy docs
on:
push:
pull_request:
branches: [master]
jobs:
build:
name: Deploy docs
runs-on: ubuntu-latest
steps:
- name: Download source
uses: actions/checkout@v2
with:
fetch-depth: 0 # Prevent shallow clone
- name: Install Crystal
uses: oprypin/install-crystal@v1
- name: Install Python
uses: actions/setup-python@v2
- name: Install Python libs
run: |
pip install --no-deps -r docs/requirements.txt
- name: Configure Git
run: |
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
- name: Build site
run: |
mkdocs build --strict
- name: Deploy to gh-pages
if: startsWith(github.ref, 'refs/tags/v')
run: |
mike deploy --push --update-aliases --prefix=api "${GITHUB_REF#refs/tags/v}" latest
mike set-default --push --prefix=api "${GITHUB_REF#refs/tags/v}"
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/docs/
/lib/
/bin/
/.shards/
Expand All @@ -8,3 +7,4 @@
# Dependencies will be locked in application that uses them
/shard.lock

/site/
50 changes: 50 additions & 0 deletions docs/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
* [Home](README.md)
* [DB module](DB.md)
* Connection & session
* [Database](DB/Database.md)
* [ConnectionContext](DB/ConnectionContext.md)
* [Connection](DB/Connection.md)
* [Pool](DB/Pool.md)
* [Stats](DB/Pool/Stats.md)
* [SessionMethods](DB/SessionMethods.md)
* [PreparedQuery](DB/SessionMethods/PreparedQuery.md)
* [UnpreparedQuery](DB/SessionMethods/UnpreparedQuery.md)
* Transaction
* [Transaction](DB/Transaction.md)
* [TopLevelTransaction](DB/TopLevelTransaction.md)
* [SavePointTransaction](DB/SavePointTransaction.md)
* [BeginTransaction](DB/BeginTransaction.md)
* [QueryMethods](DB/QueryMethods.md)
* [ExecResult](DB/ExecResult.md)
* [ResultSet](DB/ResultSet.md)
* Statement
* [Statement](DB/Statement.md)
* [PoolStatement](DB/PoolStatement.md)
* [PoolUnpreparedStatement](DB/PoolUnpreparedStatement.md)
* [PoolPreparedStatement](DB/PoolPreparedStatement.md)
* [StatementMethods](DB/StatementMethods.md)
* Driver
* [Driver](DB/Driver.md)
* [DriverSpecs](DB/DriverSpecs.md)
* [ColumnDef](DB/DriverSpecs/ColumnDef.md)
* [MetadataValueConverter](DB/MetadataValueConverter.md)
* Serialization
* [Serializable](DB/Serializable.md)
* [NonStrict](DB/Serializable/NonStrict.md)
* [Field](DB/Field.md)
* [Mappable](DB/Mappable.md)
* Miscellaneous
* [Any](DB/Any.md)
* [StringKeyCache](DB/StringKeyCache.md)
* [Disposable](DB/Disposable.md)
* Errors
* [Error](DB/Error.md)
* [NoResultsError](DB/NoResultsError.md)
* [Rollback](DB/Rollback.md)
* [MappingException](DB/MappingException.md)
* [PoolResourceLost](DB/PoolResourceLost.md)
* [ConnectionLost](DB/ConnectionLost.md)
* [PoolResourceRefused](DB/PoolResourceRefused.md)
* [ConnectionRefused](DB/ConnectionRefused.md)
* [PoolRetryAttemptsExceeded](DB/PoolRetryAttemptsExceeded.md)
* [PoolTimeout](DB/PoolTimeout.md)
Empty file added docs/css/mkdocstrings.css
Empty file.
18 changes: 18 additions & 0 deletions docs/gen_doc_stubs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generate virtual doc files for the mkdocs site.
# You can also run this script directly to actually write out those files, as a preview.

import mkdocs_gen_files

# Get the documentation root object
root = mkdocs_gen_files.config['plugins']['mkdocstrings'].get_handler('crystal').collector.root

# For each type (e.g. "Foo::Bar")
for typ in root.walk_types():
# Use the file name "Foo/Bar.md"
filename = '/'.join(typ.abs_id.split('::')) + '.md'
# Make a file with the content "# ::: Foo::Bar\n"
with mkdocs_gen_files.open(filename, 'w') as f:
print(f'# ::: {typ.abs_id}', file=f)

with mkdocs_gen_files.open('README.md', 'w') as f, open('README.md') as in_f:
f.write(in_f.read())
6 changes: 6 additions & 0 deletions docs/requirements.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
mkdocs-material
mkdocstrings-crystal
mkdocs-gen-files
mkdocs-literate-nav
mkdocs-section-index
git+https://github.com/jimporter/mike.git@7cff0cc9bd434ff2db8d7c8c945d2a6befcba85f
97 changes: 97 additions & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#
# This file is autogenerated by pip-compile
# To update, run:
#
# pip-compile requirements.in
#
cached-property==1.5.2
# via mkdocstrings-crystal
click==7.1.2
# via
# mkdocs
# nltk
future==0.18.2
# via lunr
glob2==0.7
# via mkdocs-literate-nav
jinja2==2.11.3
# via
# mike
# mkdocs
# mkdocstrings
# mkdocstrings-crystal
joblib==1.0.1
# via nltk
livereload==2.6.3
# via mkdocs
lunr[languages]==0.5.8
# via mkdocs
markdown==3.3.4
# via
# mkdocs
# mkdocs-autorefs
# mkdocs-material
# mkdocstrings
# pymdown-extensions
markupsafe==1.1.1
# via
# jinja2
# mkdocstrings
# mkdocstrings-crystal
git+https://github.com/jimporter/mike.git@7cff0cc9bd434ff2db8d7c8c945d2a6befcba85f
# via -r requirements.in
mkdocs-autorefs==0.1.1
# via mkdocstrings
mkdocs-gen-files==0.3.1
# via -r requirements.in
mkdocs-literate-nav==0.3.0
# via -r requirements.in
mkdocs-material-extensions==1.0.1
# via mkdocs-material
mkdocs-material==7.0.3
# via
# -r requirements.in
# mkdocs-material-extensions
mkdocs-section-index==0.2.3
# via -r requirements.in
mkdocs==1.1.2
# via
# mike
# mkdocs-autorefs
# mkdocs-gen-files
# mkdocs-literate-nav
# mkdocs-material
# mkdocs-section-index
# mkdocstrings
mkdocstrings-crystal==0.3.1
# via -r requirements.in
mkdocstrings==0.15.0
# via mkdocstrings-crystal
nltk==3.5
# via lunr
pygments==2.8.0
# via mkdocs-material
pymdown-extensions==8.1.1
# via
# mkdocs-material
# mkdocstrings
pytkdocs==0.11.0
# via mkdocstrings
pyyaml==5.4.1
# via
# mike
# mkdocs
regex==2020.11.13
# via nltk
six==1.15.0
# via
# livereload
# lunr
tornado==6.1
# via
# livereload
# mkdocs
tqdm==4.58.0
# via nltk
verspec==0.1.0
# via mike
42 changes: 42 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
site_name: crystal-db
site_url: https://oprypin.github.io/crystal-db/api/
repo_url: https://github.com/oprypin/crystal-db
edit_uri: blob/master/docs/
use_directory_urls: false

theme:
name: material
icon:
repo: fontawesome/brands/github
features:
- navigation.sections
extra:
version:
provider: mike

extra_css:
- css/mkdocstrings.css

plugins:
- search
- gen-files:
scripts:
- docs/gen_doc_stubs.py
- mkdocstrings:
default_handler: crystal
watch: [src]
- literate-nav:
nav_file: SUMMARY.md
- section-index
- mike:
canonical_version: latest

markdown_extensions:
- pymdownx.highlight
- pymdownx.magiclink
- pymdownx.saneheaders
- pymdownx.superfences
- pymdownx.tasklist
- deduplicate-toc
- toc:
permalink: "#"
3 changes: 2 additions & 1 deletion src/db.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ require "log"
# Individual database systems are supported by specific database driver shards.
#
# Available drivers include:
#
# * [crystal-lang/crystal-sqlite3](https://github.com/crystal-lang/crystal-sqlite3) for SQLite
# * [crystal-lang/crystal-mysql](https://github.com/crystal-lang/crystal-mysql) for MySQL and MariaDB
# * [will/crystal-pg](https://github.com/will/crystal-pg) for PostgreSQL
Expand Down Expand Up @@ -88,7 +89,7 @@ module DB
alias Any = Union({{*TYPES}})
{% end %}

# Result of a `#exec` statement.
# Result of a `QueryMethods#exec` statement.
record ExecResult, rows_affected : Int64, last_insert_id : Int64

# :nodoc:
Expand Down

0 comments on commit e3e8da5

Please sign in to comment.