Skip to content

Commit

Permalink
Merge branch 'reference_types' into action_events
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerry Gleason committed Dec 14, 2012
2 parents 97f8820 + 7cf17e1 commit fd1bf88
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 44 deletions.
2 changes: 1 addition & 1 deletion lib/chunks/chunk.rb
Expand Up @@ -33,7 +33,7 @@ def initialize match_data, content
end

def inspect
"#<#{self.class}##{object_id} Txu:#{@unmask_text} t:#{@text}: C:#{@content.gsub("\n", '\\n')[0,40]}:#{@unmask_mode}:Card:#{@card.inspect} #{@cardname.nil? ? '' : " :ref:#{@cardname}::#{@ref_text}"}>"
"#<#{self.class}##{object_id} Txu:#{@unmask_text} t:#{@text}: C:#{@content.gsub("\n", '\\n')[0,40]}:#{@unmask_mode}:Card:#{@card.inspect} #{@cardname.nil? ? '' : " :ref:#{@cardname}::#{@link_text}"}>"
end

# Find all the chunks of the given type in content
Expand Down
8 changes: 4 additions & 4 deletions lib/chunks/link.rb
@@ -1,6 +1,6 @@
module Chunk
class Link < Reference
attr_accessor :ref_text, :link_type
attr_accessor :link_text, :link_type

# unless defined? WIKI_LINK
word = /\s*([^\]\|]+)\s*/
Expand All @@ -15,10 +15,10 @@ def initialize(match_data, content)
if name=match_data[1]
self.cardname = name.to_name
# matched the [[..(|..)?]] case, 1=first slot, 3=sencond
@ref_text = match_data[ match_data[2] ? 3 : 1 ]
@link_text = match_data[ match_data[2] ? 3 : 1 ]
else
# matched [..][..] case, 4=first slot, 5=second
@ref_text, self.cardname = match_data[4], match_data[5].to_name #.gsub(/_/,' ')
@link_text, self.cardname = match_data[4], match_data[5].to_name #.gsub(/_/,' ')
end
self
end
Expand All @@ -28,7 +28,7 @@ def unmask_text
end

def revert
@text = cardname == ref_text ? "[[#{cardname.to_s}]]" : "[[#{cardname.to_s}|#{ref_text}]]"
@text = cardname == link_text ? "[[#{cardname.to_s}]]" : "[[#{cardname.to_s}|#{link_text}]]"
super
end

Expand Down
4 changes: 2 additions & 2 deletions lib/chunks/reference.rb
Expand Up @@ -16,12 +16,12 @@ def refcard()
@refcard ||= refcardname && Card.fetch(refcardname)
end

def ref_text()
def link_text()
refcardname.to_s
end

def render_link()
@content.renderer.build_link(refcardname, self.ref_text)
@content.renderer.build_link(refcardname, self.link_text)
end

end
Expand Down
14 changes: 7 additions & 7 deletions lib/chunks/uri.rb
Expand Up @@ -82,7 +82,7 @@ def URIChunk.pattern
INTERNET_URI_REGEXP
end

attr_reader :user, :host, :port, :path, :query, :fragment, :ref_text
attr_reader :user, :host, :port, :path, :query, :fragment, :link_text

def self.apply_to(content)
content.gsub!( self.pattern ) do |matched_text|
Expand All @@ -100,12 +100,12 @@ def self.apply_to(content)

def initialize(match_data, content)
super
@ref_text = match_data[0]
@link_text = match_data[0]
@suspicious_preceding_character = match_data[1]
@original_scheme, @user, @host, @port, @path, @query, @fragment = match_data[2..-1]
treat_trailing_character
#Rails.logger.debug "uri_link #{@ref_text} U:#{self.uri}"
@unmask_text = "#{@content.renderer.build_link(self.uri,@ref_text)}#{@trailing_punctuation}"
#Rails.logger.debug "uri_link #{@link_text} U:#{self.uri}"
@unmask_text = "#{@content.renderer.build_link(self.uri,@link_text)}#{@trailing_punctuation}"
end

