zf

zenflows testing
git clone https://s.sonu.ch/~srfsh/zf.git
Log | Files | Refs | Submodules | README | LICENSE

emitter.ex (851B)


      1 defmodule EarmarkParser.Ast.Emitter do
      2   @moduledoc false
      3 
      4   def emit(tag, content \\ [], atts \\ [], meta \\ %{})
      5   def emit(tag, content, atts, meta) when is_binary(content) or is_tuple(content) do
      6     {tag, _to_atts(atts), [content], meta}
      7   end
      8   def emit(tag, content, atts, meta) do
      9     {tag, _to_atts(atts), content, meta}
     10   end
     11 
     12 
     13   defp _to_atts(atts)
     14   defp _to_atts(nil), do: []
     15   defp _to_atts(atts) when is_map(atts) do
     16     atts
     17     |> Enum.into([])
     18     |> Enum.map(fn {name, value} -> {to_string(name), _to_string(value)} end)
     19   end
     20   defp _to_atts(atts) do
     21     atts
     22     |> Enum.map(fn {name, value} -> {to_string(name), _to_string(value)} end)
     23   end
     24 
     25   defp _to_string(value)
     26   defp _to_string(value) when is_list(value), do: Enum.join(value, " ")
     27   defp _to_string(value), do: to_string(value)
     28 end
     29 # SPDX-License-Identifier: Apache-2.0