Skip to content

Commit

Permalink
Merge branch 'release/v0.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
ja573 committed Mar 28, 2023
2 parents b34e97d + 0a01352 commit 7006c35
Show file tree
Hide file tree
Showing 11 changed files with 730 additions and 0 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/publish_crate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Name: publish

on:
release:
types: [published]

jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
- name: Publish
uses: actions-rs/cargo@v1
with:
command: publish
args: --token ${{ secrets.CRATES_TOKEN }}
48 changes: 48 additions & 0 deletions .github/workflows/test_and_check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: test-and-check

on:
push:
branches:
- main
- develop
pull_request:

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
- name: Run tests
uses: actions-rs/cargo@v1
with:
command: test
args: --workspace --verbose
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
- name: Run linting
uses: actions-rs/cargo@v1
with:
command: clippy
args: --all --all-targets --all-features -- -D warnings
format_check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
components: rustfmt
override: true
- name: Run format
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/target
/Cargo.lock
12 changes: 12 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "cc_license"
version = "0.1.0"
authors = ["Javier Arias <[email protected]>"]
edition = "2021"
license = "MIT"
description = "Creative Commons license parser"
repository = "https://github.com/thoth-pub/cc-license"
readme = "README.md"

[dependencies]
regex = { version = "1" }
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2032, Open Book Publishers.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
cc_license
=====
A Rust library for parsing Creative Commons license URLs.

[![Build status](https://github.com/thoth-pub/cc-license/workflows/test-and-check/badge.svg)](https://github.com/thoth-pub/cc-license/actions)
[![Crates.io](https://img.shields.io/crates/v/cc_license.svg)](https://crates.io/crates/cc_license)

### Usage

To bring this crate into your repository, either add `cc_license` to your
`Cargo.toml`, or run `cargo add cc_license`.

Here's an example parsing a CC license URL:

```rust
use cc_license::License;

fn main() {
let license = License::from_url("https://creativecommons.org/licenses/by-nc-sa/4.0/")?;

assert_eq!(license.to_string(), "Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International license (CC BY-NC-SA 4.0).".to_string());
assert_eq!(license.rights(), "CC BY-NC-SA".to_string());
assert_eq!(license.rights_full(), "Attribution-NonCommercial-ShareAlike".to_string());
assert_eq!(license.version(), "4.0".to_string());
assert_eq!(license.short(), "CC BY-NC 4.0".to_string());
}
```
33 changes: 33 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use std::error::Error;
use std::fmt;

macro_rules! errors {
($($name: ident => $description: expr,)+) => {
/// Errors that can occur during parsing.
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
pub enum ParseError {
$(
$name,
)+
}

impl fmt::Display for ParseError {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
$(
ParseError::$name => fmt.write_str($description),
)+
}
}
}
}
}

impl Error for ParseError {}

errors! {
InvalidUrl => "Invalid URL",
InvalidRights => "Invalid rights string",
InvalidVersion => "Invalid version string",
InvalidPublicDomainVersion => "The version of CC0 licenses must be 1.0",
}
Loading

0 comments on commit 7006c35

Please sign in to comment.