def avoid_autolinking?
Expand All @@ -116,15 +116,15 @@ def treat_trailing_character
# If the last character matched by URI pattern is in ! or ), this may be part of the markup,
# not a URL. We should handle it as such. It is possible to do it by a regexp, but
# much easier to do programmatically
[@original_scheme, @user, @host, @port, @path, @query, @fragment, @ref_text].compact.map do |section|
[@original_scheme, @user, @host, @port, @path, @query, @fragment, @link_text].compact.map do |section|
section.gsub! /(&nbsp;)*$/, ''
end
last_char = @ref_text[-1..-1]
last_char = @link_text[-1..-1]

# if last_char == ')' or last_char == '!'
if %w{ . ) ! ? : }.member?(last_char)
@trailing_punctuation = last_char
@ref_text.chop!
@link_text.chop!
[@original_scheme, @user, @host, @port, @path, @query, @fragment].compact.last.chop!
else
@trailing_punctuation = nil
Expand Down
4 changes: 2 additions & 2 deletions lib/wagn/renderer.rb
Expand Up @@ -416,10 +416,10 @@ def replace_references old_name, new_name

if was_name = chunk.cardname and new_cardname = was_name.replace_part(old_name, new_name) and
was_name != new_cardname
Chunk::Link===chunk and link_bound = chunk.cardname == chunk.ref_text
Chunk::Link===chunk and link_bound = chunk.cardname == chunk.link_text
chunk.cardname = new_cardname
Card::Reference.where(:referee_key => was_name.key).update_all( :referee_key => new_cardname.key )
chunk.ref_text=chunk.cardname.to_s if link_bound
chunk.link_text=chunk.cardname.to_s if link_bound
end
end

