You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
723 B
32 lines
723 B
3 years ago
|
def get_random_subtitle
|
||
|
subtitles = File.readlines "misc/subtitles.txt"
|
||
|
subtitles.sample.chomp
|
||
|
end
|
||
3 years ago
|
|
||
3 years ago
|
def is_logged_in
|
||
|
session[:userid] != nil
|
||
3 years ago
|
end
|
||
|
|
||
3 years ago
|
def get_current_user
|
||
3 years ago
|
session[:userid] && User.find_by_id(session[:userid])
|
||
|
end
|
||
|
|
||
|
# Serve templates
|
||
3 years ago
|
def serve(template, locals={}, layout: :layout)
|
||
3 years ago
|
locals[:session_user] = get_current_user unless !is_logged_in
|
||
3 years ago
|
|
||
3 years ago
|
# Serve the slim template
|
||
3 years ago
|
status session[:status] if session[:status]
|
||
|
session.delete :status
|
||
3 years ago
|
slim(template, locals: locals, :layout => layout)
|
||
3 years ago
|
end
|
||
3 years ago
|
|
||
|
# Save image
|
||
3 years ago
|
def save_image imgdata, path
|
||
|
image = Magick::Image.from_blob(imgdata).first
|
||
|
image.format = "PNG"
|
||
|
File.open(path, 'wb') do |f|
|
||
3 years ago
|
image.resize_to_fill(AVATAR_SIZE, AVATAR_SIZE).write(f)
|
||
3 years ago
|
end
|
||
|
end
|