View Source MacrowEx (macrow_ex v0.1.1)

MacrowEx provides DSL for defining rules of text replacing.

examples

Examples

Define your module and write use MacrowEx.

MacrowEx provides rules/2 DSL to define replacement rules.

The second argument is function to replace and must return string.

defmodule MyMacrowEx do
  use MacrowEx

  rules "hoge", fn ->
    "ほげ"
  end

  rules "len", fn array ->
    length(array) |> Integer.to_string()
  end
end

Then apply/1 apply/2 function generates in your module.

MyMacrowEx.apply("${hoge}")
"ほげ"

MyMacrowEx.apply("${hoge} length is ${len}")
"ほげ length is 3"

You can customize default prefix ${ and suffix } as follows.

defmodule MyMacrowEx do
  use MacrowEx

  macro_prefix "{{"
  macro_suffix "}}"

  rules "hoge", fn ->
    "ほげ"
  end
end

MyMacrowEx.apply("{{hoge}}")
"ほげ"

Link to this section Summary

Link to this section Functions

Link to this macro

macro_prefix(prefix)

View Source (macro)
Link to this macro

macro_suffix(suffix)

View Source (macro)
Link to this macro

rules(src, replacer)

View Source (macro)