Class: StaticMatic::Server

### Home Classes Methods

### In Files

- lib/staticmatic/server.rb

### Parent

Object

### Methods

- ::new
- ::start
- #call

### Files

- LICENSE

### Class/Module Index

Quicksearch

- StaticMatic
- StaticMatic::Base
- StaticMatic::BuildMixin
- StaticMatic::Configuration
- StaticMatic::Error
- StaticMatic::Helpers
- StaticMatic::Helpers::AssetsHelper
- StaticMatic::Helpers::CurrentPathHelper
- StaticMatic::Helpers::FormHelper
- StaticMatic::Helpers::RenderHelper
- StaticMatic::Helpers::TagHelper
- StaticMatic::Helpers::UrlHelper
- StaticMatic::HelpersMixin
- StaticMatic::RenderMixin
- StaticMatic::RescueMixin
- StaticMatic::Server
- StaticMatic::ServerMixin
- StaticMatic::SetupMixin
- StaticMatic::TemplateError
- Compass
- Compass::AppIntegration
- Compass::AppIntegration::Staticmatic
- Compass::AppIntegration::Staticmatic::ConfigurationDefaults
- Compass::AppIntegration::Staticmatic::Installer

No matching classes.

# StaticMatic::Server

### Public Class Methods

new(staticmatic, default = nil) click to toggle source

    # File lib/staticmatic/server.rb, line 3
    def initialize(staticmatic, default = nil)
      @files = default || Rack::File.new(staticmatic.site_dir)
      @staticmatic = staticmatic

    end

start(staticmatic) click to toggle source

Starts the StaticMatic preview server

    # File lib/staticmatic/server.rb, line 45
    def self.start(staticmatic)
      [ 'INT', 'TERM' ].each do |signal|
        Signal.trap(signal) do
          puts
          puts "Exiting"
          exit!(0)
        end
      end
      port = staticmatic.configuration.preview_server_port || 3000

      host = staticmatic.configuration.preview_server_host || ""

      app = Rack::Builder.new do
        use Rack::ShowExceptions
        run StaticMatic::Server.new(staticmatic)
      end

      Rack::Handler::WEBrick.run(app, :Port => port, :Host => host)
    end

### Public Instance Methods

call(env) click to toggle source

    # File lib/staticmatic/server.rb, line 10
    def call(env)
      @staticmatic.load_helpers
      path_info = env["PATH_INFO"]

      file_dir, file_name, file_ext = expand_path(path_info)

      # remove stylesheets/ directory if applicable
      file_dir.gsub!(/^\/stylesheets\/?/, "")

      file_dir = CGI::unescape(file_dir)
      file_name = CGI::unescape(file_name)

      unless file_ext && ["html", "css"].include?(file_ext) &&
          @staticmatic.template_exists?(file_name, file_dir) &&
          File.basename(file_name) !~ /^\_/
        return @files.call(env)
      end

      res = Rack::Response.new
      res.header["Content-Type"] = "text/#{file_ext}"

      begin
        if file_ext == "css"
          res.write @staticmatic.generate_css(file_name, file_dir)
        else
          res.write @staticmatic.generate_html_with_layout(file_name, file_dir)
        end
      rescue StaticMatic::Error => e
        res.write e.message
      end

      res.finish
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.