Class: Hoe::ManualGen::PageCatalog

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/hoe/manualgen.rb

Overview

A catalog of Page objects that can be referenced by filters.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sourcedir, layoutsdir) ⇒ PageCatalog

Create a new PageCatalog that will load Page objects for .page files in the specified sourcedir.



290
291
292
293
294
295
296
297
298
299
300
301
# File 'lib/hoe/manualgen.rb', line 290

def initialize( sourcedir, layoutsdir )
	@sourcedir = sourcedir
	@layoutsdir = layoutsdir

	@pages       = []
	@path_index  = {}
	@uri_index   = {}
	@title_index = {}
	@hierarchy   = {}

	self.find_and_load_pages
end

Instance Attribute Details

#hierarchyObject (readonly)

The hierarchy of pages in the catalog, suitable for generating an on-page index



319
320
321
# File 'lib/hoe/manualgen.rb', line 319

def hierarchy
  @hierarchy
end

#layoutsdirObject (readonly)

The Pathname location of look and feel templates.



328
329
330
# File 'lib/hoe/manualgen.rb', line 328

def layoutsdir
  @layoutsdir
end

#pagesObject (readonly)

An Array of all Page objects found



322
323
324
# File 'lib/hoe/manualgen.rb', line 322

def pages
  @pages
end

#path_indexObject (readonly)

An index of the pages in the catalog by Pathname



309
310
311
# File 'lib/hoe/manualgen.rb', line 309

def path_index
  @path_index
end

#sourcedirObject (readonly)

The Pathname location of the .page files.



325
326
327
# File 'lib/hoe/manualgen.rb', line 325

def sourcedir
  @sourcedir
end

#title_indexObject (readonly)

An index of the pages in the catalog by title



312
313
314
# File 'lib/hoe/manualgen.rb', line 312

def title_index
  @title_index
end

#uri_indexObject (readonly)

An index of the pages in the catalog by the URI of their source relative to the source directory



316
317
318
# File 'lib/hoe/manualgen.rb', line 316

def uri_index
  @uri_index
end

Instance Method Details

#traverse_page_hierarchy(from = nil, &builder) ⇒ Object

Traverse the catalog’s #hierarchy, yielding to the given builder block for each entry, as well as each time a sub-hash is entered or exited, setting the type appropriately. Valid values for type are:

:entry, :section, :section_end

If the optional from value is given, it should be the Page object which is considered “current”; if the from object is the same as the hierarchy entry being yielded, it will be yielded with the type set to one of:

:current_entry, :current_section, :current_section_end

each of which correspond to the like-named type from above.

Raises:

  • (LocalJumpError)


345
346
347
348
# File 'lib/hoe/manualgen.rb', line 345

def traverse_page_hierarchy( from=nil, &builder ) # :yields: type, title, path
	raise LocalJumpError, "no block given" unless builder
	self.traverse_hierarchy( Pathname.new(''), self.hierarchy, from, &builder )
end