Expand Down
56 changes: 28 additions & 28 deletions spec/lib/chunks/uri_spec.rb
Expand Up @@ -15,113 +15,113 @@
# Simplest case
match_chunk(URIChunk, 'http://www.example.com',
:scheme =>'http', :host =>'www.example.com', :path => nil,
:ref_text => 'http://www.example.com'
:link_text => 'http://www.example.com'
)
# With trailing slash
match_chunk(URIChunk, 'http://www.example.com/',
:scheme =>'http', :host =>'www.example.com', :path => '/',
:ref_text => 'http://www.example.com/'
:link_text => 'http://www.example.com/'
)
# With trailing slash inside html tags
match_chunk(URIChunk, '<p>http://www.example.com/</p>',
:scheme =>'http', :host =>'www.example.com', :path => '/',
:ref_text => 'http://www.example.com/'
:link_text => 'http://www.example.com/'
)
# With trailing period
match_chunk(URIChunk, 'http://www.example.com/. ',
:scheme =>'http', :host =>'www.example.com', :path => '/',
:ref_text => 'http://www.example.com/'
:link_text => 'http://www.example.com/'
)
# With trailing period inside html tags
match_chunk(URIChunk, '<p>http://www.example.com/.</p>',
:scheme =>'http', :host =>'www.example.com', :path => '/',
:ref_text => 'http://www.example.com/'
:link_text => 'http://www.example.com/'
)
# With trailing &nbsp;
match_chunk(URIChunk, 'http://www.example.com/&nbsp;',
:scheme =>'http', :host =>'www.example.com', :path => '/',
:ref_text => 'http://www.example.com/'
:link_text => 'http://www.example.com/'
)
# Without http://
match_chunk(URIChunk, 'www.example.com',
:scheme =>'http', :host =>'www.example.com', :ref_text => 'www.example.com'
:scheme =>'http', :host =>'www.example.com', :link_text => 'www.example.com'
)
# two parts
match_chunk(URIChunk, 'example.com',
:scheme =>'http',:host =>'example.com', :ref_text => 'example.com'
:scheme =>'http',:host =>'example.com', :link_text => 'example.com'
)
# "unusual" base domain (was a bug in an early version)
match_chunk(URIChunk, 'http://example.com.au/',
:scheme =>'http', :host =>'example.com.au', :ref_text => 'http://example.com.au/'
:scheme =>'http', :host =>'example.com.au', :link_text => 'http://example.com.au/'
)
# "unusual" base domain without http://
match_chunk(URIChunk, 'example.com.au',
:scheme =>'http', :host =>'example.com.au', :ref_text => 'example.com.au'
:scheme =>'http', :host =>'example.com.au', :link_text => 'example.com.au'
)
# Another "unusual" base domain
match_chunk(URIChunk, 'http://www.example.co.uk/',
:scheme =>'http', :host =>'www.example.co.uk',
:ref_text => 'http://www.example.co.uk/'
:link_text => 'http://www.example.co.uk/'
)
match_chunk(URIChunk, 'example.co.uk',
:scheme =>'http', :host =>'example.co.uk', :ref_text => 'example.co.uk'
:scheme =>'http', :host =>'example.co.uk', :link_text => 'example.co.uk'
)
# With some path at the end
match_chunk(URIChunk, 'http://moinmoin.wikiwikiweb.de/HelpOnNavigation',
:scheme => 'http', :host => 'moinmoin.wikiwikiweb.de', :path => '/HelpOnNavigation',
:ref_text => 'http://moinmoin.wikiwikiweb.de/HelpOnNavigation'
:link_text => 'http://moinmoin.wikiwikiweb.de/HelpOnNavigation'
)
# With some path at the end, and withot http:// prefix
match_chunk(URIChunk, 'moinmoin.wikiwikiweb.de/HelpOnNavigation',
:scheme => 'http', :host => 'moinmoin.wikiwikiweb.de', :path => '/HelpOnNavigation',
:ref_text => 'moinmoin.wikiwikiweb.de/HelpOnNavigation'
:link_text => 'moinmoin.wikiwikiweb.de/HelpOnNavigation'
)
# With a port number
match_chunk(URIChunk, 'http://www.example.com:80',
:scheme =>'http', :host =>'www.example.com', :port => '80', :path => nil,
:ref_text => 'http://www.example.com:80')
:link_text => 'http://www.example.com:80')
# With a port number and a path
match_chunk(URIChunk, 'http://www.example.com.tw:80/HelpOnNavigation',
:scheme =>'http', :host =>'www.example.com.tw', :port => '80', :path => '/HelpOnNavigation',
:ref_text => 'http://www.example.com.tw:80/HelpOnNavigation')
:link_text => 'http://www.example.com.tw:80/HelpOnNavigation')
# With a query
match_chunk(URIChunk, 'http://www.example.com.tw:80/HelpOnNavigation?arg=val',
:scheme =>'http', :host =>'www.example.com.tw', :port => '80', :path => '/HelpOnNavigation',
:query => 'arg=val',
:ref_text => 'http://www.example.com.tw:80/HelpOnNavigation?arg=val')
:link_text => 'http://www.example.com.tw:80/HelpOnNavigation?arg=val')
# Query with two arguments
match_chunk(URIChunk, 'http://www.example.com.tw:80/HelpOnNavigation?arg=val&arg2=val2',
:scheme =>'http', :host =>'www.example.com.tw', :port => '80', :path => '/HelpOnNavigation',
:query => 'arg=val&arg2=val2',
:ref_text => 'http://www.example.com.tw:80/HelpOnNavigation?arg=val&arg2=val2')
:link_text => 'http://www.example.com.tw:80/HelpOnNavigation?arg=val&arg2=val2')
# with an anchor
match_chunk(URIChunk, 'irc://irc.freenode.net#recentchangescamp',
:scheme =>'irc', :host =>'irc.freenode.net',
:fragment => '#recentchangescamp',
:ref_text => 'irc://irc.freenode.net#recentchangescamp')
:link_text => 'irc://irc.freenode.net#recentchangescamp')

