From 5444ad51078217c6f4b76dfef68e7305f706556f Mon Sep 17 00:00:00 2001 From: albert Date: Sat, 22 Oct 2011 17:23:33 -0400 Subject: [PATCH] fix dtext styles --- .../stylesheets/common/020_base.css.scss | 5 +- app/assets/stylesheets/common/dtext.css.scss | 4 ++ app/controllers/wiki_pages_controller.rb | 9 +++ app/logical/d_text.rb | 59 ++++++++----------- app/views/wiki_pages/show.html.erb | 2 +- config/routes.rb | 3 + test/unit/artist_test.rb | 2 +- test/unit/dtext_test.rb | 31 ++++++---- 8 files changed, 68 insertions(+), 47 deletions(-) diff --git a/app/assets/stylesheets/common/020_base.css.scss b/app/assets/stylesheets/common/020_base.css.scss index fdc275def..af218d40d 100644 --- a/app/assets/stylesheets/common/020_base.css.scss +++ b/app/assets/stylesheets/common/020_base.css.scss @@ -40,7 +40,7 @@ em { font-style: italic; } -h1, h2, h3 { +h1, h2, h3, h4, h5, h6 { font-family: Tahoma; font-weight: bold; line-height: 1.25em; @@ -54,7 +54,8 @@ h2 { font-size: $h2_size; } -h3 { +h3, h4, h5, h6 { + font-weight: bold; font-size: $h3_size; } diff --git a/app/assets/stylesheets/common/dtext.css.scss b/app/assets/stylesheets/common/dtext.css.scss index 995589eef..2697d5c55 100644 --- a/app/assets/stylesheets/common/dtext.css.scss +++ b/app/assets/stylesheets/common/dtext.css.scss @@ -16,6 +16,10 @@ div.prose { h3 { padding: $h3_padding; } + + h4, h5, h6 { + padding: 0; + } ul { margin-left: 1em; diff --git a/app/controllers/wiki_pages_controller.rb b/app/controllers/wiki_pages_controller.rb index cfdeeef5f..eb05da19c 100644 --- a/app/controllers/wiki_pages_controller.rb +++ b/app/controllers/wiki_pages_controller.rb @@ -54,6 +54,15 @@ class WikiPagesController < ApplicationController @wiki_page.revert_to!(@version) respond_with(@wiki_page) end + + def show_or_new + @wiki_page = WikiPage.find_by_name(params[:title]) + if @wiki_page + redirect_to wiki_page_path(@wiki_page) + else + redirect_to new_wiki_page_path(:wiki_page => {:title => params[:title]}) + end + end private def normalize_search_params diff --git a/app/logical/d_text.rb b/app/logical/d_text.rb index e3fc6d4ff..b851798b7 100644 --- a/app/logical/d_text.rb +++ b/app/logical/d_text.rb @@ -17,25 +17,29 @@ class DText str.gsub!(/\n/m, "
") str.gsub!(/\[b\](.+?)\[\/b\]/i, '\1') str.gsub!(/\[i\](.+?)\[\/i\]/i, '\1') - str.gsub!(/(?])$/ + url.chop! + ch = $1 + else + ch = "" end - link.gsub!(/"/, '"') - '' + text + '' + stop - end - str.gsub!(/\[url\](http.+?)\[\/url\]/i) do - %{#{$1}} - end - str.gsub!(/\[url=(http.+?)\](.+?)\[\/url\]/m) do - %{#{$2}} + '' + text + '' + ch end + # str.gsub!(/\[url\](http.+?)\[\/url\]/i) do + # %{#{$1}} + # end + # str.gsub!(/\[url=(http.+?)\](.+?)\[\/url\]/m) do + # %{#{$2}} + # end str = parse_aliased_wiki_links(str) str = parse_wiki_links(str) str = parse_post_links(str) @@ -44,34 +48,23 @@ class DText end def self.parse_aliased_wiki_links(str) - str.gsub(/\[\[(.+?)\|(.+?)\]\]/m) do - text = CGI.unescapeHTML($1) + str.gsub(/\[\[([^\|\]]+)\|([^\]]+)\]\]/m) do + text = CGI.unescapeHTML($1).tr("_", " ") title = CGI.unescapeHTML($2) - wiki_page = WikiPage.find_title_and_id(title) - - if wiki_page - %{#{h(text)}} - else - %{#{h(text)}} - end + %{#{h(text)}} end end def self.parse_wiki_links(str) - str.gsub(/\[\[(.+?)\]\]/) do + str.gsub(/\[\[([^\]]+)\]\]/) do title = CGI.unescapeHTML($1) - wiki_page = WikiPage.find_title_and_id(title) - - if wiki_page - %{#{h(title)}} - else - %{#{h(title)}} - end + text = title.tr("_", " ") + %{#{h(text)}} end end def self.parse_post_links(str) - str.gsub(/\{\{(.+?)\}\}/) do + str.gsub(/\{\{([^\}]+)\}\}/) do tags = CGI.unescapeHTML($1) %{#{h(tags)}} end diff --git a/app/views/wiki_pages/show.html.erb b/app/views/wiki_pages/show.html.erb index 0d70bb055..0e40e7809 100644 --- a/app/views/wiki_pages/show.html.erb +++ b/app/views/wiki_pages/show.html.erb @@ -5,7 +5,7 @@

<%= @wiki_page.pretty_title %>

-
+
<%= format_text(@wiki_page.body) %>
diff --git a/config/routes.rb b/config/routes.rb index ae30ab9d3..eb1f0a698 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -136,6 +136,9 @@ Danbooru::Application.routes.draw do member do put :revert end + collection do + get :show_or_new + end end resources :wiki_page_versions, :only => [:index, :show] diff --git a/test/unit/artist_test.rb b/test/unit/artist_test.rb index 2baf3738c..2cd6bf03a 100644 --- a/test/unit/artist_test.rb +++ b/test/unit/artist_test.rb @@ -19,7 +19,7 @@ class ArtistTest < ActiveSupport::TestCase @post = Factory.create(:post, :tag_string => "aaa") @artist = Factory.create(:artist, :name => "aaa") @artist.reload - @artist.update_attributes(:is_banned => true) + @artist.update_attributes(:is_banned => true, :as => :admin) @post.reload end diff --git a/test/unit/dtext_test.rb b/test/unit/dtext_test.rb index c9a0a0d9b..33f1441ba 100644 --- a/test/unit/dtext_test.rb +++ b/test/unit/dtext_test.rb @@ -12,8 +12,8 @@ class DTextTest < ActiveSupport::TestCase end def test_wiki_links - assert_equal("

a b c

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

a spoiler c

", p("a [[spoiler]] c")) + assert_equal("

a b c

", p("a [[b]] c")) + assert_equal("

a spoiler c

", p("a [[spoiler]] c")) end def test_spoilers @@ -46,16 +46,22 @@ class DTextTest < ActiveSupport::TestCase assert_equal('

a (http://test.com) b

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

test

', p('[url=http://test.com]test[/url]')) - assert_equal('

"1" 2

', p('"1" [url=http://two.com]2[/url]')) - assert_equal('

"1" 2 & 3

', p('"1" [url=http://three.com]2 & 3[/url]')) + # def test_links + # assert_equal('

test

', p('[url=http://test.com]test[/url]')) + # assert_equal('

"1" 2

', p('"1" [url=http://two.com]2[/url]')) + # assert_equal('

"1" 2 & 3

', p('"1" [url=http://three.com]2 & 3[/url]')) + # end + + def test_old_syle_links + assert_equal('

test

', p('"test":http://test.com')) + assert_equal('

"1" 2

', p('"1" "2":http://two.com')) + assert_equal('

"1" 2 & 3

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

a bob. b

', p('a [url=http://test.com]bob[/url]. b')) - assert_equal('

bob

', p('[i][url=http://test.com]bob[/url][/i]')) - end + # def test_aliased_urls + # assert_equal('

a bob. b

', p('a [url=http://test.com]bob[/url]. b')) + # assert_equal('

bob

', p('[i][url=http://test.com]bob[/url][/i]')) + # end def test_lists assert_equal('
  • a
', p('* a')) @@ -78,4 +84,9 @@ class DTextTest < ActiveSupport::TestCase 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 + assert_equal('

1 | 4

', p("[[1|2 3]] | [[4|5 6]]")) + assert_equal("

Tags (howto:tag | howto:tag checklist | Tag Groups)

", p("Tags [b]([[howto:tag|Tagging Guidelines]] | [[howto:tag_checklist|Tag Checklist]] | [[Tag Groups]])[/b]")) + end end