Skip to content

Commit 03a099a

Browse files
committed
Initial release
0 parents  commit 03a099a

File tree

18 files changed

+683
-0
lines changed

18 files changed

+683
-0
lines changed

.formatter.exs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Used by "mix format"
2+
[
3+
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
4+
]

.github/workflows/elixir.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Elixir CI
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
jobs:
10+
test:
11+
12+
name: Build and test
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/checkout@v3
17+
- name: Set up Elixir
18+
uses: erlef/setup-beam@988e02bfe678367a02564f65ca2e37726dc0268f
19+
with:
20+
elixir-version: '1.13.4' # Define the elixir version [required]
21+
otp-version: '24.3.4.2' # Define the OTP version [required]
22+
- name: Restore dependencies cache
23+
uses: actions/cache@v3
24+
with:
25+
path: deps
26+
key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }}
27+
restore-keys: ${{ runner.os }}-mix-
28+
- name: Install dependencies
29+
run: mix deps.get
30+
- name: Run tests
31+
run: mix test

.gitignore

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# The directory Mix will write compiled artifacts to.
2+
/_build/
3+
4+
# If you run "mix test --cover", coverage assets end up here.
5+
/cover/
6+
7+
# The directory Mix downloads your dependencies sources to.
8+
/deps/
9+
10+
# Where third-party dependencies like ExDoc output generated docs.
11+
/doc/
12+
13+
# Ignore .fetch files in case you like to edit your project deps locally.
14+
/.fetch
15+
16+
# If the VM crashes, it generates a dump, let's ignore it too.
17+
erl_crash.dump
18+
19+
# Also ignore archive artifacts (built via "mix archive.build").
20+
*.ez
21+
22+
# Ignore package tarball (built via "mix hex.build").
23+
fast_syndication-*.tar
24+
25+
# Temporary files, for example, from tests.
26+
/tmp/

.tool-versions

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
elixir 1.13.4
2+
erlang 24.3.4.2

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [0.1.0] - 2022-08-17
9+
### Added
10+
- Initial release for parsing RSS and Atom feeds

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# FastSyndication
2+
3+
Minimal wrapper around Rust NIFs for fast RSS and Atom feed parsing
4+
5+
## Usage
6+
7+
```elixir
8+
iex(1)> {:ok, map_of_rss} = FastRSS.parse(%{rss_string: "...rss_feed_string..."})
9+
iex(2)> {:ok, map_of_atom} = FastRSS.parse(%{atom_string: "...rss_feed_string..."})
10+
```

lib/fast_syndication.ex

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
defmodule FastSyndication do
2+
defmodule Native do
3+
use Rustler, otp_app: :fast_syndication, crate: "fastsyndication"
4+
5+
def parse_atom(_a), do: :erlang.nif_error(:nif_not_loaded)
6+
def parse_rss(_a), do: :erlang.nif_error(:nif_not_loaded)
7+
end
8+
9+
def parse(""), do: {:error, "Cannot parse blank string"}
10+
11+
def parse(%{atom_string: atom_string}) when is_binary(atom_string) do
12+
atom_string
13+
|> Native.parse_atom()
14+
|> map_to_tuple()
15+
end
16+
17+
def parse(%{rss_string: rss_string}) when is_binary(rss_string) do
18+
rss_string
19+
|> Native.parse_rss()
20+
|> map_to_tuple()
21+
end
22+
23+
def parse(_somethig_else), do: {:error, "RSS feed must be passed in as a string"}
24+
25+
defp map_to_tuple(%{"Ok" => map}), do: {:ok, map}
26+
defp map_to_tuple({:ok, map}), do: {:ok, map}
27+
defp map_to_tuple(%{"Err" => msg}), do: {:error, msg}
28+
defp map_to_tuple({:error, msg}), do: {:error, msg}
29+
end

mix.exs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
defmodule FastSyndication.MixProject do
2+
use Mix.Project
3+
4+
@source_url "https://github.com/mikhailbot/fast_syndication"
5+
@version "0.1.0"
6+
7+
def project do
8+
[
9+
app: :fast_syndication,
10+
version: @version,
11+
elixir: "~> 1.13",
12+
start_permanent: Mix.env() == :prod,
13+
deps: deps(),
14+
15+
# hex
16+
description: "Fast Elixir RSS and Atom feed parser",
17+
package: package()
18+
]
19+
end
20+
21+
# Run "mix help compile.app" to learn about applications.
22+
def application do
23+
[
24+
extra_applications: [:logger]
25+
]
26+
end
27+
28+
# Run "mix help deps" to learn about dependencies.
29+
defp deps do
30+
[
31+
{:rustler, "~> 0.25.0"}
32+
]
33+
end
34+
35+
defp package() do
36+
[
37+
files: [
38+
"lib",
39+
"native/fastsyndication/.cargo",
40+
"native/fastsyndication/src",
41+
"native/fastsyndication/Cargo.toml",
42+
"native/fastsyndication/Cargo.lock",
43+
"mix.exs",
44+
"README.md",
45+
"LICENSE"
46+
],
47+
maintainers: ["Mikhail Delport"],
48+
licenses: ["Apache-2.0"],
49+
links: %{
50+
"Changelog" => "#{@source_url}/blob/master/CHANGELOG.md",
51+
"GitHub" => @source_url
52+
}
53+
]
54+
end
55+
end

mix.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
%{
2+
"jason": {:hex, :jason, "1.3.0", "fa6b82a934feb176263ad2df0dbd91bf633d4a46ebfdffea0c8ae82953714946", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "53fc1f51255390e0ec7e50f9cb41e751c260d065dcba2bf0d08dc51a4002c2ac"},
3+
"rustler": {:hex, :rustler, "0.25.0", "32526b51af7e58a740f61941bf923486ce6415a91c3934cc16c281aa201a2240", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:toml, "~> 0.6", [hex: :toml, repo: "hexpm", optional: false]}], "hexpm", "6b43a11a37fe79c6234d88c4102ab5dfede7a6a764dc5c7b539956cfa02f3cf4"},
4+
"toml": {:hex, :toml, "0.6.2", "38f445df384a17e5d382befe30e3489112a48d3ba4c459e543f748c2f25dd4d1", [:mix], [], "hexpm", "d013e45126d74c0c26a38d31f5e8e9b83ea19fc752470feb9a86071ca5a672fa"},
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[target.'cfg(target_os = "macos")']
2+
rustflags = [
3+
"-C", "link-arg=-undefined",
4+
"-C", "link-arg=dynamic_lookup",
5+
]

0 commit comments

Comments
 (0)