Skip to content

Commit

Permalink
Updating readme and getting ready for 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
akoutmos committed Apr 24, 2022
1 parent da8a775 commit 632620d
Show file tree
Hide file tree
Showing 7 changed files with 296 additions and 30 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.0.0] - 2022-04-23

### Added

- Updated documentation

## [0.2.1] - 2020-05-11

### Fixed
Expand Down
84 changes: 74 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,40 @@
# Unplug
<!--START-->
<p align="center">
<img align="center" width="40%" src="guides/images/logo.svg" alt="Unplug Logo">
<img align="center" width="40%" src="guides/images/logo_text.png" alt="Unplug Logo">
</p>

[![Hex.pm](https://img.shields.io/hexpm/v/unplug.svg)](http://hex.pm/packages/unplug) [![Build Status](https://travis-ci.org/akoutmos/unplug.svg?branch=master)](https://travis-ci.org/akoutmos/unplug) [![Coverage Status](https://coveralls.io/repos/github/akoutmos/unplug/badge.svg?branch=master)](https://coveralls.io/github/akoutmos/unplug?branch=master)
<p align="center">
Unplug allows you to conditionally execute your plug modules at run-time in your Phoenix/Plug applications!
</p>

Unplug is an Elixir library that you can use to conditionally execute your plug modules at
run-time in your Phoenix/Plug applications.
<p align="center">
<a href="https://hex.pm/packages/unplug">
<img alt="Hex.pm" src="https://img.shields.io/hexpm/v/unplug?style=for-the-badge">
</a>

<a href="https://github.com/akoutmos/unplug/actions">
<img alt="GitHub Workflow Status (master)" src="https://img.shields.io/github/workflow/status/akoutmos/unplug/Unplug%20CI/master?label=Build%20Status&style=for-the-badge">
</a>

<a href="https://coveralls.io/github/akoutmos/unplug?branch=master">
<img alt="Coveralls master branch" src="https://img.shields.io/coveralls/github/akoutmos/unplug/master?style=for-the-badge">
</a>

<a href="https://github.com/sponsors/akoutmos">
<img alt="Support Unplug" src="https://img.shields.io/badge/Support%20Unplug-%E2%9D%A4-lightblue?style=for-the-badge">
</a>
</p>

<br>
<!--END-->

# Contents

- [Installation](#installation)
- [Supporting Unplug](#supporting-unplug)
- [Setting Up Unplug](#setting-up-unplug)
- [Attribution](#attribution)

## Installation

Expand All @@ -12,7 +43,7 @@ The package can be installed by adding `:unplug` to your list of dependencies in
```elixir
def deps do
[
{:unplug, "~> 0.2.1"}
{:unplug, "~> 1.0.0"}
]
end
```
Expand All @@ -33,7 +64,36 @@ experience and is in line with Phoenix and Plug conventions.

With those in place, you are all set and ready to use Unplug

## Usage
## Supporting Unplug

If you rely on Unplug in your applications, it would much appreciated if you can give back to the
project in order to help ensure its continued development.

Checkout my [GitHub Sponsorship page](https://github.com/sponsors/akoutmos) if you want to help out!

### Gold Sponsors

<a href="https://github.com/sponsors/akoutmos/sponsorships?sponsor=akoutmos&tier_id=58083">
<img align="center" height="175" src="guides/images/your_logo_here.png" alt="Support the project">
</a>

### Silver Sponsors

<a href="https://github.com/sponsors/akoutmos/sponsorships?sponsor=akoutmos&tier_id=58082">
<img align="center" height="150" src="guides/images/your_logo_here.png" alt="Support the project">
</a>

### Bronze Sponsors

<a href="https://smartlogic.io/" style="margin-right: 10px;" target="_blank">
<img align="center" height="50" src="guides/images/smartlogic-logo-teal-400.png" alt="SmartLogic Consultancy">
</a>

<a href="https://github.com/sponsors/akoutmos/sponsorships?sponsor=akoutmos&tier_id=17615">
<img align="center" height="125" src="guides/images/your_logo_here.png" alt="Support the project">
</a>

## Setting Up Unplug

Unplug can be used anywhere you would typically use the `plug` macro. For example, let's say you want
to skip the `Plug.Telemetry` plug for certain routes (to cut down on noise in your logs for example).
Expand Down Expand Up @@ -92,7 +152,7 @@ plug Unplug,
If the above example, we only want to expose our Prometheus metrics if the request is coming from a known safe source
(as a side note there are better ways to secure your metrics...don't use this in production).

## Provided Predicates
### Provided Predicates

Unplug provides the following predicates out of the box:

Expand All @@ -110,10 +170,10 @@ Unplug provides the following predicates out of the box:
| `Unplug.Predicates.RequestHeaderNotEquals` | Given a request header, do not execute the plug if the request value matches the expected value |
| `Unplug.Predicates.RequestPathEquals` | Given a request path, execute the plug if the request value matches the expected value |
| `Unplug.Predicates.RequestPathNotEquals` | Given a request path, do not execute the plug if the request value matches the expected value |
| `Unplug.Predicates.RequestPathIn` | Given a request path, execute the plug if the request value is in the the provided enumerable of values |
| `Unplug.Predicates.RequestPathNotIn` | Given a request path, do not execute the plug if the request value is in the the provided enumerable of values |
| `Unplug.Predicates.RequestPathIn` | Given a request path, execute the plug if the request value is in the provided enumerable of values |
| `Unplug.Predicates.RequestPathNotIn` | Given a request path, do not execute the plug if the request value is in the provided enumerable of values |

## Writing Your Own Predicates
### Writing Your Own Predicates

To write your own Unplug predicate, all you have to do is implement the `Unplug.Predicate` behavior and provide
a `call/2` function that will return a boolean value.
Expand All @@ -137,3 +197,7 @@ plug Unplug,
if: {MyApp.UnplugPredicates.MethodEquals, "DELETE"},
do: MyApp.MyPlugs.DeleteAuditLoggerPlug
```

## Attribution

- The logo for the project is an edited version of an SVG image from the [unDraw project](https://undraw.co/)
136 changes: 136 additions & 0 deletions guides/images/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added guides/images/logo_text.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added guides/images/your_logo_here.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
74 changes: 66 additions & 8 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ defmodule Unplug.MixProject do
homepage_url: "https://hex.pm/packages/unplug",
description: "A plug that can be used to conditionally invoke other plugs",
start_permanent: Mix.env() == :prod,
docs: [
main: "readme",
extras: ["README.md"]
],
docs: docs(),
package: package(),
deps: deps(),
test_coverage: [tool: ExCoveralls],
Expand All @@ -40,21 +37,82 @@ defmodule Unplug.MixProject do
defp elixirc_paths(:test), do: ["lib", "test/test_plugs", "test/test_predicates"]
defp elixirc_paths(_), do: ["lib"]

defp package() do
defp package do
[
name: "unplug",
files: ~w(lib mix.exs README.md LICENSE CHANGELOG.md),
licenses: ["MIT"],
links: %{"GitHub" => "https://github.com/akoutmos/unplug"}
maintainers: ["Alex Koutmos"],
links: %{
"GitHub" => "https://github.com/akoutmos/unplug",
"Sponsor" => "https://github.com/sponsors/akoutmos"
}
]
end

defp docs do
[
main: "readme",
source_ref: "master",
logo: "guides/images/logo.svg",
extras: ["README.md"]
]
end

# Run "mix help deps" to learn about dependencies.
defp deps do
[
{:plug, "~> 1.8"},
{:ex_doc, "~> 0.21", only: :dev, runtime: false},
{:excoveralls, "~> 0.12", only: :test, runtime: false}
{:ex_doc, "~> 0.28.3", only: :dev, runtime: false},
{:excoveralls, "~> 0.14.4", only: :test, runtime: false}
]
end

defp aliases do
[
docs: [&massage_readme/1, "docs", &copy_files/1]
]
end

defp copy_files(_) do
# Set up directory structure
File.mkdir_p!("./doc/guides/images")

# Copy over image files
"./guides/images/"
|> File.ls!()
|> Enum.each(fn image_file ->
File.cp!("./guides/images/#{image_file}", "./doc/guides/images/#{image_file}")
end)

# Clean up previous file massaging
File.rm!("./README.md")
File.rename!("./README.md.orig", "./README.md")
end

defp massage_readme(_) do
hex_docs_friendly_header_content = """
<br>
<img align="center" width="33%" src="guides/images/logo.svg" alt="Unplug Logo" style="margin-left:33%">
<img align="center" width="70%" src="guides/images/logo_text.png" alt="Unplug Logo" style="margin-left:15%">
<br>
<div align="center">Unplug allows you to conditionally execute your plug modules at run-time in your Phoenix/Plug applications!</div>
<br>
--------------------
[![Hex.pm](https://img.shields.io/hexpm/v/unplug?style=for-the-badge)](http://hex.pm/packages/unplug)
[![Build Status](https://img.shields.io/github/workflow/status/akoutmos/unplug/Unplug%20CI/master?label=Build%20Status&style=for-the-badge)](https://github.com/akoutmos/unplug/actions)
[![Coverage Status](https://img.shields.io/coveralls/github/akoutmos/unplug/master?style=for-the-badge)](https://coveralls.io/github/akoutmos/prom_ex?branch=master)
[![Support Unplug](https://img.shields.io/badge/Support%20Unplug-%E2%9D%A4-lightblue?style=for-the-badge)](https://github.com/sponsors/akoutmos)
"""

File.cp!("./README.md", "./README.md.orig")

readme_contents = File.read!("./README.md")

massaged_readme =
Regex.replace(~r/<!--START-->(.|\n)*<!--END-->/, readme_contents, hex_docs_friendly_header_content)

File.write!("./README.md", massaged_readme)
end
end
Loading

0 comments on commit 632620d

Please sign in to comment.