Sha256: fe0571def720e05dcabe1cba797242417d563712efb1029f65849c4dbc7a0f9d

Contents?: true

Size: 1.48 KB

Versions: 14

Compression:

Stored size: 1.48 KB

Contents

# frozen_string_literal: true

class Bridgetown::Site
  module SSR
    def self.included(base)
      base.extend ClassMethods
    end

    module ClassMethods
      # Establish an SSR pipeline for a persistent backend process
      def start_ssr!(loaders_manager: nil, &block)
        if Bridgetown::Current.site
          raise Bridgetown::Errors::FatalException, "Bridgetown SSR already started! " \
                                                    "Check your Rack app for threading issues"
        end

        site = new(Bridgetown::Current.preloaded_configuration, loaders_manager: loaders_manager)
        site.enable_ssr
        site.ssr_setup(&block)

        site
      end
    end

    def ssr?
      @ssr_enabled == true
    end

    def enable_ssr
      Bridgetown.logger.info "SSR:", "enabled."
      @ssr_enabled = true
    end

    def ssr_setup(&block)
      config.serving = true
      Bridgetown::Hooks.trigger :site, :pre_read, self
      defaults_reader.tap do |d|
        d.path_defaults.clear
        d.read
      end
      reader.read_layouts
      collections.data.tap do |coll|
        coll.read
        self.data = coll.merge_data_resources
      end
      Bridgetown::Hooks.trigger :site, :post_read, self

      block&.call(self) # provide additional setup hook
      return if Bridgetown.env.production?

      Bridgetown::Watcher.watch(self, config, &block)
    end

    def disable_ssr
      Bridgetown.logger.info "SSR:", "now disabled."
      @ssr_enabled = false
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
bridgetown-core-1.3.4 lib/bridgetown-core/concerns/site/ssr.rb
bridgetown-core-1.3.3 lib/bridgetown-core/concerns/site/ssr.rb
bridgetown-core-1.3.2 lib/bridgetown-core/concerns/site/ssr.rb
bridgetown-core-1.3.1 lib/bridgetown-core/concerns/site/ssr.rb
bridgetown-core-1.3.0 lib/bridgetown-core/concerns/site/ssr.rb
bridgetown-core-1.3.0.beta3 lib/bridgetown-core/concerns/site/ssr.rb
bridgetown-core-1.3.0.beta2 lib/bridgetown-core/concerns/site/ssr.rb
bridgetown-core-1.3.0.beta1 lib/bridgetown-core/concerns/site/ssr.rb
bridgetown-core-1.2.0 lib/bridgetown-core/concerns/site/ssr.rb
bridgetown-core-1.2.0.beta5 lib/bridgetown-core/concerns/site/ssr.rb
bridgetown-core-1.2.0.beta4 lib/bridgetown-core/concerns/site/ssr.rb
bridgetown-core-1.2.0.beta3 lib/bridgetown-core/concerns/site/ssr.rb
bridgetown-core-1.2.0.beta2 lib/bridgetown-core/concerns/site/ssr.rb
bridgetown-core-1.2.0.beta1 lib/bridgetown-core/concerns/site/ssr.rb