<commit_before>module Locomotive
  module EditableElementsHelper

    def editable_element_input_options(editable_element, index, options = {})
      {
        label:        editable_element.slug,
        placeholder:  false,
        hint:         editable_element.hint,
        wrapper_html: {
          id:   "#{editable_element.type.to_s.dasherize}-#{index}",
          data: { block: editable_element.block || '' }
        }
      }.merge(options)
    end

    def nice_editable_elements_path
      _path = params[:preview_path] || current_site.localized_page_fullpath(@page, current_content_locale)
      _path = 'index' if _path.blank?

      truncate('/' + _path, length: 50)
    end

    def ordered_editable_elements(editable_elements_by_block)
      list = []
      @editable_elements_by_block.each do |block, editable_elements|
        list += editable_elements.sort { |(page, element)| element.priority || 1 }
      end
      list
    end

    def options_for_page_blocks(editable_elements_by_block)
      options_for_select(
        [[t('.blocks.all'), '']] +
        editable_elements_by_block.keys.map do |name|
          name.nil? ? [t('.blocks.unknown'), '_unknown'] : [name, name]
        end)
    end

  end
end
<commit_msg>order editable elements by their priority inside a block + refresh the editable element views when a page has been updated (bug)<commit_after>module Locomotive
  module EditableElementsHelper

    def editable_element_input_options(editable_element, index, options = {})
      {
        label:        editable_element.slug,
        placeholder:  false,
        hint:         editable_element.hint,
        wrapper_html: {
          id:   "#{editable_element.type.to_s.dasherize}-#{editable_element._id}",
          data: { block: editable_element.block || '' }
        }
      }.merge(options)
    end

    def nice_editable_elements_path
      _path = params[:preview_path] || current_site.localized_page_fullpath(@page, current_content_locale)
      _path = 'index' if _path.blank?

      truncate('/' + _path, length: 50)
    end

    def ordered_editable_elements(editable_elements_by_block)
      list = []
      @editable_elements_by_block.each do |block, editable_elements|
        list += editable_elements.sort { |(_, a), (_, b) | (b.priority || 1) <=> (a.priority || 1) }
      end
      list
    end

    def options_for_page_blocks(editable_elements_by_block)
      options_for_select(
        [[t('.blocks.all'), '']] +
        editable_elements_by_block.keys.map do |name|
          name.nil? ? [t('.blocks.unknown'), '_unknown'] : [name, name]
        end)
    end

  end
end

{'fraction_non_alphanumeric': 0.11009870918754745, 'fraction_numerical': 0.0026575550493545936, 'mean_word_length': 2.7589158345221114, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6713827', 'n_tokens_mistral': 833, 'n_tokens_neox': 820, 'n_words': 160}