diff --git a/db/migrations/015_bingo_about.rb b/db/migrations/015_bingo_about.rb new file mode 100644 index 0000000..32ae7f2 --- /dev/null +++ b/db/migrations/015_bingo_about.rb @@ -0,0 +1,7 @@ +Sequel.migration do + change do + # Optional prose for the datacenter page, per locale. No fallback to ru: + # Russian text on the en page would be worse than none. + %w[ru en uk].each { |l| add_column :bingo_datacenters, :"about_#{l}", String, text: true } + end +end diff --git a/lib/bingo.rb b/lib/bingo.rb index 0b052b5..050f2d7 100644 --- a/lib/bingo.rb +++ b/lib/bingo.rb @@ -143,6 +143,11 @@ module Bingo key.delete_prefix(Photo::PREFIX) end + # Paragraphs of the datacenter page's prose in exactly this locale. + def about(locale) + self[:"about_#{locale}"].to_s.strip.split(/\n\s*\n/).map(&:strip) + end + # 1200x630 JPEG for og:image (every preview client renders it); the # webp dialog variant until it exists. def og_file diff --git a/lib/bingo_admin.rb b/lib/bingo_admin.rb index e010bbe..9be3839 100644 --- a/lib/bingo_admin.rb +++ b/lib/bingo_admin.rb @@ -4,7 +4,7 @@ require 'uri' # Registered into AsxpioWeb, so AdminAuth (HTTP Basic) and CSRF apply. module BingoAdmin DC_TEXT = %w[name_ru name_en name_uk city_ru city_en city_uk operator mw mw_type status - photo_credit photo_source_url info_url].freeze + photo_credit photo_source_url info_url about_ru about_en about_uk].freeze module Helpers def bingo_public_url diff --git a/test/bingo_test.rb b/test/bingo_test.rb index 1bf0232..8699fd4 100644 --- a/test/bingo_test.rb +++ b/test/bingo_test.rb @@ -252,6 +252,16 @@ class BingoTest < Minitest::Test refute_includes last_response.body, 'rel="prev"' end + def test_dc_about_text + @app = AsxpioWeb + token = admin_token("/admin/bingo/dc/#{@dcs[1].id}") + post "/admin/bingo/dc/#{@dcs[1].id}", dc_params(authenticity_token: token, about_en: "First para.\r\n\r\nSecond."), admin_env + assert_equal "First para.\r\n\r\nSecond.", @dcs[1].refresh.about_en + public = Rack::MockRequest.new(BingoWeb) # rack-test's session is bound to AsxpioWeb now + assert_includes public.get('/en/dc/dc-2').body, '

First <b>para</b>.

Second.

' + refute_includes public.get('/ru/dc/dc-2').body, 'Second.' # no fallback across languages + end + def test_reserve_dc_has_a_page Bingo::Datacenter.create(slug: 'dc-26', position: 26, name_ru: 'ЦОД 26', city_ru: 'Тверь', operator: 'Op') get '/ru/dc/dc-26' diff --git a/views/admin/bingo/edit.erb b/views/admin/bingo/edit.erb index d70e03d..a37c7f6 100644 --- a/views/admin/bingo/edit.erb +++ b/views/admin/bingo/edit.erb @@ -65,6 +65,9 @@
+ <% %w[ru en uk].each do |l| %> +
+ <% end %> <% if can?('bingo', 'write') %><% end %> diff --git a/views/bingo/dc.erb b/views/bingo/dc.erb index 5beced5..f1b10c6 100644 --- a/views/bingo/dc.erb +++ b/views/bingo/dc.erb @@ -14,6 +14,7 @@

<%= dc.l(:name, @locale) %>

<%== erb :_dc_meta, layout: false, locals: { dc: dc } %>

<%= dc_facts(dc).join(' ') %>

+ <% dc.about(@locale).each do |para| %>

<%= para %>

<% end %>

<%= t(:incidents) %>

<%== erb :_dc_incidents, layout: false, locals: { dc: dc } %>