diff --git a/config/config.exs b/config/config.exs index 25661e48..2c797a1a 100644 --- a/config/config.exs +++ b/config/config.exs @@ -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, diff --git a/lib/philomena/markdown.ex b/lib/philomena/markdown.ex index d25cac8d..fbff2a48 100644 --- a/lib/philomena/markdown.ex +++ b/lib/philomena/markdown.ex @@ -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 diff --git a/lib/philomena/native.ex b/lib/philomena/native.ex new file mode 100644 index 00000000..b5950029 --- /dev/null +++ b/lib/philomena/native.ex @@ -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 diff --git a/native/philomena_markdown/Cargo.lock b/native/philomena/Cargo.lock similarity index 99% rename from native/philomena_markdown/Cargo.lock rename to native/philomena/Cargo.lock index dc8a70b6..f808352d 100644 --- a/native/philomena_markdown/Cargo.lock +++ b/native/philomena/Cargo.lock @@ -429,7 +429,7 @@ dependencies = [ ] [[package]] -name = "philomena_markdown" +name = "philomena" version = "0.3.0" dependencies = [ "comrak", diff --git a/native/philomena_markdown/Cargo.toml b/native/philomena/Cargo.toml similarity index 88% rename from native/philomena_markdown/Cargo.toml rename to native/philomena/Cargo.toml index a0460a7d..2ef3e497 100644 --- a/native/philomena_markdown/Cargo.toml +++ b/native/philomena/Cargo.toml @@ -1,11 +1,11 @@ [package] -name = "philomena_markdown" +name = "philomena" version = "0.3.0" authors = ["Xe ", "Luna ", "Liam White "] edition = "2018" [lib] -name = "philomena_markdown" +name = "philomena" path = "src/lib.rs" crate-type = ["dylib"] diff --git a/native/philomena_markdown/README.md b/native/philomena/README.md similarity index 100% rename from native/philomena_markdown/README.md rename to native/philomena/README.md diff --git a/native/philomena_markdown/src/lib.rs b/native/philomena/src/lib.rs similarity index 72% rename from native/philomena_markdown/src/lib.rs rename to native/philomena/src/lib.rs index e8fdcfab..03bcf8b1 100644 --- a/native/philomena_markdown/src/lib.rs +++ b/native/philomena/src/lib.rs @@ -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) } diff --git a/native/philomena_markdown/.cargo/config b/native/philomena_markdown/.cargo/config deleted file mode 100644 index a125291f..00000000 --- a/native/philomena_markdown/.cargo/config +++ /dev/null @@ -1,5 +0,0 @@ -[target.x86_64-apple-darwin] -rustflags = [ - "-C", "link-arg=-undefined", - "-C", "link-arg=dynamic_lookup", -]