ensl.org/lib/extra.rb
Luke Barratt 24eabf89e6 Changed newrelic configuration to load from environment variables
Changed login field text
Changed database configuration connection pool size to be configured via dotenv
Use a single BBcode parser library
Added better translations coverage
Code formatting
Increases maximum article text limit
Added database cleaner with the deletion strategy during testing
2014-03-30 20:50:52 +01:00

66 lines
No EOL
1.4 KiB
Ruby

module Extra
CODING_HTML = 0
CODING_BBCODE = 1
CODING_MARKDOWN = 2
def check_params params, filter
(params.instance_of?(Array) ? params : params.keys).each do |key|
return false unless filter.include? key.to_sym
end
return true
end
def error_messages
self.errors.full_messages.uniq
end
def codings
{CODING_HTML => "Plain HTML", CODING_BBCODE => "BBCode", CODING_MARKDOWN => "Markdown"}
end
def bbcode_to_html(text)
Sanitize.clean(text.to_s).bbcode_to_html.gsub(/\n|\r\n/, "<br />").html_safe
end
def move_up scope, column = "position"
n = 0
objects = self.class.all :conditions => scope, :order => column
objects.each do |item|
if item.id == id and n > 0
old_position = item.read_attribute :column
item.update_attribute column, objects.fetch(n-1).read_attribute(:column)
objects.fetch(n-1).update_attribute column, old_position
end
n = n + 1
end
end
def move_down scope, column = "position"
n = 0
objects = self.class.all :conditions => scope, :order => column
objects.each do |item|
if item.id == id and n < (objects.length-1)
old_position = item.read_attribute :column
item.update_attribute column, objects.fetch(n+1).read_attribute(:column)
objects.fetch(n+1).update_attribute column, old_position
end
n = n + 1
end
end
def can_show? cuser
true
end
def can_create? cuser
true
end
def can_update? cuser
true
end
def can_destroy? cuser
true
end
end