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-17.0.4 lib/pageflow/help_entries.rb
pageflow-17.0.3 lib/pageflow/help_entries.rb
pageflow-17.0.2 lib/pageflow/help_entries.rb
pageflow-17.0.1 lib/pageflow/help_entries.rb
pageflow-17.0.0 lib/pageflow/help_entries.rb
pageflow-16.2.0 lib/pageflow/help_entries.rb
pageflow-16.1.0 lib/pageflow/help_entries.rb
pageflow-16.0.0 lib/pageflow/help_entries.rb
pageflow-15.8.0 lib/pageflow/help_entries.rb
pageflow-14.5.2 lib/pageflow/help_entries.rb
pageflow-15.7.1 lib/pageflow/help_entries.rb
pageflow-15.7.0 lib/pageflow/help_entries.rb
pageflow-15.6.1 lib/pageflow/help_entries.rb
pageflow-15.6.0 lib/pageflow/help_entries.rb
pageflow-15.5.0 lib/pageflow/help_entries.rb
pageflow-15.4.0 lib/pageflow/help_entries.rb
pageflow-15.3.0 lib/pageflow/help_entries.rb
pageflow-15.2.2 lib/pageflow/help_entries.rb
pageflow-15.2.1 lib/pageflow/help_entries.rb
pageflow-15.2.0 lib/pageflow/help_entries.rb