# HTTPS
match_chunk(URIChunk, 'https://www.example.com',
:scheme =>'https', :host =>'www.example.com', :port => nil, :path => nil, :query => nil,
:ref_text => 'https://www.example.com')
:link_text => 'https://www.example.com')
# FTP
match_chunk(URIChunk, 'ftp://www.example.com',
:scheme =>'ftp', :host =>'www.example.com', :port => nil, :path => nil, :query => nil,
:ref_text => 'ftp://www.example.com')
:link_text => 'ftp://www.example.com')
# mailto
match_chunk(URIChunk, 'mailto:jdoe123@example.com',
:scheme =>'mailto', :host =>'example.com', :port => nil, :path => nil, :query => nil,
:user => 'jdoe123', :ref_text => 'mailto:jdoe123@example.com')
:user => 'jdoe123', :link_text => 'mailto:jdoe123@example.com')
# something nonexistant
match_chunk(URIChunk, 'foobar://www.example.com',
:scheme =>'foobar', :host =>'www.example.com', :port => nil, :path => nil, :query => nil,
:ref_text => 'foobar://www.example.com')
:link_text => 'foobar://www.example.com')

# Soap opera (the most complex case imaginable... well, not really, there should be more evil)
match_chunk(URIChunk, 'http://www.example.com.tw:80/~jdoe123/Help%20Me%20?arg=val&arg2=val2',
:scheme =>'http', :host =>'www.example.com.tw', :port => '80',
:path => '/~jdoe123/Help%20Me%20', :query => 'arg=val&arg2=val2',
:ref_text => 'http://www.example.com.tw:80/~jdoe123/Help%20Me%20?arg=val&arg2=val2')
:link_text => 'http://www.example.com.tw:80/~jdoe123/Help%20Me%20?arg=val&arg2=val2')

# from 0.9 bug reports
match_chunk(URIChunk, 'http://www2.pos.to/~tosh/ruby/rdtool/en/doc/rd-draft.html',
Expand All @@ -135,7 +135,7 @@

it "should test_email_uri" do
match_chunk(URIChunk, 'mail@example.com',
:user => 'mail', :host => 'example.com', :ref_text => 'mail@example.com'
:user => 'mail', :host => 'example.com', :link_text => 'mail@example.com'
)
end

Expand All @@ -154,7 +154,7 @@
'This "hobix (hobix)":http://hobix.com/sample.jpg is a Textile link.')
# just to be sure ...
match_chunk(URIChunk, 'This http://hobix.com/sample.jpg should match',
:ref_text => 'http://hobix.com/sample.jpg')
:link_text => 'http://hobix.com/sample.jpg')
end

it "should test_inline_html" do
Expand All @@ -164,7 +164,7 @@

it "should test_non_uri" do
# "so" is a valid country code; "libproxy.so" is a valid url
match_chunk(URIChunk, 'libproxy.so', :ref_text => 'libproxy.so')
match_chunk(URIChunk, 'libproxy.so', :link_text => 'libproxy.so')

assert_conversion_does_not_apply URIChunk, 'httpd.conf'
# THIS ONE'S BUSTED.. Ethan fix??
Expand Down Expand Up @@ -223,7 +223,7 @@
# normal
match_chunk(LocalURIChunk, 'http://perforce:8001/toto.html',
:scheme => 'http', :host => 'perforce',
:port => '8001', :ref_text => 'http://perforce:8001/toto.html')
:port => '8001', :link_text => 'http://perforce:8001/toto.html')

# in parentheses
match_chunk(LocalURIChunk, 'URI (http://localhost:2500) in brackets',
Expand Down

0 comments on commit fd1bf88

Please sign in to comment.