Skip to content

Commit

Permalink
Version 3.0.0 release (#177)
Browse files Browse the repository at this point in the history
* Version 3.0.0 release

* Version 3.0.0 release

* Version 3.0.0 release

* Version 3.0.0 release

* Version 3.0.0 release

* Version 3.0.0 release
  • Loading branch information
sobolevn committed Sep 12, 2021
1 parent 77cd4a0 commit f77d426
Show file tree
Hide file tree
Showing 9 changed files with 118 additions and 53 deletions.
73 changes: 73 additions & 0 deletions .github/workflows/test.yml
@@ -0,0 +1,73 @@
name: test

'on':
push:
pull_request:
branches:
# Branches from forks have the form 'user:branch-name'. Reference:
# https://github.community/t/how-to-trigger-an-action-on-push-or-pull-request-but-not-both/16662/9
- '**:**'
workflow_dispatch:

jobs:
build:

runs-on: ubuntu-latest
env:
MIX_ENV: test
strategy:
matrix:
elixir: ['1.10', '1.11', '1.12']
otp: ['23', '24']
continue-on-error: false

steps:
- uses: actions/checkout@v2

- name: Setup elixir
uses: erlef/setup-elixir@v1
with:
elixir-version: ${{ matrix.elixir }}
otp-version: ${{ matrix.otp }}

- name: Get deps cache
uses: actions/cache@v2
with:
path: deps/
key: deps-${{ matrix.otp }}-${{ matrix.elixir }}-${{ hashFiles('**/mix.lock') }}

- name: Get build cache
uses: actions/cache@v2
with:
path: _build/test/
key: build-${{ matrix.otp }}-${{ matrix.elixir }}-${{ hashFiles('**/mix.lock') }}

- name: Install Dependencies
run: |
mix local.rebar --force
mix local.hex --force
mix deps.get
mix compile
- name: Run linters
run: |
mix format --check-formatted
mix credo --strict
- name: Run Tests
run: mix coveralls.github
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Retrieve PLT Cache
uses: actions/cache@v2
id: plt-cache
with:
path: priv/plts
key: plts-${{ matrix.otp }}-${{ matrix.elixir }}-${{ hashFiles('**/mix.lock') }}

- name: Create PLTs
if: steps.plt-cache.outputs.cache-hit != 'true'
run: |
mkdir -p priv/plts
mix dialyzer --plt
- name: Run dialyzer
run: mix dialyzer --no-check
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -6,6 +6,7 @@
/tmp
erl_crash.dump
*.ez
/priv/plts

#### osx ####
*.DS_Store
Expand Down
23 changes: 0 additions & 23 deletions .travis.yml

This file was deleted.

15 changes: 15 additions & 0 deletions CHANGELOG.md
Expand Up @@ -5,6 +5,21 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).


## v3.0.0 - 2021-09-12

### Features

- Now support `elixir>=1.10`
- Updates `ecto` to `3.7`
- Updates bunch of other deps to newer versions

### Misc

- Moves from Travis to GitHub Actions
- Adds `mix format` support


## v2.0.1 - 2019-10-16

### Bugfixes
Expand Down
18 changes: 8 additions & 10 deletions README.md
@@ -1,17 +1,15 @@
# EctoAutoslugField

