85 lines
2.5 KiB
Elixir
85 lines
2.5 KiB
Elixir
defmodule Outlook.InternalTree do
|
|
|
|
alias Outlook.InternalTree.{Html,Modifiers,RawInternalBasic,InternalTree,Translation,TunitModifications}
|
|
alias Outlook.HtmlPreparations.HtmlPreparation
|
|
alias Outlook.{Hyphenation, Translations}
|
|
|
|
def render_html(tree) do
|
|
tree
|
|
|> HtmlPreparation.strip_whitespace_textnodes()
|
|
|> Html.to_html()
|
|
end
|
|
|
|
require Logger
|
|
def apply_modifier(tree, modifier, nids, opts \\ %{}) do
|
|
# Logger.info modifier
|
|
Modifiers.traverse_tree(tree, modifier, nids, opts)
|
|
end
|
|
|
|
def partition_text(tree) do
|
|
# validate_sibling_collocation(tree)
|
|
tree
|
|
|> RawInternalBasic.set_split_markers()
|
|
|> RawInternalBasic.partition_to_tunits()
|
|
end
|
|
|
|
def add_phx_click_event(tree, opts) do
|
|
phx_opts = %{
|
|
"phx-click": Keyword.get(opts, :click),
|
|
"phx-value-nid": fn n -> n.nid end
|
|
}
|
|
phx_opts = case Keyword.has_key?(opts, :target) do
|
|
true -> Map.put(phx_opts, "phx-target", Keyword.get(opts, :target) |> to_string)
|
|
false -> phx_opts
|
|
end
|
|
options = Map.put(%{}, Keyword.get(opts, :nodes, :elements), phx_opts)
|
|
garnish(tree, options)
|
|
end
|
|
|
|
def garnish(tree, options) do
|
|
options = Enum.reduce(
|
|
~w(el_ids el_names tu_ids)a,
|
|
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
|
|
|
|
def render_translation(tree, translation) do
|
|
Translation.render_translation(tree, translation)
|
|
end
|
|
|
|
def render_public_content(tree, translation, language) do
|
|
Translation.render_translation(tree, translation)
|
|
|> Html.render_doc()
|
|
|> Hyphenation.hyphenate(language)
|
|
end
|
|
|
|
def legacy_export(translation_id) do
|
|
translation = Translations.get_translation!(translation_id)
|
|
content= Translation.render_translation(translation.article.content, translation.content)
|
|
|> garnish(%{tunits: %{class: "ttrans", "data-ttrans-status": fn n -> Map.get(n, :status) end}})
|
|
|> Html.render_doc
|
|
|> Hyphenation.hyphenate(translation.language)
|
|
IO.puts "writing export.html to #{File.cwd!}"
|
|
File.write("export.html", content)
|
|
end
|
|
|
|
def get_tunit_ids(tree) do
|
|
InternalTree.collect_tunit_ids(tree)
|
|
end
|
|
|
|
def modify_tunits(tree, modifier, tu_ids) do
|
|
TunitModifications.apply_modifier(tree, modifier, tu_ids)
|
|
end
|
|
|
|
def tunit_modifiers() do
|
|
TunitModifications.modifiers()
|
|
end
|
|
end
|