GithubHelp home page GithubHelp logo

koyo-miyamura / macrow_ex Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 21 KB

MacrowEx provides DSL for defining rules of text replacing. It's inspired by https://github.com/syguer/macrow Ruby gem.

Home Page: https://hexdocs.pm/macrow_ex/MacrowEx.html#content

License: MIT License

Elixir 100.00%

macrow_ex's Introduction

MacrowEx

hex.pm version hex.pm

MacrowEx provides DSL for defining rules of text replacing.

It's inspired by https://github.com/syguer/macrow Ruby gem.

Installation

If available in Hex, the package can be installed by adding macrow_ex to your list of dependencies in mix.exs:

def deps do
  [
    {:macrow_ex, "~> 0.1.1"}
  ]
end

How to use

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}", [1,2,3])
"ほげ 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}}")
"ほげ"

Format

When you do not want to format DSL provided by MacrowEx, try to write in your .formatter.exs as follows.

[
  import_deps: [:macrow_ex]
]

macrow_ex's People

Contributors

koyo-miyamura avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.