Merge branch 'master' into allow-no-nickname

Conflicts:
	app/views/home/ordergroup.html.haml
	app/views/login/new_password.html.haml
	app/views/shared/_auto_complete_users.rhtml
	app/views/shared/memberships/_current_members.rhtml
	app/views/shared/memberships/_non_members.rhtml
This commit is contained in:
wvengen 2013-11-18 11:42:49 +01:00
commit 66ac3be81f
63 changed files with 428 additions and 438 deletions

View file

@ -0,0 +1,18 @@
FoodsoftWiki
============
This plugin adds wiki pages to foodsoft. A new 'Wiki' menu is added next to
the 'Foodcoops' menu in the navigation bar.
This plugin is enabled by default in foodsoft, so you don't need to do anything
to install it. If you still want to, for example when it has been disabled,
add the following to foodsoft's Gemfile:
```Gemfile
# we use the git version of acts_as_versioned, so this needs to be in foodsoft's Gemfile
gem 'acts_as_versioned', git: 'git://github.com/technoweenie/acts_as_versioned.git'
gem 'foodsoft_wiki', path: 'lib/foodsoft_wiki'
```
This plugin is part of the foodsoft package and uses the GPL-3 license (see
foodsoft's LICENSE for the full license text).

View file

@ -0,0 +1,40 @@
#!/usr/bin/env rake
begin
require 'bundler/setup'
rescue LoadError
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
end
begin
require 'rdoc/task'
rescue LoadError
require 'rdoc/rdoc'
require 'rake/rdoctask'
RDoc::Task = Rake::RDocTask
end
RDoc::Task.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'FoodsoftWiki'
rdoc.options << '--line-numbers'
rdoc.rdoc_files.include('README.rdoc')
rdoc.rdoc_files.include('lib/**/*.rb')
end
APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
load 'rails/tasks/engine.rake'
Bundler::GemHelper.install_tasks
require 'rake/testtask'
Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.libs << 'test'
t.pattern = 'test/**/*_test.rb'
t.verbose = false
end
task :default => :test

View file

@ -0,0 +1,130 @@
# encoding: utf-8
class PagesController < ApplicationController
def index
@page = Page.find_by_permalink "Home"
if @page
render :action => 'show'
else
redirect_to all_pages_path
end
end
def show
if params[:permalink]
@page = Page.find_by_permalink(params[:permalink])
elsif params[:id]
page = Page.find_by_id(params[:id])
if page.nil?
flash[:error] = I18n.t('pages.cshow.error_noexist')
redirect_to all_pages_path and return
else
redirect_to wiki_page_path(page.permalink) and return
end
end
if @page.nil?
redirect_to new_page_path(:title => params[:permalink])
elsif @page.redirect?
page = Page.find_by_id(@page.redirect)
unless page.nil?
flash[:notice] = I18n.t('pages.cshow.redirect_notice', :page => @page.title)
redirect_to wiki_page_path(page.permalink)
end
end
end
def new
@page = Page.new
@page.title = params[:title].gsub("_", " ") if params[:title]
@page.parent = Page.find_by_permalink(params[:parent]) if params[:parent]
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @page }
end
end
def edit
@page = Page.find(params[:id])
end
def create
@page = current_user.pages.build(params[:page])
if params[:preview]
render :action => 'new'
else
if @page.save
flash[:notice] = I18n.t('pages.create.notice')
redirect_to(wiki_page_path(@page.permalink))
else
render :action => "new"
end
end
end
def update
@page = Page.find(params[:id])
@page.attributes = params[:page].merge({:user => current_user})
if params[:preview]
@page.attributes = params[:page]
render :action => 'edit'
else
if @page.save
@page.parent_id = parent_id if (!params[:parent_id].blank? \
and params[:parent_id] != @page_id)
flash[:notice] = I18n.t('pages.update.notice')
redirect_to wiki_page_path(@page.permalink)
else
render :action => "edit"
end
end
rescue ActiveRecord::StaleObjectError
flash[:error] = I18n.t('pages.error_stale_object')
redirect_to wiki_page_path(@page.permalink)
end
def destroy
@page = Page.find(params[:id])
@page.destroy
flash[:notice] = I18n.t('pages.destroy.notice', :page => @page.title)
redirect_to wiki_path
end
def all
@pages = Page.non_redirected
@partial = params[:view] || 'recent_changes'
if params[:name]
@pages = @pages.where("title LIKE ?", "%#{params[:name]}%").limit(20).order('updated_at DESC')
@partial = 'title_list'
else
order = case @partial
when 'recent_changes' then
'updated_at DESC'
when 'site_map' then
'created_at DESC'
when 'title_list' then
'title DESC'
end
@pages.order(order)
end
end
def version
@page = Page.find(params[:id])
@version = Page::Version.find_by_page_id_and_lock_version params[:id], params[:version]
end
def revert
@page = Page.find(params[:id])
@page.revert_to!(params[:version].to_i)
redirect_to wiki_page_path(@page.permalink)
end
end

