Sha256: a6804b0cce1816699500fb0266e640dc5a4ebb2f407f2a9588ce1cbe238dc821

Contents?: true

Size: 1.91 KB

Versions: 15

Compression:

Stored size: 1.91 KB

Contents

module Awestruct

  class PageLoader

    attr_reader :site
    attr_reader :root_dir

    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

    def ignore?(path)
      site.config.ignore.include?( path ) 
    end

    def load_all(prepare=:inline)
      pages = []
      root_dir.find do |path|
        if ( path == root_dir )
          #puts "skip #{path}"
          next
        end
        basename = File.basename( path )
        if ( basename == '.htaccess' )
          #special case
        elsif ( basename =~ /^[_.]/ )
          #puts "skip #{path} and prune"
          Find.prune
          next
        end
        relative_path = path.relative_path_from( root_dir ).to_s
        if ignore?(relative_path)
          #puts "skip ignored #{path} and prune"
          Find.prune
          next
        end
        unless path.directory?
          page = load_page( path, prepare )
          if ( page )
            #puts "loaded! #{path} and added to site"
            #inherit_front_matter( page )
            site.send( @target ) << page
            pages << page
          end
        end
      end
      if ( prepare == :post )
        pages.each{|p| p.prepare!} 
      end
    end

    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

  end

end

Version data entries

15 entries across 15 versions & 2 rubygems

Version Path
awestruct-0.4.5 lib/awestruct/page_loader.rb
awestruct-0.4.4 lib/awestruct/page_loader.rb
awestruct-0.4.3 lib/awestruct/page_loader.rb
awestruct-0.4.2 lib/awestruct/page_loader.rb
awestruct-0.4.2.x10 lib/awestruct/page_loader.rb
awestruct-0.4.2.x9 lib/awestruct/page_loader.rb
awestruct-0.4.2.x8 lib/awestruct/page_loader.rb
awestruct-0.4.2.x7 lib/awestruct/page_loader.rb
awestruct-0.4.2.x6 lib/awestruct/page_loader.rb
awestruct-0.4.2.x5 lib/awestruct/page_loader.rb
awestruct-0.4.2.x4 lib/awestruct/page_loader.rb
awestruct-0.4.2.x3 lib/awestruct/page_loader.rb
awestruct-0.4.2.x2 lib/awestruct/page_loader.rb
awestruct-0.4.2.x1 lib/awestruct/page_loader.rb
awestructx-0.4.1.x1 lib/awestruct/page_loader.rb