Closed hasaniskandar closed 1 year ago
Hmm, there is a good reason why I put the line at the top of the file but I can't remember. I'm going to investigate it...
Noted.
There's another problem, which is solved by the PR: When you open the Navigation (of the std provided navbar) the tree isn't rendered hierarchically well (initially)
You'll have to persist the page (each time), before you'll have this rendered right, displayed here:
I am not really sure, if there might be side-effects, as I noticed that anytime all the properties are camelized when they're load from the editor (but not initially when app/views/maglev/editor/show.html.erb
is rendered):
I now used a really dirty workaround in a monkey patch to get these problems sorted out without adding this PR, but in the meantime I'd expect the original proposal from @hasaniskandar might work reliably ...?
def camelcase_relevant_props(obj, props)
case obj
when Array
obj.map { |item| camelcase_relevant_props(item, props) }
when Hash
Hash[obj.map { |key, value|
key_was_sym = key.is_a?(Symbol)
if props.include?(key.to_sym)
camelized_key = key.to_s.camelize(:lower)
[key_was_sym ? camelized_key.to_sym : camelized_key, camelcase_relevant_props(value, props)]
else
[key, camelcase_relevant_props(value, props)]
end
}]
else
obj
end
end
camelize_page_props = %i[parent_id link_label link_id link_type section_id open_new_window alt_text].freeze
json.sections camelcase_relevant_props(services.get_page_sections.call(page: page), camelize_page_props)
thanks a lot @hasaniskandar and also @pgruener for your help!
Fixes #47, fixes #48.