Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

New design, images, and page locking feature

  • Loading branch information...
commit 6515865cfc4e2b0446d66f2ac636f61ecfc6754c 1 parent 926fd45
Jeremy McAnally authored
View
1  .caprc
@@ -0,0 +1 @@
+require 'deprec/recipes'
View
3  Capfile
@@ -0,0 +1,3 @@
+load 'deploy' if respond_to?(:namespace) # cap2 differentiator
+Dir['vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }
+load 'config/deploy'
View
20 app/controllers/pages_controller.rb
@@ -129,6 +129,26 @@ def destroy
end
end
+ def lock
+ @page = Page.find_by_permalink(params[:id])
+
+ Page.without_revision do
+ if @page.locked?
+ @page.locked = false
+ RAILS_DEFAULT_LOGGER.info "UNLOCK"
+ else
+ @page.locked = true
+ RAILS_DEFAULT_LOGGER.info "LOCK"
+ end
+
+ @page.save
+ end
+
+ respond_to do |format|
+ format.html { redirect_to(wiki_page_url(@page)) }
+ format.xml { head :ok }
+ end
+ end
def check_private
@page = Page.find_by_permalink(params[:id])
View
6 app/helpers/pages_helper.rb
@@ -2,16 +2,16 @@ module PagesHelper
def wikified_body(body)
r = RedCloth.new(body)
- r.gsub!(/\[\[(.*)(\|(.*))?\]\]/) {wiki_link(*$1.split("|"))}
+ r.gsub!(/\[\[(.*)(\|(.*))?\]\]/) {wiki_link(*$1.split("|")[0..1])}
r.to_html
end
def wiki_link(wiki_words, link_text = nil)
permalink = wiki_words.downcase.gsub(' ', '-')
if Page.exists?(:permalink => permalink)
- link_to ((link_text || wiki_words), wiki_page_url(permalink))
+ link_to ((link_text || wiki_words), wiki_page_url(permalink), :class => "wiki_link")
else
- link_to ((link_text || wiki_words), wiki_page_url(permalink), :class => "new_wiki_link")
+ link_to ((link_text || wiki_words), wiki_page_url(permalink), :class => "wiki_link new_wiki_link")
end
end
View
6 app/models/page.rb
@@ -17,9 +17,12 @@
class Page < ActiveRecord::Base
belongs_to :user
acts_as_versioned
+ self.non_versioned_columns << 'locked'
attr_accessor :ip, :agent, :referrer
acts_as_indexed :fields => [:title, :body, :author]
+ validates_presence_of :title
+
before_save :set_permalink
def validate
@@ -44,7 +47,7 @@ def request=(request)
def set_permalink
if self.permalink.blank?
- self.permalink = Page.count == 0 ? "home" : "#{title.downcase.strip.gsub(' ', '-')}"
+ self.permalink = Page.count == 0 ? "home" : "#{title.downcase.strip.gsub(/ |\.|@/, '-')}"
end
end
@@ -60,5 +63,4 @@ def self.find_all_by_wiki_word(wiki_word)
pages = self.find(:all)
pages.select {|p| p.body =~ /#{wiki_word}/i}
end
-
end
View
2  app/models/user.rb
@@ -22,7 +22,7 @@ class User < ActiveRecord::Base
attr_accessor :password
attr_protected :admin
- has_many :pages
+ has_many :pages, :order => 'title ASC'
validates_presence_of :login, :email, :if => :not_openid?
validates_presence_of :password, :if => :password_required?
View
8 app/views/layouts/application.html.erb
@@ -13,7 +13,7 @@
<div id="header">
<div id="navbar"></div>
- <h1><%= link_to site.title, wiki_page_url("home"), :id => "site_name" %></h1>
+ <h1><%= image_tag 'rails.png', :style => 'float: left; margin-right: 10px; margin-bottom: 10px' %> <%= link_to site.title, wiki_page_url("home"), :id => "site_name" %> <span id="subtitle"><br />The community wiki</span></h1>
</div><!-- end #header -->
<div id="container">
@@ -29,6 +29,12 @@
</script>
<%= yield %>
+
+ <div id="bottom">
+ All content is released under the GNU Free Documentation License.<br />
+ Wiki powered by Signal, hosted by Slicehost.
+ </div>
+
</div><!-- end #main -->
<div id="right">
View
2  app/views/pages/revision.html.erb
@@ -10,7 +10,7 @@
<ul class="meta_info">
<li><%= link_to('View previous revision', revision_page_url(:id => @page.permalink, :version => (@page.previous.version))) if @page.previous %></li>
<li><%= link_to('View next revision', revision_page_url(:id => @page.permalink, :version => (@page.next.version))) if @page.next %></li>
- <li><%= link_to "Rollback to this revision", rollback_page_url(:id => @page.permalink, :version => (@page.version)) unless current_revision(@page.page_id, @page.version)%></li>
+ <li><%= link_to "Rollback to this revision", rollback_page_url(:id => @page.permalink, :version => (@page.version)) unless current_revision(@page.page_id, @page.version) || (Page.find(@page.page_id).locked? && !current_user.admin?) %></li>
<li><%= link_to 'Return to current revision', wiki_page_url(@page.permalink) %></li>
</ul>
<% end -%>
View
9 app/views/pages/show.html.erb
@@ -1,4 +1,4 @@
-<h2><%=h @page.title %></h2>
+<h2 class="title"><%=h @page.title %></h2>
<p class="wiki_body">
@@ -8,9 +8,12 @@
<% content_for :right do -%>
<h5>Author: <%= author(@page.user_id) %></h5>
<ul class="meta_info">
- <li><%= link_to 'Edit this page', edit_page_path(@page) %></li>
+ <li><%= link_to 'Edit this page', edit_page_path(@page) unless @page.locked? && !current_user.admin? %></li>
+ <li><%= link_to((@page.locked? ? "Unlock this page" : "Lock this page"), lock_page_path(@page)) if logged_in? && current_user.admin? %></li>
+
+ <li><%= link_to "Delete this page and all revisions", page_path(@page), :method => :delete if logged_in? && current_user.admin? && @page.permalink != 'home' %></li>
+
<li><%= link_to('View previous revision', revision_page_url(:id => @page.permalink, :version => (@page.version - 1) )) if (@page.versions.size > 1 && @page.version > 1) %></li>
<li><%= link_to 'Return to home', pages_path unless @page.permalink == "home" %></li>
- <li><%= link_to "Delete this page and all revisions", page_path(@page), :method => :delete %></li>
</ul>
<% end -%>
View
109 config/deploy.rb
@@ -0,0 +1,109 @@
+set :application, "Rails Wiki"
+set :scm, :git
+set :repository, ""
+
+# If you aren't deploying to /u/apps/#{application} on the target
+# servers (which is the default), you can specify the actual location
+# via the :deploy_to variable:
+# set :deploy_to, "/var/www/#{application}"
+
+# If you aren't using Subversion to manage your source code, specify
+# your SCM below:
+# set :scm, :subversion
+
+role :app, "your app-server here"
+role :web, "your web-server here"
+role :db, "your db-server here", :primary => true
+
+# my custom stack install, including all necessary packages for rails, mysql, and nginx
+
+task :install_rails_stack_with_nginx do
+ setup_user_perms
+ enable_universe # we'll need some packages from the 'universe' repository
+ disable_cdrom_install # we don't want to have to insert cdrom
+ install_packages_for_rails # install packages that come with distribution
+ install_rubygems
+ install_gems
+ install_nginx
+end
+
+task :setup_firewall do
+ sudo 'echo \'#!/bin/bash\' >> /tmp/firewall.sh'
+ sudo 'echo \'sudo iptables -A INPUT -j ACCEPT -p tcp --destination-port 80 -i eth0\' >> /tmp/firewall.sh'
+ sudo 'echo \'sudo iptables -A INPUT -j ACCEPT -p tcp --destination-port 443 -i eth0\' >> /tmp/firewall.sh'
+ sudo 'echo \'sudo iptables -A INPUT -j ACCEPT -p tcp --destination-port 22 -i eth0\' >> /tmp/firewall.sh'
+ sudo 'echo \'sudo iptables -A INPUT -j DROP -p tcp -i eth0\' >> /tmp/firewall.sh'
+ sudo 'chown root:root /tmp/firewall.sh'
+ sudo 'chmod +x /tmp/firewall.sh'
+ sudo 'mv /tmp/firewall.sh /etc/init.d/'
+ sudo '/etc/init.d/firewall.sh'
+ sudo 'update-rc.d firewall.sh defaults'
+end
+
+# nginx recipes
+
+task :install_nginx do
+ install_pcre
+ version = 'nginx-0.5.35'
+ set :src_package, {
+ :file => version + '.tar.gz',
+ :dir => version,
+ :url => "http://sysoev.ru/nginx/#{version}.tar.gz",
+ :unpack => "tar -xzvf #{version}.tar.gz;",
+ :configure => './configure --sbin-path=/usr/local/sbin --with-http_ssl_module;',
+ :make => 'make;',
+ :install => 'make install;',
+ }
+ deprec.download_src(src_package, src_dir)
+ deprec.install_from_src(src_package, src_dir)
+ sudo 'wget http://notrocketsurgery.com/files/nginx -O /etc/init.d/nginx'
+ sudo 'chmod 755 /etc/init.d/nginx'
+ send(run_method, "update-rc.d nginx defaults")
+end
+
+task :configure_nginx do
+ stop_nginx
+ sudo "cp #{release_path}/config/nginx.conf /usr/local/nginx/conf/"
+ start_nginx
+end
+
+task :install_pcre do
+ apt.install({:base => ['libpcre3', 'libpcre3-dev']}, :stable)
+end
+
+task :start_nginx do
+ sudo '/etc/init.d/nginx start'
+end
+
+task :restart_nginx do
+ sudo '/etc/init.d/nginx restart'
+end
+
+task :stop_nginx do
+ sudo '/etc/init.d/nginx stop'
+end
+
+task :create_database_yml do
+ run "cp #{release_path}/config/database.yml.production #{release_path}/config/database.yml"
+end
+
+# here is my section to tie this all together and make it as easy as three cap instructions to setup a new server
+task :deploy_first_time do
+ setup
+ deploy
+ create_database_yml
+ setup_mysql
+ migrate
+ configure_mongrel_cluster
+ configure_nginx
+ restart_mongrel_cluster
+ start_nginx
+end
+
+# overwrite the deprec read_config task so that it grabs the right config
+def read_config
+ db_config = YAML.load_file('config/database.yml.production')
+ set :db_user, db_config[rails_env]["username"]
+ set :db_password, db_config[rails_env]["password"]
+ set :db_name, db_config[rails_env]["database"]
+end
View
2  config/routes.rb
@@ -4,7 +4,7 @@
map.resource :session
map.resource :site, :member => {:expire_cache => :get, :mark_all_private => :get}
map.resources :users
- map.resources :pages, :member => {:revision => :get, :rollback => :get}, :collection => {:search => :get}
+ map.resources :pages, :member => {:revision => :get, :rollback => :get, :lock => :get}, :collection => {:search => :get}
map.resources :attachments
map.login '/login', :controller => 'sessions', :action => 'new'
View
9 db/migrate/011_add_locked_to_pages.rb
@@ -0,0 +1,9 @@
+class AddLockedToPages < ActiveRecord::Migration
+ def self.up
+ add_column :pages, :locked, :boolean
+ end
+
+ def self.down
+ remove_column :pages, :locked
+ end
+end
View
28 db/schema.rb
@@ -9,7 +9,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 10) do
+ActiveRecord::Schema.define(:version => 11) do
create_table "attachments", :force => true do |t|
t.integer "size"
@@ -52,7 +52,7 @@
t.string "permalink"
t.datetime "created_at"
t.datetime "updated_at"
- t.boolean "private_page"
+ t.boolean "private_page", :default => false
end
create_table "pages", :force => true do |t|
@@ -62,10 +62,34 @@
t.string "permalink"
t.datetime "created_at"
t.datetime "updated_at"
+ t.boolean "private_page", :default => false
+ t.integer "version", :default => 1
+ t.boolean "locked"
+ end
+
+ create_table "pg", :force => true do |t|
+ t.string "title"
+ t.text "body"
+ t.integer "user_id"
+ t.string "permalink"
+ t.datetime "created_at"
+ t.datetime "updated_at"
t.boolean "private_page"
t.integer "version"
end
+ create_table "pv", :force => true do |t|
+ t.integer "page_id"
+ t.integer "version"
+ t.string "title"
+ t.text "body"
+ t.integer "user_id"
+ t.string "permalink"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ t.boolean "private_page"
+ end
+
create_table "sites", :force => true do |t|
t.string "title"
t.string "akismet_key"
View
60 nginx.conf
@@ -0,0 +1,60 @@
+worker_processes 6;
+pid /var/run/nginx.pid;
+events {
+ worker_connections 1024;
+}
+http {
+ include /usr/local/nginx/conf/mime.types;
+ default_type application/octet-stream;
+ log_format main '$remote_addr - $remote_user [$time_local] '
+ '"$request" $status $body_bytes_sent "$http_referer" '
+ '"$http_user_agent" "$http_x_forwarded_for"';
+ access_log /var/log/nginx_access.log main;
+ error_log /var/log/nginx_error.log debug;
+ sendfile on;
+ tcp_nopush on;
+ tcp_nodelay off;
+ gzip on;
+ gzip_http_version 1.0;
+ gzip_comp_level 2;
+ gzip_proxied any;
+ gzip_types text/plain text/html text/css application/x-javascript text/xml application/xml
+ application/xml+rss text/javascript;
+ upstream mongrel {
+ server 127.0.0.1:5000;
+ server 127.0.0.1:5001;
+ server 127.0.0.1:5002;
+ }
+ server {
+ listen 80;
+ client_max_body_size 50M;
+ # configure the next line to point to your deploy location
+ root /path_to_your_app/current/public;
+ access_log /var/log/nginx.vhost.access.log main;
+ if (-f $document_root/system/maintenance.html) {
+ rewrite ^(.*)$ /system/maintenance.html last;
+ break;
+ }
+ location / {
+ proxy_set_header X-Real-IP $remote_addr;
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+ proxy_set_header Host $http_host;
+ proxy_redirect false;
+ proxy_max_temp_file_size 0;
+ if (-f $request_filename) {
+ break;
+ }
+ if (-f $request_filename/index.html) {
+ rewrite (.*) $1/index.html break;
+ }
+ if (!-f $request_filename) {
+ proxy_pass http://mongrel;
+ break;
+ }
+ }
+ error_page 500 502 503 504 /500.html;
+ location = /500.html {
+ root /path_to_your_app/current/public;
+ }
+ }
+}
View
BIN  public/images/external.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  public/images/herobackground.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  public/images/rails.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  public/images/tile.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  public/images/tile.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  public/images/topbluefade.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
87 public/stylesheets/style.css
@@ -3,7 +3,8 @@
******************************************************************/
body {
- background: #DEDEDE;
+ background: #fff url('/images/topbluefade.gif') repeat-x;
+ background-position: 0px 60px;
font-family:Arial,Helvetica,sans-serif;
margin:0pt;
padding:0pt;
@@ -41,7 +42,13 @@ a {
#site_name {
text-decoration: none;
- color: black;
+ color: white;
+ text-shadow: 2pt 2pt black;
+}
+
+#subtitle {
+ font-size: 8pt;
+ color: #884444;
}
/******************************************************************
@@ -49,9 +56,9 @@ a {
******************************************************************/
#header {
- padding:10px 4%;
+ padding: 10px 5px 15px 5px;
border-bottom: 2px solid black;
- background: white;
+ background: #1e0000 url('/images/tile.png');
}
#header ul#nav {
@@ -73,41 +80,73 @@ a {
font-size: 1.3em;
}
+#header a {
+ color: white;
+ text-decoration: none;
+ font-weight: bold;
+}
+
/******************************************************************
#Container and #Main color and layout control
******************************************************************/
#container {
- margin: 15px 50px;
- padding: 20px;
+ margin: 1px 0px;
+ padding: 0px;
min-width: 970px;
}
#main {
float: left;
- width: 600px;
+ width: 750px;
min-width: 400px;
margin: 0;
- padding: 20px;
+ padding: 0px 25px;
background: white;
- border-bottom: 3px solid grey;
+ border-bottom: 3px solid #333;
+ border-right: 2px solid #666;
}
-#main h2 {
- margin: 0;
- padding: 0;
- font-size: 1.3em;
+#main h1, h2 {
+ font-size: 16pt;
+ color: #666;
+}
+
+#main h3 {
+ font-size: 14pt;
+ color: #666;
}
+#main h4, h5, h6 {
+ font-size: 12pt;
+ color: #666;
+}
+
+#main h2.title {
+ color: #000;
+ font-size: 18pt;
+ border-bottom: 1px dotted #ddd;
+ padding-bottom: 5px;
+}
+
+#main a {
+ text-decoration: none;
+ border-bottom: 1px dotted #00f;
+}
+
+#main a:after { content: url('/images/external.png'); }
+
+#main a.wiki_link:after { content: ""; }
+
/******************************************************************
Meta info layout/styling
******************************************************************/
#right {
float: left;
- margin-left:3%;
+ margin-left:20px;
margin-right:0pt;
- margin-top:1em;
+ margin-top:20px;
width:19%;
}
@@ -215,3 +254,21 @@ a.attachment_link {
text-decoration: none;
margin: 0 auto;
}
+
+/******************************************************************
+ Code layout
+******************************************************************/
+CODE {
+ overflow: hidden;
+}
+
+PRE {
+ overflow: auto;
+}
+
+#bottom {
+ text-align: center;
+ font-size: 8pt;
+ color: #666;
+ margin: 30px 0px 20px 0px;
+}
Please sign in to comment.
Something went wrong with that request. Please try again.