mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-23 20:18:00 +01:00
Rename crate to philomena and change nif mod to Philomena.Native
This commit is contained in:
parent
758c306036
commit
1bf7c647a1
8 changed files with 21 additions and 21 deletions
|
@ -37,8 +37,8 @@ config :philomena, PhilomenaWeb.Endpoint,
|
||||||
pubsub_server: Philomena.PubSub
|
pubsub_server: Philomena.PubSub
|
||||||
|
|
||||||
# Markdown
|
# Markdown
|
||||||
config :philomena, Philomena.Markdown,
|
config :philomena, Philomena.Native,
|
||||||
crate: "philomena_markdown",
|
crate: "philomena",
|
||||||
mode: :release
|
mode: :release
|
||||||
|
|
||||||
config :phoenix, :template_engines,
|
config :phoenix, :template_engines,
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
defmodule Philomena.Markdown do
|
defmodule Philomena.Markdown do
|
||||||
use Rustler, otp_app: :philomena
|
|
||||||
|
|
||||||
@markdown_chars ~r/[\*_\[\]\(\)\^`\%\\~<>#\|]/
|
@markdown_chars ~r/[\*_\[\]\(\)\^`\%\\~<>#\|]/
|
||||||
|
|
||||||
# When your NIF is loaded, it will override this function.
|
# When your NIF is loaded, it will override this function.
|
||||||
def to_html(_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: :erlang.nif_error(:nif_not_loaded)
|
def to_html_unsafe(text), do: Philomena.Native.markdown_to_html_unsafe(text)
|
||||||
|
|
||||||
def escape_markdown(text) do
|
def escape_markdown(text) do
|
||||||
@markdown_chars
|
@markdown_chars
|
||||||
|
|
7
lib/philomena/native.ex
Normal file
7
lib/philomena/native.ex
Normal 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
|
|
@ -429,7 +429,7 @@ dependencies = [
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "philomena_markdown"
|
name = "philomena"
|
||||||
version = "0.3.0"
|
version = "0.3.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"comrak",
|
"comrak",
|
|
@ -1,11 +1,11 @@
|
||||||
[package]
|
[package]
|
||||||
name = "philomena_markdown"
|
name = "philomena"
|
||||||
version = "0.3.0"
|
version = "0.3.0"
|
||||||
authors = ["Xe <https://github.com/Xe>", "Luna <https://github.com/Meow>", "Liam White <https://github.com/liamwhite>"]
|
authors = ["Xe <https://github.com/Xe>", "Luna <https://github.com/Meow>", "Liam White <https://github.com/liamwhite>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
name = "philomena_markdown"
|
name = "philomena"
|
||||||
path = "src/lib.rs"
|
path = "src/lib.rs"
|
||||||
crate-type = ["dylib"]
|
crate-type = ["dylib"]
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
use comrak::{markdown_to_html, ComrakOptions};
|
use comrak::ComrakOptions;
|
||||||
use jemallocator::Jemalloc;
|
use jemallocator::Jemalloc;
|
||||||
|
|
||||||
#[global_allocator]
|
#[global_allocator]
|
||||||
static GLOBAL: Jemalloc = Jemalloc;
|
static GLOBAL: Jemalloc = Jemalloc;
|
||||||
|
|
||||||
rustler::init! {
|
rustler::init! {
|
||||||
"Elixir.Philomena.Markdown",
|
"Elixir.Philomena.Native",
|
||||||
[to_html, to_html_unsafe]
|
[markdown_to_html, markdown_to_html_unsafe]
|
||||||
}
|
}
|
||||||
|
|
||||||
fn common_options() -> ComrakOptions {
|
fn common_options() -> ComrakOptions {
|
||||||
|
@ -24,17 +24,17 @@ fn common_options() -> ComrakOptions {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rustler::nif(schedule = "DirtyCpu")]
|
#[rustler::nif(schedule = "DirtyCpu")]
|
||||||
fn to_html(input: String) -> String {
|
fn markdown_to_html(input: String) -> String {
|
||||||
let mut options = common_options();
|
let mut options = common_options();
|
||||||
options.render.escape = true;
|
options.render.escape = true;
|
||||||
|
|
||||||
markdown_to_html(&input, &options)
|
comrak::markdown_to_html(&input, &options)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rustler::nif(schedule = "DirtyCpu")]
|
#[rustler::nif(schedule = "DirtyCpu")]
|
||||||
fn to_html_unsafe(input: String) -> String {
|
fn markdown_to_html_unsafe(input: String) -> String {
|
||||||
let mut options = common_options();
|
let mut options = common_options();
|
||||||
options.render.unsafe_ = true;
|
options.render.unsafe_ = true;
|
||||||
|
|
||||||
markdown_to_html(&input, &options)
|
comrak::markdown_to_html(&input, &options)
|
||||||
}
|
}
|
|
@ -1,5 +0,0 @@
|
||||||
[target.x86_64-apple-darwin]
|
|
||||||
rustflags = [
|
|
||||||
"-C", "link-arg=-undefined",
|
|
||||||
"-C", "link-arg=dynamic_lookup",
|
|
||||||
]
|
|
Loading…
Reference in a new issue