Sha256: 87671683770b6f8a297c3c83c83f1496a132ab0773f6c302f9486c6147165ec7

Contents?: true

Size: 1.72 KB

Versions: 1

Compression:

Stored size: 1.72 KB

Contents

module Schreihals
  class App < Sinatra::Base
    set :views, ['./views/', File.expand_path('../../views/', __FILE__)]
    set :public_folder, File.expand_path('../../public/', __FILE__)

    use Schreihals::Static
    use Rack::ShowExceptions
    use Rack::Cache
    use Rack::Codehighlighter, :coderay, :markdown => true, :element => "pre>code", :pattern => /\A:::(\w+)\s*\n/

    helpers Schreihals::Helpers
    include Schreihals::Actions

    configure do
      set :blog_title, "My Schreihals Blog"
      set :blog_url, ""
      set :blog_description, ""
      set :author_name, "Author"
      set :disqus_name, nil
      set :google_analytics_id, nil
      set :gauges_id, nil
      set :read_more, "Read Complete Article"
      set :documents_store, :filesystem
      set :documents_source, './posts'
      set :documents_cache, nil
      set :twitter_id, nil
      set :footer, ""
    end

    def refresh_documents_now?
      !Post.documents.any?
    end

    def refresh_documents!
      case settings.documents_store
      when :filesystem
        Post.load_from_directory(settings.documents_source)
      # when :dropbox
      #   Post.load_from_dropbox(settings.documents_source)
      else
        raise "Unknown documents store '#{settings.documents_store}'."
      end
    end

    def render_page(slug)
      if @post = Post.with_slug(slug)
        haml :post
      else
        halt 404
      end
    end

    def absolutionize(url)
      if should_absolutionize?(url)
        "#{base_url}#{url}"
      else
        url
      end
    end

    def should_absolutionize?(url)
      url && url[0] == '/'
    end

    def base_url
      "#{env['rack.url_scheme']}://#{env['HTTP_HOST']}"
    end

    not_found do
      haml :"404"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
schreihals-0.0.3 lib/schreihals/app.rb