Commit f99a9e55ca272e86b02861d098ea70a8414795d5

Authored by Caio Almeida
Committed by Daniela Feitosa
1 parent 71878155

Layout of activities - not ready

app/models/article.rb
... ... @@ -2,7 +2,7 @@ require 'hpricot'
2 2  
3 3 class Article < ActiveRecord::Base
4 4  
5   - track_actions :create_article, :after_create, :keep_params => [:name, :url, :lead], :if => Proc.new { |a| a.is_trackable? && !a.image? }
  5 + track_actions :create_article, :after_create, :keep_params => [:name, :url, :lead, :first_image], :if => Proc.new { |a| a.is_trackable? && !a.image? }
6 6  
7 7 # xss_terminate plugin can't sanitize array fields
8 8 before_save :sanitize_tag_list
... ... @@ -566,6 +566,11 @@ class Article &lt; ActiveRecord::Base
566 566 ActionTracker::Record.find_by_target_type_and_target_id 'Article', self.id
567 567 end
568 568  
  569 + def first_image
  570 + img = Hpricot(self.lead.to_s).search('img[@src]').first || Hpricot(self.body.to_s).search('img').first
  571 + img.nil? ? '' : img.attributes['src']
  572 + end
  573 +
569 574 private
570 575  
571 576 def sanitize_tag_list
... ...
app/views/profile/_comment.rhtml
... ... @@ -4,8 +4,7 @@
4 4 <div class="comment-content comment-logged-in">
5 5  
6 6 <% if Person.find(comment.author_id) %>
7   - <%= link_to image_tag(profile_icon(Person.find(comment.author_id), :minor)) +
8   - content_tag('span', Person.find(comment.author_id).name, :class => 'comment-info'),
  7 + <%= link_to image_tag(profile_icon(Person.find(comment.author_id), :minor)),
9 8 Person.find(comment.author_id).url,
10 9 :class => 'comment-picture',
11 10 :title => Person.find(comment.author_id).name
... ... @@ -13,10 +12,8 @@
13 12 <% end %>
14 13  
15 14 <div class="comment-details">
16   - <h4><%= comment.title %></h4>
17 15 <div class="comment-text">
18   - <p/>
19   - <%= txt2html comment.body %>
  16 + <%= link_to(Person.find(comment.author_id).name, Person.find(comment.author_id).url) %><br /><%= txt2html comment.body %>
20 17 </div>
21 18 <div class="profile-activity-time">
22 19 <%= time_ago_as_sentence(comment.created_at) %>
... ...
app/views/profile/_create_article.rhtml
... ... @@ -3,7 +3,7 @@
3 3 </div>
4 4 <div class='profile-activity-description'>
5 5 <p class='profile-activity-text'><%= link_to activity.user.name, activity.user.url %> <%= describe activity %></p>
6   - <p class='profile-activity-text'><%= activity.params['lead'] %></p>
  6 + <div class='profile-activity-lead'><%= image_tag(activity.params['first_image']) if activity.params['first_image'] %><%= strip_tags(activity.params['lead']).gsub(/(\xA0|\xC2|\s)+/, ' ').gsub(/^\s+/, '') %></div>
7 7 <p class='profile-activity-time'><%= time_ago_as_sentence(activity.created_at) + ' ' + _('ago') %></p>
8 8 <div class='profile-wall-actions'>
9 9 <%= link_to_remote(content_tag(:span, _('Remove')), :url =>{:action => 'remove_activity', :activity_id => activity.id}, :update => "profile-activity-item-#{activity.id}") if logged_in? && current_person == @profile %>
... ...
app/views/profile/_profile_activity.rhtml
... ... @@ -2,10 +2,6 @@
2 2 <%= render :partial => activity.verb, :locals => { :activity => activity }%>
3 3 <hr />
4 4  
5   - <% if logged_in? && current_person.follows?(activity.user) %>
6   - <span class='profile-wall-send-reply'><%= link_to_function _('Comment'), "hide_and_show(['#profile-wall-reply-response-#{activity.id}'],['#profile-wall-reply-#{activity.id}', '#profile-wall-reply-form-#{activity.id}']);$('reply_content_#{activity.id}').value='';$('reply_content_#{activity.id}').focus();$('activity_id_#{activity.id}').value='#{activity.id}';return false", :class => "profile-send-reply" %></span>
7   - <% end %>
8   -
9 5 <ul class="profile-wall-activities-comments" style='padding-left: 50px;width:auto'>
10 6 <%= render :partial => 'comment', :collection => activity.comments %>
11 7 </ul>
... ...
config/environments/development.rb
1 1 # Settings specified here will take precedence over those in config/environment.rb
2 2  
3   -# The production environment is meant for finished, "live" apps.
4   -# Code is not reloaded between requests
5   -config.cache_classes = true
  3 +# In the development environment your application's code is reloaded on
  4 +# every request. This slows down response time but is perfect for development
  5 +# since you don't have to restart the webserver when you make code changes.
  6 +config.cache_classes = false
