From 9e2c13cd900c894af4479b8d7dbb3ac008feb053 Mon Sep 17 00:00:00 2001 From: nelsonic Date: Fri, 18 Aug 2023 03:33:47 +0100 Subject: [PATCH] create initial version of sort for https://github.com/dwyl/mvp/issues/408#issuecomment-1682668331 --- .formatter.exs | 4 + .gitignore | 38 +++++++++ CHANGELOG.md | 3 + README.md | 184 +++++++++++++++++------------------------- analysis_options.yaml | 30 +++++++ coveralls.json | 8 ++ lib/sort.ex | 49 +++++++++++ lib/srt.dart | 34 ++++++++ mix.exs | 72 +++++++++++++++++ mix.lock | 18 +++++ pubspec.yaml | 14 ++++ sort.json | 17 ++++ test/sort_test.dart | 10 +++ test/sort_test.exs | 16 ++++ test/test_helper.exs | 1 + 15 files changed, 388 insertions(+), 110 deletions(-) create mode 100644 .formatter.exs create mode 100644 CHANGELOG.md create mode 100644 analysis_options.yaml create mode 100644 coveralls.json create mode 100644 lib/sort.ex create mode 100644 lib/srt.dart create mode 100644 mix.exs create mode 100644 mix.lock create mode 100644 pubspec.yaml create mode 100644 sort.json create mode 100644 test/sort_test.dart create mode 100644 test/sort_test.exs create mode 100644 test/test_helper.exs diff --git a/.formatter.exs b/.formatter.exs new file mode 100644 index 0000000..d2cda26 --- /dev/null +++ b/.formatter.exs @@ -0,0 +1,4 @@ +# Used by "mix format" +[ + inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"] +] diff --git a/.gitignore b/.gitignore index bfb1212..c6275a8 100644 --- a/.gitignore +++ b/.gitignore @@ -26,4 +26,42 @@ build/Release # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git node_modules +# Mac noise .DS_Store + +# The directory Mix will write compiled artifacts to. +/_build/ + +# If you run "mix test --cover", coverage assets end up here. +/cover/ + +# The directory Mix downloads your dependencies sources to. +/deps/ + +# Where third-party dependencies like ExDoc output generated docs. +/doc/ + +# Ignore .fetch files in case you like to edit your project deps locally. +/.fetch + +# If the VM crashes, it generates a dump, let's ignore it too. +erl_crash.dump + +# Also ignore archive artifacts (built via "mix archive.build"). +*.ez + +# Ignore package tarball (built via "mix hex.build"). +sort-*.tar + +# Temporary files, for example, from tests. +/tmp/ + +# Node for JSONLint +node_modules +# ignore noise +package-lock.json + +# Dart package +.dart_tool/ +pubspec.lock +build diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..effe43c --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,3 @@ +## 1.0.0 + +- Initial version. diff --git a/README.md b/README.md index a6cbf69..da0e8bb 100644 --- a/README.md +++ b/README.md @@ -1,138 +1,102 @@ -# Hapi.js Socket.io Redis Riot.js Chat Example [Work in Progress] +
-This example adds [Riot.js](http://muut.com/riotjs/) to our popular [Hapi.js Socket.io and Redis Publish/Subscribe chat application example](https://github.com/dwyl/hapi-socketio-redis-chat-example), as per issue [#20]( https://github.com/dwyl/hapi-socketio-redis-chat-example/issues/20). +# `sort` -The commits have been added in step-by-step so it should be simple to follow along. Watch this space! +![Elixir Build Status](https://img.shields.io/github/actions/workflow/status/dwyl/sort/elixir.yml?label=Elixir&style=flat-square) +![Dart Build Status](https://img.shields.io/github/actions/workflow/status/dwyl/sort/dart.yml?label=Dart&style=flat-square) +[![codecov.io](https://img.shields.io/codecov/c/github/dwyl/sort/main.svg?style=flat-square)](http://codecov.io/github/dwyl/sort?branch=main) +[![Hex.pm](https://img.shields.io/hexpm/v/sort?color=brightgreen&style=flat-square)](https://hex.pm/packages/sort) +[![pub package](https://img.shields.io/pub/v/sort.svg?color=brightgreen&style=flat-square)](https://pub.dev/packages/sort) +[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat-square)](https://github.com/dwyl/sort#contributing) +[![HitCount](http://hits.dwyl.com/dwyl/sort.svg)](http://hits.dwyl.com/dwyl/sort) -+ [ ] Add links to Riot documentation throughout & encourage pre-reading +
-##Deciding where to add Riot.js +# Why? -We took our [basic chat app example](https://github.com/dwyl/hapi-socketio-redis-chat-example) and decided to add in Riot.js to replace the portion of the code where HTML was being dynamically generated. +We needed a way to manage the `sort` (order) +in our `App` both on the `server` (`Elixir`) and `mobile` (`Flutter`) client. +So we wrote this mini package that works in both languages. -```javascript -//code snipped from client.js -function renderMessage(msg) { - msg = JSON.parse(msg); - var html = "
  • "; - html += "" + getTime(msg.t) + " "; - html += "" + msg.n + ": "; - html += "" + msg.m + ""; - html += "
  • "; - $('#messages').append(html); // append to list - return; -} -``` -
    - -##Add Riot to the app & get it to display simple dummy data - -### 1. [Adds Riot.js 'Hello World'](https://github.com/dwyl/hapi-socketio-redis-riot-chat-example/commit/13742162d8894e49684a6d27dcf1ea65f122180c?diff=split&w=1) -Our first task is to add our [custom riot tag](https://muut.com/riotjs/guide/) into `index.html` and have it display some content (in this case, "Hello World"). This ensures we have Riot set up properly. -+ Add the [Riot CDN](https://muut.com/riotjs/download.html) in a script tag at the bottom of your `index.html` (use the version which includes the _compiler_) -+ Add your custom element (``) to the body of `index.html` -+ Create your `.tag` file (where your _Riot code_ will live, in this case `message.tag`) and link it to `index.html` using a script tag (don't forget to add `type='riot/tag'`) - + `.tag` is a riot file extension with special syntax so you shouldn't worry if your text editor doesn't have syntax highlighting. - + _Note: You **can** call your `.tag` file whatever you like as long as you reference it correctly in `index.html` - we recommend keeping it to the name of your component so the contents of the file are immediately obvious_ -+ Inside your `.tag` file, make sure your 'Hello World' is contained within the custom tags you have added `index.html`. In our case, it should look like this: - -```html - -

    Hello World!

    -
    -``` +# What? +[`sort.json`](https://github.com/dwyl/sort/blob/main/lib/sort.json) +is a maintainable list of sort objects/maps +that anyone can read +to be informed of **`sort`** +used in our App(s). +It makes it easier for us to keep them +in one place +and means +anyone can contribute. -### 2. [Adds dummy array of data & iterates through it with Riot](https://github.com/dwyl/hapi-socketio-redis-riot-chat-example/compare/13742162d8894e49684a6d27dcf1ea65f122180c...9d8d80ab628bd71282a0eaf66ebb343d0358ca0c?diff=split) -We're using Riot to replace dynamically generated HTML so we need to make sure our Riot code can do the same job. We will **create some dummy data and render it with Riot**. -+ Create some dummy data in the form of an array - + This will be in your `` element within `message.tag` and should be contained within `