From 7cb7c2fbab58c47f6da369f047b77d8d6ddfec1c Mon Sep 17 00:00:00 2001 From: evazion Date: Fri, 14 Jul 2017 23:34:52 -0500 Subject: [PATCH] Remove ruby DText implementation (#3206). --- app/controllers/dtext_previews_controller.rb | 2 +- app/helpers/application_helper.rb | 16 +- app/helpers/post_appeals_helper.rb | 2 +- app/helpers/post_flags_helper.rb | 2 +- app/logical/d_text.rb | 332 ------------------ app/presenters/wiki_page_presenter.rb | 2 +- app/views/artist_commentaries/_show.html.erb | 6 +- app/views/artist_commentaries/index.html.erb | 4 +- .../artist_commentary_versions/index.html.erb | 3 +- app/views/artists/_show.html.erb | 2 +- app/views/bans/index.html.erb | 2 +- app/views/bans/show.html.erb | 2 +- .../comments/partials/show/_comment.html.erb | 2 +- app/views/dmails/show.html.erb | 2 +- app/views/forum_posts/_forum_post.html.erb | 2 +- .../user/dmail_filters/edit.html.erb | 2 +- app/views/mod_actions/index.html.erb | 2 +- .../dashboards/_activity_mod_action.html.erb | 2 +- .../_activity_user_feedback.html.erb | 2 +- app/views/pools/show.html.erb | 2 +- app/views/post_appeals/_new.html.erb | 2 +- app/views/post_appeals/index.html.erb | 2 +- .../_compact_counts.html.erb | 2 +- app/views/post_disapprovals/_counts.html.erb | 2 +- app/views/post_events/index.html.erb | 2 +- app/views/post_flags/_new.html.erb | 2 +- app/views/post_flags/index.html.erb | 2 +- app/views/post_replacements/_new.html.erb | 2 +- .../posts/partials/index/_excerpt.html.erb | 6 +- app/views/tag_aliases/show.html.erb | 2 +- app/views/tag_implications/show.html.erb | 2 +- app/views/uploads/new.html.erb | 2 +- app/views/user_feedbacks/index.html.erb | 2 +- app/views/user_feedbacks/show.html.erb | 2 +- app/views/user_mailer/forum_notice.html.erb | 2 +- app/views/users/_ban_notice.html.erb | 2 +- app/views/users/_statistics.html.erb | 2 +- app/views/wiki_page_versions/show.html.erb | 2 +- app/views/wiki_pages/show.html.erb | 2 +- test/unit/dtext_test.rb | 196 ----------- 40 files changed, 47 insertions(+), 582 deletions(-) delete mode 100644 test/unit/dtext_test.rb diff --git a/app/controllers/dtext_previews_controller.rb b/app/controllers/dtext_previews_controller.rb index 3ad3ab3ac..7fd6c901e 100644 --- a/app/controllers/dtext_previews_controller.rb +++ b/app/controllers/dtext_previews_controller.rb @@ -1,5 +1,5 @@ class DtextPreviewsController < ApplicationController def create - render :inline => "<%= format_text(params[:body], :ragel => true) %>" + render :inline => "<%= format_text(params[:body]) %>" end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 16f124f13..95b2e01ec 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -49,20 +49,12 @@ module ApplicationHelper raw %{#{text}} end - def format_text(text, ragel: true, **options) - if ragel - raw DTextRagel.parse(text, **options) - else - DText.parse(text) - end + def format_text(text, **options) + raw DTextRagel.parse(text, **options) end - def strip_dtext(text, options = {}) - if options[:ragel] - raw(DTextRagel.parse_strip(text)) - else - DText.parse_strip(text) - end + def strip_dtext(text) + raw(DTextRagel.parse_strip(text)) end def error_messages_for(instance_name) diff --git a/app/helpers/post_appeals_helper.rb b/app/helpers/post_appeals_helper.rb index 052b006d4..a19ebee73 100644 --- a/app/helpers/post_appeals_helper.rb +++ b/app/helpers/post_appeals_helper.rb @@ -4,7 +4,7 @@ module PostAppealsHelper html << ' diff --git a/app/views/uploads/new.html.erb b/app/views/uploads/new.html.erb index a24c6ab0e..94b6421fb 100644 --- a/app/views/uploads/new.html.erb +++ b/app/views/uploads/new.html.erb @@ -4,7 +4,7 @@ <% if CurrentUser.can_upload? %>
- <%= format_text(@upload_notice_wiki.try(&:body), :ragel => true) %> + <%= format_text(@upload_notice_wiki.try(&:body)) %>
<% unless CurrentUser.can_upload_free? %> diff --git a/app/views/user_feedbacks/index.html.erb b/app/views/user_feedbacks/index.html.erb index 114342d6a..005e7d1bc 100644 --- a/app/views/user_feedbacks/index.html.erb +++ b/app/views/user_feedbacks/index.html.erb @@ -18,7 +18,7 @@ <%= link_to_user feedback.user %> <%= link_to_user feedback.creator %> <%= compact_time(feedback.created_at) %> - <%= format_text(feedback.body, :ragel => true) %> + <%= format_text(feedback.body) %> <% if feedback.editable_by?(CurrentUser.user) %> <%= link_to "edit", edit_user_feedback_path(feedback) %> diff --git a/app/views/user_feedbacks/show.html.erb b/app/views/user_feedbacks/show.html.erb index 12a871af8..34efbfb57 100644 --- a/app/views/user_feedbacks/show.html.erb +++ b/app/views/user_feedbacks/show.html.erb @@ -6,7 +6,7 @@
  • Creator <%= link_to_user @user_feedback.creator %>
  • Date <%= @user_feedback.created_at %>
  • Category <%= @user_feedback.category %>
  • -
  • Message <%= format_text @user_feedback.body, :ragel => true %>
  • +
  • Message <%= format_text @user_feedback.body %>
  • <% if @user_feedback.editable_by?(CurrentUser.user) %> diff --git a/app/views/user_mailer/forum_notice.html.erb b/app/views/user_mailer/forum_notice.html.erb index 7ba08cfa5..39bb1fd88 100644 --- a/app/views/user_mailer/forum_notice.html.erb +++ b/app/views/user_mailer/forum_notice.html.erb @@ -4,7 +4,7 @@

    <%= forum_post.creator_name %> said:

    - <%= format_text(forum_post.body, :ragel => true) %> + <%= format_text(forum_post.body) %>


    diff --git a/app/views/users/_ban_notice.html.erb b/app/views/users/_ban_notice.html.erb index 20b58df08..14194123d 100644 --- a/app/views/users/_ban_notice.html.erb +++ b/app/views/users/_ban_notice.html.erb @@ -1,5 +1,5 @@

    Your account has been temporarily banned

    -

    Reason: <%= format_text CurrentUser.user.recent_ban.reason, :ragel => true %>

    +

    Reason: <%= format_text CurrentUser.user.recent_ban.reason %>

    Your ban will expire in <%= time_ago_in_words(CurrentUser.user.recent_ban.expires_at) %>

    diff --git a/app/views/users/_statistics.html.erb b/app/views/users/_statistics.html.erb index f9244056e..25d63d60c 100644 --- a/app/views/users/_statistics.html.erb +++ b/app/views/users/_statistics.html.erb @@ -25,7 +25,7 @@ <% if user.is_banned? && user.recent_ban %> Ban reason - <%= format_text presenter.ban_reason, :ragel => true %> + <%= format_text presenter.ban_reason %> <% end %> diff --git a/app/views/wiki_page_versions/show.html.erb b/app/views/wiki_page_versions/show.html.erb index dcdfa1ce3..8cc04eb07 100644 --- a/app/views/wiki_page_versions/show.html.erb +++ b/app/views/wiki_page_versions/show.html.erb @@ -11,7 +11,7 @@

    <%= wiki_page_other_names_list(@wiki_page_version) %>

    <% end %> - <%= format_text(@wiki_page_version.body, :ragel => true) %> + <%= format_text(@wiki_page_version.body) %> <% else %>

    The artist has requested removal of this page.

    <% end %> diff --git a/app/views/wiki_pages/show.html.erb b/app/views/wiki_pages/show.html.erb index 6037c7d7f..c7c278abb 100644 --- a/app/views/wiki_pages/show.html.erb +++ b/app/views/wiki_pages/show.html.erb @@ -22,7 +22,7 @@

    <%= wiki_page_other_names_list(@wiki_page) %>

    <% end %> - <%= format_text(@wiki_page.body, :ragel => true) %> + <%= format_text(@wiki_page.body) %> <% if @wiki_page.artist %>

    <%= link_to "View artist", @wiki_page.artist %>

    diff --git a/test/unit/dtext_test.rb b/test/unit/dtext_test.rb deleted file mode 100644 index 735954a72..000000000 --- a/test/unit/dtext_test.rb +++ /dev/null @@ -1,196 +0,0 @@ -require "test_helper" - -class DTextTest < ActiveSupport::TestCase - def p(s) - DText.parse(s) - end - - def test_mentions - assert_equal('

    @bob

    ', p("@bob")) - assert_equal('

    hi @bob

    ', p("hi @bob")) - assert_equal('

    this is not @.@ @_@ @bob

    ', p("this is not @.@ @_@ @bob")) - assert_equal('

    multiple @bob @anna

    ', p("multiple @bob @anna")) - end - - def test_sanitize_heart - assert_equal('

    <3

    ', p("<3")) - end - - def test_sanitize_less_than - assert_equal('

    <

    ', p("<")) - end - - def test_sanitize_greater_than - assert_equal('

    >

    ', p(">")) - end - - def test_sanitize_ampersand - assert_equal('

    &

    ', p("&")) - end - - def test_wiki_links - assert_equal("

    a b c

    ", p("a [[b]] c")) - end - - def test_wiki_links_spoiler - assert_equal("

    a spoiler c

    ", p("a [[spoiler]] c")) - end - - def test_spoilers_inline - assert_equal("

    this is

    an inline spoiler

    .

    ", p("this is [spoiler]an inline spoiler[/spoiler].")) - end - - def test_spoilers_block - assert_equal("

    this is

    a block spoiler

    .

    ", p("this is\n\n[spoiler]\na block spoiler\n[/spoiler].")) - end - - def test_spoilers_with_no_closing_tag_1 - assert_equal("

    this is a spoiler with no closing tag

    new text

    ", p("[spoiler]this is a spoiler with no closing tag\n\nnew text")) - end - - def test_spoilers_with_no_closing_tag_2 - assert_equal("

    this is a spoiler with no closing tag
    new text

    ", p("[spoiler]this is a spoiler with no closing tag\nnew text")) - end - - def test_spoilers_with_no_closing_tag_block - assert_equal("

    this is a block spoiler with no closing tag

    ", p("[spoiler]\nthis is a block spoiler with no closing tag")) - end - - def test_spoilers_nested - assert_equal("

    this is

    a nested

    spoiler

    ", p("[spoiler]this is [spoiler]a nested[/spoiler] spoiler[/spoiler]")) - end - - def test_paragraphs - assert_equal("

    abc

    ", p("abc")) - end - - def test_paragraphs_with_newlines_1 - assert_equal("

    a
    b
    c

    ", p("a\nb\nc")) - end - - def test_paragraphs_with_newlines_2 - assert_equal("

    a

    b

    ", p("a\n\nb")) - end - - def test_headers - assert_equal("

    header

    ", p("h1. header")) - end - - def test_headers_with_ids - assert_equal("

    header

    ", p("h1#header-id. header")) - end - - def test_quote_blocks - assert_equal('

    test

    ', p("[quote]\ntest\n[/quote]")) - end - - def test_quote_blocks_nested - assert_equal("

    a

    b

    c

    ", p("[quote]\na\n[quote]\nb\n[/quote]\nc\n[/quote]")) - end - - def test_code - assert_equal("
    for (i=0; i<5; ++i) {\n  printf(1);\n}\n\nexit(1);\n\n
    ", p("[code]for (i=0; i<5; ++i) {\n printf(1);\n}\n\nexit(1);")) - end - - def test_urls - assert_equal('

    a http://test.com b

    ', p('a http://test.com b')) - end - - def test_urls_with_newline - assert_equal('

    http://test.com
    b

    ', p("http://test.com\nb")) - end - - def test_urls_with_paths - assert_equal('

    a http://test.com/~bob/image.jpg b

    ', p('a http://test.com/~bob/image.jpg b')) - end - - def test_urls_with_fragment - assert_equal('

    a http://test.com/home.html#toc b

    ', p('a http://test.com/home.html#toc b')) - end - - def test_auto_urls - assert_equal('

    a http://test.com. b

    ', p('a http://test.com. b')) - end - - def test_auto_urls_in_parentheses - assert_equal('

    a (http://test.com) b

    ', p('a (http://test.com) b')) - end - - def test_old_style_links - assert_equal('

    test

    ', p('"test":http://test.com')) - end - - def test_old_style_links_with_special_entities - assert_equal('

    "1" 2 & 3

    ', p('"1" "2 & 3":http://three.com')) - end - - def test_new_style_links - assert_equal('

    test

    ', p('"test":[http://test.com]')) - end - - def test_new_style_links_with_parentheses - assert_equal('

    test

    ', p('"test":[http://test.com/(parentheses)]')) - assert_equal('

    (test)

    ', p('("test":[http://test.com/(parentheses)])')) - assert_equal('

    [test]

    ', p('["test":[http://test.com/(parentheses)]]')) - end - - def test_lists_1 - assert_equal('', p('* a')) - end - - def test_lists_2 - assert_equal('', p("* a\n* b").gsub(/\n/, "")) - end - - def test_lists_nested - assert_equal('', p("* a\n** b").gsub(/\n/, "")) - end - - def test_lists_inline - assert_equal('', p("* post #1").gsub(/\n/, "")) - end - - def test_lists_not_preceded_by_newline - assert_equal('

    ab

    ', p("a\nb\n* c\n* d").gsub(/\n/, "")) - end - - def test_lists_with_multiline_items - assert_equal('

    a

    ', p("a\n* b\nc\n* d\ne").gsub(/\n/, "")) - end - - def test_inline_tags - assert_equal('

    tag

    ', p("{{tag}}")) - end - - def test_inline_tags_conjunction - assert_equal('

    tag1 tag2

    ', p("{{tag1 tag2}}")) - end - - def test_inline_tags_special_entities - assert_equal('

    <3

    ', p("{{<3}}")) - end - - def test_extra_newlines - assert_equal('

    a

    b

    ', p("a\n\n\n\n\n\n\nb\n\n\n\n")) - end - - def test_complex_links_1 - assert_equal("

    2 3 | 5 6

    ", p("[[1|2 3]] | [[4|5 6]]")) - end - - def test_complex_links_2 - assert_equal("

    Tags (Tagging Guidelines | Tag Checklist | Tag Groups)

    ", p("Tags [b]([[howto:tag|Tagging Guidelines]] | [[howto:tag_checklist|Tag Checklist]] | [[Tag Groups]])[/b]")) - end - - def test_table - assert_equal("
    header
    post #100
    ", p("[table][thead][tr][th]header[/th][/tr][/thead][tbody][tr][td]post #100[/td][/tr][/tbody][/table]")) - end - - def test_table_with_newlines - assert_equal("\n\n
    header
    post #100
    ", p("[table]\n[thead]\n[tr]\n[th]header[/th][/tr][/thead][tbody][tr][td]post #100[/td][/tr][/tbody][/table]")) - end - - def test_forum_links - assert_equal('

    topic #1234/p4

    ', p("topic #1234/p4")) - end -end