Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

sort of upgraded to Sinatra 0.9

  • Loading branch information...
commit 12f8c96a873a778359b3c53f7b58977b46a24212 1 parent d8510a5
@bomberstudios authored
View
2  Rakefile
@@ -19,7 +19,7 @@ task :test do
end
task :install do
- sh("sudo gem install rack rdiscount haml builder feedvalidator validatable english mongrel daemons")
+ sh("sudo gem install rack rdiscount haml builder feedvalidator validatable english daemons")
sh("git submodule init")
sh("git submodule update")
end
View
72 bliki.rb
@@ -1,7 +1,8 @@
-require "rubygems"
-require "lib/sinatra/lib/sinatra"
-require "lib/sinatra-cache/lib/cache"
+require 'rubygems'
+require 'sinatra'
require "lib/stone/lib/stone"
+require 'sass'
+
require "rdiscount"
Dir["lib/*.rb"].each do |f|
require f
@@ -14,17 +15,17 @@
#####################################################################################
# Setup
def stone_start
- Stone.start(Dir.pwd + "/db/#{Sinatra.env.to_s}", Dir.glob(File.join(Dir.pwd,"models/*")))
+ Stone.start(Dir.pwd + "/db/#{Sinatra::Application.environment.to_s}", Dir.glob(File.join(Dir.pwd,"models/*")))
end
def load_config
YAML::load(File.exist?('config.yml') ? File.read('config.yml') : File.read('config.sample.yml')).to_hash.each do |k,v|
set k, v
end
- theme = Sinatra.options.theme || "default"
+ theme = Sinatra::Application.theme || "default"
set :views, "themes/#{theme}"
end
def set_options_for env
- Sinatra.options.send(env).each do |k,v|
+ Sinatra::Application.send(env).each do |k,v|
set k, v
end
end
@@ -72,8 +73,20 @@ def set_options_for env
# Atom Feed
get '/feed/' do
content_type 'application/atom+xml', :charset => "utf-8"
- @posts = Post.all(:order => {:updated_at => :desc}).first(Sinatra.options.limit)
- cache(builder(:feed))
+ @posts = Post.all(:order => {:updated_at => :desc}).first(Sinatra::Application.limit)
+ builder(:feed)
+end
+
+
+#####################################################################################
+# CSS
+get '/base.css' do
+ sass(:base)
+end
+
+# Theme support
+get '/:type/:filename.:ext' do
+ send_file "themes/#{Sinatra::Application.theme}/#{params[:type]}/#{params[:filename]}.#{params[:ext]}", :disposition => "inline"
end
@@ -81,23 +94,23 @@ def set_options_for env
# Blog: Home
get '/' do
all_posts = Post.all(:order => {:created_at => :desc})
- @posts = all_posts.first(Sinatra.options.limit)
- if all_posts.size > Sinatra.options.limit
- @archives = all_posts[(Sinatra.options.limit)...Sinatra.options.limit*2]
+ @posts = all_posts.first(Sinatra::Application.limit)
+ if all_posts.size > Sinatra::Application.limit
+ @archives = all_posts[(Sinatra::Application.limit)...Sinatra::Application.limit*2]
end
- cache(erb(:home))
+ erb(:home)
end
# Blog: New Post
get '/new' do
- auth
+ #auth
erb(:edit)
end
post '/new' do
auth
post = Post.new(params)
- expire_cache "/"
- expire_cache "/feed/"
+ # expire_cache "/"
+ # expire_cache "/feed/"
# Ping
pingomatic
redirect "/"
@@ -107,7 +120,7 @@ def set_options_for env
['/:year/:month/:day/:slug/','/post/:slug'].each do |route|
get route do
@post = Post.first :nicetitle => params[:slug]
- cache(erb(:view))
+ erb(:view)
end
end
@@ -121,9 +134,9 @@ def set_options_for env
auth
post = Post[params[:id]]
post.update_attributes(params)
- expire_cache "/"
- expire_cache "/feed/"
- expire_cache post.link
+ # expire_cache "/"
+ # expire_cache "/feed/"
+ # expire_cache post.link
redirect post.link
end
@@ -137,7 +150,7 @@ def set_options_for env
if @post.nil?
redirect "/#{params[:slug]}/new"
else
- cache(erb(:view))
+ erb(:view)
end
end
end
@@ -163,7 +176,7 @@ def set_options_for env
auth
post = Page[params[:id]]
post.update_attributes(params)
- expire_cache post.link
+ # expire_cache post.link
redirect post.link
end
@@ -173,21 +186,10 @@ def set_options_for env
get '/tag/:name' do
@tag = params[:name]
all_posts = (Post.all :tags.includes => @tag,:order => {:created_at => :desc}) + (Page.all :tags.includes => @tag,:order => {:created_at => :desc})
- @posts = all_posts.first(Sinatra.options.limit)
- if all_posts.size > Sinatra.options.limit
- @archives = all_posts[(Sinatra.options.limit)...all_posts.size]
+ @posts = all_posts.first(Sinatra::Application.limit)
+ if all_posts.size > Sinatra::Application.limit
+ @archives = all_posts[(Sinatra::Application.limit)...all_posts.size]
end
erb(:archive)
end
-
-#####################################################################################
-# CSS
-get '/base.css' do
- cache(sass(:base))
-end
-
-# Theme support
-get '/:type/:filename.:ext' do
- send_file "themes/#{Sinatra.options.theme}/#{params[:type]}/#{params[:filename]}.#{params[:ext]}", :disposition => "inline"
-end
View
2  config.ru
@@ -1,7 +1,7 @@
ENV['GEM_PATH'] = ENV['HOME'] + '/.gems'
require 'rubygems'
-require 'lib/sinatra/lib/sinatra'
+require 'sinatra'
Sinatra::Application.default_options.merge!(
:run => false,
View
12 lib/auth.rb
@@ -41,7 +41,7 @@ def decode_credentials
def authentication_request(realm)
status(401)
- header("WWW-Authenticate" => %(Basic realm="#{realm.gsub(/"/, "")}"))
+ headers("WWW-Authenticate" => %(Basic realm="#{realm.gsub(/"/, "")}"))
throw :halt, "HTTP Basic: Access denied.\n"
end
@@ -49,12 +49,16 @@ def authentication_request(realm)
end
module Sinatra
- class EventContext
+ module Authorization
include HttpAuthentication::Basic
def auth
authenticate_or_request_with_http_basic do |user_name, password|
- user_name == Sinatra.options.username && Digest::SHA1.hexdigest(password) == Sinatra.options.password
- end if Sinatra.options.use_auth
+ user_name == Sinatra::Application.username && Digest::SHA1.hexdigest(password) == Sinatra::Application.password
+ end if Sinatra::Application.use_auth
end
end
+end
+
+helpers do
+ include Sinatra::Authorization
end
View
12 lib/helpers.rb
@@ -12,12 +12,12 @@ def tag_list tags, where=""
end
def pingomatic
begin
- return if Sinatra.options.ping == false
+ return if Sinatra::Application.ping == false
require "erb"
require "net/http"
- blog_name = ERB::Util.url_encode(Sinatra.options.name)
- url = ERB::Util.url_encode(Sinatra.options.base_url)
- feed_url = ERB::Util.url_encode(Sinatra.options.base_url + "/feed/")
+ blog_name = ERB::Util.url_encode(Sinatra::Application.name)
+ url = ERB::Util.url_encode(Sinatra::Application.base_url)
+ feed_url = ERB::Util.url_encode(Sinatra::Application.base_url + "/feed/")
ping_url = "http://pingomatic.com/ping/?title=#{blog_name}&blogurl=#{url}&rssurl=#{feed_url}&chk_weblogscom=on&chk_blogs=on&chk_technorati=on&chk_feedburner=on&chk_syndic8=on&chk_newsgator=on&chk_myyahoo=on&chk_pubsubcom=on&chk_blogdigger=on&chk_blogrolling=on&chk_blogstreet=on&chk_moreover=on&chk_weblogalot=on&chk_icerocket=on&chk_newsisfree=on&chk_topicexchange=on&chk_google=on&chk_tailrank=on&chk_bloglines=on&chk_aiderss=on"
Net::HTTP.get(URI.parse(ping_url))
rescue Exception => e
@@ -27,14 +27,14 @@ def pingomatic
def reinvigorate
return "<script type=\"text/javascript\" src=\"http://include.reinvigorate.net/re_.js\"></script>
<script type=\"text/javascript\">
- re_(\"#{Sinatra.options.reinvigorate_code}\");
+ re_(\"#{Sinatra::Application.reinvigorate_code}\");
</script>"
end
def atom_time date
date.strftime("%Y-%m-%dT%H:%M:%SZ")
end
def disqus
- return "<div id=\"disqus_thread\"></div><script type=\"text/javascript\" src=\"http://disqus.com/forums/#{Sinatra.options.disqus_id}/embed.js\"></script><noscript><a href=\"http://#{Sinatra.options.disqus_id}.disqus.com/?url=ref\">View the discussion thread.</a></noscript><a href=\"http://disqus.com\" class=\"dsq-brlink\">blog comments powered by <span class=\"logo-disqus\">Disqus</span></a>" unless @post.is_a? Page
+ return "<div id=\"disqus_thread\"></div><script type=\"text/javascript\" src=\"http://disqus.com/forums/#{Sinatra::Application.disqus_id}/embed.js\"></script><noscript><a href=\"http://#{Sinatra::Application.disqus_id}.disqus.com/?url=ref\">View the discussion thread.</a></noscript><a href=\"http://disqus.com\" class=\"dsq-brlink\">blog comments powered by <span class=\"logo-disqus\">Disqus</span></a>" unless @post.is_a? Page
end
def post_navigation
html = ""
View
2  lib/plugin/post_talk_like_a_pirate.rb
@@ -1,7 +1,7 @@
# This filter only modifies posts.
class Post
def plugin_talk_like_a_pirate content
- return content unless Sinatra.options.talk_like_a_pirate
+ return content unless Sinatra::Application.talk_like_a_pirate
content.gsub!(/This is a/,"Arr, tis' a")
content.gsub!(/ a /," ye olde ")
end
View
2  lib/plugin/wikilinks.rb
@@ -1,7 +1,7 @@
module BlikiContent
def plugin_wikilinks content
content.gsub(/\[\[(\w+)\]\]/) do |m|
- "<a href=\"#{Sinatra.options.base_url}/#{$1.slugalize}\">#{$1}</a>"
+ "<a href=\"#{Sinatra::Application.base_url}/#{$1.slugalize}\">#{$1}</a>"
end
end
end
View
2  lib/plugin/wikiwords.rb
@@ -7,7 +7,7 @@ def plugin_wikiwords content
"WONDERFUL_CODE_BLOCK"
end
content.gsub!(/\b([A-Z]+)([a-z]+)([A-Z]+)\w+\b/) do |m|
- "<a href=\"#{Sinatra.options.base_url}/#{m.strip.downcase}\">#{m.strip}</a>"
+ "<a href=\"#{Sinatra::Application.base_url}/#{m.strip.downcase}\">#{m.strip}</a>"
end
content.gsub(/WONDERFUL_CODE_BLOCK/) do |code|
code_blocks.shift
View
26 test/test_bliki.rb
@@ -30,7 +30,7 @@ def teardown
assert_instance_of Module, Sinatra
end
test "Views folder is correctly setup" do
- assert_equal "themes/#{Sinatra.options.theme}", Sinatra.options.views
+ assert_equal "themes/#{Sinatra::Application.theme}", Sinatra::Application.views
end
test "Application is running" do
get_it "/"
@@ -40,7 +40,7 @@ def teardown
# Content
test "Title is Ok" do
get_it "/"
- assert body.scan(/#{Sinatra.options.title}/).size > 0
+ assert body.scan(/#{Sinatra::Application.title}/).size > 0
end
# Mock content
@@ -149,14 +149,14 @@ def teardown
test "wikilinks are converted to links" do
new_page = Page.new(:title => "test_page", :body => "[[wikilink1]] [[wikilink2]]", :tags => "wiki")
get_it "/test_page"
- assert body.scan("<a href=\"#{Sinatra.options.base_url}/wikilink1\">wikilink1</a>").size > 0
- assert body.scan("<a href=\"#{Sinatra.options.base_url}/wikilink2\">wikilink2</a>").size > 0
+ assert body.scan("<a href=\"#{Sinatra::Application.base_url}/wikilink1\">wikilink1</a>").size > 0
+ assert body.scan("<a href=\"#{Sinatra::Application.base_url}/wikilink2\">wikilink2</a>").size > 0
end
test "WikiWords are converted to links" do
new_page = Page.new(:title => "test_wikiwords", :body => "WikiWord WikiWikiWord", :tags => "wiki")
get_it "/test_wikiwords"
- assert body.scan("<a href=\"#{Sinatra.options.base_url}/wikiword\">WikiWord</a>").size > 0
- assert body.scan("<a href=\"#{Sinatra.options.base_url}/wikiwikiword\">WikiWikiWord</a>").size > 0
+ assert body.scan("<a href=\"#{Sinatra::Application.base_url}/wikiword\">WikiWord</a>").size > 0
+ assert body.scan("<a href=\"#{Sinatra::Application.base_url}/wikiwikiword\">WikiWikiWord</a>").size > 0
end
# CSS: Base CSS
@@ -168,23 +168,23 @@ def teardown
# Attachments
test "attachment relationships work at model level" do
post_with_attach = Post.new(:title => "Post with attach", :body => "this post has an attach", :tags => "attach")
- a = Attachment.new(:name => "foo", :path => Sinatra.options.public, :content => File.open("README.markdown").read, :post_id => post_with_attach.id)
- b = Attachment.new(:name => "bar", :path => Sinatra.options.public, :content => File.open("README.markdown").read, :post_id => post_with_attach.id)
+ a = Attachment.new(:name => "foo", :path => Sinatra::Application.public, :content => File.open("README.markdown").read, :post_id => post_with_attach.id)
+ b = Attachment.new(:name => "bar", :path => Sinatra::Application.public, :content => File.open("README.markdown").read, :post_id => post_with_attach.id)
assert_equal 2, post_with_attach.attachments.size
end
test "Attachments are created with unique names" do
- a = Attachment.new(:name => "test_one", :path => Sinatra.options.public, :content => File.open("README.markdown").read)
+ a = Attachment.new(:name => "test_one", :path => Sinatra::Application.public, :content => File.open("README.markdown").read)
assert a.save == true
- b = Attachment.new(:name => "test_one", :path => Sinatra.options.public, :content => File.open("README.markdown").read)
+ b = Attachment.new(:name => "test_one", :path => Sinatra::Application.public, :content => File.open("README.markdown").read)
assert b.save == false
end
test "Files are created when saving attachments" do
- a = Attachment.new(:name => "attach", :path => Sinatra.options.public, :content => File.open("README.markdown").read)
+ a = Attachment.new(:name => "attach", :path => Sinatra::Application.public, :content => File.open("README.markdown").read)
assert a.save == true, "File already exists"
- assert File.exist?(Sinatra.options.public / a.name ), "File not created"
+ assert File.exist?(Sinatra::Application.public / a.name ), "File not created"
end
test "Content for attachments is saved correctly" do
- a = Attachment.new(:name => "attach_content", :path => Sinatra.options.public, :content => File.open("README.markdown").read)
+ a = Attachment.new(:name => "attach_content", :path => Sinatra::Application.public, :content => File.open("README.markdown").read)
assert File.open(a.path / a.name,"r").read.scan("bliki").size > 1
end
View
2  themes/default/archive.erb
@@ -1,4 +1,4 @@
- <h2>Everything tagged with ‘<%= @tag %>’ on <%= Sinatra.options.name %>:</h2>
+ <h2>Everything tagged with ‘<%= @tag %>’ on <%= Sinatra::Application.name %>:</h2>
<div class="group">
<% @posts.each do |post| %>
<h2 class="title"><%= link_to post.title, post.link %></h2>
View
3  themes/default/base.sass
@@ -1,4 +1,3 @@
-/ Global Styles
body
margin: 0
padding: 1em
@@ -89,7 +88,7 @@ a:hover
margin-top: 1.3em
line-height: 1em
.meta
- / background-color: #ccc
+ background-color: #ccc
h2, h3
margin: 0
h3
View
8 themes/default/feed.builder
@@ -1,8 +1,8 @@
-base_url = Sinatra.options.base_url
+base_url = Sinatra::Application.base_url
feed_url = base_url + "/feed/"
-title = Sinatra.options.name + " - " + Sinatra.options.title
-limit = Sinatra.options.limit
-author_name = Sinatra.options.author_name
+title = Sinatra::Application.name + " - " + Sinatra::Application.title
+limit = Sinatra::Application.limit
+author_name = Sinatra::Application.author_name
author_uri = base_url
# Build feed
xml.instruct! :xml, :version => "1.0"
View
2  themes/default/home.erb
@@ -6,7 +6,7 @@
<div class="body">
<%= post.content %>
</div>
- <%= "<p><a href='#{post.link}#disqus_thread'>View Comments</a></p>" if Sinatra.options.use_comments %>
+ <%= "<p><a href='#{post.link}#disqus_thread'>View Comments</a></p>" if Sinatra::Application.use_comments %>
</div>
<!-- .post -->
<% end %>
View
10 themes/default/layout.erb
@@ -1,14 +1,14 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title><%= Sinatra.options.name %><%= " - #{@post.title}" unless @post.nil? %><%= " - #{@page.title}" unless @page.nil? %></title>
+ <title><%= Sinatra::Application.name %><%= " - #{@post.title}" unless @post.nil? %><%= " - #{@page.title}" unless @page.nil? %></title>
<link rel="stylesheet" href="/base.css" type="text/css" media="screen" title="base" charset="utf-8" />
- <link rel="alternate" type="application/rss+xml" title="<%= Sinatra.options.name %> Atom Feed" href="<%= Sinatra.options.base_url %>/feed/" />
+ <link rel="alternate" type="application/rss+xml" title="<%= Sinatra::Application.name %> Atom Feed" href="<%= Sinatra::Application.base_url %>/feed/" />
</head>
<body>
<div id="header">
- <h1><%= link_to Sinatra.options.name, "/" %></h1>
- <small><%= Sinatra.options.title %></small>
+ <h1><%= link_to Sinatra::Application.name, "/" %></h1>
+ <small><%= Sinatra::Application.title %></small>
</div>
<div id="content">
<%= yield %>
@@ -16,7 +16,7 @@
<!-- #content -->
<div id="about">
<h4>about</h4>
- <p>this is the home of <%= Sinatra.options.author_name %>.</p>
+ <p>this is the home of <%= Sinatra::Application.author_name %>.</p>
<h4>i talk about <%= tag_list @tags %></h4>
</div>
<!-- #about -->
View
4 themes/default/view.erb
@@ -1,10 +1,10 @@
<div class="<%= @post.class.to_s.downcase %>">
<h2 class="title"><%= @post.title %></h2>
- <small>posted on <%= @post.date %> by <%= Sinatra.options.author_name %>, tagged with <%= tag_list @post.tags %></small>
+ <small>posted on <%= @post.date %> by <%= Sinatra::Application.author_name %>, tagged with <%= tag_list @post.tags %></small>
<div class="body">
<%= @post.content %>
</div>
- <%= disqus if Sinatra.options.use_comments %>
+ <%= disqus if Sinatra::Application.use_comments %>
<%= post_navigation %>
</div>
<!-- .post -->
Please sign in to comment.
Something went wrong with that request. Please try again.