auto indent

This commit is contained in:
EricTYL 2019-11-05 14:07:59 +08:00
parent 710661a3fb
commit 809a9fa3b9
1 changed files with 57 additions and 56 deletions

View File

@ -17,45 +17,45 @@ class GalleriesController < ApplicationController
tags << tag0 tags << tag0
tags << tag1 tags << tag1
end end
def index
albums = Album.filter_by_categories.filter_by_tags.asc(:order) def index
galleries = albums.collect do |a| albums = Album.filter_by_categories.filter_by_tags.asc(:order)
doc = Nokogiri::HTML(a.description.to_s) galleries = albums.collect do |a|
alt_text = doc.text.empty? ? 'gallery image' : doc.text doc = Nokogiri::HTML(a.description.to_s)
{ alt_text = doc.text.empty? ? 'gallery image' : doc.text
"album-name" => a.name, {
"album-description" => a.description, "album-name" => a.name,
"alt_title" => alt_text, "album-description" => a.description,
"link_to_show" => OrbitHelper.url_to_show(a.to_param), "alt_title" => alt_text,
"thumb-src" => a.cover_path || "/assets/gallery/default.jpg" "link_to_show" => OrbitHelper.url_to_show(a.to_param),
} "thumb-src" => a.cover_path || "/assets/gallery/default.jpg"
end }
end
{ {
"albums" => galleries, "albums" => galleries,
"extras" => {"widget-title"=>"Gallery"}, "extras" => {"widget-title"=>"Gallery"},
"total_pages" => albums.total_pages "total_pages" => albums.total_pages
} }
end end
def show def show
params = OrbitHelper.params params = OrbitHelper.params
album = Album.find_by_param(params[:uid]) album = Album.find_by_param(params[:uid])
flag = show_desc? flag = show_desc?
images = album.album_images.asc(:order).collect do |a| images = album.album_images.asc(:order).collect do |a|
alt_text = (a.description.nil? || a.description == "" ? "gallery image" : a.description) alt_text = (a.description.nil? || a.description == "" ? "gallery image" : a.description)
{ {
"image-description" => a.description, "image-description" => a.description,
"alt_title" => alt_text, "alt_title" => alt_text,
"link_to_show" => "/xhr/galleries/theater/" + a.id.to_s, "link_to_show" => "/xhr/galleries/theater/" + a.id.to_s,
"thumb-src" => a.file.thumb.url "thumb-src" => a.file.thumb.url
}
end
{
"images" => images,
"data" => {"album-title"=>album.name,
"album-description" => (flag ? "<p><span>#{album.description}</span></p>" : "")}
} }
end
{
"images" => images,
"data" => {"album-title"=>album.name,
"album-description" => (flag ? "<p><span>#{album.description}</span></p>" : "")}
}
end end
def widget def widget
@ -108,15 +108,15 @@ class GalleriesController < ApplicationController
images = album.album_images.asc(:order) images = album.album_images.asc(:order)
output = Array.new output = Array.new
images.each do |values| images.each do |values|
alt_text = (values.description.nil? || values.description == "" ? "gallery image" : values.description) alt_text = (values.description.nil? || values.description == "" ? "gallery image" : values.description)
output << { _id: values.id.to_s, output << { _id: values.id.to_s,
description: values.description, description: values.description,
title: values.title, title: values.title,
alt_title: alt_text, alt_title: alt_text,
url: values.file.url, url: values.file.url,
file: values.file.as_json[:file], file: values.file.as_json[:file],
gallery_album_id: values.album_id, gallery_album_id: values.album_id,
tags: values.tags} tags: values.tags}
end end
return output return output
end end
@ -126,28 +126,29 @@ class GalleriesController < ApplicationController
albumid = image.album_id albumid = image.album_id
album = Album.find(albumid) album = Album.find(albumid)
images = album.album_images.asc(:order) images = album.album_images.asc(:order)
data = { data = {
"album" => album, "album" => album,
"image" => image.id.to_s, "image" => image.id.to_s,
"images" => imgs(albumid) "images" => imgs(albumid)
} }
render :json => {"data" => data}.to_json
render :json => {"data" => data}.to_json
end end
private private
def show_desc?
tags = OrbitHelper.page_tags if tags.blank? def show_desc?
tags = [tags].flatten.uniq tags = OrbitHelper.page_tags if tags.blank?
tags = [tags].flatten.uniq
flag = true
tag_temp = Tag.all.select{|value| tags.include? value.id.to_s}
tag_temp_length = 0
tag_temp.each do |value|
if value.name==I18n.t('gallery.show_desc')
flag = true flag = true
tag_temp = Tag.all.select{|value| tags.include? value.id.to_s} elsif value.name==I18n.t('gallery.not_show_desc')
tag_temp_length = 0 flag = false
tag_temp.each do |value| end
if value.name==I18n.t('gallery.show_desc')
flag = true
elsif value.name==I18n.t('gallery.not_show_desc')
flag = false
end
end
flag
end end
flag
end
end end