Merge pull request #194 from foodcoop-adam/plugin-move

Better support for plugins (engines) + move wiki to plugin
This commit is contained in:
wvengen 2013-11-12 03:46:15 -08:00
commit bb5a67033d
36 changed files with 185 additions and 37 deletions

View file

@ -48,6 +48,9 @@ class OrdersController < ApplicationController
end
send_data pdf.to_pdf, filename: pdf.filename, type: 'application/pdf'
end
format.text do
send_data text_fax_template, filename: @order.name+'.txt', type: 'text/plain'
end
end
end
@ -101,12 +104,14 @@ class OrdersController < ApplicationController
rescue => error
redirect_to orders_url, alert: I18n.t('errors.general_msg', :msg => error.message)
end
protected
# Renders the fax-text-file
# e.g. for easier use with online-fax-software, which don't accept pdf-files
# TODO move to text template
def text_fax_template
order = Order.find(params[:id])
supplier = order.supplier
supplier = @order.supplier
contact = FoodsoftConfig[:contact].symbolize_keys
text = I18n.t('orders.fax.heading', :name => FoodsoftConfig[:name])
text += "\n#{Supplier.human_attribute_name(:customer_number)}: #{supplier.customer_number}" unless supplier.customer_number.blank?
@ -117,15 +122,13 @@ class OrdersController < ApplicationController
text += "****** " + I18n.t('orders.fax.articles') + "\n\n"
text += I18n.t('orders.fax.number') + " " + I18n.t('orders.fax.amount') + " " + I18n.t('orders.fax.name') + "\n"
# now display all ordered articles
order.order_articles.ordered.all(:include => [:article, :article_price]).each do |oa|
@order.order_articles.ordered.all(:include => [:article, :article_price]).each do |oa|
number = oa.article.order_number
(8 - number.size).times { number += " " }
quantity = oa.units_to_order.to_i.to_s
quantity = " " + quantity if quantity.size < 2
text += "#{number} #{quantity} #{oa.article.name}\n"
end
send_data text,
:type => 'text/plain; charset=utf-8; header=present',
:disposition => "attachment; filename=#{order.name}"
text
end
end

View file

@ -1,130 +0,0 @@
# 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

@ -1,59 +0,0 @@
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

@ -1,56 +0,0 @@
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

@ -17,7 +17,6 @@ class User < ActiveRecord::Base
has_many :assignments, :dependent => :destroy
has_many :tasks, :through => :assignments
has_many :send_messages, :class_name => "Message", :foreign_key => "sender_id"
has_many :pages, :foreign_key => 'updated_by'
has_many :created_orders, :class_name => 'Order', :foreign_key => 'created_by_user_id', :dependent => :nullify
attr_accessor :password, :settings_attributes

View file

@ -1,3 +1,3 @@
%tr.edit_inline{:id=> "edit_"+@article.id.to_s}
%td{:colspan=>"10"}
= t('.note', article: h(@article.name), drop_link: link_to(t('.drop'), :controller => 'orders', :action => 'edit', :id => @order)).html_safe
= t('.note', article: h(@article.name), drop_link: link_to(t('.drop'), edit_order_path(@order))).html_safe

View file

@ -4,7 +4,7 @@
%li.nav-header= t '.foodcoop'
%li= link_to t('.members'), foodcoop_users_path
%li= link_to t('.tasks'), user_tasks_path
%li= link_to t('.write_message'), :controller => "messages", :action => "new"
%li= link_to t('.write_message'), new_message_path
- has_ordergroup = !@current_user.ordergroup.nil?
- has_orders_role = @current_user.role_orders?

View file

@ -5,7 +5,7 @@
%h3
= h(t('.user.title', user: @current_user.nick))
%small= t '.user.since', when: distance_of_time_in_words(Time.now, @current_user.created_on)
= simple_form_for(@current_user, :url => { :action => 'update_profile'}) do |f|
= simple_form_for(@current_user, :url => update_profile_path) do |f|
= render :partial => 'shared/user_form_fields', :locals => {:f => f}
.form-actions
= submit_tag t('ui.save'), class: 'btn'

View file

@ -1,6 +1,6 @@
- title t('.title')
= t('.body').html_safe
= simple_form_for User.new, url: {action: 'reset_password'} do |form|
= simple_form_for User.new, url: reset_password_path do |form|
= form.input :email
.form-actions
= form.submit t('.submit'), class: 'btn'

View file

@ -1,6 +1,6 @@
- title t('.title')
= t('.body', user: h(@user.nick)).html_safe
= simple_form_for @user, :url => {:action => 'update_password', :id => @user.id, :token => @user.reset_password_token} do |form|
= simple_form_for @user, :url => update_password_path(@user.id, :token => @user.reset_password_token) do |form|
= form.input :password
= form.input :password_confirmation
.form-actions

View file

@ -50,7 +50,7 @@
%li= order_pdf(@order, :articles, t('.download.article_pdf'))
%li= order_pdf(@order, :matrix, t('.download.matrix_pdf'))
%li= order_pdf(@order, :fax, t('.download.fax_pdf'))
%li= link_to t('.download.fax_txt'), {action: 'text_fax_template', id: @order }, {title: t('.download.download_file')}
%li= link_to t('.download.fax_txt'), order_path(@order, format: :txt), {title: t('.download.download_file')}
%section#articles_table
= render 'articles', order: @order

View file

@ -1,9 +0,0 @@
- 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

@ -1,85 +0,0 @@
- 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

@ -1,8 +0,0 @@
-ident = 20 * level
%tr
%td{:style => "padding-left: #{ident}px"}
= link_to page.title, wiki_page_path(page.permalink)
%td #{page.user.try(:nick)} (#{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

@ -1,8 +0,0 @@
%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

@ -1,12 +0,0 @@
%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

@ -1,8 +0,0 @@
%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

@ -1,17 +0,0 @@
- 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

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

View file

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

View file

@ -1,51 +0,0 @@
- 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)
= "(#{User.find_by_id(version.updated_by).try(:nick)})"
- 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: h(@page.user.try(:nick)), when: format_datetime(@page.updated_at))

View file

@ -1,11 +0,0 @@
- 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: User.find(@version.updated_by).nick
%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

@ -13,5 +13,5 @@
- @tasks.each do |task|
%tr
%td= task.due_date unless task.due_date.nil?
%td= link_to t('.task_format', name: task.name, duration: task.duration), :controller => "tasks", :action => "show", :id => task
%td= link_to t('.task_format', name: task.name, duration: task.duration), task_path(task)
%td= task_assignments task