lib/utopia/content/links.rb
# Give an index of all links that can be reached from the given path.
Give an index of all links that can be reached from the given path.
Give an index of all links that can be reached from the given path .
def index(path, name: nil, locale: nil, display: :display, sort: :order, sort_default: 0, directories: true, files: true, virtuals: true, indices: false)
				ordered = links(path).ordered.dup
				ignore = []
				ignore << :directory unless directories
				ignore << :file unless files
				ignore << :virtual unless virtuals
				ignore << :index unless indices
				if ignore.any?
					ordered.reject!{|link| ignore.include?(link.kind)}
				end
				if display
					ordered.reject!{|link| link.info[display] == false}
				end
				if name
					ordered.select!{|link| name === link.name}
				end
				if locale
					locales = {}
					ordered.each do |link|
						if link.locale == locale
							locales[link.name] = link
						elsif link.locale == nil
							locales[link.name] ||= link
						end
					end
					ordered = locales.values
				end
				if sort
					ordered.sort_by!{|link| [link[sort] || sort_default, link.title]}
				end
				return ordered
			end
def index ( path , name : nil , locale : nil , display : :display , sort : :order , sort_default : 0 , directories : true , files : true , virtuals : true , indices : false ) ordered = links ( path ) . ordered . dup ignore = [ ] ignore << :directory unless directories ignore << :file unless files ignore << :virtual unless virtuals ignore << :index unless indices if ignore . any? ordered . reject! { | link | ignore . include? ( link . kind ) } end if display ordered . reject! { | link | link . info [ display ] == false } end if name ordered . select! { | link | name === link . name } end if locale locales = { } ordered . each do | link | if link . locale == locale locales [ link . name ] = link elsif link . locale == nil locales [ link . name ] ||= link end end ordered = locales . values end if sort ordered . sort_by! { | link | [ link [ sort ] || sort_default , link . title ] } end return ordered end
Give an index of all links that can be reached from the given path.
Give an index of all links that can be reached from the given path .
# Ignore specific kinds of links: # Filter links by display key: # Filter links by name: # We use pattern === name, which matches either the whole string, or matches a regexp. # Filter by locale: # Order by sort key: # Sort by sort_key, otherwise by title.
path
name
locale
display
sort
sort_default
directories
files
virtuals
indices