[Git][noosfero/noosfero][cherry-pick-653c2931] Merge branch 'metadata-article-image' into 'master'

Rodrigo Souto gitlab at mg.gitlab.com
Mon May 23 09:33:22 BRT 2016


Rodrigo Souto pushed to branch cherry-pick-653c2931 at Noosfero / noosfero


Commits:
23d7c1ef by Larissa Reis at 2016-05-23T12:33:18+00:00
Merge branch 'metadata-article-image' into 'master'

Includes article image to body images paths listing

The article image is the main image that represents the article so it
should be included in the listing, at the beginning. This is specially
useful for metadata plugin usage.

See merge request !847
- - - - -


2 changed files:

- app/models/article.rb
- test/unit/article_test.rb


Changes:

=====================================
app/models/article.rb
=====================================
--- a/app/models/article.rb
+++ b/app/models/article.rb
@@ -788,11 +788,13 @@ class Article < ActiveRecord::Base
   end
 
   def body_images_paths
-    Nokogiri::HTML.fragment(self.body.to_s).css('img[src]').collect do |i|
+    paths = Nokogiri::HTML.fragment(self.body.to_s).css('img[src]').collect do |i|
       src = i['src']
       src = URI.escape src if self.new_record? # xss_terminate runs on save
       (self.profile && self.profile.environment) ? URI.join(self.profile.environment.top_url, src).to_s : src
     end
+    paths.unshift(URI.join(self.profile.environment.top_url, self.image.public_filename).to_s) if self.image.present?
+    paths
   end
 
   def more_comments_label


=====================================
test/unit/article_test.rb
=====================================
--- a/test/unit/article_test.rb
+++ b/test/unit/article_test.rb
@@ -1487,6 +1487,17 @@ class ArticleTest < ActiveSupport::TestCase
     assert_includes a.body_images_paths, 'http://test.com/noosfero.png'
   end
 
+  should 'always put article image first in images paths list in article body' do
+    Environment.any_instance.stubs(:default_hostname).returns('noosfero.org')
+    a = create(TinyMceArticle, :name => 'test', :image_builder => {
+      :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')
+    }, :profile_id => @profile.id)
+    a.save!
+    a.body = 'Noosfero <img src="http://noosfero.com/test.png" /> test <img src="http://test.com/noosfero.png" />'
+    a.image.stubs(:public_filename).returns('/files/rails.png')
+    assert_equal 'http://noosfero.org/files/rails.png', a.body_images_paths[0]
+  end
+
   should 'escape utf8 characters correctly' do
     Environment.any_instance.stubs(:default_hostname).returns('noosfero.org')
     a = build TinyMceArticle, profile: @profile



View it on GitLab: https://gitlab.com/noosfero/noosfero/commit/23d7c1ef00c01e21ac344950d719bfe28fd5c168
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20160523/09322604/attachment-0001.html>


More information about the Noosfero-dev mailing list