Update garnish and render_doc functions
Now all element node attributes have to be threaded through the eph.attributes which is done by the garnish function.
This commit is contained in:
@ -33,6 +33,11 @@ defmodule Outlook.InternalTree do
|
||||
options,
|
||||
fn prop, opts -> Map.put_new(opts, prop, []) end
|
||||
)
|
||||
options = Enum.reduce(
|
||||
~w(elements tunits)a,
|
||||
options,
|
||||
fn prop, opts -> Map.put_new(opts, prop, %{}) end
|
||||
)
|
||||
InternalTree.garnish(tree, options)
|
||||
end
|
||||
|
||||
|
||||
@ -2,23 +2,13 @@ defmodule Outlook.InternalTree.InternalTree do
|
||||
|
||||
alias Outlook.InternalTree.{InternalNode,TranslationUnit}
|
||||
|
||||
def garnish([%TranslationUnit{} = node | rest], %{tunits: _} = options) do
|
||||
def garnish([%TranslationUnit{} = node | rest], options) do
|
||||
[ set_attributes(node, options.tunits, options.tu_ids)
|
||||
| garnish(rest, options) ]
|
||||
end
|
||||
|
||||
def garnish([%TranslationUnit{} = node | rest], options) do
|
||||
[ node | garnish(rest, options) ]
|
||||
end
|
||||
|
||||
def garnish([%InternalNode{type: :element} = node | rest], %{elements: _} = options) do
|
||||
node = set_attributes(node, options.elements, options.el_ids, options.el_names)
|
||||
[ %InternalNode{node |
|
||||
content: garnish(node.content, options)
|
||||
} | garnish(rest, options) ]
|
||||
end
|
||||
|
||||
def garnish([%InternalNode{type: :element} = node | rest], options) do
|
||||
node = set_attributes(node, options.elements, options.el_ids, options.el_names)
|
||||
[ %InternalNode{node |
|
||||
content: garnish(node.content, options)
|
||||
} | garnish(rest, options) ]
|
||||
@ -56,14 +46,16 @@ defmodule Outlook.InternalTree.InternalTree do
|
||||
end
|
||||
|
||||
defp set_attributes(node, atts) do
|
||||
attributes = Map.get(atts, :atts, %{})
|
||||
attributes = if Map.has_key?(atts, :phx) do
|
||||
# TODO: for all keys in atts.phx create a respective entry
|
||||
Map.put(attributes, "phx-click",atts.phx.click)
|
||||
# TODO: only convert to string if present
|
||||
|> Map.put("phx-target", atts.phx.target |> to_string)
|
||||
|> Map.put("phx-value-nid", node.nid)
|
||||
end
|
||||
node_atts = Map.get(node, :attributes, %{})
|
||||
|> Map.merge(Map.get(node.eph, :attributes, %{}))
|
||||
attributes = Enum.map(atts, fn {k,v} ->
|
||||
nv = case is_function(v) do
|
||||
true -> v.(node)
|
||||
false -> v
|
||||
end
|
||||
{k,nv}
|
||||
end)
|
||||
|> Enum.into(node_atts)
|
||||
%{node | eph: Map.put(node.eph, :attributes, attributes)}
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user