Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

DRYing up with a helper.

This can also be used easily in a theme, eg. to provide a link on the
comments page.
  • Loading branch information...
commit 158166191eb70c0860e95ce76efd1b9f7aed380b 1 parent 823dde2
@smathy authored
View
14 app/helpers/post_helper.rb
@@ -203,4 +203,18 @@ def author_info(post, prefix = 'by ', archive_token = get_pref('ARCHIVE_TOKEN'))
end
end
+ def syntax_link( filter = get_pref('TEXT_FILTER'))
+ filters = {
+ 'markdown' => { :id => 'markdown', :url => 'http://daringfireball.net/projects/markdown/syntax' },
+ 'textile' => { :id => 'textile', :url => 'http://www.textism.com/tools/textile/' },
+ 'convert line breaks' => { :id => 'clb' },
+ 'plain text' => { :id => 'plaintext' }
+ }
+ return content_tag( :span,
+ %Q{<b>#{filter.titleize}</b> enabled. } + ( filters[filter][:url] ? %Q{See the #{link_to('syntax rules', filters[filter][:url], :title => 'Syntax rules', :target => '_blank')} for help.} : "" ),
+ :id => "#{filters[filter][:id]}_syntax_link",
+ :class => 'small gray'
+ )
+ end
+
end
View
10 app/views/admin/posts/_post_form.html.erb
@@ -15,13 +15,9 @@ end
<%= text_field 'post', 'title', :size => '58', :class => 'normal_i_width' %></td></tr>
<tr><td><label for="post_body_raw"><b>Body</b></label></td><td>
-<%= text_area 'post', 'body_raw', :rows => '28', :cols => '59', :wrap => 'virtual', :class => 'normal_i_width' %><br/><span id="markdown_syntax_link" class="small gray"<%= ' style="display: none;"' unless (params[:action] == 'post_new' and get_pref('TEXT_FILTER') == 'markdown') or (params[:action] != 'post_new' and @post.text_filter == 'markdown') %>><b>Markdown</b> syntax enabled. See the <%= link_to('syntax rules', 'http://daringfireball.net/projects/markdown/syntax', :title => 'Syntax rules', :target => '_blank') %> for help.</span>
-
-<span id="textile_syntax_link" class="small gray"<%= ' style="display: none;"' unless (params[:action] == 'post_new' and get_pref('TEXT_FILTER') == 'textile') or (params[:action] != 'post_new' and @post.text_filter == 'textile') %>><b>Textile</b> syntax enabled. See the <%= link_to('syntax rules', 'http://www.textism.com/tools/textile/', :title => 'Syntax rules', :target => '_blank') %> for help.</span>
-
-<span id="clb_syntax_link" class="small gray"<%= ' style="display: none;"' unless (params[:action] == 'post_new' and get_pref('TEXT_FILTER') == 'convert line breaks') or (params[:action] != 'post_new' and @post.text_filter == 'convert line breaks') %>><b>Convert line breaks</b> mode enabled.</span>
-
-<span id="plaintext_syntax_link" class="small gray"<%= ' style="display: none;"' unless (params[:action] == 'post_new' and get_pref('TEXT_FILTER') == 'plain text') or (params[:action] != 'post_new' and @post.text_filter == 'plain text') %>><b>Plain text</b> mode enabled.</span></td></tr>
+ <%= text_area 'post', 'body_raw', :rows => '28', :cols => '59', :wrap => 'virtual', :class => 'normal_i_width' %><br/>
+ <%= syntax_link( params[:action] == 'post_new' ? get_pref('TEXT_FILTER') : @post.text_filter ) %>
+</td></tr>
<tr><td><label for="post_tag_list">Tags</label></td><td>
<%= text_field 'post', 'tag_list', :size => '58', :class => 'normal_i_width', :onkeyup => 'highlight_tags(this)' %><br/>
Please sign in to comment.
Something went wrong with that request. Please try again.