• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

タグ
未設定

よく使われているワード(クリックで追加)

javaandroidc++linuxc#objective-ccocoa誰得qtrubybathyscaphegamephpguiwindows翻訳cpythonomegattwitterframeworkbtronarduinovb.net計画中(planning stage)directxpreviewertestゲームエンジンdom

コミットメタ情報

リビジョンcfbe4a169bf772504c85a5bcd675d0ce4f981c89 (tree)
日時2017-08-30 04:15:35
作者HMML <hmml3939@gmai...>
コミッターHMML

ログメッセージ

Change themes json formatting.

変更サマリ

差分

--- a/app/controllers/themes_controller.rb
+++ b/app/controllers/themes_controller.rb
@@ -8,6 +8,9 @@ class ThemesController < ApplicationController
88 @themes = @themes.where('name LIKE :q OR author LIKE :q OR short_desc LIKE :q', q: "%#{params[:q]}%")
99 end
1010 @themes = @themes.page(params[:page])
11+ if request.format == "json"
12+ @themes = @themes.per(5)
13+ end
1114 respond_with(@themes)
1215 end
1316
--- a/app/models/theme.rb
+++ b/app/models/theme.rb
@@ -5,13 +5,16 @@ class Theme < ApplicationRecord
55 attr_accessor :archive_update_required
66 enum day_frame: {white: '@builtin/white', black: '@builtin/black'}, _prefix: 'day_frame'
77
8- preview_opts = {
9- styles: {
10- p500: {geometry: '500x500>', format: 'png'},
11- p300: {geometry: '300x300>', format: 'png'},
12- p100: {geometry: '100x100>', format: 'png'},
13- },
14- }
8+ preview_opts = {styles: {}}
9+ %w(png webp).each do |fmt|
10+ [500, 300, 100].each do |size|
11+ preview_opts[:styles]["#{fmt}#{size}".to_sym] =
12+ {geometry: "#{size}x#{size}>", format: fmt}
13+ fmt == "webp" and
14+ preview_opts[:styles]["#{fmt}#{size}".to_sym][:convert_options] = "-quality 75"
15+ end
16+ end
17+
1518 4.times do |idx|
1619 has_attached_file "preview#{idx+1}", preview_opts
1720 end
--- a/app/views/themes/_theme.json.jbuilder
+++ b/app/views/themes/_theme.json.jbuilder
@@ -1,6 +1,14 @@
11 json.extract! theme, :id, :name, :short_desc, :author, :url,
22 :allow_orig_dl, :created_at, :updated_at, :license_cc, :license_pcl,
33 :license_yukari, :license_other, :license_other_url
4+4.times do |idx|
5+ if request.user_agent =~ /Android|Chrome/
6+ json.__send__ "preview#{idx+1}", asset_url(theme.public_send("preview#{idx+1}").url(:webp100))
7+ else
8+ json.__send__ "preview#{idx+1}", asset_url(theme.public_send("preview#{idx+1}").url(:png100))
9+ end
10+end
11+json.archive_digest theme.theme_archive_fingerprint
412 json.archive_url archive_theme_url(theme)
513 json.path theme_path(theme, format: :json)
614 json.theme_url theme_url(theme, format: :json)
--- a/app/views/themes/index.html.haml
+++ b/app/views/themes/index.html.haml
@@ -10,7 +10,7 @@
1010 .icons
1111 - 3.times do |idx|
1212 .day-frame.day-frame-80
13- = link_to image_tag(theme.public_send("preview#{idx+2}").url(:p100)), theme
13+ = link_to image_tag(theme.public_send("preview#{idx+2}").url(:png100)), theme
1414 .clearfix
1515 %h4= link_to theme.name, theme
1616 .author= link_to theme.author, theme
--- a/app/views/themes/index.json.jbuilder
+++ b/app/views/themes/index.json.jbuilder
@@ -1 +1,5 @@
1-json.array! @themes, partial: 'themes/theme', as: :theme
1+json.themes @themes, partial: 'themes/theme', as: :theme
2+json.extract! @themes, :total_pages, :current_page, :total_count
3+json.is_first_page @themes.first_page?
4+json.is_last_page @themes.last_page?
5+json.per_page @themes.limit_value
--- a/config/application.rb
+++ b/config/application.rb
@@ -17,6 +17,7 @@ module MmwPsh
1717 # Settings in config/environments/* take precedence over those specified here.
1818 # Application configuration should go into files in config/initializers
1919 # -- all .rb files in that directory are automatically loaded.
20+ config.middleware.use Rack::ContentLength
2021
2122 config.time_zone = 'UTC'
2223