Sha256: 212ee324de6ac69f4dbd1957a0424e14835a65f3cca67f23990de01611a39db9

Contents?: true

Size: 1 KB

Versions: 1

Compression:

Stored size: 1 KB

Contents

class Guinness::Application

  attr_accessor :settings, :builder

  def initialize(options = {})
    @settings = { output_dir: '../' }.merge options

    app = self
    @builder = Rack::Builder.new do
      use Rack::CommonLogger
      use Rack::ShowStatus      # Nice looking 404s and other messages
      use Rack::ShowExceptions  # Nice looking errors
      run Guinness::Server.new app
    end
  end

  def drink
    Rack::Handler::Thin.run @builder, Port: 9393
  end

  def build
    FileUtils.cd @settings[:root] do
      # collect all files that don't start with '_'
      files = Dir[File.join('**', '*')].reject { |f| f =~ /(^_|\/_)/ }

      files.each do |file|
        path = File.join @settings[:output_dir], file

        if Tilt[path]
          body = Guinness::View.new(file).render
          File.open(path.chomp(File.extname(path)), 'w') { |f| f.write body }
        elsif Dir.exists? file
          FileUtils.mkpath path
        else
          FileUtils.cp file, path
        end
      end
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
guinness-0.0.2 lib/guinness/application.rb