Sha256: e9148444302d6a6aac953f27f130e665470d156dac67d021053163c7877d7b5c

Contents?: true

Size: 1.55 KB

Versions: 1

Compression:

Stored size: 1.55 KB

Contents

module JekyllAdmin
  class Server < Sinatra::Base
    namespace "/configuration" do
      get do
        json(
          :content     => parsed_configuration,
          :raw_content => raw_configuration
        )
      end

      put do
        write_file(configuration_path, configuration_body)
        json request_payload
      end

      private

      def overrides
        {
          "source" => sanitized_path("/"),
        }
      end

      # Computed configuration, with updates and defaults
      def configuration
        @configuration ||= Jekyll.configuration(overrides)
      end

      # Configuration data, as read by Jekyll
      def parsed_configuration
        configuration.read_config_file(configuration_path)
      end

      # Raw configuration content, as it sits on disk
      def raw_configuration
        File.read(
          configuration_path,
          Jekyll::Utils.merged_file_read_opts(site, {})
        )
      end

      # Returns the path to the *first* config file discovered
      def configuration_path
        sanitized_path configuration.config_files(overrides).first
      end

      # The user's uploaded configuration for updates
      # Instead of extracting `raw_content` directly from the `request_payload`,
      #   assign the data to a new variable and then extract the `raw_content`
      #   from it to circumvent CORS violation in `development` mode.
      def configuration_body
        payload = request_payload
        payload["raw_content"]
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jekyll-admin-0.9.0 lib/jekyll-admin/server/configuration.rb