Rename crate to philomena and change nif mod to Philomena.Native

This commit is contained in:
byte[] 2021-09-12 19:19:31 -04:00
parent 758c306036
commit 1bf7c647a1
8 changed files with 21 additions and 21 deletions

View file

@ -37,8 +37,8 @@ config :philomena, PhilomenaWeb.Endpoint,
pubsub_server: Philomena.PubSub
# Markdown
config :philomena, Philomena.Markdown,
crate: "philomena_markdown",
config :philomena, Philomena.Native,
crate: "philomena",
mode: :release
config :phoenix, :template_engines,

View file

@ -1,11 +1,9 @@
defmodule Philomena.Markdown do
use Rustler, otp_app: :philomena
@markdown_chars ~r/[\*_\[\]\(\)\^`\%\\~<>#\|]/
# When your NIF is loaded, it will override this function.
def to_html(_text), do: :erlang.nif_error(:nif_not_loaded)
def to_html_unsafe(_text), do: :erlang.nif_error(:nif_not_loaded)
def to_html(text), do: Philomena.Native.markdown_to_html(text)
def to_html_unsafe(text), do: Philomena.Native.markdown_to_html_unsafe(text)
def escape_markdown(text) do
@markdown_chars

7
lib/philomena/native.ex Normal file
View file

@ -0,0 +1,7 @@
defmodule Philomena.Native do
use Rustler, otp_app: :philomena
# When your NIF is loaded, it will override this function.
def markdown_to_html(_text), do: :erlang.nif_error(:nif_not_loaded)
def markdown_to_html_unsafe(_text), do: :erlang.nif_error(:nif_not_loaded)
end

View file

@ -429,7 +429,7 @@ dependencies = [
]
[[package]]
name = "philomena_markdown"
name = "philomena"
version = "0.3.0"
dependencies = [
"comrak",

View file

@ -1,11 +1,11 @@
[package]
name = "philomena_markdown"
name = "philomena"
version = "0.3.0"
authors = ["Xe <https://github.com/Xe>", "Luna <https://github.com/Meow>", "Liam White <https://github.com/liamwhite>"]
edition = "2018"
[lib]
name = "philomena_markdown"
name = "philomena"
path = "src/lib.rs"
crate-type = ["dylib"]

View file

@ -1,12 +1,12 @@
use comrak::{markdown_to_html, ComrakOptions};
use comrak::ComrakOptions;
use jemallocator::Jemalloc;
#[global_allocator]
static GLOBAL: Jemalloc = Jemalloc;
rustler::init! {
"Elixir.Philomena.Markdown",
[to_html, to_html_unsafe]
"Elixir.Philomena.Native",
[markdown_to_html, markdown_to_html_unsafe]
}
fn common_options() -> ComrakOptions {
@ -24,17 +24,17 @@ fn common_options() -> ComrakOptions {
}
#[rustler::nif(schedule = "DirtyCpu")]
fn to_html(input: String) -> String {
fn markdown_to_html(input: String) -> String {
let mut options = common_options();
options.render.escape = true;
markdown_to_html(&input, &options)
comrak::markdown_to_html(&input, &options)
}
#[rustler::nif(schedule = "DirtyCpu")]
fn to_html_unsafe(input: String) -> String {
fn markdown_to_html_unsafe(input: String) -> String {
let mut options = common_options();
options.render.unsafe_ = true;
markdown_to_html(&input, &options)
comrak::markdown_to_html(&input, &options)
}

View file

@ -1,5 +0,0 @@
[target.x86_64-apple-darwin]
rustflags = [
"-C", "link-arg=-undefined",
"-C", "link-arg=dynamic_lookup",
]