Sha256: 6793bcaafbc2ffc95202926fb926b129c77c6c534bd21aec3845c05abf619916

Contents?: true

Size: 1.35 KB

Versions: 102

Compression:

Stored size: 1.35 KB

Contents

module Pageflow
  class HelpEntries
    include Enumerable

    def initialize
      @help_entries = []
      @help_entries_by_name = {}
    end

    # Add a section to the help dialog displayed in the editor.
    #
    # Translation keys for the help entry are derived from its name by
    # appending ".menu_item" and ".text". Text is parsed as markdown.
    #
    # @param [String] name  Translation key prefix
    # @param [Hash] options
    # @option options [String] :parent  Name of the parent help entry
    # @option options [Fixnum] :priority (10) Entries with higher
    #          priority come first in the entry list.
    def register(name, options = {})
      help_entry = HelpEntry.new(name, options)
      @help_entries_by_name[name] = help_entry

      collection = find_collection(options[:parent])

      collection << help_entry
      collection.sort_by! { |help_entry| -help_entry.priority }
    end

    # @api private
    def flat
      map do |help_entry|
        [help_entry, help_entry.children]
      end.flatten
    end

    def each(&block)
      @help_entries.each(&block)
    end

    private

    def find_collection(name)
      if name
        parent = @help_entries_by_name.fetch(name) do
          throw "Help entry with name #{name} not found."
        end

        parent.children
      else
        @help_entries
      end
    end
  end
end

Version data entries

102 entries across 102 versions & 1 rubygems

Version Path
pageflow-15.0.0.beta2 lib/pageflow/help_entries.rb
pageflow-15.0.0.beta1 lib/pageflow/help_entries.rb
pageflow-14.3.0 lib/pageflow/help_entries.rb
pageflow-14.2.1 lib/pageflow/help_entries.rb
pageflow-14.2.0 lib/pageflow/help_entries.rb
pageflow-14.1.1 lib/pageflow/help_entries.rb
pageflow-14.1.0 lib/pageflow/help_entries.rb
pageflow-14.0.0 lib/pageflow/help_entries.rb
pageflow-14.0.0.rc2 lib/pageflow/help_entries.rb
pageflow-14.0.0.rc1 lib/pageflow/help_entries.rb
pageflow-14.0.0.beta3 lib/pageflow/help_entries.rb
pageflow-14.0.0.beta2 lib/pageflow/help_entries.rb
pageflow-14.0.0.beta1 lib/pageflow/help_entries.rb
pageflow-13.6.0 lib/pageflow/help_entries.rb
pageflow-13.5.0 lib/pageflow/help_entries.rb
pageflow-13.4.0 lib/pageflow/help_entries.rb
pageflow-13.3.0 lib/pageflow/help_entries.rb
pageflow-13.2.0 lib/pageflow/help_entries.rb
pageflow-12.6.0 lib/pageflow/help_entries.rb
pageflow-13.1.0 lib/pageflow/help_entries.rb