mirror of
https://github.com/ENSL/ensl.org.git
synced 2024-12-27 13:01:02 +00:00
24eabf89e6
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
66 lines
No EOL
1.4 KiB
Ruby
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 |