Skip to content

Commit

Permalink
support image and links in the chats
Browse files Browse the repository at this point in the history
  • Loading branch information
brickgao committed Sep 9, 2016
1 parent 3fd02a9 commit 3a5c5cd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
1 change: 0 additions & 1 deletion app/assets/stylesheets/messages.scss
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
}
.message-body {
max-width: 250px;
max-height: 50px;
margin: 0 10px;
padding: 10px;
text-align: $textAlign;
Expand Down
10 changes: 10 additions & 0 deletions app/views/layouts/_chat_content.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<% for tag, b, e in parse_content(content) %>
<% if tag == :link %>
<a href="<%= content[b...e] %>"><%= content[b...e] %></a>
<% elsif tag == :image %>
<img src="<%= content[b...e] %>"/>
<% else %>
<%= content[b...e] %>
<% end %>
<% end %>
<br/>
8 changes: 6 additions & 2 deletions app/views/messages/show_chat.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
<% if message.to.id != current_user.id %>
<div>
<div class="message-body">
<%= message.body %>
<% message.body.split(/\r?\n/).each do |paragraph| %>
<%= render 'layouts/chat_content', :content => paragraph %>
<% end %>
</div>
</div>
<% end %>
Expand All @@ -19,7 +21,9 @@
<% if message.to.id == current_user.id %>
<div>
<div class="message-body">
<%= message.body %>
<% message.body.split(/\r?\n/).each do |paragraph| %>
<%= render 'layouts/chat_content', :content => paragraph %>
<% end %>
</div>
</div>
<% end %>
Expand Down

0 comments on commit 3a5c5cd

Please sign in to comment.