Class: Strelka::CMS::PageFilter::AutoIndex
- Inherits:
-
Strelka::CMS::PageFilter
- Object
- Strelka::CMS::PageFilter
- Strelka::CMS::PageFilter::AutoIndex
- Defined in:
- lib/strelka/cms/pagefilter/autoindex.rb
Overview
Generate an index for any pages matching the specified pattern
with one or more options.
<?autoindex «pattern» [option]+ ?>
Styles are implemented with templates placed in the data/templates/autoindex/ directory.
Examples:
<?autoindex *.page ?>
<?autoindex *.page with default ?>
<?autoindex *.page with dl, sort by date ?>
<?autoindex blog/*.page limit 10 ?>
<?autoindex /*.page ?>
<?autoindex /it/is/*.page ?>
<?autoindex /it/is/*.page with filetree ?>
<?autoindex /it/**/*.page ?>
Constant Summary collapse
- PI =
PI ::= ‘<?’ PITarget (S (Char* - (Char* ‘?>’ Char*)))? ‘?>’
%r{ <\? autoindex # Instruction Target \s+ (\S+) # glob for pages to link [$1] (.*?) # options [$2] \s* \?> }xm
- DEFAULT_STYLE =
Default style template
'default'
- DEFAULT_TEMPLATE_DIR =
Autoindex templates subdirectory
Pathname( 'autoindex' )
- NO_CATALOG_COMMENT =
The comment that’s inserted if the target page doesn’t know what catalog it belongs to.
%Q{<!-- AutoIndex skipped: page doesn't have a catalog -->}
Instance Method Summary collapse
-
#generate_index(pattern, page, catalog, options) ⇒ Object
Create an HTML fragment.
-
#process(source, page) ⇒ Object
Process the given
source
for <?autoindex …
Instance Method Details
#generate_index(pattern, page, catalog, options) ⇒ Object
Create an HTML fragment.
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/strelka/cms/pagefilter/autoindex.rb', line 82 def generate_index( pattern, page, catalog, ) self.log.debug "Generating (%p) autoindex for page = %p in catalog: %p. Options = %p" % [ pattern, page, catalog, ] = self.( ) style = .style || DEFAULT_STYLE pages = if pattern.start_with?( '/' ) self.log.debug " absolute pattern; matching relative to catalog basedir %p" % [ catalog.basedir.to_s ] catalog.matching_pattern( pattern ).to_a else self.log.debug " relative pattern; matching relative to page directory %p" % [ page.path.dirname.to_s ] catalog.relative_to( page.path.dirname ).matching_pattern( pattern ).to_a end pages = self.sort_pages( pages, ) if .sortkey style = style + '.tmpl' unless style =~ /\.tmpl$/ style = DEFAULT_TEMPLATE_DIR + style self.log.debug " generating an HTML index fragment for %d pages under %s" % [ pages.length, pattern ] template = Inversion::Template.load( style ) template.pages = pages template.source_page = page template.catalog = catalog template. = return template.to_s end |
#process(source, page) ⇒ Object
Process the given source
for <?autoindex … ?> processing-instructions
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/strelka/cms/pagefilter/autoindex.rb', line 59 def process( source, page ) self.log.info "Looking for autoindex directives..." if catalog = page.catalog self.log.debug "Processing autoindex directives." source.gsub!( PI ) do |match| self.log.debug " got: %p" % [ match ] # Grab the tag values pattern = $1 = $2 self.log.debug "Generating an index for %p relative to %p." % [ pattern, page.path ] self.generate_index( pattern, page, catalog, ) end return source else self.log.debug "Not generating autoindex sections: no catalog" return source.gsub( PI, NO_CATALOG_COMMENT ) end end |