Sha256: 77ce029d498507eb11371d1f964d8e742e435a660f8be73cb07c9697af877028

Contents?: true

Size: 996 Bytes

Versions: 3

Compression:

Stored size: 996 Bytes

Contents

module Stylish
  module Developer
    class Server
      def self.call(env)
        route = Route.request(env)
        status, headers, body = route.respond()

        headers["Content-Length"]                 = Rack::Utils.bytesize(body[0]).to_s
        headers["Access-Control-Allow-Origin"]    = "*"
        headers["Access-Control-Allow-Methods"]   = "GET, POST, PUT"

        [status, headers, body]
      end

      def self.config
        Stylish::Developer.config
      end

      def self.sprockets
        return config.environment if config.environment

        @sprockets_environment ||= Sprockets::Environment.new(library.root).tap do |env|
          library.packages.each do |pkg|
            pkg.root.children.select(&:directory?).each do |dir|
              env.append_path(dir)
            end
          end
        end
      end

      def self.root
        Pathname(config.root || Dir.pwd())
      end

      def self.library
        config.library
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
stylish-0.3.1 lib/stylish/developer/server.rb
stylish-0.3.0 lib/stylish/developer/server.rb
stylish-0.0.2 lib/stylish/developer/server.rb