Skip to content

Commit

Permalink
Added newlines handling, changed bbcode function name to parse_text, …
Browse files Browse the repository at this point in the history
…added missing parenthesis
  • Loading branch information
CvX authored and CvX committed Nov 4, 2009
1 parent b00cd14 commit a00460f
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 8 deletions.
5 changes: 4 additions & 1 deletion app/helpers/application_helper.rb
@@ -1,6 +1,6 @@
# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
def bbcode(text)
def parse_text (text)
# Code snippets
text.gsub!(/\[code=?["']?(.*?)["']?\](.*?)\[\/code\]/mis) { CodeRay.scan($2.strip, ($1.blank? ? :plain : $1.to_sym)).div(:line_numbers => :table)}
text = sanitize(text, :tags => %w(span div table tr td br pre tt), :attributes => %w(id class style))
Expand All @@ -19,6 +19,9 @@ def bbcode(text)
# URLs
text.gsub!(/\[url=["']?(.*?)["']?\](.*?)\[\/url\]/mis) { "<a rel='nofollow' href='" << $1 << "'>" << $2 << "</a>" }

# handle newlines
text.gsub!(/(.*)(\r)+?\n/) { $1 << "<br />\n" }

# handle with care...
bbcode_ext(text)
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/users/show.html.erb
Expand Up @@ -25,7 +25,7 @@
<% end %>
<% unless @user.signature.blank? %><br />
____________<br />
<%= bbcode(@user.signature) %>
<%= parse_text(@user.signature) %>
<% end %>
</td>
</tr>
Expand Down
2 changes: 1 addition & 1 deletion app/views/messages/show.html.erb
Expand Up @@ -10,7 +10,7 @@
</tr>

<tr>
<td><%= bbcode(@message.text) %></td>
<td><%= parse_text(@message.text) %></td>
</tr>

<tr>
Expand Down
4 changes: 2 additions & 2 deletions app/views/posts/_post.html.erb
Expand Up @@ -48,10 +48,10 @@
</td>

<td valign='top' colspan='2' valign='top'>
<%= bbcode(post.text) %>
<%= parse_text(post.text) %>
<% if post.user.can?(:use_signature, @forum) && !post.user.signature.blank? %><br />
____________<br />
<%= bbcode(post.user.signature) %>
<%= parse_text(post.user.signature) %>
<% end %>
<% if !post.edits.empty? %>
Expand Down
4 changes: 2 additions & 2 deletions app/views/users/show.html.erb
Expand Up @@ -20,15 +20,15 @@
<td valign='top'>
<b><%= t(:Date_joined) %>:</b> <%= @user.created_at.strftime date_display %> <br />
<b><%= t(:Posts) %>:</b> <%= @user.posts.size %>, <%= t(:about) %> <%= @posts_percentage %>% <%= t(:of_all_posts_on_this_forum) %><br />
<b><%= t(:Bans) %>:</b> <%= @user %> <%= t(:has_been_banned, :count => @user.ban_times %><br />
<b><%= t(:Bans) %>:</b> <%= @user %> <%= t(:has_been_banned, :count => @user.ban_times) %><br />
<% if !@user.ban_time.nil? && @user.ban_time > Time.now %>
<h2><%= t(:is_currently_banned, :user => @user) %>!</h2>
<%= t(:banned_by, :user => @user.banned_by.login) %><%= t(:ban_expires_in, :time => time_ago_in_words(@user.ban_time)) %>.<br /><br />
<%= t(:reason_stated_was, :reason => @user.ban_reason) %></i><br /><br />
<% end %>
<% unless @user.signature.blank? %><br />
____________<br />
<%= bbcode sanitize(@user.signature) %>
<%= parse_text(@user.signature) %>
<% end %>
</td>
</tr>
Expand Down
2 changes: 1 addition & 1 deletion spec/helpers/application_helper_spec.rb
Expand Up @@ -19,6 +19,6 @@ class TestView < ActionView::Base
end

it "should correctly encapsulate double quotes" do
TestView.new.bbcode('[quote="Kitten"][quote="Dog"]QUOTE INSIDE[/quote]QUOTE OUTSIDE[/quote]').should eql("<div class='center'><div class='quote'><b>Kitten wrote:</b><div class='center'><div class='quote'><b>Dog wrote:</b></div></div>QUOTE OUTSIDE</div></div>")
TestView.new.parse_text('[quote="Kitten"][quote="Dog"]QUOTE INSIDE[/quote]QUOTE OUTSIDE[/quote]').should eql("<div class='center'><div class='quote'><b>Kitten wrote:</b><div class='center'><div class='quote'><b>Dog wrote:</b></div></div>QUOTE OUTSIDE</div></div>")
end
end

0 comments on commit a00460f

Please sign in to comment.