Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e08fb2e
Showing
29 changed files
with
16,126 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
source 'http://rubygems.org' | ||
gem 'bundler' | ||
gem 'sequel' | ||
gem 'sinatra' | ||
gem 'rack' | ||
gem 'sinatra-flash', :require => 'sinatra/flash' | ||
gem 'dm-core' | ||
gem 'dm-validations' | ||
gem 'dm-types' | ||
gem 'dm-migrations' | ||
gem 'dm-sqlite-adapter' | ||
gem 'rdiscount' | ||
gem 'nokogiri' | ||
gem 'shotgun' | ||
gem 'heroku' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
GEM | ||
remote: http://rubygems.org/ | ||
specs: | ||
addressable (2.2.7) | ||
bcrypt-ruby (3.0.1) | ||
data_objects (0.10.8) | ||
addressable (~> 2.1) | ||
dm-core (1.2.0) | ||
addressable (~> 2.2.6) | ||
dm-do-adapter (1.2.0) | ||
data_objects (~> 0.10.6) | ||
dm-core (~> 1.2.0) | ||
dm-migrations (1.2.0) | ||
dm-core (~> 1.2.0) | ||
dm-sqlite-adapter (1.2.0) | ||
dm-do-adapter (~> 1.2.0) | ||
do_sqlite3 (~> 0.10.6) | ||
dm-types (1.2.1) | ||
bcrypt-ruby (~> 3.0.0) | ||
dm-core (~> 1.2.0) | ||
fastercsv (~> 1.5.4) | ||
json (~> 1.6.1) | ||
multi_json (~> 1.0.3) | ||
stringex (~> 1.3.0) | ||
uuidtools (~> 2.1.2) | ||
dm-validations (1.2.0) | ||
dm-core (~> 1.2.0) | ||
do_sqlite3 (0.10.8) | ||
data_objects (= 0.10.8) | ||
fastercsv (1.5.4) | ||
heroku (2.22.0) | ||
launchy (>= 0.3.2) | ||
netrc (~> 0.7.1) | ||
rest-client (~> 1.6.1) | ||
rubyzip | ||
json (1.6.6) | ||
launchy (2.1.0) | ||
addressable (~> 2.2.6) | ||
mime-types (1.18) | ||
multi_json (1.0.4) | ||
netrc (0.7.1) | ||
nokogiri (1.5.2) | ||
rack (1.4.0) | ||
rack-protection (1.2.0) | ||
rack | ||
rdiscount (1.6.8) | ||
rest-client (1.6.7) | ||
mime-types (>= 1.16) | ||
rubyzip (0.9.6.1) | ||
sequel (3.31.0) | ||
shotgun (0.9) | ||
rack (>= 1.0) | ||
sinatra (1.3.2) | ||
rack (~> 1.3, >= 1.3.6) | ||
rack-protection (~> 1.2) | ||
tilt (~> 1.3, >= 1.3.3) | ||
sinatra-flash (0.3.0) | ||
sinatra (>= 1.0.0) | ||
stringex (1.3.2) | ||
tilt (1.3.3) | ||
uuidtools (2.1.2) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
bundler | ||
dm-core | ||
dm-migrations | ||
dm-sqlite-adapter | ||
dm-types | ||
dm-validations | ||
heroku | ||
nokogiri | ||
rack | ||
rdiscount | ||
sequel | ||
shotgun | ||
sinatra | ||
sinatra-flash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Copyright (c) 2012, Worldly Wisdom Ventures LLC | ||
|
||
Permission is hereby granted, free of charge, to any person | ||
obtaining a copy of this software and associated documentation | ||
files (the "Software"), to deal in the Software without | ||
restriction, including without limitation the rights to use, | ||
copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the | ||
Software is furnished to do so, subject to the following | ||
conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
``` $ heroku addons:add shared-database | ||
``` $ heroku config:add ADMIN_USER=username | ||
``` $ heroku config:add ADMIN_PASS=t0psecret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
require 'rubygems' | ||
require 'sinatra' | ||
require 'dm-core' | ||
require 'dm-validations' | ||
require 'dm-types' | ||
require 'dm-migrations' | ||
|
||
DataMapper.setup(:default, ENV['DATABASE_URL'] || "sqlite3://#{Dir.pwd}/database.db") | ||
|
||
class Page | ||
include DataMapper::Resource | ||
property :id, Serial | ||
property :slug, String | ||
property :title, String | ||
property :content, Text | ||
property :last_updated, DateTime | ||
property :sidebar, Enum[ :yes, :no ], :default => :no | ||
end | ||
|
||
DataMapper.auto_migrate! | ||
|
||
task :setup do | ||
@page = Page.create(:slug => 'home') | ||
@page.slug = 'home' | ||
@page.title = 'Home' | ||
@page.content = 'This is the home page. Press the edit button below to get started.' | ||
@page.last_updated = Time.now | ||
@page.sidebar = :no | ||
@page.save | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
TODO | ||
==== | ||
|
||
+ Add markdown-to-html conversion on content pages | ||
+ Add basic thin / DB support for Heroku hosting | ||
+ Update to Bootstrap 2.0 | ||
|
||
|
||
DONE | ||
==== | ||
|
||
+ Add license (MIT) | ||
+ Add Markdown mark to sidebar guide | ||
+ Fix editing update error (wasn't re-setting slug on @page.save) | ||
+ Create "setup" rake command | ||
+ Convert style guide to Markdown | ||
+ Convert :sidebar to enum | ||
+ Create basic get routes | ||
+ Create basic post/edit routes | ||
+ Create basic delete routes | ||
+ Create "list all" page |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
# Inspired by the following: | ||
# http://rubylearning.com/blog/2009/03/20/interview-ryan-tomayko-on-sinatra/ | ||
# https://gist.github.com/8ff54cdfd44e1a6485e2 | ||
# http://ididitmyway.heroku.com/past/2010/11/9/sinatra_settings_and_configuration/ | ||
|
||
require 'rubygems' | ||
require 'sinatra' | ||
require 'sinatra/flash' | ||
require 'dm-core' | ||
require 'dm-validations' | ||
require 'dm-types' | ||
require 'dm-migrations' | ||
require 'rdiscount' | ||
require 'shotgun' | ||
|
||
DataMapper.setup(:default, ENV['DATABASE_URL'] || "sqlite3://#{Dir.pwd}/database.db") | ||
|
||
class Page | ||
include DataMapper::Resource | ||
property :id, Serial | ||
property :slug, String | ||
property :title, String | ||
property :content, Text | ||
property :last_updated, DateTime | ||
property :sidebar, Enum[ :yes, :no ], :default => :no | ||
end | ||
|
||
DataMapper.finalize | ||
DataMapper.auto_upgrade! | ||
|
||
enable :sessions | ||
|
||
# Authentication | ||
use Rack::Auth::Basic, "Restricted Area" do |username, password| | ||
[username, password] == [ENV['ADMIN_USER'], ENV['ADMIN_PASS']] | ||
end | ||
|
||
# Converts page name into post slug | ||
def slugify(content) | ||
content.downcase.gsub(/ /, '-').gsub(/[^a-z0-9_-]/, '').squeeze('-') | ||
end | ||
|
||
# Sets index page as "home" | ||
get '/' do | ||
redirect '/home/' | ||
end | ||
|
||
# Creates new note from "new page" form | ||
post '/' do | ||
if params[:userinput].empty? | ||
redirect '/' | ||
else | ||
@page = Page.first_or_create(:title => params[:userinput], :slug => slugify(params[:userinput])) | ||
@page.content = "This is a new page. Add content by clicking the Edit button below." | ||
@page.last_updated = Time.now | ||
@page.save | ||
flash[:notice] = "Page successfully created." | ||
redirect "/#{@page.slug}/" | ||
end | ||
end | ||
|
||
# List all pages in database | ||
get '/all/' do | ||
@page = Page.new | ||
@page.title = 'All Pages' | ||
@page.slug = 'all' | ||
@pages = Page.all | ||
@sidebars = Page.all(:sidebar => 'yes') | ||
erb :all | ||
end | ||
|
||
# Displays requested note | ||
get '/:url/' do | ||
@page = Page.first(:slug => params[:url]) | ||
if @page == nil | ||
flash[:notice] = "Requested page not found!" | ||
redirect '/home/' | ||
else | ||
@pages = Page.all | ||
@sidebars = Page.all(:sidebar => 'yes') | ||
erb :show | ||
end | ||
end | ||
|
||
# Edits requested note | ||
get '/:url/edit' do | ||
@page = Page.first(:slug => params[:url]) | ||
@sidebars = Page.all(:sidebar => 'yes') | ||
erb :edit | ||
end | ||
|
||
# Saves user edits to note | ||
post '/:url/edit' do | ||
@page = Page.first(:slug => params[:url]) | ||
@page.title = params[:title] | ||
@page.content = params[:content] | ||
@page.sidebar = params[:sidebar] | ||
@page.last_updated = Time.now | ||
if @page.slug != 'home' | ||
@page.slug = slugify(params[:title]) | ||
end | ||
@page.save | ||
flash[:notice] = "Page edit saved." | ||
redirect "/#{@page.slug}/" | ||
end | ||
|
||
# Readies requested note for deletion | ||
get '/:url/delete' do | ||
@page = Page.first(:slug => params[:url]) | ||
@pages = Page.all | ||
@sidebars = Page.all(:sidebar => 'yes') | ||
erb :delete | ||
end | ||
|
||
# Deletes specified note | ||
delete '/:url/' do | ||
@page = Page.first(:slug => params[:url]) | ||
@page.destroy | ||
flash[:notice] = "Page deleted." | ||
redirect '/home/' | ||
end | ||
|
||
# Redirects user to homepage if a note is not found | ||
not_found do | ||
flash[:notice] = "Requested page not found!" | ||
redirect '/home/' | ||
end | ||
|
||
# Unauthorized | ||
error 401 do | ||
erb :unauthorized | ||
end |
Oops, something went wrong.