diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 550ce3c..a5af7e0 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -15,14 +15,6 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-class RedCloth
- # Patch for RedCloth. Fixed in RedCloth r128 but _why hasn't released it yet.
- # http://code.whytheluckystiff.net/redcloth/changeset/128
- def hard_break( text )
- text.gsub!( /(.)\n(?!\n|\Z| *([#*=]+(\s|$)|[{|]))/, "\\1
" ) if hard_breaks
- end
-end
-
module ApplicationHelper
def current_role
@@ -112,7 +104,27 @@ module ApplicationHelper
# textilize text according to system settings and RedCloth availability
def textilizable(text, options = {})
return "" if text.blank?
+
+ # when using an image link, try to use an attachment, if possible
+ attachments = options[:attachments]
+ if attachments
+ text = text.gsub(/!([<>=]*)(\S+\.(gif|jpg|jpeg|png))!/) do |m|
+ align = $1
+ filename = $2
+ rf = Regexp.new(filename, Regexp::IGNORECASE)
+ # search for the picture in attachments
+ if found = attachments.detect { |att| att.filename =~ rf }
+ image_url = url_for :controller => 'attachments', :action => 'download', :id => found.id
+ "!#{align}#{image_url}!"
+ else
+ "!#{align}#{filename}!"
+ end
+ end
+ end
+ text = (Setting.text_formatting == 'textile') ?
+ Redmine::WikiFormatting.to_html(text) : simple_format(auto_link(h(text)))
+
# different methods for formatting wiki links
case options[:wiki_links]
when :local
@@ -148,36 +160,22 @@ module ApplicationHelper
link_to((title || page), format_wiki_link.call(link_project, Wiki.titleize(page)), :class => 'wiki-page')
end
- # turn issue ids into links
+ # turn issue and revision ids into links
# example:
# #52 -> #52
- text = text.gsub(/#(\d+)(?=\b)/) {|m| link_to "##{$1}", {:controller => 'issues', :action => 'show', :id => $1}, :class => 'issue' }
-
- # turn revision ids into links (@project needed)
- # example:
- # r52 -> r52 (@project.id is 6)
- text = text.gsub(/(?=\b)r(\d+)(?=\b)/) {|m| link_to "r#{$1}", {:controller => 'repositories', :action => 'revision', :id => project.id, :rev => $1}, :class => 'changeset' } if project
-
- # when using an image link, try to use an attachment, if possible
- attachments = options[:attachments]
- if attachments
- text = text.gsub(/!([<>=]*)(\S+\.(gif|jpg|jpeg|png))!/) do |m|
- align = $1
- filename = $2
- rf = Regexp.new(filename, Regexp::IGNORECASE)
- # search for the picture in attachments
- if found = attachments.detect { |att| att.filename =~ rf }
- image_url = url_for :controller => 'attachments', :action => 'download', :id => found.id
- "!#{align}#{image_url}!"
- else
- "!#{align}#{filename}!"
- end
+ # r52 -> r52 (project.id is 6)
+ text = text.gsub(%r{([\s,-^])(#|r)(\d+)(?=[[:punct:]]|\s|<|$)}) do |m|
+ leading, otype, oid = $1, $2, $3
+ link = nil
+ if otype == 'r'
+ link = link_to("r#{oid}", {:controller => 'repositories', :action => 'revision', :id => project.id, :rev => oid}, :class => 'changeset') if project
+ else
+ link = link_to("##{oid}", {:controller => 'issues', :action => 'show', :id => oid}, :class => 'issue')
end
+ leading + (link || "#{otype}#{oid}")
end
-
- # finally textilize text
- @do_textilize ||= (Setting.text_formatting == 'textile') && (ActionView::Helpers::TextHelper.method_defined? "textilize")
- text = @do_textilize ? auto_link(RedCloth.new(text, [:hard_breaks]).to_html) : simple_format(auto_link(h(text)))
+
+ text
end
# Same as Rails' simple_format helper without using paragraphs
diff --git a/lib/redcloth.rb b/lib/redcloth.rb
new file mode 100644
index 0000000..1228af6
--- /dev/null
+++ b/lib/redcloth.rb
@@ -0,0 +1,1130 @@
+# vim:ts=4:sw=4:
+# = RedCloth - Textile and Markdown Hybrid for Ruby
+#
+# Homepage:: http://whytheluckystiff.net/ruby/redcloth/
+# Author:: why the lucky stiff (http://whytheluckystiff.net/)
+# Copyright:: (cc) 2004 why the lucky stiff (and his puppet organizations.)
+# License:: BSD
+#
+# (see http://hobix.com/textile/ for a Textile Reference.)
+#
+# Based on (and also inspired by) both:
+#
+# PyTextile: http://diveintomark.org/projects/textile/textile.py.txt
+# Textism for PHP: http://www.textism.com/tools/textile/
+#
+#
+
+# = RedCloth
+#
+# RedCloth is a Ruby library for converting Textile and/or Markdown
+# into HTML. You can use either format, intermingled or separately.
+# You can also extend RedCloth to honor your own custom text stylings.
+#
+# RedCloth users are encouraged to use Textile if they are generating
+# HTML and to use Markdown if others will be viewing the plain text.
+#
+# == What is Textile?
+#
+# Textile is a simple formatting style for text
+# documents, loosely based on some HTML conventions.
+#
+# == Sample Textile Text
+#
+# h2. This is a title
+#
+# h3. This is a subhead
+#
+# This is a bit of paragraph.
+#
+# bq. This is a blockquote.
+#
+# = Writing Textile
+#
+# A Textile document consists of paragraphs. Paragraphs
+# can be specially formatted by adding a small instruction
+# to the beginning of the paragraph.
+#
+# h[n]. Header of size [n].
+# bq. Blockquote.
+# # Numeric list.
+# * Bulleted list.
+#
+# == Quick Phrase Modifiers
+#
+# Quick phrase modifiers are also included, to allow formatting
+# of small portions of text within a paragraph.
+#
+# \_emphasis\_
+# \_\_italicized\_\_
+# \*strong\*
+# \*\*bold\*\*
+# ??citation??
+# -deleted text-
+# +inserted text+
+# ^superscript^
+# ~subscript~
+# @code@
+# %(classname)span%
+#
+# ==notextile== (leave text alone)
+#
+# == Links
+#
+# To make a hypertext link, put the link text in "quotation
+# marks" followed immediately by a colon and the URL of the link.
+#
+# Optional: text in (parentheses) following the link text,
+# but before the closing quotation mark, will become a Title
+# attribute for the link, visible as a tool tip when a cursor is above it.
+#
+# Example:
+#
+# "This is a link (This is a title) ":http://www.textism.com
+#
+# Will become:
+#
+# This is a link
+#
+# == Images
+#
+# To insert an image, put the URL for the image inside exclamation marks.
+#
+# Optional: text that immediately follows the URL in (parentheses) will
+# be used as the Alt text for the image. Images on the web should always
+# have descriptive Alt text for the benefit of readers using non-graphical
+# browsers.
+#
+# Optional: place a colon followed by a URL immediately after the
+# closing ! to make the image into a link.
+#
+# Example:
+#
+# !http://www.textism.com/common/textist.gif(Textist)!
+#
+# Will become:
+#
+#
+#
+# With a link:
+#
+# !/common/textist.gif(Textist)!:http://textism.com
+#
+# Will become:
+#
+#
+#
+# == Defining Acronyms
+#
+# HTML allows authors to define acronyms via the tag. The definition appears as a
+# tool tip when a cursor hovers over the acronym. A crucial aid to clear writing,
+# this should be used at least once for each acronym in documents where they appear.
+#
+# To quickly define an acronym in Textile, place the full text in (parentheses)
+# immediately following the acronym.
+#
+# Example:
+#
+# ACLU(American Civil Liberties Union)
+#
+# Will become:
+#
+# ACLU
+#
+# == Adding Tables
+#
+# In Textile, simple tables can be added by seperating each column by
+# a pipe.
+#
+# |a|simple|table|row|
+# |And|Another|table|row|
+#
+# Attributes are defined by style definitions in parentheses.
+#
+# table(border:1px solid black).
+# (background:#ddd;color:red). |{}| | | |
+#
+# == Using RedCloth
+#
+# RedCloth is simply an extension of the String class, which can handle
+# Textile formatting. Use it like a String and output HTML with its
+# RedCloth#to_html method.
+#
+# doc = RedCloth.new "
+#
+# h2. Test document
+#
+# Just a simple test."
+#
+# puts doc.to_html
+#
+# By default, RedCloth uses both Textile and Markdown formatting, with
+# Textile formatting taking precedence. If you want to turn off Markdown
+# formatting, to boost speed and limit the processor:
+#
+# class RedCloth::Textile.new( str )
+
+class RedCloth < String
+
+ VERSION = '3.0.4'
+ DEFAULT_RULES = [:textile, :markdown]
+
+ #
+ # Two accessor for setting security restrictions.
+ #
+ # This is a nice thing if you're using RedCloth for
+ # formatting in public places (e.g. Wikis) where you
+ # don't want users to abuse HTML for bad things.
+ #
+ # If +:filter_html+ is set, HTML which wasn't
+ # created by the Textile processor will be escaped.
+ #
+ # If +:filter_styles+ is set, it will also disable
+ # the style markup specifier. ('{color: red}')
+ #
+ attr_accessor :filter_html, :filter_styles
+
+ #
+ # Accessor for toggling hard breaks.
+ #
+ # If +:hard_breaks+ is set, single newlines will
+ # be converted to HTML break tags. This is the
+ # default behavior for traditional RedCloth.
+ #
+ attr_accessor :hard_breaks
+
+ # Accessor for toggling lite mode.
+ #
+ # In lite mode, block-level rules are ignored. This means
+ # that tables, paragraphs, lists, and such aren't available.
+ # Only the inline markup for bold, italics, entities and so on.
+ #
+ # r = RedCloth.new( "And then? She *fell*!", [:lite_mode] )
+ # r.to_html
+ # #=> "And then? She fell!"
+ #
+ attr_accessor :lite_mode
+
+ #
+ # Accessor for toggling span caps.
+ #
+ # Textile places `span' tags around capitalized
+ # words by default, but this wreaks havoc on Wikis.
+ # If +:no_span_caps+ is set, this will be
+ # suppressed.
+ #
+ attr_accessor :no_span_caps
+
+ #
+ # Establishes the markup predence. Available rules include:
+ #
+ # == Textile Rules
+ #
+ # The following textile rules can be set individually. Or add the complete
+ # set of rules with the single :textile rule, which supplies the rule set in
+ # the following precedence:
+ #
+ # refs_textile:: Textile references (i.e. [hobix]http://hobix.com/)
+ # block_textile_table:: Textile table block structures
+ # block_textile_lists:: Textile list structures
+ # block_textile_prefix:: Textile blocks with prefixes (i.e. bq., h2., etc.)
+ # inline_textile_image:: Textile inline images
+ # inline_textile_link:: Textile inline links
+ # inline_textile_span:: Textile inline spans
+ # glyphs_textile:: Textile entities (such as em-dashes and smart quotes)
+ #
+ # == Markdown
+ #
+ # refs_markdown:: Markdown references (for example: [hobix]: http://hobix.com/)
+ # block_markdown_setext:: Markdown setext headers
+ # block_markdown_atx:: Markdown atx headers
+ # block_markdown_rule:: Markdown horizontal rules
+ # block_markdown_bq:: Markdown blockquotes
+ # block_markdown_lists:: Markdown lists
+ # inline_markdown_link:: Markdown links
+ attr_accessor :rules
+
+ # Returns a new RedCloth object, based on _string_ and
+ # enforcing all the included _restrictions_.
+ #
+ # r = RedCloth.new( "h1. A bold man", [:filter_html] )
+ # r.to_html
+ # #=>"
#{ code }
#{ after }" )
+ end
+ end
+
+ def lT( text )
+ text =~ /\#$/ ? 'o' : 'u'
+ end
+
+ def hard_break( text )
+ text.gsub!( /(.)\n(?!\Z| *([#*=]+(\s|$)|[{|]))/, "\\1#{ blk }
"
+ else
+ blk = "\t#{ blk }
" + end + end + # hard_break blk + blk + "\n#{ code_blk }" + end + end + + end.join( "\n\n" ) ) + end + + def textile_bq( tag, atts, cite, content ) + cite, cite_title = check_refs( cite ) + cite = " cite=\"#{ cite }\"" if cite + atts = shelve( atts ) if atts + "\t\n\t\t" + end + + def textile_p( tag, atts, cite, content ) + atts = shelve( atts ) if atts + "\t<#{ tag }#{ atts }>#{ content }#{ tag }>" + end + + alias textile_h1 textile_p + alias textile_h2 textile_p + alias textile_h3 textile_p + alias textile_h4 textile_p + alias textile_h5 textile_p + alias textile_h6 textile_p + + def textile_fn_( tag, num, atts, cite, content ) + atts << " id=\"fn#{ num }\"" + content = "#{ num } #{ content }" + atts = shelve( atts ) if atts + "\t#{ content }
\n\t
#{ content }
" + end + + BLOCK_RE = /^(([a-z]+)(\d*))(#{A}#{C})\.(?::(\S+))? (.*)$/m + + def block_textile_prefix( text ) + if text =~ BLOCK_RE + tag,tagpre,num,atts,cite,content = $~[1..6] + atts = pba( atts ) + + # pass to prefix handler + if respond_to? "textile_#{ tag }", true + text.gsub!( $&, method( "textile_#{ tag }" ).call( tag, atts, cite, content ) ) + elsif respond_to? "textile_#{ tagpre }_", true + text.gsub!( $&, method( "textile_#{ tagpre }_" ).call( tagpre, num, atts, cite, content ) ) + end + end + end + + SETEXT_RE = /\A(.+?)\n([=-])[=-]* *$/m + def block_markdown_setext( text ) + if text =~ SETEXT_RE + tag = if $2 == "="; "h1"; else; "h2"; end + blk, cont = "<#{ tag }>#{ $1 }#{ tag }>", $' + blocks cont + text.replace( blk + cont ) + end + end + + ATX_RE = /\A(\#{1,6}) # $1 = string of #'s + [ ]* + (.+?) # $2 = Header text + [ ]* + \#* # optional closing #'s (not counted) + $/x + def block_markdown_atx( text ) + if text =~ ATX_RE + tag = "h#{ $1.length }" + blk, cont = "<#{ tag }>#{ $2 }#{ tag }>\n\n", $' + blocks cont + text.replace( blk + cont ) + end + end + + MARKDOWN_BQ_RE = /\A(^ *> ?.+$(.+\n)*\n*)+/m + + def block_markdown_bq( text ) + text.gsub!( MARKDOWN_BQ_RE ) do |blk| + blk.gsub!( /^ *> ?/, '' ) + flush_left blk + blocks blk + blk.gsub!( /^(\S)/, "\t\\1" ) + "\n#{ blk }\n\n\n" + end + end + + MARKDOWN_RULE_RE = /^(#{ + ['*', '-', '_'].collect { |ch| '( ?' + Regexp::quote( ch ) + ' ?){3,}' }.join( '|' ) + })$/ + + def block_markdown_rule( text ) + text.gsub!( MARKDOWN_RULE_RE ) do |blk| + "
|.|^) # start of line?
+ \! # opening
+ (\<|\=|\>)? # optional alignment atts
+ (#{C}) # optional style,class atts
+ (?:\. )? # optional dot-space
+ ([^\s(!]+?) # presume this is the src
+ \s? # optional space
+ (?:\(((?:[^\(\)]|\([^\)]+\))+?)\))? # optional title
+ \! # closing
+ (?::#{ HYPERLINK })? # optional href
+ /x
+
+ def inline_textile_image( text )
+ text.gsub!( IMAGE_RE ) do |m|
+ stln,algn,atts,url,title,href,href_a1,href_a2 = $~[1..8]
+ atts = pba( atts )
+ atts = " src=\"#{ url }\"#{ atts }"
+ atts << " title=\"#{ title }\"" if title
+ atts << " alt=\"#{ title }\""
+ # size = @getimagesize($url);
+ # if($size) $atts.= " $size[3]";
+
+ href, alt_title = check_refs( href ) if href
+ url, url_title = check_refs( url )
+
+ out = ''
+ out << "" if href
+ out << ""
+ out << "#{ href_a1 }#{ href_a2 }" if href
+
+ if algn
+ algn = h_align( algn )
+ if stln == "
" + out = "
#{ out }" + else + out = "#{ stln }
, etc.
+ if $1
+ if line =~ OFFTAG_OPEN
+ codepre += 1
+ elsif line =~ OFFTAG_CLOSE
+ codepre -= 1
+ codepre = 0 if codepre < 0
+ end
+ elsif codepre.zero?
+ glyphs_textile( line, level + 1 )
+ else
+ htmlesc( line, :NoQuotes )
+ end
+ # p [level, codepre, line]
+
+ line
+ end
+ end
+ end
+
+ def rip_offtags( text )
+ if text =~ /<.*>/
+ ## strip and encode content
+ codepre, used_offtags = 0, {}
+ text.gsub!( OFFTAG_MATCH ) do |line|
+ if $3
+ offtag, aftertag = $4, $5
+ codepre += 1
+ used_offtags[offtag] = true
+ if codepre - used_offtags.length > 0
+ htmlesc( line, :NoQuotes ) unless used_offtags['notextile']
+ @pre_list.last << line
+ line = ""
+ else
+ htmlesc( aftertag, :NoQuotes ) if aftertag and not used_offtags['notextile']
+ line = ""
+ @pre_list << "#{ $3 }#{ aftertag }"
+ end
+ elsif $1 and codepre > 0
+ if codepre - used_offtags.length > 0
+ htmlesc( line, :NoQuotes ) unless used_offtags['notextile']
+ @pre_list.last << line
+ line = ""
+ end
+ codepre -= 1 unless codepre.zero?
+ used_offtags = {} if codepre.zero?
+ end
+ line
+ end
+ end
+ text
+ end
+
+ def smooth_offtags( text )
+ unless @pre_list.empty?
+ ## replace content
+ text.gsub!( // ) { @pre_list[$1.to_i] }
+ end
+ end
+
+ def inline( text )
+ [/^inline_/, /^glyphs_/].each do |meth_re|
+ @rules.each do |rule_name|
+ method( rule_name ).call( text ) if rule_name.to_s.match( meth_re )
+ end
+ end
+ end
+
+ def h_align( text )
+ H_ALGN_VALS[text]
+ end
+
+ def v_align( text )
+ V_ALGN_VALS[text]
+ end
+
+ def textile_popup_help( name, windowW, windowH )
+ ' ' + name + '
'
+ end
+
+ # HTML cleansing stuff
+ BASIC_TAGS = {
+ 'a' => ['href', 'title'],
+ 'img' => ['src', 'alt', 'title'],
+ 'br' => [],
+ 'i' => nil,
+ 'u' => nil,
+ 'b' => nil,
+ 'pre' => nil,
+ 'kbd' => nil,
+ 'code' => ['lang'],
+ 'cite' => nil,
+ 'strong' => nil,
+ 'em' => nil,
+ 'ins' => nil,
+ 'sup' => nil,
+ 'sub' => nil,
+ 'del' => nil,
+ 'table' => nil,
+ 'tr' => nil,
+ 'td' => ['colspan', 'rowspan'],
+ 'th' => nil,
+ 'ol' => nil,
+ 'ul' => nil,
+ 'li' => nil,
+ 'p' => nil,
+ 'h1' => nil,
+ 'h2' => nil,
+ 'h3' => nil,
+ 'h4' => nil,
+ 'h5' => nil,
+ 'h6' => nil,
+ 'blockquote' => ['cite']
+ }
+
+ def clean_html( text, tags = BASIC_TAGS )
+ text.gsub!( /]*)>/ ) do
+ raw = $~
+ tag = raw[2].downcase
+ if tags.has_key? tag
+ pcs = [tag]
+ tags[tag].each do |prop|
+ ['"', "'", ''].each do |q|
+ q2 = ( q != '' ? q : '\s' )
+ if raw[3] =~ /#{prop}\s*=\s*#{q}([^#{q2}]+)#{q}/i
+ attrv = $1
+ next if prop == 'src' and attrv =~ %r{^(?!http)\w+:}
+ pcs << "#{prop}=\"#{$1.gsub('"', '\\"')}\""
+ break
+ end
+ end
+ end if tags[tag]
+ "<#{raw[1]}#{pcs.join " "}>"
+ else
+ " "
+ end
+ end
+ end
+end
+
diff --git a/lib/redmine/wiki_formatting.rb b/lib/redmine/wiki_formatting.rb
new file mode 100644
index 0000000..b6b2ff8
--- /dev/null
+++ b/lib/redmine/wiki_formatting.rb
@@ -0,0 +1,79 @@
+require 'redcloth'
+
+module Redmine
+ module WikiFormatting
+
+ private
+
+ class TextileFormatter < RedCloth
+ RULES = [:inline_auto_link, :inline_auto_mailto, :textile ]
+
+ def initialize(*args)
+ super
+ self.hard_breaks=true
+ end
+
+ def to_html
+ super(*RULES).to_s
+ end
+
+ private
+
+ # Patch for RedCloth. Fixed in RedCloth r128 but _why hasn't released it yet.
+ # http://code.whytheluckystiff.net/redcloth/changeset/128
+ def hard_break( text )
+ text.gsub!( /(.)\n(?!\n|\Z| *([#*=]+(\s|$)|[{|]))/, "\\1
" ) if hard_breaks
+ end
+
+ AUTO_LINK_RE = %r{
+ ( # leading text
+ <\w+.*?>| # leading HTML tag, or
+ [^=<>!:'"/]| # leading punctuation, or
+ ^ # beginning of line
+ )
+ (
+ (?:https?://)| # protocol spec, or
+ (?:www\.) # www.*
+ )
+ (
+ [-\w]+ # subdomain or domain
+ (?:\.[-\w]+)* # remaining subdomains or domain
+ (?::\d+)? # port
+ (?:/(?:(?:[~\w\+%-]|(?:[,.;:][^\s$]))+)?)* # path
+ (?:\?[\w\+%&=.;-]+)? # query string
+ (?:\#[\w\-]*)? # trailing anchor
+ )
+ ([[:punct:]]|\s|<|$) # trailing text
+ }x unless const_defined?(:AUTO_LINK_RE)
+
+ # Turns all urls into clickable links (code from Rails).
+ def inline_auto_link(text)
+ text.gsub!(AUTO_LINK_RE) do
+ all, a, b, c, d = $&, $1, $2, $3, $4
+ if a =~ /=]?/
+ # don't replace URL's that are already linked
+ # and URL's prefixed with ! !> !< != (textile images)
+ all
+ else
+ text = b + c
+ %(#{a}#{text}#{d})
+ end
+ end
+ end
+
+ # Turns all email addresses into clickable links (code from Rails).
+ def inline_auto_mailto(text)
+ text.gsub!(/([\w\.!#\$%\-+.]+@[A-Za-z0-9\-]+(\.[A-Za-z0-9\-]+)+)/) do
+ text = $1
+ %{#{text}}
+ end
+ end
+ end
+
+ public
+
+ def self.to_html(text, options = {})
+ TextileFormatter.new(text).to_html
+ end
+ end
+end
diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css
index f756a56..6f01a67 100644
--- a/public/stylesheets/application.css
+++ b/public/stylesheets/application.css
@@ -615,11 +615,11 @@ div.wiki table, div.wiki td, div.wiki th {
div.wiki a {
background-position: 0% 60%;
background-repeat: no-repeat;
- padding-left: 12px;
+ padding-left: 14px;
background-image: url(../images/external.png);
}
-div.wiki a.wiki-page, div.wiki a.issue, div.wiki a.changeset {
+div.wiki a.wiki-page, div.wiki a.issue, div.wiki a.changeset, div.wiki a.email {
padding-left: 0;
background-image: none;
}
diff --git a/test/helper_testcase.rb b/test/helper_testcase.rb
new file mode 100644
index 0000000..aba6784
--- /dev/null
+++ b/test/helper_testcase.rb
@@ -0,0 +1,35 @@
+# Re-raise errors caught by the controller.
+class StubController < ApplicationController
+ def rescue_action(e) raise e end;
+ attr_accessor :request, :url
+end
+
+class HelperTestCase < Test::Unit::TestCase
+
+ # Add other helpers here if you need them
+ include ActionView::Helpers::ActiveRecordHelper
+ include ActionView::Helpers::TagHelper
+ include ActionView::Helpers::FormTagHelper
+ include ActionView::Helpers::FormOptionsHelper
+ include ActionView::Helpers::FormHelper
+ include ActionView::Helpers::UrlHelper
+ include ActionView::Helpers::AssetTagHelper
+ include ActionView::Helpers::PrototypeHelper
+
+ def setup
+ super
+
+ @request = ActionController::TestRequest.new
+ @controller = StubController.new
+ @controller.request = @request
+
+ # Fake url rewriter so we can test url_for
+ @controller.url = ActionController::UrlRewriter.new @request, {}
+
+ ActionView::Helpers::AssetTagHelper::reset_javascript_include_default
+ end
+
+ def test_dummy
+ # do nothing - required by test/unit
+ end
+end
diff --git a/test/test_helper.rb b/test/test_helper.rb
index b5218c2..542d4ce 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -18,6 +18,7 @@
ENV["RAILS_ENV"] ||= "test"
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
require 'test_help'
+require File.expand_path(File.dirname(__FILE__) + '/helper_testcase')
class Test::Unit::TestCase
# Transactional fixtures accelerate your tests by wrapping each test method
diff --git a/test/unit/helpers/application_helper_test.rb b/test/unit/helpers/application_helper_test.rb
new file mode 100644
index 0000000..c618cec
--- /dev/null
+++ b/test/unit/helpers/application_helper_test.rb
@@ -0,0 +1,66 @@
+# redMine - project management software
+# Copyright (C) 2006-2007 Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+require File.dirname(__FILE__) + '/../../test_helper'
+
+class ApplicationHelperTest < HelperTestCase
+ include ApplicationHelper
+ fixtures :projects
+
+ def setup
+ super
+ end
+
+ def test_auto_links
+ to_test = {
+ 'http://foo.bar' => 'http://foo.bar',
+ 'www.foo.bar' => 'www.foo.bar',
+ 'http://foo.bar/page?p=1&t=z&s=' => 'http://foo.bar/page?p=1&t=z&s=',
+ 'http://foo.bar/page#125' => 'http://foo.bar/page#125'
+ }
+ to_test.each { |text, result| assert_equal "#{result}
", textilizable(text) }
+ end
+
+ def test_auto_mailto
+ assert_equal '',
+ textilizable('test@foo.bar')
+ end
+
+ def test_textile_tags
+ to_test = {
+ # inline images
+ '!http://foo.bar/image.jpg!' => '
',
+ 'floating !>http://foo.bar/image.jpg!' => 'floating
',
+ # textile links
+ 'This is a "link":http://foo.bar' => 'This is a link',
+ '"link (Link title)":http://foo.bar' => 'link'
+ }
+ to_test.each { |text, result| assert_equal "#{result}
", textilizable(text) }
+ end
+
+ def test_redmine_links
+ issue_link = link_to('#52', {:controller => 'issues', :action => 'show', :id => 52}, :class => 'issue')
+ changeset_link = link_to('r19', {:controller => 'repositories', :action => 'revision', :id => 1, :rev => 19}, :class => 'changeset')
+
+ to_test = {
+ '#52, #52 and #52.' => "#{issue_link}, #{issue_link} and #{issue_link}.",
+ 'r19' => changeset_link
+ }
+ @project = Project.find(1)
+ to_test.each { |text, result| assert_equal "#{result}
", textilizable(text) }
+ end
+end
diff --git a/test/unit/setting_test.rb b/test/unit/setting_test.rb
index c3d27fa..44240ef 100644
--- a/test/unit/setting_test.rb
+++ b/test/unit/setting_test.rb
@@ -20,7 +20,7 @@ require File.dirname(__FILE__) + '/../test_helper'
class SettingTest < Test::Unit::TestCase
def test_read_default
- assert_equal "redMine", Setting.app_title
+ assert_equal "Redmine", Setting.app_title
assert Setting.self_registration?
assert !Setting.login_required?
end