[Git][noosfero/noosfero][master] 2 commits: Includes article image to body images paths listing
Larissa Reis
gitlab at mg.gitlab.com
Sun May 8 10:06:39 BRT 2016
Larissa Reis pushed to branch master at Noosfero / noosfero
Commits:
8cea790d by Larissa Reis at 2016-05-08T08:30:11-03:00
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.
- - - - -
653c2931 by Larissa Reis at 2016-05-08T13:06:19+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
@@ -806,11 +806,13 @@ class Article < ApplicationRecord
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
@@ -1483,6 +1483,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/compare/1eb7f90295f07aabd220dbcde0753f2245b0923b...653c2931243734f3370f411c77946bbf2230e5a0
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20160508/97b003ad/attachment-0001.html>
More information about the Noosfero-dev
mailing list