Class: Awestruct::PageLoader
- Inherits:
-
Object
- Object
- Awestruct::PageLoader
- Defined in:
- lib/awestruct/page_loader.rb
Instance Attribute Summary collapse
-
#root_dir ⇒ Object
readonly
Returns the value of attribute root_dir.
-
#site ⇒ Object
readonly
Returns the value of attribute site.
Instance Method Summary collapse
- #ignore?(path) ⇒ Boolean
-
#initialize(site, target = :pages) ⇒ PageLoader
constructor
A new instance of PageLoader.
- #load_all(prepare = :inline) ⇒ Object
- #load_page(path, prepare = :inline) ⇒ Object
Constructor Details
#initialize(site, target = :pages) ⇒ PageLoader
Returns a new instance of PageLoader.
10 11 12 13 14 15 16 17 18 |
# File 'lib/awestruct/page_loader.rb', line 10 def initialize(site, target=:pages) @site = site @target = target @root_dir = site.config.dir if ( @target == :layouts ) @root_dir = Pathname.new( File.join( root_dir, '_layouts/' ) ) end end |
Instance Attribute Details
#root_dir ⇒ Object (readonly)
Returns the value of attribute root_dir.
8 9 10 |
# File 'lib/awestruct/page_loader.rb', line 8 def root_dir @root_dir end |
#site ⇒ Object (readonly)
Returns the value of attribute site.
7 8 9 |
# File 'lib/awestruct/page_loader.rb', line 7 def site @site end |
Instance Method Details
#ignore?(path) ⇒ Boolean
20 21 22 |
# File 'lib/awestruct/page_loader.rb', line 20 def ignore?(path) site.config.ignore.include?( path ) end |
#load_all(prepare = :inline) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/awestruct/page_loader.rb', line 24 def load_all(prepare=:inline) raise "No such dir #{root_dir}" unless File.directory?(root_dir) pages = [] root_dir.find do |path| if ( path == root_dir ) $LOG.debug "skip #{path}" if (site.config.verbose) if $LOG.debug? next end basename = File.basename( path ) if ( basename == '.htaccess' ) #special case elsif ( basename =~ /^[_.]/ ) $LOG.debug "skip #{path} and prune" if (site.config.verbose) if $LOG.debug? Find.prune next end relative_path = path.relative_path_from( root_dir ).to_s if ignore?(relative_path) $LOG.debug "skip ignored #{path} and prune" if (site.config.verbose) if $LOG.debug? Find.prune next end unless path.directory? $LOG.debug "loading #{relative_path}" if (site.config.verbose) if $LOG.debug? page = load_page( path, prepare ) if ( page && !page.draft ) $LOG.debug "loaded! #{path} and added to site" if $LOG.debug? #inherit_front_matter( page ) site.send( @target ) << page pages << page end end end if ( prepare == :post ) pages.each{|p| p.prepare!} end end |
#load_page(path, prepare = :inline) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/awestruct/page_loader.rb', line 62 def load_page(path,prepare=:inline) pathname = case( path ) when Pathname then pathname = path else pathname = Pathname.new( path ) end chain = site.engine.pipeline.handler_chains[ path ] return nil if chain.nil? handler = chain.create(site, Pathname.new(path)) p = Page.new( site, handler ) if ( @target == :layouts ) p.__is_layout = true else p.__is_layout = false end p.track_dependencies! if prepare == :inline p.prepare! end p end |