mirror of
https://github.com/projekteuler/projekteuler.git
synced 2025-12-10 08:46:41 +01:00
Merge pull request #79 from projekteuler/translation_styling
Allow translation content styling through scrubber
This commit is contained in:
commit
9b46f9bcc5
13
app/scrubbers/translation_content_scrubber.rb
Normal file
13
app/scrubbers/translation_content_scrubber.rb
Normal file
@ -0,0 +1,13 @@
|
||||
class TranslationContentScrubber < Rails::Html::PermitScrubber
|
||||
def initialize
|
||||
super
|
||||
self.tags = %w( strong em b i p code pre tt samp kbd var sub
|
||||
sup dfn cite big small address hr br div span h1 h2 h3 h4 h5 h6 ul ol li dl dt dd abbr
|
||||
acronym a img blockquote del ins )
|
||||
self.attributes = %w( href src width height alt cite datetime title class name xml:lang abbr style )
|
||||
end
|
||||
|
||||
def skip_node?(node)
|
||||
node.text?
|
||||
end
|
||||
end
|
||||
@ -23,7 +23,7 @@
|
||||
|
||||
<%= panel do %>
|
||||
<div class="panel-body problem-content">
|
||||
<%= sanitize @translation.content %>
|
||||
<%= sanitize @translation.content, scrubber: TranslationContentScrubber.new %>
|
||||
</div>
|
||||
<% end %>
|
||||
<div class="text-center">
|
||||
|
||||
@ -11,7 +11,7 @@
|
||||
<% end %>
|
||||
<%= panel do %>
|
||||
<div class="panel-body problem-content">
|
||||
<%= sanitize @problem.content %>
|
||||
<%= sanitize @problem.content, scrubber: TranslationContentScrubber.new %>
|
||||
</div>
|
||||
<% end %>
|
||||
<div class="text-center">
|
||||
|
||||
@ -27,9 +27,9 @@ class Admin::DashboardControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
test "should fail incorrect problem count" do
|
||||
login_admin
|
||||
post admin_dashboard_update_problem_count_url(problem_count: 2)
|
||||
post admin_dashboard_update_problem_count_url(problem_count: 3)
|
||||
assert_redirected_to admin_dashboard_index_url
|
||||
assert_equal 3, Problem.count
|
||||
assert_equal 4, Problem.count
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@ -22,4 +22,12 @@ class ProblemsControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_redirected_to problem_path(id: 2)
|
||||
end
|
||||
|
||||
test "should contain HTML styles in translation content" do
|
||||
get problem_url(id: 4)
|
||||
assert_response :success
|
||||
assert_select ".problem-content" do
|
||||
assert_select "b", 1
|
||||
assert_select 'p[style="text-align:center;"]', 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
4
test/fixtures/problems.yml
vendored
4
test/fixtures/problems.yml
vendored
@ -11,3 +11,7 @@ two:
|
||||
three:
|
||||
id: 3
|
||||
|
||||
four:
|
||||
id: 4
|
||||
translation: translation_with_html
|
||||
|
||||
|
||||
6
test/fixtures/translations.yml
vendored
6
test/fixtures/translations.yml
vendored
@ -17,3 +17,9 @@ translation_two_alternative:
|
||||
title: Second title
|
||||
content: The changed content for the second problem
|
||||
status: 0
|
||||
|
||||
translation_with_html:
|
||||
problem_id: 4
|
||||
title: Some title
|
||||
content: 'p>This is some <b>custom</b> text.</p><p style="text-align:center;">This is centered.</p>'
|
||||
status: 1
|
||||
@ -26,7 +26,7 @@ class ProblemTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
test "should return correct number of translated problems" do
|
||||
assert_equal 2, Problem.translated_count
|
||||
assert_equal 3, Problem.translated_count
|
||||
end
|
||||
|
||||
test "should allow for problem count updating" do
|
||||
@ -44,7 +44,7 @@ class ProblemTest < ActiveSupport::TestCase
|
||||
assert_raises ArgumentError do
|
||||
Problem.update_count(1)
|
||||
end
|
||||
assert_equal 3, Problem.count()
|
||||
assert_equal 4, Problem.count()
|
||||
assert_equal "First title", Problem.find(1).title
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
Reference in New Issue
Block a user