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