chore: rubocop
chore: fix api test conventions chore: rubocop -A spec/ chore: more rubocop -A fix failing test rubocop fixes removes helper methods that are in my opinion dead code more rubocop fixes rubocop -a --auto-gen-config
This commit is contained in:
parent
f6fb804bbe
commit
fb2b4d8a8a
331 changed files with 4263 additions and 4507 deletions
|
|
@ -1,20 +1,20 @@
|
|||
class PagesController < ApplicationController
|
||||
before_action -> { require_plugin_enabled FoodsoftWiki }
|
||||
before_action :catch_special_pages, only: [:show, :new]
|
||||
before_action :catch_special_pages, only: %i[show new]
|
||||
|
||||
skip_before_action :authenticate, :only => :all
|
||||
before_action :only => :all do
|
||||
authenticate_or_token(['wiki', 'all'])
|
||||
skip_before_action :authenticate, only: :all
|
||||
before_action only: :all do
|
||||
authenticate_or_token(%w[wiki all])
|
||||
end
|
||||
before_action do
|
||||
content_for :head, view_context.rss_meta_tag
|
||||
end
|
||||
|
||||
def index
|
||||
@page = Page.find_by_permalink "Home"
|
||||
@page = Page.find_by_permalink 'Home'
|
||||
|
||||
if @page
|
||||
render :action => 'show'
|
||||
render action: 'show'
|
||||
else
|
||||
redirect_to all_pages_path
|
||||
end
|
||||
|
|
@ -34,11 +34,11 @@ class PagesController < ApplicationController
|
|||
end
|
||||
|
||||
if @page.nil?
|
||||
redirect_to new_page_path(:title => params[:permalink])
|
||||
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)
|
||||
flash[:notice] = I18n.t('pages.cshow.redirect_notice', page: @page.title)
|
||||
redirect_to wiki_page_path(page.permalink)
|
||||
end
|
||||
end
|
||||
|
|
@ -46,12 +46,12 @@ class PagesController < ApplicationController
|
|||
|
||||
def new
|
||||
@page = Page.new
|
||||
@page.title = params[:title].gsub("_", " ") if params[:title]
|
||||
@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 }
|
||||
format.xml { render xml: @page }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -60,36 +60,32 @@ class PagesController < ApplicationController
|
|||
end
|
||||
|
||||
def create
|
||||
@page = Page.new(params[:page].merge({ :user => current_user }))
|
||||
@page = Page.new(params[:page].merge({ user: current_user }))
|
||||
|
||||
if params[:preview]
|
||||
render :action => 'new'
|
||||
render action: 'new'
|
||||
elsif @page.save
|
||||
flash[:notice] = I18n.t('pages.create.notice')
|
||||
redirect_to(wiki_page_path(@page.permalink))
|
||||
else
|
||||
if @page.save
|
||||
flash[:notice] = I18n.t('pages.create.notice')
|
||||
redirect_to(wiki_page_path(@page.permalink))
|
||||
else
|
||||
render :action => "new"
|
||||
end
|
||||
render action: 'new'
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
@page = Page.find(params[:id])
|
||||
@page.attributes = params[:page].merge({ :user => current_user })
|
||||
@page.attributes = params[:page].merge({ user: current_user })
|
||||
|
||||
if params[:preview]
|
||||
@page.attributes = params[:page]
|
||||
render :action => 'edit'
|
||||
render action: 'edit'
|
||||
elsif @page.save
|
||||
@page.parent_id = parent_id if params[:parent_id].present? \
|
||||
&& params[:parent_id] != @page_id
|
||||
flash[:notice] = I18n.t('pages.update.notice')
|
||||
redirect_to wiki_page_path(@page.permalink)
|
||||
else
|
||||
if @page.save
|
||||
@page.parent_id = parent_id if (!params[:parent_id].blank? \
|
||||
&& params[:parent_id] != @page_id)
|
||||
flash[:notice] = I18n.t('pages.update.notice')
|
||||
redirect_to wiki_page_path(@page.permalink)
|
||||
else
|
||||
render :action => "edit"
|
||||
end
|
||||
render action: 'edit'
|
||||
end
|
||||
rescue ActiveRecord::StaleObjectError
|
||||
flash[:error] = I18n.t('pages.error_stale_object')
|
||||
|
|
@ -100,7 +96,7 @@ class PagesController < ApplicationController
|
|||
@page = Page.find(params[:id])
|
||||
@page.destroy
|
||||
|
||||
flash[:notice] = I18n.t('pages.destroy.notice', :page => @page.title)
|
||||
flash[:notice] = I18n.t('pages.destroy.notice', page: @page.title)
|
||||
redirect_to wiki_path
|
||||
end
|
||||
|
||||
|
|
@ -109,23 +105,23 @@ class PagesController < ApplicationController
|
|||
@partial = params[:view] || 'site_map'
|
||||
|
||||
if params[:name]
|
||||
@pages = @pages.where("title LIKE ?", "%#{params[:name]}%").limit(20)
|
||||
@pages = @pages.where('title LIKE ?', "%#{params[:name]}%").limit(20)
|
||||
@partial = 'title_list'
|
||||
end
|
||||
if params[:sort]
|
||||
sort = case params[:sort]
|
||||
when "title" then "title"
|
||||
when "title_reverse" then "title DESC"
|
||||
when "last_updated" then "updated_at DESC"
|
||||
when "last_updated_reverse" then "updated_at"
|
||||
sort = if params[:sort]
|
||||
case params[:sort]
|
||||
when 'title' then 'title'
|
||||
when 'title_reverse' then 'title DESC'
|
||||
when 'last_updated' then 'updated_at DESC'
|
||||
when 'last_updated_reverse' then 'updated_at'
|
||||
end
|
||||
else
|
||||
sort = "title"
|
||||
end
|
||||
else
|
||||
'title'
|
||||
end
|
||||
@pages = @pages.order(sort)
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.rss { render :layout => false }
|
||||
format.rss { render layout: false }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -150,15 +146,15 @@ class PagesController < ApplicationController
|
|||
|
||||
def variables
|
||||
keys = Foodsoft::ExpansionVariables.variables.keys
|
||||
@variables = Hash[keys.map { |k| [k, Foodsoft::ExpansionVariables.get(k)] }]
|
||||
@variables = keys.index_with { |k| Foodsoft::ExpansionVariables.get(k) }
|
||||
render 'variables'
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def catch_special_pages
|
||||
if params[:id] == 'Help:Foodsoft_variables'
|
||||
variables
|
||||
end
|
||||
return unless params[:id] == 'Help:Foodsoft_variables'
|
||||
|
||||
variables
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,70 +2,70 @@ module PagesHelper
|
|||
include WikiCloth
|
||||
|
||||
def rss_meta_tag
|
||||
tag.link(rel: "alternate", type: "application/rss+xml", title: "RSS", href: all_pages_rss_url).html_safe
|
||||
tag.link(rel: 'alternate', type: 'application/rss+xml', title: 'RSS', href: all_pages_rss_url).html_safe
|
||||
end
|
||||
|
||||
def wikified_body(body, title = nil)
|
||||
FoodsoftWiki::WikiParser.new(data: body + "\n", params: { referer: title }).to_html(noedit: true).html_safe
|
||||
rescue => e
|
||||
rescue StandardError => e
|
||||
# try the following with line breaks: === one === == two == = three =
|
||||
content_tag :span, class: 'alert alert-error' do
|
||||
I18n.t '.wikicloth_exception', :msg => e
|
||||
I18n.t '.wikicloth_exception', msg: e
|
||||
end.html_safe
|
||||
end
|
||||
|
||||
def link_to_wikipage(page, text = nil)
|
||||
if text == nil
|
||||
link_to page.title, wiki_page_path(:permalink => page.permalink)
|
||||
if text.nil?
|
||||
link_to page.title, wiki_page_path(permalink: page.permalink)
|
||||
else
|
||||
link_to text, wiki_page_path(:permalink => page.permalink)
|
||||
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
|
||||
return if 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_wikipage(page, text)
|
||||
link_to text, new_page_path(title: permalink)
|
||||
end
|
||||
else
|
||||
link_to_wikipage(page, text)
|
||||
end
|
||||
end
|
||||
|
||||
def generate_toc(body)
|
||||
toc = String.new
|
||||
body.gsub(/^([=]{1,6})\s*(.*?)\s*(\1)/) do
|
||||
number = $1.length - 1
|
||||
name = $2
|
||||
body.gsub(/^(={1,6})\s*(.*?)\s*(\1)/) do
|
||||
number = ::Regexp.last_match(1).length - 1
|
||||
name = ::Regexp.last_match(2)
|
||||
|
||||
toc << "*" * number + " #{name}\n"
|
||||
toc << (('*' * number) + " #{name}\n")
|
||||
end
|
||||
|
||||
unless toc.blank?
|
||||
FoodsoftWiki::WikiParser.new(data: toc).to_html.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
|
||||
return if toc.blank?
|
||||
|
||||
FoodsoftWiki::WikiParser.new(data: toc).to_html.gsub(/<li>([^<>\n]*)/) do
|
||||
name = ::Regexp.last_match(1)
|
||||
anchor = name.gsub(/\s/, '_').gsub(/[^a-zA-Z_]/, '')
|
||||
"<li><a href='##{anchor}'>#{name.truncate(20)}</a>"
|
||||
end.html_safe
|
||||
end
|
||||
|
||||
def parent_pages_to_select(current_page)
|
||||
unless current_page.homepage? # Homepage is the page trees root!
|
||||
if current_page.homepage?
|
||||
[]
|
||||
else # Homepage is the page trees root!
|
||||
Page.non_redirected.reject { |p| p == current_page || p.ancestors.include?(current_page) }
|
||||
else
|
||||
Array.new
|
||||
end
|
||||
end
|
||||
|
||||
# return url for all_pages rss feed
|
||||
def all_pages_rss_url(options = {})
|
||||
token = TokenVerifier.new(['wiki', 'all']).generate
|
||||
all_pages_url({ :format => 'rss', :token => token }.merge(options))
|
||||
token = TokenVerifier.new(%w[wiki all]).generate
|
||||
all_pages_url({ format: 'rss', token: token }.merge(options))
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,61 +1,62 @@
|
|||
class Page < ApplicationRecord
|
||||
include ActsAsTree
|
||||
|
||||
belongs_to :user, :foreign_key => 'updated_by'
|
||||
belongs_to :user, foreign_key: 'updated_by'
|
||||
|
||||
acts_as_versioned version_column: :lock_version
|
||||
self.non_versioned_columns += %w(permalink created_at title)
|
||||
self.non_versioned_columns += %w[permalink created_at title]
|
||||
|
||||
acts_as_tree :order => "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
|
||||
before_validation :set_permalink, on: :create
|
||||
before_validation :update_permalink, on: :update
|
||||
after_update :create_redirect
|
||||
|
||||
scope :non_redirected, -> { where(:redirect => nil) }
|
||||
scope :no_parent, -> { where(:parent_id => nil) }
|
||||
scope :non_redirected, -> { where(redirect: nil) }
|
||||
scope :no_parent, -> { where(parent_id: nil) }
|
||||
|
||||
def self.permalink(title)
|
||||
title.gsub(/[\/\.,;@\s]/, "_").gsub(/[\"\']/, "")
|
||||
title.gsub(%r{[/.,;@\s]}, '_').gsub(/["']/, '')
|
||||
end
|
||||
|
||||
def homepage?
|
||||
permalink == "Home"
|
||||
permalink == 'Home'
|
||||
end
|
||||
|
||||
def self.dashboard
|
||||
where(permalink: "Dashboard").first
|
||||
where(permalink: 'Dashboard').first
|
||||
end
|
||||
|
||||
def self.public_front_page
|
||||
where(permalink: "Public_frontpage").first
|
||||
where(permalink: 'Public_frontpage').first
|
||||
end
|
||||
|
||||
def self.welcome_mail
|
||||
where(permalink: "Welcome_mail").first
|
||||
where(permalink: 'Welcome_mail').first
|
||||
end
|
||||
|
||||
def set_permalink
|
||||
unless title.blank?
|
||||
self.permalink = Page.count == 0 ? "Home" : Page.permalink(title)
|
||||
end
|
||||
return if title.blank?
|
||||
|
||||
self.permalink = Page.count == 0 ? 'Home' : Page.permalink(title)
|
||||
end
|
||||
|
||||
def diff
|
||||
current = versions.latest
|
||||
old = versions.where(["page_id = ? and lock_version < ?", current.page_id, current.lock_version]).order('lock_version DESC').first
|
||||
old = versions.where(['page_id = ? and lock_version < ?', current.page_id,
|
||||
current.lock_version]).order('lock_version DESC').first
|
||||
|
||||
if old
|
||||
o = ''
|
||||
Diffy::Diff.new(old.body, current.body).each do |line|
|
||||
case line
|
||||
when /^\+/ then o += "#{line.chomp}<br />" unless line.chomp == "+"
|
||||
when /^-/ then o += "#{line.chomp}<br />" unless line.chomp == "-"
|
||||
when /^\+/ then o += "#{line.chomp}<br />" unless line.chomp == '+'
|
||||
when /^-/ then o += "#{line.chomp}<br />" unless line.chomp == '-'
|
||||
end
|
||||
end
|
||||
o
|
||||
|
|
@ -67,19 +68,19 @@ class Page < ApplicationRecord
|
|||
protected
|
||||
|
||||
def update_permalink
|
||||
if changed.include?("title")
|
||||
set_permalink
|
||||
self.old_title = changes["title"].first # Save title for creating redirect
|
||||
end
|
||||
return unless changed.include?('title')
|
||||
|
||||
set_permalink
|
||||
self.old_title = changes['title'].first # Save title for creating redirect
|
||||
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
|
||||
return if 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
|
||||
|
|
|
|||
|
|
@ -1,16 +1,16 @@
|
|||
xml.instruct! :xml, :version => "1.0"
|
||||
xml.rss :version => "2.0" do
|
||||
xml.instruct! :xml, version: '1.0'
|
||||
xml.rss version: '2.0' do
|
||||
xml.channel do
|
||||
xml.title FoodsoftConfig[:name] + " Wiki"
|
||||
xml.description ""
|
||||
xml.title FoodsoftConfig[:name] + ' Wiki'
|
||||
xml.description ''
|
||||
xml.link FoodsoftConfig[:homepage]
|
||||
|
||||
for page in @pages
|
||||
xml.item do
|
||||
xml.title page.title
|
||||
xml.description page.diff, :type => "html"
|
||||
xml.description page.diff, type: 'html'
|
||||
xml.author User.find_by_id(page.updated_by).try(:display)
|
||||
xml.pubDate page.updated_at.to_s(:rfc822)
|
||||
xml.pubDate page.updated_at.to_fs(:rfc822)
|
||||
xml.link wiki_page_path(page.permalink)
|
||||
xml.guid page.updated_at.to_i
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue