I have been thinking about this problem, but I can't figure out the steps to build my function:
I have an hiccup like html data as input, this structure is composed by html and custom elements, example:
format: [tag-name options & body]
[:a {} []] ;; simple
[:a {} [[:span {} []]]] ;; nested component
[:other {} []] ;; custom component at tag-name
[:a {} [[:other {} []]]] ;; custom component at body
Every time the structure have a custom element, I should render(replace) it by the html representation that is in the database
, the custom element may be present at tag-name or body:
(def example
[:div {} [[:a {} []]
[:custom {} []]]])
(def database {
:custom [[:a {} []
[:div {} []]})
(def expected-result
[:div {} [[:a {} []]
[:a {} []]
[:div {} []]]])
The problem was: How create a function that takes this data, look for the tag and body of the component, if there's a custom element replace it by the database
element, after the replace it, look at it again, if there's new components do this steps again...
I already have a function(custom-component?) that takes a tag name and returns a boolean if is a custom element:
(custom-component? :a) ;; false
(custom-component? :test) ;; true
Thanks for any help, I'm really stuck on this.