Sha256: b32f74e7895053573148c7bc2a41e90892079a18513804e0b25ac1a17ef7cac4

Contents?: true

Size: 1.37 KB

Versions: 7

Compression:

Stored size: 1.37 KB

Contents

# -*- encoding: utf-8 -*-

require 'webgen/websiteaccess'
require 'webgen/source'

module Webgen::Source

  # This class is used to provide access to sources provided by resources.
  class Resource

    include Webgen::WebsiteAccess

    # The glob (see File.fnmatch) specifying the resources.
    attr_reader :glob

    # The glob (see File.fnmatch) specifying the paths that should be used from the resources.
    attr_reader :paths_glob

    # The prefix that should optionally be stripped from the paths.
    attr_reader :strip_prefix

    # Create a new resource source for the the +glob+ and use only those paths matching +paths_glob+
    # while stripping +strip_prefix+ off the path.
    def initialize(glob, paths_glob = nil, strip_prefix = nil)
      @glob, @paths_glob, @strip_prefix = glob, paths_glob, strip_prefix
    end

    # Return all paths associated with the resources identified by #glob.
    def paths
      if !defined?(@paths)
        stack = Stacked.new
        website.config['resources'].select {|name, infos| File.fnmatch(@glob, name)}.sort.each do |name, infos|
          stack.add([['/', constant(infos.first).new(*infos[1..-1])]])
        end
        @paths = stack.paths
        @paths = @paths.select {|p| File.fnmatch(@paths_glob, p)} if @paths_glob
        @paths.collect! {|p| p.mount_at('/', @strip_prefix)} if @strip_prefix
      end
      @paths
    end

  end

end

Version data entries

7 entries across 7 versions & 3 rubygems

Version Path
gettalong-webgen-0.5.8.20090507 lib/webgen/source/resource.rb
gettalong-webgen-0.5.9.20090620 lib/webgen/source/resource.rb
gettalong-webgen-0.5.9.20090626 lib/webgen/source/resource.rb
thewoolleyman-webgen-0.5.8.20090419 lib/webgen/source/resource.rb
webgen-0.5.10 lib/webgen/source/resource.rb
webgen-0.5.9 lib/webgen/source/resource.rb
webgen-0.5.8 lib/webgen/source/resource.rb