From 4c2e6b96ef1a215c542a9cb1abdce5f9fcc5927c Mon Sep 17 00:00:00 2001 From: George Dietrich Date: Thu, 24 Dec 2020 10:16:50 -0500 Subject: [PATCH 01/23] Fix typo (#3) * Fix typo * Add note about strict arg --- src/abstract_negotiator.cr | 2 ++ src/athena-negotiation.cr | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/abstract_negotiator.cr b/src/abstract_negotiator.cr index 6c014e2..dd72401 100644 --- a/src/abstract_negotiator.cr +++ b/src/abstract_negotiator.cr @@ -11,6 +11,8 @@ abstract class Athena::Negotiation::AbstractNegotiator(HeaderType) # Returns the best `HeaderType` type based on the provided *header* value and *priorities*. # + # If *strict* is `true`, an `ANG::Exceptions::Exception` will be raised if the *header* contains an invalid value, otherwise it is ignored. + # # See `Athena::Negotiation` for examples. def best(header : String, priorities : Indexable(String), strict : Bool = false) : HeaderType? raise ArgumentError.new "priorities should not be empty." if priorities.empty? diff --git a/src/athena-negotiation.cr b/src/athena-negotiation.cr index 1b36c62..f760d47 100644 --- a/src/athena-negotiation.cr +++ b/src/athena-negotiation.cr @@ -67,7 +67,7 @@ alias ANG = Athena::Negotiation # accept.coding # => "gzip" # ``` # -# The `ANG::EncodingNegotiator` type returns an `ANG::AcceptEncoding`, or `nil` if negotiating the best character set has failed. +# The `ANG::EncodingNegotiator` type returns an `ANG::AcceptEncoding`, or `nil` if negotiating the best encoding has failed. # # ### Language # @@ -84,7 +84,7 @@ alias ANG = Athena::Negotiation # accept.script # => "hans" # ``` # -# The `ANG::LanguageNegotiator` type returns an `ANG::AcceptLanguage`, or `nil` if negotiating the best character set has failed. +# The `ANG::LanguageNegotiator` type returns an `ANG::AcceptLanguage`, or `nil` if negotiating the best language has failed. module Athena::Negotiation # Returns a lazily initialized `ANG::Negotiator` singleton instance. class_getter(negotiator) { ANG::Negotiator.new } From 9e2579d622cd0036d840f567941693236172943d Mon Sep 17 00:00:00 2001 From: George Dietrich Date: Fri, 29 Jan 2021 22:34:18 -0500 Subject: [PATCH 02/23] Finish porting docs to mkdocs (#4) --- .github/workflows/deployment.yml | 27 --------------------------- README.md | 3 ++- shard.yml | 4 ++-- 3 files changed, 4 insertions(+), 30 deletions(-) delete mode 100644 .github/workflows/deployment.yml diff --git a/.github/workflows/deployment.yml b/.github/workflows/deployment.yml deleted file mode 100644 index 095862e..0000000 --- a/.github/workflows/deployment.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: Deployment - -on: - push: - branches: - - master - -jobs: - deploy_docs: - runs-on: ubuntu-latest - container: - image: crystallang/crystal:latest-alpine - steps: - - name: Install Build Dependencies - run: apk add --update rsync - - uses: actions/checkout@v2 - - name: Install Dependencies - run: shards install - - name: Build - run: crystal docs lib/athena-spec/src/athena-spec.cr src/athena-negotiation.cr - - name: Deploy - uses: JamesIves/github-pages-deploy-action@3.7.1 - with: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - BRANCH: gh-pages - FOLDER: docs - SINGLE_COMMIT: true diff --git a/README.md b/README.md index eb8264a..1f7b4fd 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,8 @@ dependencies: ## Documentation -Everything is documented in the [API Docs](https://athena-framework.github.io/negotiation/Athena/Negotiation.html). +If using the component on its own, checkout the [API documentation](https://athenaframework.org/Negotiation). +If using the component as part of Athena, also checkout the [external documentation](https://athenaframework.org/components/negotiation). ## Contributing diff --git a/shard.yml b/shard.yml index 1f5a48e..63be182 100644 --- a/shard.yml +++ b/shard.yml @@ -1,6 +1,6 @@ name: athena-negotiation -version: 0.1.0 +version: 0.1.1 crystal: '>= 0.35.0' @@ -8,7 +8,7 @@ license: MIT repository: https://github.com/athena-framework/negotiation -documentation: https://athena-framework.github.io/negotiation/Athena/Negotiation.html +documentation: https://athenaframework.org/Negotiation description: | Framework agnostic content negotiation library. From 5fc45d1908ef3fc6428cdef2178d70832dc90379 Mon Sep 17 00:00:00 2001 From: George Dietrich Date: Thu, 4 Feb 2021 21:59:55 -0500 Subject: [PATCH 03/23] Fix some typos in the docs (#5) --- src/abstract_negotiator.cr | 4 ++-- src/accept.cr | 2 +- src/accept_encoding.cr | 4 ++-- src/accept_language.cr | 4 ++-- src/base_accept.cr | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/abstract_negotiator.cr b/src/abstract_negotiator.cr index dd72401..0f67a51 100644 --- a/src/abstract_negotiator.cr +++ b/src/abstract_negotiator.cr @@ -9,7 +9,7 @@ abstract class Athena::Negotiation::AbstractNegotiator(HeaderType) end end - # Returns the best `HeaderType` type based on the provided *header* value and *priorities*. + # Returns the best `HeaderType` based on the provided *header* value and *priorities*. # # If *strict* is `true`, an `ANG::Exceptions::Exception` will be raised if the *header* contains an invalid value, otherwise it is ignored. # @@ -41,7 +41,7 @@ abstract class Athena::Negotiation::AbstractNegotiator(HeaderType) match.nil? ? nil : accepted_priorties[match.index] end - # Returns an array of `HeaderType` types that the provided *header* allows, ordered so that the `#best` match is first. + # Returns an array of `HeaderType` that the provided *header* allows, ordered so that the `#best` match is first. # # ``` # header = "text/*;q=0.3, text/html;q=0.7, text/html;level=1, text/html;level=2;q=0.4, */*;q=0.5" diff --git a/src/accept.cr b/src/accept.cr index 34d85ec..8a4b6df 100644 --- a/src/accept.cr +++ b/src/accept.cr @@ -5,7 +5,7 @@ require "./base_accept" # ``` # accept = ANG::Accept.new "application/json; q = 0.75; charset = UTF-8" # -# accept.header # => "application/json; q = 0.9; charset = UTF-8" +# accept.header # => "application/json; q = 0.75; charset = UTF-8" # accept.normalized_header # => "application/json; charset=UTF-8" # accept.parameters # => {"charset" => "UTF-8"} # accept.quality # => 0.75 diff --git a/src/accept_encoding.cr b/src/accept_encoding.cr index 5157935..138922e 100644 --- a/src/accept_encoding.cr +++ b/src/accept_encoding.cr @@ -5,8 +5,8 @@ require "./base_accept" # ``` # accept = ANG::AcceptEncoding.new "gzip; q = 0.5; key=value" # -# accept.header # => "gzip-1; q = 0.5; key=value" -# accept.normalized_header # => "gzip-1; key=value" +# accept.header # => "gzip; q = 0.5; key=value" +# accept.normalized_header # => "gzip; key=value" # accept.parameters # => {"key" => "value"} # accept.quality # => 0.5 # accept.coding # => "gzip" diff --git a/src/accept_language.cr b/src/accept_language.cr index b4c3115..f0a2ed6 100644 --- a/src/accept_language.cr +++ b/src/accept_language.cr @@ -19,11 +19,11 @@ struct Athena::Negotiation::AcceptLanguage < Athena::Negotiation::BaseAccept getter language : String # Returns the region, if any, for this `AcceptLanguage` header. - # E.x. if the `#language_range` is `zh-Hans-CN`, the language would be `cn` + # E.x. if the `#language_range` is `zh-Hans-CN`, the region would be `cn` getter region : String? = nil # Returns the script, if any, for this `AcceptLanguage` header. - # E.x. if the `#language_range` is `zh-Hans-CN`, the language would be `hans` + # E.x. if the `#language_range` is `zh-Hans-CN`, the script would be `hans` getter script : String? = nil def initialize(value : String) diff --git a/src/base_accept.cr b/src/base_accept.cr index fc9507d..f11d50e 100644 --- a/src/base_accept.cr +++ b/src/base_accept.cr @@ -1,7 +1,7 @@ # Base type for properties/logic all [Accept*](https://tools.ietf.org/html/rfc7231#section-5.3) headers share. abstract struct Athena::Negotiation::BaseAccept # Returns the full unaltered header `self` represents. - # E.x. `text/html` or `unicode-1-1;q=0.8` or `zh-Hans-CN`. + # E.x. `text/html`, `unicode-1-1;q=0.8`, or `zh-Hans-CN`. getter header : String # Returns a normalized version of the `#header`, excluding the `#quality` parameter. From 333abca50dc8f9ebe93b419690d0462d5f3aa2f5 Mon Sep 17 00:00:00 2001 From: syeopite <70992037+syeopite@users.noreply.github.com> Date: Fri, 13 Aug 2021 12:31:50 -0700 Subject: [PATCH 04/23] Use correct version in installation instructions (#6) * Use correct version in installation instructions --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1f7b4fd..5f1726c 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Framework agnostic [content negotiation](https://tools.ietf.org/html/rfc7231#sec dependencies: athena-negotiation: github: athena-framework/negotiation - version: ~> 1.0.0 + version: ~> 0.1.0 ``` 2. Run `shards install` From c15379251a2b7fcd2c18b193b01efc80053147ef Mon Sep 17 00:00:00 2001 From: George Dietrich Date: Sat, 9 Oct 2021 16:32:12 -0400 Subject: [PATCH 05/23] Update CI configuration (#8) * Leverage centralized workflow configuration * Update scheduled run so it executes _after_ nightlies are published --- .github/workflows/athena.yml | 12 +++++++++ .github/workflows/ci.yml | 48 ------------------------------------ 2 files changed, 12 insertions(+), 48 deletions(-) create mode 100644 .github/workflows/athena.yml delete mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/athena.yml b/.github/workflows/athena.yml new file mode 100644 index 0000000..166dd6c --- /dev/null +++ b/.github/workflows/athena.yml @@ -0,0 +1,12 @@ +name: Athena + +on: + pull_request: + branches: + - 'master' + schedule: + - cron: '37 0 * * *' # Nightly at 00:37 + +jobs: + CI: + uses: athena-framework/actions/.github/workflows/ci.yml@master diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index 34c5a4b..0000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,48 +0,0 @@ -name: CI - -on: - pull_request: - branches: - - 'master' - schedule: - - cron: '0 21 * * *' - -jobs: - check_format: - runs-on: ubuntu-latest - container: - image: crystallang/crystal:latest-alpine - steps: - - uses: actions/checkout@v2 - - name: Format - run: crystal tool format --check - coding_standards: - runs-on: ubuntu-latest - container: - image: crystallang/crystal:latest-alpine - steps: - - uses: actions/checkout@v2 - - name: Install Dependencies - run: shards install - - name: Ameba - run: ./bin/ameba - test_latest: - runs-on: ubuntu-latest - container: - image: crystallang/crystal:latest-alpine - steps: - - uses: actions/checkout@v2 - - name: Install Dependencies - run: shards install - - name: Specs - run: crystal spec --order random --error-on-warnings - test_nightly: - runs-on: ubuntu-latest - container: - image: crystallang/crystal:nightly-alpine - steps: - - uses: actions/checkout@v2 - - name: Install Dependencies - run: shards install - - name: Specs - run: crystal spec --order random --error-on-warnings From 3982e1b52345acf7e8baa7b3e8904cc803bfdef7 Mon Sep 17 00:00:00 2001 From: George Dietrich Date: Thu, 16 Dec 2021 19:08:49 -0500 Subject: [PATCH 06/23] Post monorepo cleanup * Revamp CI GHA workflow * Remove CI scripts from components * Normalize READMEs to point back to monorepo --- .github/workflows/athena.yml | 12 ------------ README.md | 12 ++---------- 2 files changed, 2 insertions(+), 22 deletions(-) delete mode 100644 .github/workflows/athena.yml diff --git a/.github/workflows/athena.yml b/.github/workflows/athena.yml deleted file mode 100644 index 166dd6c..0000000 --- a/.github/workflows/athena.yml +++ /dev/null @@ -1,12 +0,0 @@ -name: Athena - -on: - pull_request: - branches: - - 'master' - schedule: - - cron: '37 0 * * *' # Nightly at 00:37 - -jobs: - CI: - uses: athena-framework/actions/.github/workflows/ci.yml@master diff --git a/README.md b/README.md index 5f1726c..80cac21 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Negotiation -[![CI](https://github.com/athena-framework/negotiation/workflows/CI/badge.svg)](https://github.com/athena-framework/negotiation/actions?query=workflow%3ACI) +[![CI](https://github.com/athena-framework/athena/workflows/CI/badge.svg)](https://github.com/athena-framework/athena/actions/workflows/ci.yml) [![Latest release](https://img.shields.io/github/release/athena-framework/negotiation.svg)](https://github.com/athena-framework/negotiation/releases) Framework agnostic [content negotiation](https://tools.ietf.org/html/rfc7231#section-5.3) library based on [willdurand/Negotiation](https://github.com/willdurand/Negotiation). @@ -25,12 +25,4 @@ If using the component as part of Athena, also checkout the [external documentat ## Contributing -1. Fork it (https://github.com/athena-framework/negotiation/fork) -2. Create your feature branch (`git checkout -b my-new-feature`) -3. Commit your changes (`git commit -am 'Add some feature'`) -4. Push to the branch (`git push origin my-new-feature`) -5. Create a new Pull Request - -## Contributors - -- [George Dietrich](https://github.com/blacksmoke16) - creator and maintainer +[Report issues](https://github.com/athena-framework/athena/issues) and send [Pull Requests](https://github.com/athena-framework/athena/pulls) in the [main Athena repository](https://github.com/athena-framework/athena). From 5824495ba74205088841ca9f6b48d7bdfbb1cc36 Mon Sep 17 00:00:00 2001 From: George Dietrich Date: Fri, 7 Jan 2022 19:54:02 -0500 Subject: [PATCH 07/23] Remove extra spaces between paren and method call (#143) --- spec/negotiator_spec.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/negotiator_spec.cr b/spec/negotiator_spec.cr index 2c89e54..e03e01d 100644 --- a/spec/negotiator_spec.cr +++ b/spec/negotiator_spec.cr @@ -47,7 +47,7 @@ struct NegotiatorTest < NegotiatorTestCase expected = expected.should_not be_nil accept_header.media_range.should eq expected[0] - accept_header.parameters.should eq (expected[1] || Hash(String, String).new) + accept_header.parameters.should eq(expected[1] || Hash(String, String).new) end def best_data_provider : Tuple From 24d5ab0287cb5a6c7dcb093a49f06a5c5839675f Mon Sep 17 00:00:00 2001 From: George Dietrich Date: Sat, 19 Mar 2022 11:30:52 -0400 Subject: [PATCH 08/23] Ensure each component has an accurate `VERSION` constant (#166) --- src/athena-negotiation.cr | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/athena-negotiation.cr b/src/athena-negotiation.cr index f760d47..30b8e77 100644 --- a/src/athena-negotiation.cr +++ b/src/athena-negotiation.cr @@ -86,6 +86,8 @@ alias ANG = Athena::Negotiation # # The `ANG::LanguageNegotiator` type returns an `ANG::AcceptLanguage`, or `nil` if negotiating the best language has failed. module Athena::Negotiation + VERSION = "0.1.1" + # Returns a lazily initialized `ANG::Negotiator` singleton instance. class_getter(negotiator) { ANG::Negotiator.new } From 17d5810179ddd1f43ccf85472bc8df9697bfc239 Mon Sep 17 00:00:00 2001 From: George Dietrich Date: Sat, 9 Apr 2022 12:08:06 -0400 Subject: [PATCH 09/23] Bump `ameba` to `~> 1.0` (#169) * Bump `ameba` to `~> 1.0` * Bump min crystal version for all components to `~> 1.4` * Remove now unneeded `ameba:disable` --- shard.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shard.yml b/shard.yml index 63be182..0188067 100644 --- a/shard.yml +++ b/shard.yml @@ -2,7 +2,7 @@ name: athena-negotiation version: 0.1.1 -crystal: '>= 0.35.0' +crystal: ~> 1.4 license: MIT @@ -19,7 +19,7 @@ authors: development_dependencies: ameba: github: crystal-ameba/ameba - version: ~> 0.13.0 + version: ~> 1.0 athena-spec: github: athena-framework/spec version: ~> 0.2.3 From 090b83b5f0a2828c8cbc9a3933808849065c63c3 Mon Sep 17 00:00:00 2001 From: George Dietrich Date: Tue, 26 Apr 2022 20:30:29 -0400 Subject: [PATCH 10/23] `shard.yml` cleanup (#171) * Add `athena-spec` as global dep * All dev will be done in the monorepo, so no reason for each component to have it and ameba as dependencies * Also fix `description` key of `shard.yml` --- shard.yml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/shard.yml b/shard.yml index 0188067..7f10eeb 100644 --- a/shard.yml +++ b/shard.yml @@ -15,11 +15,3 @@ description: | authors: - George Dietrich - -development_dependencies: - ameba: - github: crystal-ameba/ameba - version: ~> 1.0 - athena-spec: - github: athena-framework/spec - version: ~> 0.2.3 From 42c57abcfa2cbb50b3c879e7868cd7b1d91446b2 Mon Sep 17 00:00:00 2001 From: George Dietrich Date: Sat, 30 Apr 2022 13:24:44 -0400 Subject: [PATCH 11/23] `Getting Started` section in API docs (#172) * Shows how to get started with the component either within or outside of the framework itself. --- src/athena-negotiation.cr | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/athena-negotiation.cr b/src/athena-negotiation.cr index 30b8e77..c3a8836 100644 --- a/src/athena-negotiation.cr +++ b/src/athena-negotiation.cr @@ -16,6 +16,22 @@ alias ANG = Athena::Negotiation # The `Athena::Negotiation` component allows an application to support [content negotiation](https://tools.ietf.org/html/rfc7231#section-5.3). # The component has no dependencies and is framework agnostic; supporting various negotiators. # +# ## Getting Started +# +# If using this component within the [Athena Framework][Athena::Framework], it is already installed and required for you. +# Checkout the [manual](/components/negotiation) for some additional information on how to use it within the framework. +# +# If using it outside of the framework, you will first need to add it as a dependency: +# +# ```yaml +# dependencies: +# athena-negotiation: +# github: athena-framework/negotiation +# version: ~> 0.1.0 +# ``` +# +# Then run `shards install`, being sure to require it via `require "athena-negotiation"`. +# # ## Usage # # The main type of `Athena::Negotiation` is `ANG::AbstractNegotiator` which is used to implement negotiators for each `Accept*` header. From 74ef3ff38795205ce5b7bf3bf6c68102770a75d5 Mon Sep 17 00:00:00 2001 From: George Dietrich Date: Sat, 14 May 2022 11:06:11 -0400 Subject: [PATCH 12/23] Bump versions of sub-components & add changelogs (#178) * Bump versions of sub-components * Add changelogs to each sub-component --- CHANGELOG.md | 32 ++++++++++++++++++++++++++++++++ README.md | 1 + shard.yml | 2 +- src/athena-negotiation.cr | 2 +- 4 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..ff96272 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,32 @@ +# Changelog + +## [0.1.2] - 2022-05-14 + +_First release a part of the monorepo._ + +### Added + +- Add `VERSION` constant to `Athena::Negotiation` namespace ([#166](https://github.com/athena-framework/athena/pull/166)) (George Dietrich) +- Add getting started documentation to API docs ([#172](https://github.com/athena-framework/athena/pull/172)) (George Dietrich) + +### Changed + +- Update minimum `crystal` version to `~> 1.4.0` ([#169](https://github.com/athena-framework/athena/pull/169)) (George Dietrich) + +### Fixed + +- Correct the shard version in `README.md` ([#6](https://github.com/athena-framework/negotiation/pull/6)) (syeopite) + +## [0.1.1] - 2021-02-04 + +### Changed + +- Migrate documentation to [MkDocs](https://mkdocstrings.github.io/crystal/) ([#4](https://github.com/athena-framework/negotiation/pull/4)) (George Dietrich) + +## [0.1.0] - 2020-12-24 + +_Initial release._ + +[0.1.2]: https://github.com/athena-framework/negotiation/releases/tag/v0.1.2 +[0.1.1]: https://github.com/athena-framework/negotiation/releases/tag/v0.1.1 +[0.1.0]: https://github.com/athena-framework/negotiation/releases/tag/v0.1.0 diff --git a/README.md b/README.md index 80cac21..6342542 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # Negotiation +[![Common Changelog](https://common-changelog.org/badge.svg)](https://common-changelog.org) [![CI](https://github.com/athena-framework/athena/workflows/CI/badge.svg)](https://github.com/athena-framework/athena/actions/workflows/ci.yml) [![Latest release](https://img.shields.io/github/release/athena-framework/negotiation.svg)](https://github.com/athena-framework/negotiation/releases) diff --git a/shard.yml b/shard.yml index 7f10eeb..3e40894 100644 --- a/shard.yml +++ b/shard.yml @@ -1,6 +1,6 @@ name: athena-negotiation -version: 0.1.1 +version: 0.1.2 crystal: ~> 1.4 diff --git a/src/athena-negotiation.cr b/src/athena-negotiation.cr index c3a8836..22c8690 100644 --- a/src/athena-negotiation.cr +++ b/src/athena-negotiation.cr @@ -102,7 +102,7 @@ alias ANG = Athena::Negotiation # # The `ANG::LanguageNegotiator` type returns an `ANG::AcceptLanguage`, or `nil` if negotiating the best language has failed. module Athena::Negotiation - VERSION = "0.1.1" + VERSION = "0.1.2" # Returns a lazily initialized `ANG::Negotiator` singleton instance. class_getter(negotiator) { ANG::Negotiator.new } From 67d966e702ff752e81794d23f9086beef8ea419f Mon Sep 17 00:00:00 2001 From: George Dietrich Date: Fri, 11 Nov 2022 19:47:27 -0500 Subject: [PATCH 13/23] Fix Typos + Spell Check CI (#222) * Add spellcheck CI job and fix existing typos * Add spec to bug caused by typo --- spec/negotiator_spec.cr | 2 +- src/negotiator.cr | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/spec/negotiator_spec.cr b/spec/negotiator_spec.cr index e03e01d..f267d92 100644 --- a/spec/negotiator_spec.cr +++ b/spec/negotiator_spec.cr @@ -86,7 +86,7 @@ struct NegotiatorTest < NegotiatorTestCase {php_pear_header, {"audio/midi"}, {"audio/midi", nil}}, {"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", {"application/rss+xml"}, {"application/rss+xml", nil}}, - # Case sensitiviy + # Case sensitivity {"text/* ; q=0.3, TEXT/html ;Q=0.7, text/html ; level=1, texT/Html ;leVel = 2 ;q=0.4, */* ; q=0.5", {"text/html; level=2"}, {"text/html", {"level" => "2"}}}, {"text/* ; q=0.3, text/html;Q=0.7, text/html ;level=1, text/html; level=2;q=0.4, */*;q=0.5", {"text/HTML; level=3"}, {"text/html", {"level" => "3"}}}, diff --git a/src/negotiator.cr b/src/negotiator.cr index 18b3042..5ebc3f8 100644 --- a/src/negotiator.cr +++ b/src/negotiator.cr @@ -12,7 +12,7 @@ class Athena::Negotiation::Negotiator < Athena::Negotiation::AbstractNegotiator( accept_sub_type = accept.sub_type priority_sub_type = priority.sub_type - intercection = accept.parameters.each_with_object({} of String => String) do |(k, v), params| + intersection = accept.parameters.each_with_object({} of String => String) do |(k, v), params| priority.parameters.tap do |pp| params[k] = v if pp.has_key?(k) && pp[k] == v end @@ -24,9 +24,9 @@ class Athena::Negotiation::Negotiator < Athena::Negotiation::AbstractNegotiator( if ( (accept_type == "*" || type_equals) && (accept_sub_type == "*" || sub_type_equals) && - intercection.size == accept.parameters.size + intersection.size == accept.parameters.size ) - score = 100 * (type_equals ? 1 : 0) + 10 * (sub_type_equals ? 1 : 0) + intercection.size + score = 100 * (type_equals ? 1 : 0) + 10 * (sub_type_equals ? 1 : 0) + intersection.size return ANG::AcceptMatch.new accept.quality * priority.quality, score, index end @@ -49,9 +49,9 @@ class Athena::Negotiation::Negotiator < Athena::Negotiation::AbstractNegotiator( if ( (accept_sub_type == "*" || priority_sub_type == "*" || sub_type_equals) && (accept_plus == "*" || priority_plus == '*' || plus_equals) && - intercection.size == accept.parameters.size + intersection.size == accept.parameters.size ) - score = 100 * (type_equals ? 1 : 0) + 10 * (sub_type_equals ? 1 : 0) + (plus_equals ? 1 : 0) + intercection.size + score = 100 * (type_equals ? 1 : 0) + 10 * (sub_type_equals ? 1 : 0) + (plus_equals ? 1 : 0) + intersection.size return ANG::AcceptMatch.new accept.quality * priority.quality, score, index end From 132842516088f0937ff82076c2e846ef452218f4 Mon Sep 17 00:00:00 2001 From: George Dietrich Date: Sun, 5 Feb 2023 20:16:41 -0500 Subject: [PATCH 14/23] Doc updates (#261) * Point external docs to new paths for Athena 0.18.0 * Add new typo corrections * Fix `TestWith` annotation docs --- README.md | 2 +- src/athena-negotiation.cr | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6342542..25f56d1 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ dependencies: ## Documentation If using the component on its own, checkout the [API documentation](https://athenaframework.org/Negotiation). -If using the component as part of Athena, also checkout the [external documentation](https://athenaframework.org/components/negotiation). +If using the component as part of Athena, also checkout the [external documentation](https://athenaframework.org/architecture/negotiation). ## Contributing diff --git a/src/athena-negotiation.cr b/src/athena-negotiation.cr index 22c8690..17e1e71 100644 --- a/src/athena-negotiation.cr +++ b/src/athena-negotiation.cr @@ -19,7 +19,7 @@ alias ANG = Athena::Negotiation # ## Getting Started # # If using this component within the [Athena Framework][Athena::Framework], it is already installed and required for you. -# Checkout the [manual](/components/negotiation) for some additional information on how to use it within the framework. +# Checkout the [manual](/architecture/negotiation) for some additional information on how to use it within the framework. # # If using it outside of the framework, you will first need to add it as a dependency: # From 14b5e0589e5d3fdb1264420c62b94653e354a6f8 Mon Sep 17 00:00:00 2001 From: George Dietrich Date: Sat, 18 Feb 2023 12:02:11 -0500 Subject: [PATCH 15/23] Athena Framework `0.18.0` prep (#266) * Bump `config` component * Bump `console` component * Bump `dependency-injection` component * Bump `event-dispatcher` component * Bump `negotation` component * Bump `routing` component * Bump `serializer` component * Bump `spec` component * Bump `validator` component * Update `release.sh` to allow tagging multiple components at once --- CHANGELOG.md | 7 +++++++ shard.yml | 2 +- src/athena-negotiation.cr | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ff96272..15f9f40 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## [0.1.3] - 2023-02-18 + +### Changed + +- Update some links in preparation for Athena Framework `0.18.0` ([#261](https://github.com/athena-framework/athena/pull/261)) (George Dietrich) + ## [0.1.2] - 2022-05-14 _First release a part of the monorepo._ @@ -27,6 +33,7 @@ _First release a part of the monorepo._ _Initial release._ +[0.1.3]: https://github.com/athena-framework/negotiation/releases/tag/v0.1.3 [0.1.2]: https://github.com/athena-framework/negotiation/releases/tag/v0.1.2 [0.1.1]: https://github.com/athena-framework/negotiation/releases/tag/v0.1.1 [0.1.0]: https://github.com/athena-framework/negotiation/releases/tag/v0.1.0 diff --git a/shard.yml b/shard.yml index 3e40894..9f10d15 100644 --- a/shard.yml +++ b/shard.yml @@ -1,6 +1,6 @@ name: athena-negotiation -version: 0.1.2 +version: 0.1.3 crystal: ~> 1.4 diff --git a/src/athena-negotiation.cr b/src/athena-negotiation.cr index 17e1e71..36fafcc 100644 --- a/src/athena-negotiation.cr +++ b/src/athena-negotiation.cr @@ -102,7 +102,7 @@ alias ANG = Athena::Negotiation # # The `ANG::LanguageNegotiator` type returns an `ANG::AcceptLanguage`, or `nil` if negotiating the best language has failed. module Athena::Negotiation - VERSION = "0.1.2" + VERSION = "0.1.3" # Returns a lazily initialized `ANG::Negotiator` singleton instance. class_getter(negotiator) { ANG::Negotiator.new } From 748c63ebd055036f038b34960a7aeb3698e712aa Mon Sep 17 00:00:00 2001 From: George Dietrich Date: Sun, 16 Apr 2023 12:17:31 -0400 Subject: [PATCH 16/23] Upgrade ameba & typos CI (#283) * Bump ameba to `~> 1.4.0` * Bump typos to `1.14.6` --- src/language_negotiator.cr | 2 +- src/negotiator.cr | 22 ++++++++-------------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/language_negotiator.cr b/src/language_negotiator.cr index 4d0304c..e82d1c9 100644 --- a/src/language_negotiator.cr +++ b/src/language_negotiator.cr @@ -12,7 +12,7 @@ class Athena::Negotiation::LanguageNegotiator < Athena::Negotiation::AbstractNeg base_equal = accept_base.downcase == priority_base.downcase sub_equal = accept_sub.try &.downcase == priority_sub.try &.downcase - if ((accept_base == "*" || base_equal) && (accept_sub.nil? || sub_equal)) + if (accept_base == "*" || base_equal) && (accept_sub.nil? || sub_equal) score = 10 * (base_equal ? 1 : 0) + (sub_equal ? 1 : 0) return ANG::AcceptMatch.new accept.quality * priority.quality, score, index diff --git a/src/negotiator.cr b/src/negotiator.cr index 5ebc3f8..53cd001 100644 --- a/src/negotiator.cr +++ b/src/negotiator.cr @@ -21,11 +21,9 @@ class Athena::Negotiation::Negotiator < Athena::Negotiation::AbstractNegotiator( type_equals = accept_type.downcase == priority_type.downcase sub_type_equals = accept_sub_type.downcase == priority_sub_type.downcase - if ( - (accept_type == "*" || type_equals) && - (accept_sub_type == "*" || sub_type_equals) && - intersection.size == accept.parameters.size - ) + if (accept_type == "*" || type_equals) && + (accept_sub_type == "*" || sub_type_equals) && + intersection.size == accept.parameters.size score = 100 * (type_equals ? 1 : 0) + 10 * (sub_type_equals ? 1 : 0) + intersection.size return ANG::AcceptMatch.new accept.quality * priority.quality, score, index @@ -36,21 +34,17 @@ class Athena::Negotiation::Negotiator < Athena::Negotiation::AbstractNegotiator( accept_sub_type, accept_plus = self.split_sub_type accept_sub_type priority_sub_type, priority_plus = self.split_sub_type priority_sub_type - if ( - !(accept_type == "*" || type_equals) || - !(accept_sub_type == "*" || priority_sub_type == "*" || accept_plus == "*" || priority_plus == "*") - ) + if !(accept_type == "*" || type_equals) || + !(accept_sub_type == "*" || priority_sub_type == "*" || accept_plus == "*" || priority_plus == "*") return nil end sub_type_equals = accept_sub_type.downcase == priority_sub_type.downcase plus_equals = accept_plus.downcase == priority_plus.downcase - if ( - (accept_sub_type == "*" || priority_sub_type == "*" || sub_type_equals) && - (accept_plus == "*" || priority_plus == '*' || plus_equals) && - intersection.size == accept.parameters.size - ) + if (accept_sub_type == "*" || priority_sub_type == "*" || sub_type_equals) && + (accept_plus == "*" || priority_plus == '*' || plus_equals) && + intersection.size == accept.parameters.size score = 100 * (type_equals ? 1 : 0) + 10 * (sub_type_equals ? 1 : 0) + (plus_equals ? 1 : 0) + intersection.size return ANG::AcceptMatch.new accept.quality * priority.quality, score, index end From 3f71823d20bc76e2c71718ce842eaef8a234dd2c Mon Sep 17 00:00:00 2001 From: George Dietrich Date: Sat, 7 Oct 2023 11:30:22 -0400 Subject: [PATCH 17/23] Address all mkdocs link warnings (#319) --- src/athena-negotiation.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/athena-negotiation.cr b/src/athena-negotiation.cr index 36fafcc..380eef9 100644 --- a/src/athena-negotiation.cr +++ b/src/athena-negotiation.cr @@ -19,7 +19,7 @@ alias ANG = Athena::Negotiation # ## Getting Started # # If using this component within the [Athena Framework][Athena::Framework], it is already installed and required for you. -# Checkout the [manual](/architecture/negotiation) for some additional information on how to use it within the framework. +# Checkout the [manual](../architecture/negotiation.md) for some additional information on how to use it within the framework. # # If using it outside of the framework, you will first need to add it as a dependency: # From 34510029632d9979dd024b4f1b9d564f69f4bce7 Mon Sep 17 00:00:00 2001 From: George Dietrich Date: Mon, 9 Oct 2023 10:54:50 -0400 Subject: [PATCH 18/23] Create `CONTRIBUTING.md` (#317) --- CONTRIBUTING.md | 3 +++ README.md | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..9bbfb49 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,3 @@ +# Contributing + +This repository is a read-only mirror. Please refer the [main Athena repository](https://github.com/athena-framework/athena/blob/master/CONTRIBUTING.md) on how to start contributing. diff --git a/README.md b/README.md index 25f56d1..51b81a6 100644 --- a/README.md +++ b/README.md @@ -26,4 +26,4 @@ If using the component as part of Athena, also checkout the [external documentat ## Contributing -[Report issues](https://github.com/athena-framework/athena/issues) and send [Pull Requests](https://github.com/athena-framework/athena/pulls) in the [main Athena repository](https://github.com/athena-framework/athena). +Read the general [Contributing Guide](./CONTRIBUTING.md) for information on how to get started. From 80d2019d388b7b81eae590e0e89e546200b1f6a3 Mon Sep 17 00:00:00 2001 From: George Dietrich Date: Mon, 9 Oct 2023 22:06:47 -0400 Subject: [PATCH 19/23] Release Time! (#322) --- CHANGELOG.md | 5 +++++ shard.yml | 2 +- src/athena-negotiation.cr | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 15f9f40..a542e3e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## [0.1.4] - 2023-10-09 + +_Administrative release, no functional changes_ + ## [0.1.3] - 2023-02-18 ### Changed @@ -33,6 +37,7 @@ _First release a part of the monorepo._ _Initial release._ +[0.1.4]: https://github.com/athena-framework/negotiation/releases/tag/v0.1.4 [0.1.3]: https://github.com/athena-framework/negotiation/releases/tag/v0.1.3 [0.1.2]: https://github.com/athena-framework/negotiation/releases/tag/v0.1.2 [0.1.1]: https://github.com/athena-framework/negotiation/releases/tag/v0.1.1 diff --git a/shard.yml b/shard.yml index 9f10d15..1902808 100644 --- a/shard.yml +++ b/shard.yml @@ -1,6 +1,6 @@ name: athena-negotiation -version: 0.1.3 +version: 0.1.4 crystal: ~> 1.4 diff --git a/src/athena-negotiation.cr b/src/athena-negotiation.cr index 380eef9..db3d0da 100644 --- a/src/athena-negotiation.cr +++ b/src/athena-negotiation.cr @@ -102,7 +102,7 @@ alias ANG = Athena::Negotiation # # The `ANG::LanguageNegotiator` type returns an `ANG::AcceptLanguage`, or `nil` if negotiating the best language has failed. module Athena::Negotiation - VERSION = "0.1.3" + VERSION = "0.1.4" # Returns a lazily initialized `ANG::Negotiator` singleton instance. class_getter(negotiator) { ANG::Negotiator.new } From 2b683817c109fb0f1c6a8bac1b84be1a6a8cf457 Mon Sep 17 00:00:00 2001 From: George Dietrich Date: Thu, 21 Mar 2024 23:43:37 -0400 Subject: [PATCH 20/23] Website integration (#365) --- .gitignore | 1 - docs/README.md | 83 +++++++++++++++++++++++++++++++++++++ mkdocs.yml | 31 ++++++++++++++ shard.yml | 2 +- src/athena-negotiation.cr | 87 --------------------------------------- 5 files changed, 115 insertions(+), 89 deletions(-) create mode 100644 docs/README.md create mode 100644 mkdocs.yml diff --git a/.gitignore b/.gitignore index 0bbd4a9..82f1ad5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -/docs/ /lib/ /bin/ /.shards/ diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 0000000..c5ef2b6 --- /dev/null +++ b/docs/README.md @@ -0,0 +1,83 @@ +The `Athena::Negotiation` component allows an application to support [content negotiation](https://tools.ietf.org/html/rfc7231#section-5.3). +The component has no dependencies and is framework agnostic; supporting various negotiators. + +## Installation + +First, install the component by adding the following to your `shard.yml`, then running `shards install`: + +```yaml +dependencies: + athena-negotiation: + github: athena-framework/negotiation + version: ~> 0.1.0 +``` + +## Usage + +The main type of [Athena::Negotiation][] is [ANG::AbstractNegotiator][] which is used to implement negotiators for each `Accept*` header. +`Athena::Negotiation` exposes class level getters for each negotiator; that return a lazily initialized singleton instance. +Each negotiator exposes two methods: [ANG::AbstractNegotiator#best][] and [ANG::AbstractNegotiator#ordered_elements][]. + +### Media Type + +```crystal +negotiator = ANG.negotiator + +accept_header = "text/html, application/xhtml+xml, application/xml;q=0.9" +priorities = ["text/html; charset=UTF-8", "application/json", "application/xml;q=0.5"] + +accept = negotiator.best(accept_header, priorities).not_nil! + +accept.media_range # => "text/html" +accept.parameters # => {"charset" => "UTF-8"} +``` + +The [ANG::Negotiator][] type returns an [ANG::Accept][], or `nil` if negotiating the best media type has failed. + +### Character Set + +```crystal +negotiator = ANG.charset_negotiator + +accept_header = "ISO-8859-1, UTF-8; q=0.9" +priorities = ["iso-8859-1;q=0.3", "utf-8;q=0.9", "utf-16;q=1.0"] + +accept = negotiator.best(accept_header, priorities).not_nil! + +accept.charset # => "utf-8" +accept.quality # => 0.9 +``` + +The [ANG::CharsetNegotiator][] type returns an [ANG::AcceptCharset][], or `nil` if negotiating the best character set has failed. + +### Encoding + +```crystal +negotiator = ANG.encoding_negotiator + +accept_header = "gzip;q=1.0, identity; q=0.5, *;q=0" +priorities = ["gzip", "foo"] + +accept = negotiator.best(accept_header, priorities).not_nil! + +accept.coding # => "gzip" +``` + +The [ANG::EncodingNegotiator][] type returns an [ANG::AcceptEncoding][], or `nil` if negotiating the best encoding has failed. + +### Language + +```crystal +negotiator = ANG.language_negotiator + +accept_header = "en; q=0.1, fr; q=0.4, zh-Hans-CN; q=0.9, de; q=0.2" +priorities = ["de", "zh-Hans-CN", "en"] + +accept = negotiator.best(accept_header, priorities).not_nil! + +accept.language # => "zh" +accept.region # => "cn" +accept.script # => "hans" +``` + +The [ANG::LanguageNegotiator][] type returns an [ANG::AcceptLanguage][], or `nil` if negotiating the best language has failed. diff --git a/mkdocs.yml b/mkdocs.yml new file mode 100644 index 0000000..08ced2d --- /dev/null +++ b/mkdocs.yml @@ -0,0 +1,31 @@ +INHERIT: ../../../mkdocs-common.yml + +site_name: Negotiation +site_url: https://athenaframework.org/Negotiation/ +repo_url: https://github.com/athena-framework/negotiation + +nav: + - Introduction: README.md + - Back to Manual: project://. + - API: + - Aliases: aliases.md + - Top Level: top_level.md + - '*' + +plugins: + - search + - section-index + - literate-nav + - gen-files: + scripts: + - ../../../gen_doc_stubs.py + - mkdocstrings: + default_handler: crystal + custom_templates: ../../../docs/templates + handlers: + crystal: + crystal_docs_flags: + - ./docs/index.cr + - ./lib/athena-negotiation/src/athena-negotiation.cr + source_locations: + lib/athena-negotiation: https://github.com/athena-framework/negotiation/blob/v{shard_version}/{file}#L{line} diff --git a/shard.yml b/shard.yml index 1902808..a69be44 100644 --- a/shard.yml +++ b/shard.yml @@ -14,4 +14,4 @@ description: | Framework agnostic content negotiation library. authors: - - George Dietrich + - George Dietrich diff --git a/src/athena-negotiation.cr b/src/athena-negotiation.cr index db3d0da..b348ef0 100644 --- a/src/athena-negotiation.cr +++ b/src/athena-negotiation.cr @@ -14,93 +14,6 @@ require "./exceptions/*" alias ANG = Athena::Negotiation # The `Athena::Negotiation` component allows an application to support [content negotiation](https://tools.ietf.org/html/rfc7231#section-5.3). -# The component has no dependencies and is framework agnostic; supporting various negotiators. -# -# ## Getting Started -# -# If using this component within the [Athena Framework][Athena::Framework], it is already installed and required for you. -# Checkout the [manual](../architecture/negotiation.md) for some additional information on how to use it within the framework. -# -# If using it outside of the framework, you will first need to add it as a dependency: -# -# ```yaml -# dependencies: -# athena-negotiation: -# github: athena-framework/negotiation -# version: ~> 0.1.0 -# ``` -# -# Then run `shards install`, being sure to require it via `require "athena-negotiation"`. -# -# ## Usage -# -# The main type of `Athena::Negotiation` is `ANG::AbstractNegotiator` which is used to implement negotiators for each `Accept*` header. -# `Athena::Negotiation` exposes class level getters for each negotiator; that return a lazily initialized singleton instance. -# Each negotiator exposes two methods: `ANG::AbstractNegotiator#best` and `ANG::AbstractNegotiator#ordered_elements`. -# -# ### Media Type -# -# ``` -# negotiator = ANG.negotiator -# -# accept_header = "text/html, application/xhtml+xml, application/xml;q=0.9" -# priorities = ["text/html; charset=UTF-8", "application/json", "application/xml;q=0.5"] -# -# accept = negotiator.best(accept_header, priorities).not_nil! -# -# accept.media_range # => "text/html" -# accept.parameters # => {"charset" => "UTF-8"} -# ``` -# -# The `ANG::Negotiator` type returns an `ANG::Accept`, or `nil` if negotiating the best media type has failed. -# -# ### Character Set -# -# ``` -# negotiator = ANG.charset_negotiator -# -# accept_header = "ISO-8859-1, UTF-8; q=0.9" -# priorities = ["iso-8859-1;q=0.3", "utf-8;q=0.9", "utf-16;q=1.0"] -# -# accept = negotiator.best(accept_header, priorities).not_nil! -# -# accept.charset # => "utf-8" -# accept.quality # => 0.9 -# ``` -# -# The `ANG::CharsetNegotiator` type returns an `ANG::AcceptCharset`, or `nil` if negotiating the best character set has failed. -# -# ### Encoding -# -# ``` -# negotiator = ANG.encoding_negotiator -# -# accept_header = "gzip;q=1.0, identity; q=0.5, *;q=0" -# priorities = ["gzip", "foo"] -# -# accept = negotiator.best(accept_header, priorities).not_nil! -# -# accept.coding # => "gzip" -# ``` -# -# The `ANG::EncodingNegotiator` type returns an `ANG::AcceptEncoding`, or `nil` if negotiating the best encoding has failed. -# -# ### Language -# -# ``` -# negotiator = ANG.language_negotiator -# -# accept_header = "en; q=0.1, fr; q=0.4, zh-Hans-CN; q=0.9, de; q=0.2" -# priorities = ["de", "zh-Hans-CN", "en"] -# -# accept = negotiator.best(accept_header, priorities).not_nil! -# -# accept.language # => "zh" -# accept.region # => "cn" -# accept.script # => "hans" -# ``` -# -# The `ANG::LanguageNegotiator` type returns an `ANG::AcceptLanguage`, or `nil` if negotiating the best language has failed. module Athena::Negotiation VERSION = "0.1.4" From f6a843890fce0c7ecaeaa11e35fe5bf91488fe01 Mon Sep 17 00:00:00 2001 From: George Dietrich Date: Tue, 9 Apr 2024 20:10:37 -0400 Subject: [PATCH 21/23] Release time! (#393) --- CHANGELOG.md | 7 +++++++ README.md | 18 ++---------------- shard.yml | 2 +- src/athena-negotiation.cr | 2 +- 4 files changed, 11 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a542e3e..d54ee29 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## [0.1.5] - 2024-04-09 + +### Changed + +- Integrate website into monorepo ([#365](https://github.com/athena-framework/athena/pull/365)) (George Dietrich) + ## [0.1.4] - 2023-10-09 _Administrative release, no functional changes_ @@ -37,6 +43,7 @@ _First release a part of the monorepo._ _Initial release._ +[0.1.5]: https://github.com/athena-framework/negotiation/releases/tag/v0.1.5 [0.1.4]: https://github.com/athena-framework/negotiation/releases/tag/v0.1.4 [0.1.3]: https://github.com/athena-framework/negotiation/releases/tag/v0.1.3 [0.1.2]: https://github.com/athena-framework/negotiation/releases/tag/v0.1.2 diff --git a/README.md b/README.md index 51b81a6..6a1e9e4 100644 --- a/README.md +++ b/README.md @@ -6,23 +6,9 @@ Framework agnostic [content negotiation](https://tools.ietf.org/html/rfc7231#section-5.3) library based on [willdurand/Negotiation](https://github.com/willdurand/Negotiation). -## Installation +## Getting Started -1. Add the dependency to your `shard.yml`: - -```yaml -dependencies: - athena-negotiation: - github: athena-framework/negotiation - version: ~> 0.1.0 -``` - -2. Run `shards install` - -## Documentation - -If using the component on its own, checkout the [API documentation](https://athenaframework.org/Negotiation). -If using the component as part of Athena, also checkout the [external documentation](https://athenaframework.org/architecture/negotiation). +Checkout the [Documentation](https://athenaframework.org/Negotiation). ## Contributing diff --git a/shard.yml b/shard.yml index a69be44..b15ac1f 100644 --- a/shard.yml +++ b/shard.yml @@ -1,6 +1,6 @@ name: athena-negotiation -version: 0.1.4 +version: 0.1.5 crystal: ~> 1.4 diff --git a/src/athena-negotiation.cr b/src/athena-negotiation.cr index b348ef0..12ddf3a 100644 --- a/src/athena-negotiation.cr +++ b/src/athena-negotiation.cr @@ -15,7 +15,7 @@ alias ANG = Athena::Negotiation # The `Athena::Negotiation` component allows an application to support [content negotiation](https://tools.ietf.org/html/rfc7231#section-5.3). module Athena::Negotiation - VERSION = "0.1.4" + VERSION = "0.1.5" # Returns a lazily initialized `ANG::Negotiator` singleton instance. class_getter(negotiator) { ANG::Negotiator.new } From d821e338397adb92e4340b0d3eda325b169d0c9d Mon Sep 17 00:00:00 2001 From: George Dietrich Date: Fri, 24 May 2024 10:12:32 -0400 Subject: [PATCH 22/23] Use `utf-8` as lowercase is preferred (#417) --- docs/README.md | 6 +++--- spec/negotiator_spec.cr | 6 +++--- src/accept.cr | 8 ++++---- src/base_accept.cr | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/docs/README.md b/docs/README.md index c5ef2b6..94b03ef 100644 --- a/docs/README.md +++ b/docs/README.md @@ -24,12 +24,12 @@ Each negotiator exposes two methods: [ANG::AbstractNegotiator#best][] and [ANG:: negotiator = ANG.negotiator accept_header = "text/html, application/xhtml+xml, application/xml;q=0.9" -priorities = ["text/html; charset=UTF-8", "application/json", "application/xml;q=0.5"] +priorities = ["text/html; charset=utf-8", "application/json", "application/xml;q=0.5"] accept = negotiator.best(accept_header, priorities).not_nil! accept.media_range # => "text/html" -accept.parameters # => {"charset" => "UTF-8"} +accept.parameters # => {"charset" => "utf-8"} ``` The [ANG::Negotiator][] type returns an [ANG::Accept][], or `nil` if negotiating the best media type has failed. @@ -39,7 +39,7 @@ The [ANG::Negotiator][] type returns an [ANG::Accept][], or `nil` if negotiating ```crystal negotiator = ANG.charset_negotiator -accept_header = "ISO-8859-1, UTF-8; q=0.9" +accept_header = "ISO-8859-1, utf-8; q=0.9" priorities = ["iso-8859-1;q=0.3", "utf-8;q=0.9", "utf-16;q=1.0"] accept = negotiator.best(accept_header, priorities).not_nil! diff --git a/spec/negotiator_spec.cr b/spec/negotiator_spec.cr index f267d92..353942d 100644 --- a/spec/negotiator_spec.cr +++ b/spec/negotiator_spec.cr @@ -71,9 +71,9 @@ struct NegotiatorTest < NegotiatorTestCase {"image/png, text/plain, audio/ogg", {"baz/asdf"}, nil}, {"image/png, text/plain, audio/ogg", {"audio/ogg"}, {"audio/ogg", nil}}, {"image/png, text/plain, audio/ogg", {"YO/SuP"}, nil}, - {"text/html; charset=UTF-8, application/pdf", {"text/html; charset=UTF-8"}, {"text/html", {"charset" => "UTF-8"}}}, - {"text/html; charset=UTF-8, application/pdf", {"text/html"}, nil}, - {"text/html, application/pdf", {"text/html; charset=UTF-8"}, {"text/html", {"charset" => "UTF-8"}}}, + {"text/html; charset=utf-8, application/pdf", {"text/html; charset=utf-8"}, {"text/html", {"charset" => "utf-8"}}}, + {"text/html; charset=utf-8, application/pdf", {"text/html"}, nil}, + {"text/html, application/pdf", {"text/html; charset=utf-8"}, {"text/html", {"charset" => "utf-8"}}}, # PHP"s PEAR HTTP2 assertions I took from the other lib. {php_pear_header, {"image/gif", "image/png", "application/xhtml+xml", "application/xml", "text/html", "image/jpeg", "text/plain"}, {"image/png", nil}}, diff --git a/src/accept.cr b/src/accept.cr index 8a4b6df..d69e91a 100644 --- a/src/accept.cr +++ b/src/accept.cr @@ -3,11 +3,11 @@ require "./base_accept" # Represents an [Accept](https://tools.ietf.org/html/rfc7231#section-5.3.2) header media type. # # ``` -# accept = ANG::Accept.new "application/json; q = 0.75; charset = UTF-8" +# accept = ANG::Accept.new "application/json; q = 0.75; charset = utf-8" # -# accept.header # => "application/json; q = 0.75; charset = UTF-8" -# accept.normalized_header # => "application/json; charset=UTF-8" -# accept.parameters # => {"charset" => "UTF-8"} +# accept.header # => "application/json; q = 0.75; charset = utf-8" +# accept.normalized_header # => "application/json; charset=utf-8" +# accept.parameters # => {"charset" => "utf-8"} # accept.quality # => 0.75 # accept.type # => "application" # accept.sub_type # => "json" diff --git a/src/base_accept.cr b/src/base_accept.cr index f11d50e..b9e02b8 100644 --- a/src/base_accept.cr +++ b/src/base_accept.cr @@ -10,7 +10,7 @@ abstract struct Athena::Negotiation::BaseAccept getter normalized_header : String # Returns any extension parameters included in the header `self` represents. - # E.x. `charset=UTF-8` or `version=2`. + # E.x. `charset=utf-8` or `version=2`. getter parameters : Hash(String, String) = Hash(String, String).new # Returns the [quality value](https://tools.ietf.org/html/rfc7231#section-5.3.1) of the header `self` represents. From 94cf8e33d9604104334a5b6bc42812a359d3d961 Mon Sep 17 00:00:00 2001 From: George Dietrich Date: Mon, 15 Jul 2024 14:07:30 -0400 Subject: [PATCH 23/23] Bump typos version in CI & address errors (athena-framework/athena#430) --- src/abstract_negotiator.cr | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/abstract_negotiator.cr b/src/abstract_negotiator.cr index 0f67a51..1bddf8c 100644 --- a/src/abstract_negotiator.cr +++ b/src/abstract_negotiator.cr @@ -26,9 +26,9 @@ abstract class Athena::Negotiation::AbstractNegotiator(HeaderType) raise ex if strict end - accepted_priorties = priorities.map { |p| HeaderType.new p } + accepted_priorities = priorities.map { |p| HeaderType.new p } - matches = self.find_matches accepted_headers, accepted_priorties + matches = self.find_matches accepted_headers, accepted_priorities specific_matches = matches.reduce({} of Int32 => ANG::AcceptMatch) do |acc, match| ANG::AcceptMatch.reduce acc, match @@ -38,7 +38,7 @@ abstract class Athena::Negotiation::AbstractNegotiator(HeaderType) match = specific_matches.shift? - match.nil? ? nil : accepted_priorties[match.index] + match.nil? ? nil : accepted_priorities[match.index] end # Returns an array of `HeaderType` that the provided *header* allows, ordered so that the `#best` match is first.