~cosmicrose/liberator_example

5c9d2fad46a27595fb0decd6798ec876b522272b — Rosa Richter 9 months ago 272f417
Migrate project and links to sourcehut
3 files changed, 59 insertions(+), 5 deletions(-)

A .build.yml
A .github/workflows/elixir.yml
M README.md
A .build.yml => .build.yml +22 -0
@@ 0,0 1,22 @@
image: debian/stable
repositories:
  docker: https://download.docker.com/linux/debian stretch stable 7EA0A9C3F273FCD8
packages:
  - apt-transport-https
  - ca-certificates
  - curl
  - gnupg
  - lsb-release
  - docker-ce
  - docker-ce-cli
  - containerd.io
sources:
  - https://git.sr.ht/~cosmicrose/liberator_example
tasks:
  - setup: |
      sudo apt-get install
      sudo curl -L https://github.com/earthly/earthly/releases/download/v0.5.22/earthly-linux-amd64 -o /usr/local/bin/earthly
      sudo chmod a+x /usr/local/bin/earthly
  - build: |
      cd liberator_example
      sudo /usr/local/bin/earthly -P +all

A .github/workflows/elixir.yml => .github/workflows/elixir.yml +30 -0
@@ 0,0 1,30 @@
name: CI

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

jobs:
  build:
    runs-on: ubuntu-latest
    env:
      FORCE_COLOR: 1
    steps:
    - uses: actions/checkout@v2
    - name: Put back the git branch into git (Earthly uses it for tagging)
      run: |
        branch=""
        if [ -n "$GITHUB_HEAD_REF" ]; then
          branch="$GITHUB_HEAD_REF"
        else
          branch="${GITHUB_REF##*/}"
        fi
        git checkout -b "$branch" || true
    - name: Download latest earthly
      run: "sudo /bin/sh -c 'wget https://github.com/earthly/earthly/releases/download/v0.5.22/earthly-linux-amd64 -O /usr/local/bin/earthly && chmod +x /usr/local/bin/earthly'"
    - name: Earthly version
      run: earthly --version
    - name: Run build
      run: earthly -P +all

M README.md => README.md +7 -5
@@ 1,11 1,13 @@
# Liberator Example

[![builds.sr.ht status](https://builds.sr.ht/~cosmicrose/liberator_example.svg)](https://builds.sr.ht/~cosmicrose/liberator?)

This library demonstrates how to use the [Liberator] library to create controllers that respect the HTTP specificiation.

[Liberator]: https://github.com/Cantido/liberator
[Liberator]: https://sr.ht/~cosmicrose/liberator

Check out the file at
[`lib\liberator_example_web\controllers\post_controller.ex`](https://github.com/Cantido/liberator_example/blob/main/lib/liberator_example_web/controllers/post_controller.ex)
[`lib\liberator_example_web\controllers\post_controller.ex`](https://git.sr.ht/~cosmicrose/liberator_example/tree/main/item/lib/liberator_example_web/controllers/post_controller.ex)
for an example of a controller using Liberator to pass Phoenix's generated controller tests.

## How it was made


@@ 38,14 40,14 @@ end
However, we then deleted the contents of [`LiberatorExampleWeb.PostController`] and replaced with a Liberator resource module.
Just enough functionality was added to the resource module to make [the existing controller tests] pass.

[`LiberatorExampleWeb.PostController`]: https://github.com/Cantido/liberator_example/blob/main/lib/liberator_example_web/controllers/post_controller.ex
[the existing controller tests]: https://github.com/Cantido/liberator_example/blob/main/test/liberator_example_web/controllers/post_controller_test.exs
[`LiberatorExampleWeb.PostController`]: https://git.sr.ht/~cosmicrose/liberator_example/tree/main/item/lib/liberator_example_web/controllers/post_controller.ex
[the existing controller tests]: https://git.sr.ht/~cosmicrose/liberator_example/tree/main/item/test/liberator_example_web/controllers/post_controller_test.exs

## Contributing

Questions and pull requests are more than welcome.
I follow Elixir's tenet of bad documentation being a bug,
so if anything is unclear, please [file an issue](https://github.com/Cantido/liberator_example/issues/new)!
so if anything is unclear, please let me know in our [mailing list](https://lists.sr.ht/~cosmicrose/liberator)!
Ideally, my answer to your question will be in an update to the docs.

## License