Skip to content

Commit 99b7271

Browse files
committedJan 10, 2023
Update docs + usage guide
1 parent 1dd66ee commit 99b7271

File tree

5 files changed

+119
-52
lines changed

5 files changed

+119
-52
lines changed
 

‎README.md

+27-40
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,60 @@
1-
Briefly
2-
=======
1+
# Briefly
2+
3+
<!-- MDOC -->
34

45
![Build Status](https://github.com/CargoSense/briefly/actions/workflows/main.yml/badge.svg)
56

67
Simple, robust temporary file support for Elixir.
78

89
## Highlighted Features
910

10-
* Create temporary files with prefix and extname options
11-
* Files are removed after the process that requested the file dies
12-
* File creation is based on [Plug.Upload](http://hexdocs.pm/plug/Plug.Upload.html)'s robust retry logic
13-
* Configurable; built-in support for system environment variables and fallbacks
11+
* Create temporary files with prefix and extname options.
12+
* Files are removed after the requesting process exits.
13+
* File creation is based on [Plug.Upload](http://hexdocs.pm/plug/Plug.Upload.html)'s robust retry logic.
14+
* Configurable; built-in support for system environment variables and fallbacks.
1415

15-
## Installation
16+
## Usage
1617

17-
Add as a dependency to your `mix.exs`:
18+
The fastest way to use Briefly is with [`Mix.install/2`](https://hexdocs.pm/mix/Mix.html#install/2) (requires Elixir v1.12+):
1819

1920
```elixir
20-
def deps do
21-
[
22-
briefly: "~> 0.3"
23-
]
24-
end
25-
```
21+
Mix.install([
22+
{:briefly, "~> 0.4.0"}
23+
])
2624

27-
or grab the latest with:
25+
{:ok, path} = Briefly.create()
26+
File.write!(path, "My temp file contents")
27+
File.read!(path)
28+
# => "My temp file contents"
2829

29-
```elixir
30-
{
31-
:briefly,
32-
git: "https://github.com/CargoSense/briefly",
33-
ref: "2526e9674a4e6996137e066a1295ea60962712b8"
34-
# "~> 0.4" https://github.com/CargoSense/briefly/issues/17
35-
}
30+
# When this process exits, the file at `path` is removed
3631
```
3732

38-
Install it with `mix deps.get`.
33+
If you want to use Briefly in a Mix project, you can add the above dependency to your list of dependencies in `mix.exs`.
3934

40-
## Example
35+
Briefly can also create a temporary directory:
4136

42-
Create a file:
4337

4438
```elixir
45-
{:ok, path} = Briefly.create
46-
File.write!(path, "Some Text")
47-
content = File.read!(path)
48-
# When this process exits, the file at `path` is removed
49-
```
50-
51-
Create a directory:
52-
53-
```elixir
54-
{:ok, path} = Briefly.create(directory: true)
55-
File.write!(Path.join(path, "test.txt"), "Some Text")
39+
{:ok, dir} = Briefly.create(directory: true)
40+
File.write!(Path.join(dir, "test.txt"), "Some Text")
5641
# When this process exits, the directory and file are removed
5742
```
5843

59-
See [the documentation](http://hexdocs.pm/briefly/Briefly.html#create/1) to see
60-
the options that available to `Briefly.create/1` and `Briefly.create!/1`.
44+
Refer to [the documentation](http://hexdocs.pm/briefly/Briefly.html#create/1) for a list of options that are available to `Briefly.create/1` and `Briefly.create!/1`.
6145

6246
## Configuration
6347

6448
The default, out-of-the-box settings for Briefly are equivalent to the
6549
following Mix config:
6650

6751
```elixir
52+
# config/config.exs
6853
config :briefly,
6954
directory: [{:system, "TMPDIR"}, {:system, "TMP"}, {:system, "TEMP"}, "/tmp"],
7055
default_prefix: "briefly",
7156
default_extname: ""
72-
```
57+
```
7358

7459
`directory` here declares an ordered list of possible directory definitions that Briefly will check in order.
7560

@@ -79,6 +64,8 @@ You can override the settings with your own candidates in your application Mix
7964
config (and pass `prefix` and `extname` to `Briefly.create` to override
8065
`default_prefix` and `default_extname` on a case-by-case basis).
8166

67+
<!-- MDOC -->
68+
8269
## License
8370

84-
See [LICENSE](./LICENSE).
71+
Briefly source code is released under Apache License 2.0. Refer to the [LICENSE](./LICENSE) file for more information.

‎guides/usage.livemd

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Briefly Usage Guide
2+
3+
```elixir
4+
Mix.install([
5+
{:briefly, "~> 0.4.0"}
6+
])
7+
```
8+
9+
## Temporary Files
10+
11+
Use Briefly to create a temporary file:
12+
13+
```elixir
14+
{:ok, path} = Briefly.create()
15+
```
16+
17+
Then you can write to the path and read the contents of the file:
18+
19+
```elixir
20+
File.write!(path, "My temp file contents")
21+
File.read!(path)
22+
```
23+
24+
When this process exits, the file at `path` is removed.
25+
26+
## Temporary Directories
27+
28+
Briefly can also create a temporary directory:
29+
30+
```elixir
31+
{:ok, dir} = Briefly.create(directory: true)
32+
```
33+
34+
You can use [`File.stat/1`](https://hexdocs.pm/elixir/File.html#stat/1) to check the type:
35+
36+
```elixir
37+
File.stat!(dir).type
38+
```
39+
40+
Write to a file in the directory:
41+
42+
```elixir
43+
dir |> Path.join("test.txt") |> File.write!("Some Text")
44+
dir |> Path.join("test.txt") |> File.read!()
45+
```
46+
47+
When this process exits, the directory at `dir` and the files within are removed.
48+
49+
## Cleanup
50+
51+
You can always cleanup any temporary paths already created:
52+
53+
```elixir
54+
Briefly.cleanup()
55+
```

‎lib/briefly.ex

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
defmodule Briefly do
2-
@moduledoc File.read!("#{__DIR__}/../README.md")
2+
@external_resource "README.md"
3+
@moduledoc @external_resource
4+
|> File.read!()
5+
|> String.split("<!-- MDOC -->")
6+
|> Enum.fetch!(1)
37

48
use Application
59

‎mix.exs

+27-6
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
defmodule Briefly.Mixfile do
22
use Mix.Project
33

4+
@version "0.4.0"
5+
6+
@source_url "https://github.com/CargoSense/briefly"
7+
48
def project do
59
[
610
app: :briefly,
711
version: "0.4.0",
812
elixir: "~> 1.11",
9-
source_url: "https://github.com/CargoSense/briefly",
13+
source_url: @source_url,
1014
build_embedded: Mix.env() == :prod,
1115
start_permanent: Mix.env() == :prod,
1216
package: package(),
13-
deps: deps()
17+
deps: deps(),
18+
docs: docs(),
19+
preferred_cli_env: [
20+
{:docs, :docs},
21+
{:"hex.publish", :docs}
22+
]
1423
]
1524
end
1625

@@ -32,17 +41,29 @@ defmodule Briefly.Mixfile do
3241
# Type `mix help deps` for more examples and options
3342
defp deps do
3443
[
35-
{:ex_doc, "~> 0.19", only: :dev, runtime: false}
44+
{:ex_doc, "~> 0.29", only: :docs, runtime: false}
3645
]
3746
end
3847

3948
defp package do
4049
[
4150
description: "Simple, robust temporary file support",
4251
files: ["lib", "config", "mix.exs", "README*", "LICENSE"],
43-
contributors: ["Bruce Williams"],
44-
licenses: ["Apache 2"],
45-
links: %{github: "https://github.com/CargoSense/briefly"}
52+
contributors: ["Bruce Williams", "Michael A. Crumm Jr."],
53+
licenses: ["Apache-2.0"],
54+
links: %{"GitHub" => @source_url}
55+
]
56+
end
57+
58+
defp docs do
59+
[
60+
source_url: @source_url,
61+
source_ref: "v#{@version}",
62+
deps: [],
63+
language: "en",
64+
formatters: ["html"],
65+
main: "usage",
66+
extras: ["guides/usage.livemd"]
4667
]
4768
end
4869

‎mix.lock

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
%{
2-
"earmark_parser": {:hex, :earmark_parser, "1.4.13", "0c98163e7d04a15feb62000e1a891489feb29f3d10cb57d4f845c405852bbef8", [:mix], [], "hexpm", "d602c26af3a0af43d2f2645613f65841657ad6efc9f0e361c3b6c06b578214ba"},
3-
"ex_doc": {:hex, :ex_doc, "0.24.2", "e4c26603830c1a2286dae45f4412a4d1980e1e89dc779fcd0181ed1d5a05c8d9", [:mix], [{:earmark_parser, "~> 1.4.0", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "e134e1d9e821b8d9e4244687fb2ace58d479b67b282de5158333b0d57c6fb7da"},
4-
"makeup": {:hex, :makeup, "1.0.5", "d5a830bc42c9800ce07dd97fa94669dfb93d3bf5fcf6ea7a0c67b2e0e4a7f26c", [:mix], [{:nimble_parsec, "~> 0.5 or ~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "cfa158c02d3f5c0c665d0af11512fed3fba0144cf1aadee0f2ce17747fba2ca9"},
5-
"makeup_elixir": {:hex, :makeup_elixir, "0.15.1", "b5888c880d17d1cc3e598f05cdb5b5a91b7b17ac4eaf5f297cb697663a1094dd", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.1", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "db68c173234b07ab2a07f645a5acdc117b9f99d69ebf521821d89690ae6c6ec8"},
2+
"earmark_parser": {:hex, :earmark_parser, "1.4.29", "149d50dcb3a93d9f3d6f3ecf18c918fb5a2d3c001b5d3305c926cddfbd33355b", [:mix], [], "hexpm", "4902af1b3eb139016aed210888748db8070b8125c2342ce3dcae4f38dcc63503"},
3+
"ex_doc": {:hex, :ex_doc, "0.29.1", "b1c652fa5f92ee9cf15c75271168027f92039b3877094290a75abcaac82a9f77", [:mix], [{:earmark_parser, "~> 1.4.19", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "b7745fa6374a36daf484e2a2012274950e084815b936b1319aeebcf7809574f6"},
4+
"makeup": {:hex, :makeup, "1.1.0", "6b67c8bc2882a6b6a445859952a602afc1a41c2e08379ca057c0f525366fc3ca", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "0a45ed501f4a8897f580eabf99a2e5234ea3e75a4373c8a52824f6e873be57a6"},
5+
"makeup_elixir": {:hex, :makeup_elixir, "0.16.0", "f8c570a0d33f8039513fbccaf7108c5d750f47d8defd44088371191b76492b0b", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "28b2cbdc13960a46ae9a8858c4bebdec3c9a6d7b4b9e7f4ed1502f8159f338e7"},
66
"makeup_erlang": {:hex, :makeup_erlang, "0.1.1", "3fcb7f09eb9d98dc4d208f49cc955a34218fc41ff6b84df7c75b3e6e533cc65f", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "174d0809e98a4ef0b3309256cbf97101c6ec01c4ab0b23e926a9e17df2077cbb"},
7-
"nimble_parsec": {:hex, :nimble_parsec, "1.1.0", "3a6fca1550363552e54c216debb6a9e95bd8d32348938e13de5eda962c0d7f89", [:mix], [], "hexpm", "08eb32d66b706e913ff748f11694b17981c0b04a33ef470e33e11b3d3ac8f54b"},
7+
"nimble_parsec": {:hex, :nimble_parsec, "1.2.3", "244836e6e3f1200c7f30cb56733fd808744eca61fd182f731eac4af635cc6d0b", [:mix], [], "hexpm", "c8d789e39b9131acf7b99291e93dae60ab48ef14a7ee9d58c6964f59efb570b0"},
88
}

0 commit comments

Comments
 (0)
Please sign in to comment.