View file

@ -0,0 +1,59 @@
module PagesHelper
include WikiCloth
def wikified_body(body, title = nil)
WikiCloth.new({:data => body+"\n", :link_handler => Wikilink.new, :params => {:referer => title}}).to_html.html_safe
end
def link_to_wikipage(page, text = nil)
if text == nil
link_to page.title, wiki_page_path(:permalink => page.permalink)
else
link_to text, wiki_page_path(:permalink => page.permalink)
end
end
def link_to_wikipage_by_permalink(permalink, text = nil)
unless permalink.blank?
page = Page.find_by_permalink(permalink)
if page.nil?
if text.nil?
link_to permalink, new_page_path(:title => permalink)
else
link_to text, new_page_path(:title => permalink)
end
else
link_to_wikipage(page, text)
end
end
end
def generate_toc(body)
toc = String.new
body.gsub(/^([=]{1,6})\s*(.*?)\s*(\1)/) do
number = $1.length - 1
name = $2
toc << "*" * number + " #{name}\n"
end
logger.debug toc.inspect
unless toc.blank?
toc = WikiCloth.new({:data => toc, :link_handler => Wikilink.new}).to_html
toc.gsub(/<li>([^<>\n]*)/) do
name = $1
anchor = name.gsub(/\s/, '_').gsub(/[^a-zA-Z_]/, '')
"<li><a href='##{anchor}'>#{name.truncate(20)}</a>"
end.html_safe
end
end
def parent_pages_to_select(current_page)
unless current_page.homepage? # Homepage is the page trees root!
Page.non_redirected.reject { |p| p == current_page or p.ancestors.include?(current_page) }
else
Array.new
end
end
end

View file

