Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Descriptionをmarkdownで書けるようにした kentaro/triglav#34 #40

Merged
merged 1 commit into from
Nov 8, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ gem 'omniauth-github'
gem 'octokit'

gem 'mysql2'
gem 'bluecloth'

group :development do
gem 'pry'
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ GEM
arel (3.0.2)
artii (2.0.3)
binding_of_caller (0.6.8)
bluecloth (2.2.0)
builder (3.1.4)
capistrano (2.13.5)
highline
Expand Down Expand Up @@ -394,6 +395,7 @@ PLATFORMS
DEPENDENCIES
activerecord-deprecated_finders!
artii
bluecloth
capistrano
capistrano_banner
capistrano_colors
Expand Down
5 changes: 5 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,9 @@ def current_user
def current_user=(user)
@current_user = user
end

def markdown(text)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

options = { escape_html: true, auto_links: true }
BlueCloth.new(text, options).to_html.html_safe

の方がよいですね。

options = { escape_html: true, auto_links: true }
BlueCloth.new(text, options).to_html.html_safe
end
end
2 changes: 1 addition & 1 deletion app/views/hosts/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<dt><strong><%= model_class.human_attribute_name(:is_active) %>:</strong></dt>
<dd><%= t(@host.active ? model_class.human_attribute_name(:active) : model_class.human_attribute_name(:inactive)) %></dd>
<dt><strong><%= model_class.human_attribute_name(:description) %>:</strong></dt>
<dd><%= @host.description %></dd>
<dd><%= markdown(@host.description) %></dd>
<dt><strong><%= model_class.human_attribute_name(:service) %> - <%= model_class.human_attribute_name(:role) %>:</strong></dt>
<% @host.host_relations.each do |relation| -%>
<dd><%= relation.service.name %> - <%= relation.role.name %></dd>
Expand Down
2 changes: 1 addition & 1 deletion app/views/roles/_roles.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<% roles.each do |role| %>
<tr>
<td><%= link_to role.name, role_path(role) %></td>
<td><%= role.description %></td>
<td><%= markdown(role.description) %></td>
<td><%=l role.created_at %></td>
<td>
<%= link_to t('helpers.links.edit'),
Expand Down
2 changes: 1 addition & 1 deletion app/views/roles/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<dt><strong><%= model_class.human_attribute_name(:name) %>:</strong></dt>
<dd><%= @role.name %></dd>
<dt><strong><%= model_class.human_attribute_name(:description) %>:</strong></dt>
<dd><%= @role.description %></dd>
<dd><%= markdown(@role.description) %></dd>
</dl>

<div class="form-actions">
Expand Down
2 changes: 1 addition & 1 deletion app/views/services/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<dt><strong><%= model_class.human_attribute_name(:name) %>:</strong></dt>
<dd><%= @service.name %></dd>
<dt><strong><%= model_class.human_attribute_name(:description) %>:</strong></dt>
<dd><%= @service.description %></dd>
<dd><%= markdown(@service.description) %></dd>
<% if @service.munin_url.present? -%>
<dt><strong><%= model_class.human_attribute_name(:munin_url) %>:</strong></dt>
<dd>
Expand Down
2 changes: 1 addition & 1 deletion app/views/shared/_hosts.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</td>
<td>
<% if host.description.present? -%>
<p><%= host.description %></p>
<p><%= markdown(host.description) %></p>
<% end -%>
<p>
<small><span class="label">Created at</span>
Expand Down
4 changes: 2 additions & 2 deletions app/views/shared/_services.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<% services.each do |service| %>
<tr>
<td><%= link_to service.name, service_path(service) %></td>
<td><%= service.description %></td>
<td><%= markdown(service.description) %></td>
<td><%=l service.created_at %></td>
<td>
<%= link_to t('helpers.links.edit'),
Expand All @@ -38,4 +38,4 @@
<% end %>
</tbody>
</table>
<% end -%>
<% end -%>
30 changes: 30 additions & 0 deletions spec/helpers/appliction_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
require 'spec_helper'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


describe ApplicationHelper do
describe '#markdown' do
it 'should convert text from markdown to html' do
markdown_text = <<-EOF.strip_heredoc
# Title

- foo
- bar

hoge
EOF

html_text = <<-EOF.strip_heredoc
<h1>Title</h1>

<ul>
<li>foo</li>
<li>bar</li>
</ul>


<p>hoge</p>
EOF

expect(helper.markdown(markdown_text)).to be == html_text.chomp
end
end
end