Commit d74aa7ba9234d2d5d508d87cbba645c95e713e12
1 parent
15717094
Exists in
master
and in
29 other branches
blog: add cover image for blog
(ActionItem2849) Signed-off-by: Marcos Ramos <ms.ramos@outlook.com Signed-off-by: Valéssio Brito <contato@valessiobrito.com.br> Signed-off-by: Victor Hugo Alves de Carvalho <victorhugodf.ac@gmail.com>
Showing
8 changed files
with
97 additions
and
0 deletions
Show diff stats
app/controllers/my_profile/cms_controller.rb
@@ -73,6 +73,7 @@ class CmsController < MyProfileController | @@ -73,6 +73,7 @@ class CmsController < MyProfileController | ||
73 | refuse_blocks | 73 | refuse_blocks |
74 | record_coming | 74 | record_coming |
75 | if request.post? | 75 | if request.post? |
76 | + @article.image = nil if params[:remove_image] == 'true' | ||
76 | @article.last_changed_by = user | 77 | @article.last_changed_by = user |
77 | if @article.update_attributes(params[:article]) | 78 | if @article.update_attributes(params[:article]) |
78 | if !continue | 79 | if !continue |
app/views/cms/_blog.rhtml
@@ -54,6 +54,15 @@ | @@ -54,6 +54,15 @@ | ||
54 | 54 | ||
55 | <%= labelled_form_field(_('Description:'), text_area(:article, :body, :rows => 10)) %> | 55 | <%= labelled_form_field(_('Description:'), text_area(:article, :body, :rows => 10)) %> |
56 | 56 | ||
57 | +<% f.fields_for :image_builder, @article.image do |i| %> | ||
58 | + <%= file_field_or_thumbnail(_('Cover image:'), @article.image, i)%> | ||
59 | + <%= _("Max size: %s (.jpg, .gif, .png)")% Image.max_size.to_humanreadable %> | ||
60 | +<% end %> | ||
61 | + | ||
62 | +<% unless @article.image.nil? %> | ||
63 | + <%= labelled_check_box(_('Remove cover image'),'remove_image',true,false)%> | ||
64 | +<% end %> | ||
65 | + | ||
57 | <%= labelled_form_field(_('How to display posts:'), f.select(:visualization_format, [ [ _('Full post'), 'full'], [ _('First paragraph'), 'short'] ])) %> | 66 | <%= labelled_form_field(_('How to display posts:'), f.select(:visualization_format, [ [ _('Full post'), 'full'], [ _('First paragraph'), 'short'] ])) %> |
58 | 67 | ||
59 | <%= labelled_form_field(_('Posts per page:'), f.select(:posts_per_page, Blog.posts_per_page_options)) %> | 68 | <%= labelled_form_field(_('Posts per page:'), f.select(:posts_per_page, Blog.posts_per_page_options)) %> |
app/views/content_viewer/_article_toolbar.rhtml
@@ -52,6 +52,9 @@ | @@ -52,6 +52,9 @@ | ||
52 | 52 | ||
53 | </div> | 53 | </div> |
54 | <div id="article-header"> | 54 | <div id="article-header"> |
55 | + <% if @page.blog? and !@page.image.nil? %> | ||
56 | + <div class="blog-cover"><%= image_tag(@page.image.public_filename())%></div> | ||
57 | + <% end %> | ||
55 | <%= link_to(image_tag('icons-mime/rss-feed.png'), @page.feed.url, :class => 'blog-feed-link') if @page.has_posts? && @page.feed %> | 58 | <%= link_to(image_tag('icons-mime/rss-feed.png'), @page.feed.url, :class => 'blog-feed-link') if @page.has_posts? && @page.feed %> |
56 | <%= article_title(@page, :no_link => true) %> | 59 | <%= article_title(@page, :no_link => true) %> |
57 | <%= article_translations(@page) %> | 60 | <%= article_translations(@page) %> |
features/blog.feature
@@ -15,6 +15,7 @@ Feature: blog | @@ -15,6 +15,7 @@ Feature: blog | ||
15 | And I follow "Create blog" | 15 | And I follow "Create blog" |
16 | Then I should see "My Blog" | 16 | Then I should see "My Blog" |
17 | When I fill in "Title" with "My Blog" | 17 | When I fill in "Title" with "My Blog" |
18 | + And I fill in "Address" with "my-blog" | ||
18 | And I press "Save" | 19 | And I press "Save" |
19 | And I go to joaosilva's control panel | 20 | And I go to joaosilva's control panel |
20 | Then I should see "Configure blog" | 21 | Then I should see "Configure blog" |
@@ -24,6 +25,7 @@ Feature: blog | @@ -24,6 +25,7 @@ Feature: blog | ||
24 | And I follow "Create blog" | 25 | And I follow "Create blog" |
25 | Then I should see "My Blog" | 26 | Then I should see "My Blog" |
26 | When I fill in "Title" with "My Blog" | 27 | When I fill in "Title" with "My Blog" |
28 | + And I fill in "Address" with "my-blog" | ||
27 | And I press "Save" | 29 | And I press "Save" |
28 | Then I should be on /joaosilva/my-blog | 30 | Then I should be on /joaosilva/my-blog |
29 | 31 | ||
@@ -33,6 +35,7 @@ Feature: blog | @@ -33,6 +35,7 @@ Feature: blog | ||
33 | And I follow "New content" | 35 | And I follow "New content" |
34 | When I follow "Blog" | 36 | When I follow "Blog" |
35 | And I fill in "Title" with "Blog from cms" | 37 | And I fill in "Title" with "Blog from cms" |
38 | + And I fill in "Address" with "blog-from-cms" | ||
36 | And I press "Save" | 39 | And I press "Save" |
37 | Then I should be on /joaosilva/blog-from-cms | 40 | Then I should be on /joaosilva/blog-from-cms |
38 | 41 | ||
@@ -42,12 +45,14 @@ Feature: blog | @@ -42,12 +45,14 @@ Feature: blog | ||
42 | And I follow "New content" | 45 | And I follow "New content" |
43 | And I follow "Blog" | 46 | And I follow "Blog" |
44 | And I fill in "Title" with "Blog One" | 47 | And I fill in "Title" with "Blog One" |
48 | + And I fill in "Address" with "blog-one" | ||
45 | And I press "Save" | 49 | And I press "Save" |
46 | Then I go to joaosilva's control panel | 50 | Then I go to joaosilva's control panel |
47 | And I follow "Manage Content" | 51 | And I follow "Manage Content" |
48 | And I follow "New content" | 52 | And I follow "New content" |
49 | And I follow "Blog" | 53 | And I follow "Blog" |
50 | And I fill in "Title" with "Blog Two" | 54 | And I fill in "Title" with "Blog Two" |
55 | + And I fill in "Address" with "blog-two" | ||
51 | And I press "Save" | 56 | And I press "Save" |
52 | Then I should not see "error" | 57 | Then I should not see "error" |
53 | And I should be on /joaosilva/blog-two | 58 | And I should be on /joaosilva/blog-two |
@@ -109,3 +114,24 @@ Feature: blog | @@ -109,3 +114,24 @@ Feature: blog | ||
109 | And I follow "New content" | 114 | And I follow "New content" |
110 | When I follow "Blog" | 115 | When I follow "Blog" |
111 | Then I should see "Tag list" | 116 | Then I should see "Tag list" |
117 | + | ||
118 | + Scenario: do not display the "clear cover image" when there is no uploaded image | ||
119 | + Given the following blogs | ||
120 | + | owner | name | | ||
121 | + | joaosilva | My Blog | | ||
122 | + And I go to joaosilva's control panel | ||
123 | + And I follow "Configure blog" | ||
124 | + Then I should not see "Delete cover image" | ||
125 | + | ||
126 | + # the step for attaching a file on the input only works with capybara 1.1.2, but it requires rails 1.9.3 | ||
127 | + @selenium-fixme | ||
128 | + Scenario: display cover image after uploading an image as the blog cover | ||
129 | + Given the following blogs | ||
130 | + | owner | name | | ||
131 | + | joaosilva | My Blog | | ||
132 | + And I go to joaosilva's control panel | ||
133 | + And I follow "Configure blog" | ||
134 | + And I attach the file "public/images/rails.png" to "Uploaded data" | ||
135 | + And I press "Save" | ||
136 | + When I am on /joaosilva/my-blog | ||
137 | + Then there should be a div with class "blog-cover" |
features/step_definitions/web_steps.rb
@@ -243,3 +243,7 @@ Then /^display "([^\"]*)"$/ do |element| | @@ -243,3 +243,7 @@ Then /^display "([^\"]*)"$/ do |element| | ||
243 | # * https://github.com/jnicklas/capybara/issues/76 | 243 | # * https://github.com/jnicklas/capybara/issues/76 |
244 | evaluate_script("jQuery('#{element}').show() && false;") | 244 | evaluate_script("jQuery('#{element}').show() && false;") |
245 | end | 245 | end |
246 | + | ||
247 | +Then /^there should be a div with class "([^"]*)"$/ do |klass| | ||
248 | + should have_selector('div', :class => klass) | ||
249 | +end |
public/stylesheets/application.css
@@ -932,6 +932,18 @@ code input { | @@ -932,6 +932,18 @@ code input { | ||
932 | #article-actions a{ | 932 | #article-actions a{ |
933 | white-space: nowrap; | 933 | white-space: nowrap; |
934 | } | 934 | } |
935 | + | ||
936 | +#article-header .blog-cover { | ||
937 | + overflow: hidden; | ||
938 | + display: block; | ||
939 | + width: 100%; | ||
940 | + max-height: 170px; | ||
941 | +} | ||
942 | + | ||
943 | +#article-header .blog-cover img{ | ||
944 | + width: 100%; | ||
945 | +} | ||
946 | + | ||
935 | #article-tags { | 947 | #article-tags { |
936 | font-size: 10px; | 948 | font-size: 10px; |
937 | text-align: right; | 949 | text-align: right; |
@@ -6441,3 +6453,4 @@ li.profile-activity-item.upload_image .activity-gallery-images-count-1 img { | @@ -6441,3 +6453,4 @@ li.profile-activity-item.upload_image .activity-gallery-images-count-1 img { | ||
6441 | right: 2px; | 6453 | right: 2px; |
6442 | z-index: 1; | 6454 | z-index: 1; |
6443 | } | 6455 | } |
6456 | + |
test/functional/cms_controller_test.rb
@@ -900,6 +900,15 @@ class CmsControllerTest < ActionController::TestCase | @@ -900,6 +900,15 @@ class CmsControllerTest < ActionController::TestCase | ||
900 | assert_no_tag :tag => 'a', :attributes => { :href => "/myprofile/#{profile.identifier}/cms/edit/#{profile.blog.feed.id}" } | 900 | assert_no_tag :tag => 'a', :attributes => { :href => "/myprofile/#{profile.identifier}/cms/edit/#{profile.blog.feed.id}" } |
901 | end | 901 | end |
902 | 902 | ||
903 | + should 'remove the image of an article' do | ||
904 | + blog = Blog.create(:profile_id => profile.id, :name=>'testblog', :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')}) | ||
905 | + blog.save! | ||
906 | + post :edit, :profile => profile.identifier, :id => blog.id, :remove_image => 'true' | ||
907 | + blog.reload | ||
908 | + | ||
909 | + assert_nil blog.image | ||
910 | + end | ||
911 | + | ||
903 | should 'update feed options by edit blog form' do | 912 | should 'update feed options by edit blog form' do |
904 | profile.articles << Blog.new(:name => 'Blog for test', :profile => profile) | 913 | profile.articles << Blog.new(:name => 'Blog for test', :profile => profile) |
905 | post :edit, :profile => profile.identifier, :id => profile.blog.id, :article => { :feed => { :limit => 7 } } | 914 | post :edit, :profile => profile.identifier, :id => profile.blog.id, :article => { :feed => { :limit => 7 } } |
test/unit/blog_test.rb
@@ -218,4 +218,36 @@ class BlogTest < ActiveSupport::TestCase | @@ -218,4 +218,36 @@ class BlogTest < ActiveSupport::TestCase | ||
218 | assert ! blog.empty? | 218 | assert ! blog.empty? |
219 | end | 219 | end |
220 | 220 | ||
221 | + should 'set cover image' do | ||
222 | + profile = fast_create(Profile) | ||
223 | + blog = Blog.create(:profile_id => profile.id, :name=>'testblog', :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')}) | ||
224 | + blog.save! | ||
225 | + blog.reload | ||
226 | + assert_equal blog.image(true).filename, 'rails.png' | ||
227 | + end | ||
228 | + | ||
229 | + should 'remove cover image' do | ||
230 | + profile = fast_create(Profile) | ||
231 | + blog = Blog.create(:profile_id => profile.id, :name=>'testblog', :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')}) | ||
232 | + blog.save! | ||
233 | + blog.reload | ||
234 | + | ||
235 | + blog.image = nil | ||
236 | + blog.save! | ||
237 | + blog.reload | ||
238 | + assert blog.image.nil? | ||
239 | + end | ||
240 | + | ||
241 | + should 'update cover image' do | ||
242 | + profile = fast_create(Profile) | ||
243 | + blog = Blog.create(:profile_id => profile.id, :name=>'testblog', :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')}) | ||
244 | + blog.save! | ||
245 | + blog.reload | ||
246 | + | ||
247 | + blog.image = Image.create!(:uploaded_data => fixture_file_upload('/files/noosfero-network.png', 'image/png')) | ||
248 | + blog.save! | ||
249 | + blog.reload | ||
250 | + | ||
251 | + assert_equal blog.image(true).filename, 'noosfero-network.png' | ||
252 | + end | ||
221 | end | 253 | end |