@ -0,0 +1,56 @@
class Page < ActiveRecord::Base
include ActsAsTree
belongs_to :user, :foreign_key => 'updated_by'
acts_as_versioned version_column: :lock_version, limit: 20
self.non_versioned_columns += %w(permalink created_at title)
acts_as_tree :order => "title"
attr_accessor :old_title # Save title to create redirect page when editing title
validates_presence_of :title, :body
validates_uniqueness_of :permalink, :title
before_validation :set_permalink, :on => :create
before_validation :update_permalink, :on => :update
after_update :create_redirect
scope :non_redirected, :conditions => {:redirect => nil}
scope :no_parent, :conditions => {:parent_id => nil}
def self.permalink(title)
title.gsub(/[\/\.,;@\s]/, "_").gsub(/[\"\']/, "")
end
def homepage?
permalink == "Home"
end
def set_permalink
unless title.blank?
self.permalink = Page.count == 0 ? "Home" : Page.permalink(title)
end
end
protected
def update_permalink
if changed.include?("title")
set_permalink
self.old_title = changes["title"].first # Save title for creating redirect
end
end
def create_redirect
unless old_title.blank?
Page.create :redirect => id,
:title => old_title,
:body => I18n.t('model.page.redirect', :title => title),
:permalink => Page.permalink(old_title),
:updated_by => updated_by
end
end
end

View file

@ -0,0 +1,9 @@
- content = wikified_body @page.body, @page.title
- toc = generate_toc @page.body
- unless toc.blank? or params[:preview]
- content_for :sidebar do
#wikitoc.well.well-small
%h3= t '.title_toc'
= toc
= content

View file

@ -0,0 +1,85 @@
- if params[:preview]
%section#wikiContent
= render 'body'
.row-fluid
.span8
= simple_form_for @page do |f|
= f.hidden_field :lock_version
= f.input :title, input_html: {class: 'input-xxlarge'}
= f.input :body, input_html: {class: 'input-xxlarge'}
= f.input :parent_id, as: :select, collection: parent_pages_to_select(@page)
.form-actions
= button_tag :name => 'preview', class: 'btn' do
%i.icon-search= t '.preview'
= button_tag class: 'btn' do
%i.icon-save= t 'ui.save'
= link_to t('ui.or_cancel'), @page
.span4
%h3= t '.help.title'
%table.table
%tbody
%tr
%td(colspan=2)
%b= t '.help.section_character'
%tr
%td
%i= t '.help.italic'
%td
%pre
''#{t '.help.italic'}''<br />
%tr
%td
%b= t '.help.bold'
%td
%pre '''#{t '.help.bold'}'''<br />
%tr
%td= t '.help.noformat'
%td
%pre &lt;nowiki&gt;#{t '.help.text'}&lt;/nowiki&gt;
%tr
%td(colspan=2)
%b= t '.help.section_block'
%tr
%td= t '.help.headings'
%td
%pre
\== #{t '.help.heading', level: 1} ==
%pre
\=== #{t '.help.heading', level: 2} ===
%pre
\==== #{t '.help.heading', level: 3} ====
%tr
%td= t '.help.unordered_list'
%td
%pre
* #{t '.help.list_item_1'}
%pre
** #{t '.help.list_item_2'}
%tr
%td= t '.help.ordered_list'
%td
%pre
\# #{t '.help.list_item_1'}
%pre
\# #{t '.help.list_item_2'}
%tr
%td(colspan=2)
%b= t '.help.section_link'
%tr
%td= t '.help.wiki_links'
%td
%pre
[[#{t '.help.wiki_link_ex'}]]
%tr
%td= t '.help.external_links'
%td
%pre
[http://example.net #{t '.help.external_link_ex'}]
%tr
%td(colspan=2)
%b= t '.help.section_table'
%tr
%td!= t '.help.see_tables', tables_link: link_to(t('.help.tables_link'), "http://www.mediawiki.org/wiki/Help:Tables", :target => '_blank')

View file

@ -0,0 +1,8 @@
-ident = 20 * level
%tr
%td{:style => "padding-left: #{ident}px"}
= link_to page.title, wiki_page_path(page.permalink)
%td #{show_user page.user} (#{format_datetime_timespec(page.updated_at, t('.date_format'))})
-if siteMap == 1
-for child in page.children.all
= render :partial => 'page_list_item', :locals => {:page => child, :level => level+1, :siteMap => 1}

View file

@ -0,0 +1,8 @@
%table.table.table-striped
%thead
%tr
%th= t 'pages.title'
%th= t 'pages.last_updated'
%tbody
- for page in @pages
= render :partial => "page_list_item", :locals => {:page => page, :level => 0, :siteMap => 0}

View file

@ -0,0 +1,12 @@
%table.table.table-striped
%thead
%tr
%th= t 'pages.title'
%th= t 'pages.last_updated'
- homepage = Page.find_by_permalink('Home')
- unless homepage.nil?
= render :partial => 'page_list_item', :locals => {:page => homepage, :level => 0, :siteMap => 1}
%tbody
- for page in @pages
- if page.id != homepage.try(:id)
= render :partial => 'page_list_item', :locals => {:page => page, :level => 0, :siteMap => 1}

View file

@ -0,0 +1,8 @@
%table.table.table-striped
%thead
%tr
%th= t 'pages.title'
%th= t 'pages.last_updated'
%tbody
- for page in @pages
= render :partial => "page_list_item", :locals => {:page => page, :level => 0, :siteMap => 0}

View file

@ -0,0 +1,17 @@
- title t('.title'), false
- content_for :sidebar do
= link_to t('.new_page'), new_page_path, class: 'btn btn-primary'
.navbar
.navbar-inner
%ul.nav
%li= link_to t('.recent_changes'), all_pages_path(:view => 'recent_changes')
%li= link_to t('.title_list'), all_pages_path(:view => 'title_list')
%li= link_to t('.site_map'), all_pages_path(:view => 'site_map')
= form_tag all_pages_path, method: :get, class: 'form-search pull-right' do
= text_field_tag :name, params[:name], class: 'input-medium search-query',
placeholder: t('.search.placeholder')
= submit_tag t('.search.action'), class: 'btn'
= render @partial

View file

@ -0,0 +1,3 @@
- title t('.title')
= render 'form'

View file

@ -0,0 +1,3 @@
- title t('.title')
= render 'form'

View file

@ -0,0 +1,51 @@
- title @page.title, false
- content_for :sidebar do
%p
= link_to edit_page_path(@page), class: 'btn btn-primary' do
%i.icon-edit= t '.edit'
.well.well-small
%ul.nav.nav-list
%li
%li= link_to t('.versions', count: @page.versions.count), "#versions", 'data-toggle-this' => '#versions'
- unless @page.children.empty?
%li= link_to t('.subpages'), "#subpages", 'data-toggle-this' => '#subpages'
#versions.well.well-small{:style => "display:none"}
%h3= t '.title_versions'
%ul.unstyled
- @page.versions.reverse.each do |version|
%li
= link_to I18n.l(version.updated_at, :format => t('.date_format')), version_page_path(@page, :version => version.lock_version)
= "(#{show_user(User.find_by_id(version.updated_by))})"
- unless @page.children.empty?
#subpages.well.well-small{:style => "display:none"}
%h3= t '.subpages'
%ul.unstyled
- @page.children.each do |page|
%li= link_to_wikipage(page)
%ul.breadcrumb
%li
= link_to_wikipage_by_permalink("Home", "Foodcoop-Wiki")
%span.divider /
- for page in @page.ancestors.reverse
%li
= link_to_wikipage(page)
%span.divider /
%li.active= @page.title
#wikiContent
.page-header
%h1= @page.title
= render :partial => 'body'
%hr.clear/
%p
= link_to edit_page_path(@page), class: 'btn btn-primary' do
%i.icon-edit= t '.edit'
= link_to t('.delete'), @page, class: 'btn btn-danger', :method => :delete,
:confirm => t('.delete_confirm')
!= '| ' + t('.last_updated', user: show_user(@page.user), when: format_datetime(@page.updated_at))

View file

@ -0,0 +1,11 @@
- title t('.title', title: @page.title, version: @version.lock_version)
- content_for :sidebar do
%h3= t '.title_version'
%b= "#{format_datetime_timespec(@version.updated_at, t('.date_format'))}"
%ul
%li= t '.author', user: show_user(User.find(@version.updated_by))
%li= link_to t('.view_current'), wiki_page_path(:permalink => @page.permalink)
%li= link_to t('.revert'), revert_page_path(@page, :version => @version.lock_version)
= wikified_body @version.body

View file

@ -0,0 +1,15 @@
Rails.application.routes.draw do
scope '/:foodcoop' do
resources :pages do
get :all, :on => :collection
get :version, :on => :member
get :revert, :on => :member
end
match '/wiki/:permalink' => 'pages#show', :as => 'wiki_page' # , :constraints => {:permalink => /[^\s]+/}
match '/wiki' => 'pages#show', :defaults => {:permalink => 'Home'}, :as => 'wiki'
end
end

View file

@ -0,0 +1,23 @@
class CreatePages < ActiveRecord::Migration
def self.up
create_table :pages do |t|
t.string :title
t.text :body
t.string :permalink
t.integer :lock_version, :default => 0
t.integer :updated_by
t.integer :redirect
t.integer :parent_id
t.timestamps
end
add_index :pages, :title
add_index :pages, :permalink
Page.create_versioned_table # Automaticly creates pages_versions table
end
def self.down
drop_table :pages
Page.drop_versioned_table
end
end

View file

@ -0,0 +1,24 @@
$:.push File.expand_path("../lib", __FILE__)
# Maintain your gem's version:
require "foodsoft_wiki/version"
# Describe your gem and declare its dependencies:
Gem::Specification.new do |s|
s.name = "foodsoft_wiki"
s.version = FoodsoftWiki::VERSION
s.authors = ["wvengen"]
s.email = ["dev-foodsoft@willem.engen.nl"]
s.homepage = "https://github.com/foodcoops/foodsoft"
s.summary = "Wiki plugin for foodsoft."
s.description = "Adds a wiki to foodsoft."
s.files = Dir["{app,config,db,lib}/**/*"] + ["Rakefile", "README.md"]
s.test_files = Dir["test/**/*"]
s.add_dependency "rails", "~> 3.2.15"
s.add_dependency 'wikicloth'
s.add_dependency 'acts_as_versioned' # need git version, make sure that is included in foodsoft's Gemfile
s.add_development_dependency "sqlite3"
end

View file

@ -0,0 +1,6 @@
require 'wikicloth'
require 'acts_as_versioned'
require 'foodsoft_wiki/engine'
module FoodsoftWiki
end

View file

@ -0,0 +1,14 @@
module FoodsoftWiki
class Engine < ::Rails::Engine
def navigation(primary, ctx)
primary.item :wiki, I18n.t('navigation.wiki.title'), '#', id: nil do |subnav|
subnav.item :wiki_home, I18n.t('navigation.wiki.home'), ctx.wiki_path, id: nil
subnav.item :all_pages, I18n.t('navigation.wiki.all_pages'), ctx.all_pages_path, id: nil
end
# move this last added item to just after the foodcoop menu
if i = primary.items.index(primary[:foodcoop])
primary.items.insert(i+1, primary.items.delete_at(-1))
end
end
end
end

View file

@ -0,0 +1,3 @@
module FoodsoftWiki
VERSION = "0.0.1"
end

View file

@ -1,5 +1,6 @@
begin
require 'rspec/core/rake_task'
task(:spec).clear
RSpec::Core::RakeTask.new(:spec)
task :default => :spec
rescue LoadError