[![Build Status](https://travis-ci.org/sobolevn/ecto_autoslug_field.svg?branch=master)](https://travis-ci.org/sobolevn/ecto_autoslug_field)
[![Build Status](https://github.com/sobolevn/ecto_autoslug_field/workflows/test/badge.svg?branch=master&event=push)](https://github.com/sobolevn/ecto_autoslug_field/actions?query=workflow%3Atest)
[![Coverage Status](https://coveralls.io/repos/github/sobolevn/ecto_autoslug_field/badge.svg?branch=master)](https://coveralls.io/github/sobolevn/ecto_autoslug_field?branch=master)
[![Module Version](https://img.shields.io/hexpm/v/ecto_autoslug_field.svg)](https://hex.pm/packages/ecto_autoslug_field)
[![Hex Docs](https://img.shields.io/badge/hex-docs-lightgreen.svg)](https://hexdocs.pm/ecto_autoslug_field/)
[![Total Download](https://img.shields.io/hexpm/dt/ecto_autoslug_field.svg)](https://hex.pm/packages/ecto_autoslug_field)
[![License](https://img.shields.io/hexpm/l/ecto_autoslug_field.svg)](https://github.com/sobolevn/ecto_autoslug_field/blob/master/LICENSE)
[![Last Updated](https://img.shields.io/github/last-commit/sobolevn/ecto_autoslug_field.svg)](https://github.com/sobolevn/ecto_autoslug_field/commits/master)

`ecto_autoslug_field` is a reusable [`Ecto`](https://github.com/elixir-ecto/ecto) library which can automatically create slugs from other fields. We use [`slugger`](https://github.com/h4cc/slugger) as a default slug-engine.

We only depend on the `ecto` package (we do not deal with `ecto_sql` at all).
We support `ecto >= 2.1 and ecto < 4`!
We support `ecto >= 3.7 and ecto < 4`!

See [this blog post](https://sobolevn.me/2017/07/creating-slugs-for-ecto-schemas)
for more information.
Expand All @@ -22,7 +20,7 @@ for more information.
```elixir
def deps do
[
{:ecto_autoslug_field, "~> 2.0"}
{:ecto_autoslug_field, "~> 3.0"}
]
end
```
Expand Down Expand Up @@ -73,13 +71,13 @@ defmodule EctoSlugs.Blog.Article do
timestamps()
end

def changeset(%Article{} = article, attrs) do
article
|> cast(attrs, [:title, :content, :breaking])
def changeset(model, params \\ :invalid) do
model
|> cast(params, [:title, :content, :breaking])
|> validate_required([:title, :content])
|> unique_constraint(:title)
|> TitleSlug.maybe_generate_slug
|> TitleSlug.unique_constraint
|> TitleSlug.maybe_generate_slug()
|> TitleSlug.unique_constraint()
end
end
```
Expand Down
6 changes: 4 additions & 2 deletions lib/ecto_autoslug_field/slug.ex
Expand Up @@ -48,10 +48,12 @@ defmodule EctoAutoslugField.SlugBase do
1. `atom`-key is supposed to identify the model field
2. `binary`-key is treated as a data itself, it won't be changed
"""
@spec get_sources(Changeset.t(), Keyword.t()) ::
list(atom() | binary()) | none
@spec get_sources(Changeset.t(), Keyword.t()) :: list(atom() | binary())
def get_sources(_changeset, [from: from] = _opts) do
# This code is only used in macros, so it is not tracked by `coveralls`.
# coveralls-ignore-start
[from]
# coveralls-ignore-stop
end

@doc """
Expand Down
12 changes: 4 additions & 8 deletions lib/ecto_autoslug_field/slug_generator.ex
Expand Up @@ -5,6 +5,8 @@ defmodule EctoAutoslugField.SlugGenerator do
It is suited for inner use.
"""

alias Ecto.Changeset

import Ecto.Changeset,
only: [
put_change: 3,
Expand All @@ -17,9 +19,7 @@ defmodule EctoAutoslugField.SlugGenerator do
Default slug builder.
"""
@spec build_slug(Keyword.t(), Changeset.t()) :: String.t()
def build_slug(sources, _changeset) do
do_build_slug(sources)
end
def build_slug(sources, _changeset), do: do_build_slug(sources)

@doc """
This function conditionally generates slug.
Expand Down Expand Up @@ -96,10 +96,6 @@ defmodule EctoAutoslugField.SlugGenerator do
defp get_field_data(_, source, _) when is_binary(source), do: source

defp has_value?(nil), do: false

defp has_value?(string) when is_binary(string) do
String.trim(string) != ""
end

defp has_value?(string) when is_binary(string), do: String.trim(string) != ""
defp has_value?(_), do: true
end
19 changes: 11 additions & 8 deletions mix.exs
Expand Up @@ -2,13 +2,13 @@ defmodule EctoAutoslugField.Mixfile do
use Mix.Project

@source_url "https://github.com/sobolevn/ecto_autoslug_field"
@version "2.0.1"
@version "3.0.0"

def project do
[
app: :ecto_autoslug_field,
version: @version,
elixir: "~> 1.6",
elixir: "~> 1.10",
deps: deps(),
build_embedded: Mix.env() == :prod,
start_permanent: Mix.env() == :prod,
Expand All @@ -27,7 +27,10 @@ defmodule EctoAutoslugField.Mixfile do
],

# Dialyzer:
dialyzer: [plt_add_deps: :apps_direct, plt_add_apps: [:ecto]]
dialyzer: [
plt_add_deps: :apps_direct,
plt_add_apps: [:ecto]
]
]
end

Expand All @@ -37,15 +40,15 @@ defmodule EctoAutoslugField.Mixfile do

defp deps do
[
{:ecto, ">= 2.1.0"},
{:ecto, ">= 3.7.0"},

# Slugs:
{:slugger, ">= 0.2.0"},
{:slugger, ">= 0.3.0"},

# Testing:
{:excoveralls, "~> 0.5", only: :test},
{:credo, "~> 1.0", only: [:dev, :test], runtime: false},
{:dialyxir, "~> 1.0", only: :dev, runtime: false},
{:excoveralls, "~> 0.14", only: :test},
{:credo, "~> 1.5", only: [:dev, :test], runtime: false},
{:dialyxir, "~> 1.1", only: [:dev, :test], runtime: false},

# Documentation:
{:ex_doc, ">= 0.23.0", only: :dev, runtime: false}
Expand Down
4 changes: 2 additions & 2 deletions mix.lock
Expand Up @@ -5,7 +5,7 @@
"decimal": {:hex, :decimal, "2.0.0", "a78296e617b0f5dd4c6caf57c714431347912ffb1d0842e998e9792b5642d697", [:mix], [], "hexpm", "34666e9c55dea81013e77d9d87370fe6cb6291d1ef32f46a1600230b1d44f577"},
"dialyxir": {:hex, :dialyxir, "1.1.0", "c5aab0d6e71e5522e77beff7ba9e08f8e02bad90dfbeffae60eaf0cb47e29488", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "07ea8e49c45f15264ebe6d5b93799d4dd56a44036cf42d0ad9c960bc266c0b9a"},
"earmark_parser": {:hex, :earmark_parser, "1.4.13", "0c98163e7d04a15feb62000e1a891489feb29f3d10cb57d4f845c405852bbef8", [:mix], [], "hexpm", "d602c26af3a0af43d2f2645613f65841657ad6efc9f0e361c3b6c06b578214ba"},
"ecto": {:hex, :ecto, "3.6.2", "efdf52acfc4ce29249bab5417415bd50abd62db7b0603b8bab0d7b996548c2bc", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "efad6dfb04e6f986b8a3047822b0f826d9affe8e4ebdd2aeedbfcb14fd48884e"},
"ecto": {:hex, :ecto, "3.7.1", "a20598862351b29f80f285b21ec5297da1181c0442687f9b8329f0445d228892", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "d36e5b39fc479e654cffd4dbe1865d9716e4a9b6311faff799b6f90ab81b8638"},
"erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
"ex_doc": {:hex, :ex_doc, "0.25.1", "4b736fa38dc76488a937e5ef2944f5474f3eff921de771b25371345a8dc810bc", [: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", "3200b0a69ddb2028365281fbef3753ea9e728683863d8cdaa96580925c891f67"},
"excoveralls": {:hex, :excoveralls, "0.14.2", "f9f5fd0004d7bbeaa28ea9606251bb643c313c3d60710bad1f5809c845b748f0", [:mix], [{:hackney, "~> 1.16", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "ca6fd358621cb4d29311b29d4732c4d47dac70e622850979bc54ed9a3e50f3e1"},
Expand All @@ -22,6 +22,6 @@
"parse_trans": {:hex, :parse_trans, "3.3.1", "16328ab840cc09919bd10dab29e431da3af9e9e7e7e6f0089dd5a2d2820011d8", [:rebar3], [], "hexpm", "07cd9577885f56362d414e8c4c4e6bdf10d43a8767abb92d24cbe8b24c54888b"},
"slugger": {:hex, :slugger, "0.3.0", "efc667ab99eee19a48913ccf3d038b1fb9f165fa4fbf093be898b8099e61b6ed", [:mix], [], "hexpm", "20d0ded0e712605d1eae6c5b4889581c3460d92623a930ddda91e0e609b5afba"},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.6", "cf344f5692c82d2cd7554f5ec8fd961548d4fd09e7d22f5b62482e5aeaebd4b0", [:make, :mix, :rebar3], [], "hexpm", "bdb0d2471f453c88ff3908e7686f86f9be327d065cc1ec16fa4540197ea04680"},
"telemetry": {:hex, :telemetry, "0.4.3", "a06428a514bdbc63293cd9a6263aad00ddeb66f608163bdec7c8995784080818", [:rebar3], [], "hexpm", "eb72b8365ffda5bed68a620d1da88525e326cb82a75ee61354fc24b844768041"},
"telemetry": {:hex, :telemetry, "1.0.0", "0f453a102cdf13d506b7c0ab158324c337c41f1cc7548f0bc0e130bbf0ae9452", [:rebar3], [], "hexpm", "73bc09fa59b4a0284efb4624335583c528e07ec9ae76aca96ea0673850aec57a"},
"unicode_util_compat": {:hex, :unicode_util_compat, "0.7.0", "bc84380c9ab48177092f43ac89e4dfa2c6d62b40b8bd132b1059ecc7232f9a78", [:rebar3], [], "hexpm", "25eee6d67df61960cf6a794239566599b09e17e668d3700247bc498638152521"},
}

0 comments on commit f77d426

Please sign in to comment.