6 7  
7   -# Use a different logger for distributed setups
8   -# config.logger = SyslogLogger.new
  8 +# Log error messages when you accidentally call methods on nil.
  9 +config.whiny_nils = true
9 10  
10   -# Full error reports are disabled and caching is turned on
11   -config.action_controller.consider_all_requests_local = false
12   -config.action_controller.perform_caching = true
13   -config.action_view.cache_template_loading = true
  11 +# Show full error reports and disable caching
  12 +config.action_controller.consider_all_requests_local = true
  13 +config.action_view.debug_rjs = true
  14 +config.action_controller.perform_caching = false
14 15  
15   -# Enable serving of images, stylesheets, and javascripts from an asset server
16   -# config.action_controller.asset_host = "http://assets.example.com"
17   -
18   -# Disable delivery errors, bad email addresses will be ignored
19   -# config.action_mailer.raise_delivery_errors = false
20   -
21   -config.cache_store = :mem_cache_store, "localhost"
  16 +# Don't care if the mailer can't send
  17 +config.action_mailer.raise_delivery_errors = false
... ...
public/stylesheets/application.css
... ... @@ -5883,11 +5883,24 @@ h1#agenda-title {
5883 5883 #profile-activity li, #profile-network li, #profile-wall li {
5884 5884 display: block;
5885 5885 padding: 10px;
5886   - margin-bottom: 0;
  5886 + margin-bottom: 10px;
5887 5887 background-color: #f0f0f1;
5888 5888 border-bottom: 0;
5889 5889 }
5890 5890  
  5891 +.profile-activity-lead img {
  5892 + width: 64px;
  5893 + float: left;
  5894 + margin-right: 5px;
  5895 +}
  5896 +
  5897 +.profile-activity-lead {
  5898 + width: 370px;
  5899 + float: right;
  5900 + text-align: left;
  5901 + margin: 5px 0;
  5902 +}
  5903 +
5891 5904 #profile-activity li a, #profile-network li a, #profile-wall li a,
5892 5905 #profile-wall .profile-wall-send-reply {
5893 5906 color: #333;
... ... @@ -6169,6 +6182,7 @@ h1#agenda-title {
6169 6182 background: #e8e8e8;
6170 6183 border-bottom: 1px solid #d2d2d2 !important;
6171 6184 border-top: 1px solid #fff;
  6185 + margin-bottom: 0;
6172 6186 }
6173 6187  
6174 6188 #profile-wall .profile-wall-activities-comments img {
... ...
test/unit/article_test.rb
... ... @@ -1584,4 +1584,20 @@ assert_equal &#39;bla&#39;, profile.articles.map(&amp;:comments_count)
1584 1584 assert_includes Article.created_between(from, to), article2
1585 1585 assert_not_includes Article.created_between(from, to), article3
1586 1586 end
  1587 +
  1588 + should 'get first image from lead' do
  1589 + a = fast_create(Article, :body => '<p>Foo</p><p><img src="bar.png" />Bar<img src="foo.png" /></p>',
  1590 + :abstract => '<p>Lead</p><p><img src="leadbar.png" />Bar<img src="leadfoo.png" /></p>')
  1591 + assert_equal 'leadbar.png', a.first_image
  1592 + end
  1593 +
  1594 + should 'get first image from body' do
  1595 + a = fast_create(Article, :body => '<p>Foo</p><p><img src="bar.png" />Bar<img src="foo.png" /></p>')
  1596 + assert_equal 'bar.png', a.first_image
  1597 + end
  1598 +
  1599 + should 'not get first image from anywhere' do
  1600 + a = fast_create(Article, :body => '<p>Foo</p><p>Bar</p>')
  1601 + assert_equal '', a.first_image
  1602 + end
1587 1603 end
... ...