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.
8 9 10 11 12 13 14 15 16 |
# File 'lib/awestruct/page_loader.rb', line 8 def initialize(site, target=:pages) @site = site @target = target @root_dir = site.config.dir if ( @target == :layouts ) @root_dir = site.config.layouts_dir end end |
Instance Attribute Details
#root_dir ⇒ Object (readonly)
Returns the value of attribute root_dir.
6 7 8 |
# File 'lib/awestruct/page_loader.rb', line 6 def root_dir @root_dir end |
#site ⇒ Object (readonly)
Returns the value of attribute site.
5 6 7 |
# File 'lib/awestruct/page_loader.rb', line 5 def site @site end |
Instance Method Details
#ignore?(path) ⇒ Boolean
18 19 20 |
# File 'lib/awestruct/page_loader.rb', line 18 def ignore?(path) site.config.ignore.include?( path ) end |
#load_all(prepare = :inline) ⇒ Object
22 23 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 |
# File 'lib/awestruct/page_loader.rb', line 22 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 && site.config.debug next end basename = File.basename( path ) if ( basename == '.htaccess' ) #special case elsif ( basename =~ /^[_.]/ ) $LOG.debug "skip #{path} and prune" if (site.config.verbose && site.config.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 && site.config.debug Find.prune next end unless path.directory? $LOG.debug "loading #{relative_path}" if site.config.verbose && site.config.debug page = load_page( path, prepare ) if ( page ) next if (page.draft && !(@site.show_drafts || @site.profile == 'development')) $LOG.debug "loaded! #{path} and added to site" if site.config.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
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/awestruct/page_loader.rb', line 61 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 = ::Awestruct::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 |