Sha256: 04aaad37bc271a68b3b3f43761a0a9290c087424d7d5ebbf773486284dea63d5

Contents?: true

Size: 1.9 KB

Versions: 6

Compression:

Stored size: 1.9 KB

Contents

# frozen_string_literal: true

module Bridgetown
  class Site
    require_all "bridgetown-core/concerns/site"

    include Configurable
    include Content
    include Extensible
    include Localizable
    include Processable
    include Renderable
    include SSR
    include Writable

    attr_reader   :root_dir, :source, :dest, :cache_dir, :config,
                  :liquid_renderer, :components_load_paths,
                  :includes_load_paths

    # All files not pages/documents or structured data in the source folder
    # @return [Array<StaticFile>]
    attr_accessor :static_files

    # @return [Array<Layout>]
    attr_accessor :layouts

    # @return [Array<GeneratedPage>]
    attr_accessor :generated_pages

    attr_accessor :permalink_style, :time, :data,
                  :file_read_opts, :plugin_manager, :converters,
                  :generators, :reader

    # Initialize a new Site.
    #
    # config - A Hash containing site configuration details.
    def initialize(config)
      self.config = config
      locale

      @plugin_manager  = PluginManager.new(self)
      @cleaner         = Cleaner.new(self)
      @reader          = Reader.new(self)
      @liquid_renderer = LiquidRenderer.new(self)

      ensure_not_in_dest

      Bridgetown::Current.site = self
      Bridgetown::Hooks.trigger :site, :after_init, self

      reset   # Processable
      setup   # Extensible
    end

    # Check that the destination dir isn't the source dir or a directory
    # parent to the source dir.
    def ensure_not_in_dest
      dest_pathname = Pathname.new(dest)
      Pathname.new(source).ascend do |path|
        if path == dest_pathname
          raise Errors::FatalException,
                "Destination directory cannot be or contain the Source directory."
        end
      end
    end

    def inspect
      "#<Bridgetown::Site #{metadata.inspect.delete_prefix("{").delete_suffix("}")}>"
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
bridgetown-core-1.0.0.alpha6 lib/bridgetown-core/site.rb
bridgetown-core-1.0.0.alpha5 lib/bridgetown-core/site.rb
bridgetown-core-1.0.0.alpha4 lib/bridgetown-core/site.rb
bridgetown-core-1.0.0.alpha3 lib/bridgetown-core/site.rb
bridgetown-core-1.0.0.alpha2 lib/bridgetown-core/site.rb
bridgetown-core-1.0.0.alpha1 lib/bridgetown-core/site.rb