From e3aa626489f1e33349f597c14cc4d15d8c8b8504 Mon Sep 17 00:00:00 2001 From: Jacques Distler Date: Sun, 3 Jan 2010 13:19:47 -0600 Subject: [PATCH] Better Display of Interweb Wikilinks Perhaps not the most creative use of CSS. But, at least, this will read better. --- lib/chunks/wiki.rb | 1 + lib/url_generator.rb | 3 ++- public/stylesheets/instiki.css | 4 ++++ test/fixtures/pages.yml | 8 +++++++- test/fixtures/revisions.yml | 12 +++++++++++- test/functional/file_controller_test.rb | 2 +- test/functional/wiki_controller_test.rb | 14 +++++++------- test/test_helper.rb | 15 ++++++++++----- test/unit/chunks/wiki_test.rb | 4 ++-- test/unit/page_renderer_test.rb | 12 +++++++++--- test/unit/web_test.rb | 6 +++--- 11 files changed, 57 insertions(+), 24 deletions(-) diff --git a/lib/chunks/wiki.rb b/lib/chunks/wiki.rb index 16821489..66eb6426 100644 --- a/lib/chunks/wiki.rb +++ b/lib/chunks/wiki.rb @@ -155,6 +155,7 @@ module WikiChunk if web_match @web_name = normalize_whitespace(web_match[1]) @page_name = web_match[2] + @link_text = @page_name if @link_text == web_match[0] end end diff --git a/lib/url_generator.rb b/lib/url_generator.rb index 5fc4e355..74976e81 100644 --- a/lib/url_generator.rb +++ b/lib/url_generator.rb @@ -180,7 +180,8 @@ class UrlGenerator < AbstractUrlGenerator action = web.published? && (web != @web || [:publish, :s5].include?(mode) ) ? 'published' : 'show' href = @controller.url_for :controller => 'wiki', :web => web_address, :action => action, :id => name, :only_path => true - %{#{text}} + title = web == @web ? '' : %{ title="#{web_address}"} + %{#{text}} end def html_ext diff --git a/public/stylesheets/instiki.css b/public/stylesheets/instiki.css index ade66ed8..6e5d790f 100644 --- a/public/stylesheets/instiki.css +++ b/public/stylesheets/instiki.css @@ -380,6 +380,10 @@ a,li span { color:#000; } +a.existingWikiWord[title]{ +border: 1px dashed #000; +} + a:hover,a.nav:hover, a:hover math { background-color:#000; color:#FFF; diff --git a/test/fixtures/pages.yml b/test/fixtures/pages.yml index 5944f061..b7163ef8 100644 --- a/test/fixtures/pages.yml +++ b/test/fixtures/pages.yml @@ -60,4 +60,10 @@ liquor: updated_at: <%= 40.minutes.ago.to_formatted_s(:db) %> web_id: 1 name: liquor - \ No newline at end of file + +instiki_page: + id: 10 + created_at: <%= Time.local(2004, 4, 4, 16, 50).to_formatted_s(:db) %> + updated_at: <%= Time.local(2004, 4, 4, 16, 50).to_formatted_s(:db) %> + web_id: 2 + name: HomePage \ No newline at end of file diff --git a/test/fixtures/revisions.yml b/test/fixtures/revisions.yml index 56a8535f..d7533510 100644 --- a/test/fixtures/revisions.yml +++ b/test/fixtures/revisions.yml @@ -90,4 +90,14 @@ liquor_first_revision: page_id: 9 content: "[[!redirects booze]]\n Drinky-poo. [[Instiki:HomePage|go there]]" author: Guest - ip: 127.0.0.2 \ No newline at end of file + ip: 127.0.0.2 + +instiki_home_page_first_revision: + id: 11 + created_at: <%= Time.local(2004, 4, 4, 15, 50).to_formatted_s(:db) %> + updated_at: <%= Time.local(2004, 4, 4, 15, 50).to_formatted_s(:db) %> + revised_at: <%= Time.local(2004, 4, 4, 15, 50).to_formatted_s(:db) %> + page_id: 10 + content: First revision of the HomePage end + author: AnAuthor + ip: 127.0.0.1 diff --git a/test/functional/file_controller_test.rb b/test/functional/file_controller_test.rb index 3ed6a617..19b3881c 100755 --- a/test/functional/file_controller_test.rb +++ b/test/functional/file_controller_test.rb @@ -1,6 +1,6 @@ #!/usr/bin/env ruby -require File.expand_path(File.dirname(__FILE__) + '/../test_helper') +require Rails.root.join('test', 'test_helper') require 'file_controller' require 'fileutils' require 'stringio' diff --git a/test/functional/wiki_controller_test.rb b/test/functional/wiki_controller_test.rb index bdb47ef8..e461b015 100644 --- a/test/functional/wiki_controller_test.rb +++ b/test/functional/wiki_controller_test.rb @@ -4,7 +4,7 @@ # commiting to SVN # $INSTIKI_TEST_PDFLATEX = true -require File.expand_path(File.dirname(__FILE__) + '/../test_helper') +require Rails.root.join('test', 'test_helper') require 'wiki_controller' require 'rexml/document' require 'tempfile' @@ -361,13 +361,13 @@ class WikiControllerTest < ActionController::TestCase assert_response(:success) assert_equal @liquor, r.template_objects['page'] - assert_match /go there<\/a>/, r.body + assert_match /go there<\/a>/, r.body r = process('show', 'web' => 'wiki1', 'id' => 'liquor') assert_response(:success) assert_equal @liquor, r.template_objects['page'] - assert_match /go there<\/a>/, r.body + assert_match /go there<\/a>/, r.body Web.find_by_address('instiki').update_attribute(:published, true) @@ -375,13 +375,13 @@ class WikiControllerTest < ActionController::TestCase assert_response(:success) assert_equal @liquor, r.template_objects['page'] - assert_match /go there<\/a>/, r.body + assert_match /go there<\/a>/, r.body r = process('show', 'web' => 'wiki1', 'id' => 'liquor') assert_response(:success) assert_equal @liquor, r.template_objects['page'] - assert_match /go there<\/a>/, r.body + assert_match /go there<\/a>/, r.body set_web_property :published, false @@ -389,7 +389,7 @@ class WikiControllerTest < ActionController::TestCase assert_response(:success) assert_equal @liquor, r.template_objects['page'] - assert_match /go there<\/a>/, r.body + assert_match /go there<\/a>/, r.body Web.find_by_address('instiki').update_attribute(:published, false) @@ -397,7 +397,7 @@ class WikiControllerTest < ActionController::TestCase assert_response(:success) assert_equal @liquor, r.template_objects['page'] - assert_match /go there<\/a>/, r.body + assert_match /go there<\/a>/, r.body end diff --git a/test/test_helper.rb b/test/test_helper.rb index b01b7164..6f005aa9 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -2,7 +2,7 @@ ENV['RAILS_ENV'] = 'test' # Expand the path to environment so that Ruby does not load it multiple times # File.expand_path can be removed if Ruby 1.9 is in use. -require File.expand_path(File.dirname(__FILE__) + '/../config/environment') +require File.expand_path(File.join(File.dirname(__FILE__), '..', 'config', 'environment')) require 'test_help' require 'wiki_content' @@ -20,7 +20,7 @@ class ActiveSupport::TestCase self.pre_loaded_fixtures = false self.use_transactional_fixtures = true self.use_instantiated_fixtures = false - self.fixture_path = File.dirname(__FILE__) + "/fixtures/" + self.fixture_path = Rails.root.join('test', 'fixtures', '') end # activate PageObserver @@ -28,7 +28,7 @@ PageObserver.instance class Test::Unit::TestCase def create_fixtures(*table_names) - Fixtures.create_fixtures(File.dirname(__FILE__) + "/fixtures", table_names) + Fixtures.create_fixtures(Rails.root.join('test', 'fixtures'), table_names) end # Add more helper methods to be used by all tests here... @@ -128,16 +128,21 @@ class StubUrlGenerator < AbstractUrlGenerator def page_link(mode, name, text, web_address, known_page) link = CGI.escape(name) return %{Illegal link (target contains a '.'): #{name}} if name.include?('.') + title = web_address == 'wiki1' ? '' : " title='#{web_address}'" case mode when :export if known_page then %{#{text}} else %{#{text}} end when :publish - if known_page then %{#{text}} + if known_page then %{#{text}} else %{#{text}} end else if known_page - %{#{text}} + if web_address == 'instiki' + %{#{text}} + else + %{#{text}} + end else if web_address == 'instiki' %{#{text}?} diff --git a/test/unit/chunks/wiki_test.rb b/test/unit/chunks/wiki_test.rb index 8879c2f0..f0dc1f12 100755 --- a/test/unit/chunks/wiki_test.rb +++ b/test/unit/chunks/wiki_test.rb @@ -1,7 +1,7 @@ #!/usr/bin/env ruby # encoding: UTF-8 -require File.expand_path(File.dirname(__FILE__) + '/../../test_helper') +require Rails.root.join('test', 'test_helper') require 'chunks/wiki' class WikiTest < Test::Unit::TestCase @@ -115,7 +115,7 @@ class WikiTest < Test::Unit::TestCase # empty link type assert_link_parsed_as 'page name', 'link?:', :show, '[[page name|link?:]]' # unknown link type - assert_link_parsed_as 'create_system', 'page name:create_system', :show, + assert_link_parsed_as 'create_system', 'create_system', :show, '[[page name:create_system]]' end diff --git a/test/unit/page_renderer_test.rb b/test/unit/page_renderer_test.rb index a31d44ce..9dd6acd6 100644 --- a/test/unit/page_renderer_test.rb +++ b/test/unit/page_renderer_test.rb @@ -1,7 +1,7 @@ #!/usr/bin/env ruby # encoding: UTF-8 -require File.expand_path(File.dirname(__FILE__) + '/../test_helper') +require Rails.root.join('test', 'test_helper') class PageRendererTest < ActiveSupport::TestCase fixtures :webs, :pages, :revisions, :system, :wiki_references @@ -662,10 +662,16 @@ END_THM def test_wiki_link_with_colon assert_markup_parsed_as( - "

Instiki:Colon?

", - '[[Instiki:Colon]]') + "

HomePage

", + '[[wiki1:HomePage]]') end + def test_wiki_link_with_colon_interwiki + assert_markup_parsed_as( + "

HomePage

", + '[[instiki:HomePage]]') + end + def test_list_with_tildas list_with_tildas = <<-EOL * [a](~b) diff --git a/test/unit/web_test.rb b/test/unit/web_test.rb index 7478b0ec..1e2b0de1 100644 --- a/test/unit/web_test.rb +++ b/test/unit/web_test.rb @@ -14,7 +14,7 @@ class WebTest < ActiveSupport::TestCase def test_pages_by_match add_sample_pages - assert_equal 2, @web.select { |page| page.content =~ /me/i }.length + assert_equal 3, @web.select { |page| page.content =~ /me/i }.length assert_equal 1, @web.select { |page| page.content =~ /Who/i }.length assert_equal 0, @web.select { |page| page.content =~ /none/i }.length end @@ -27,9 +27,9 @@ class WebTest < ActiveSupport::TestCase def test_delete add_sample_pages - assert_equal 2, @web.pages.length + assert_equal 3, @web.pages.length @web.remove_pages([ @web.page('EverBeenInLove') ]) - assert_equal 1, @web.pages(true).length + assert_equal 2, @web.pages(true).length end def test_initialize