Commit d74aa7ba9234d2d5d508d87cbba645c95e713e12
1 parent
15717094
Exists in
staging
and in
26 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 | 73 | refuse_blocks |
| 74 | 74 | record_coming |
| 75 | 75 | if request.post? |
| 76 | + @article.image = nil if params[:remove_image] == 'true' | |
| 76 | 77 | @article.last_changed_by = user |
| 77 | 78 | if @article.update_attributes(params[:article]) |
| 78 | 79 | if !continue | ... | ... |
app/views/cms/_blog.rhtml
| ... | ... | @@ -54,6 +54,15 @@ |
| 54 | 54 | |
| 55 | 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 | 66 | <%= labelled_form_field(_('How to display posts:'), f.select(:visualization_format, [ [ _('Full post'), 'full'], [ _('First paragraph'), 'short'] ])) %> |
| 58 | 67 | |
| 59 | 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 | 52 | |
| 53 | 53 | </div> |
| 54 | 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 | 58 | <%= link_to(image_tag('icons-mime/rss-feed.png'), @page.feed.url, :class => 'blog-feed-link') if @page.has_posts? && @page.feed %> |
| 56 | 59 | <%= article_title(@page, :no_link => true) %> |
| 57 | 60 | <%= article_translations(@page) %> | ... | ... |
features/blog.feature
| ... | ... | @@ -15,6 +15,7 @@ Feature: blog |
| 15 | 15 | And I follow "Create blog" |
| 16 | 16 | Then I should see "My Blog" |
| 17 | 17 | When I fill in "Title" with "My Blog" |
| 18 | + And I fill in "Address" with "my-blog" | |
| 18 | 19 | And I press "Save" |
| 19 | 20 | And I go to joaosilva's control panel |
| 20 | 21 | Then I should see "Configure blog" |
| ... | ... | @@ -24,6 +25,7 @@ Feature: blog |
| 24 | 25 | And I follow "Create blog" |
| 25 | 26 | Then I should see "My Blog" |
| 26 | 27 | When I fill in "Title" with "My Blog" |
| 28 | + And I fill in "Address" with "my-blog" | |
| 27 | 29 | And I press "Save" |
| 28 | 30 | Then I should be on /joaosilva/my-blog |
| 29 | 31 | |
| ... | ... | @@ -33,6 +35,7 @@ Feature: blog |
| 33 | 35 | And I follow "New content" |
| 34 | 36 | When I follow "Blog" |
| 35 | 37 | And I fill in "Title" with "Blog from cms" |
| 38 | + And I fill in "Address" with "blog-from-cms" | |
| 36 | 39 | And I press "Save" |
| 37 | 40 | Then I should be on /joaosilva/blog-from-cms |
| 38 | 41 | |
| ... | ... | @@ -42,12 +45,14 @@ Feature: blog |
| 42 | 45 | And I follow "New content" |
| 43 | 46 | And I follow "Blog" |
| 44 | 47 | And I fill in "Title" with "Blog One" |
| 48 | + And I fill in "Address" with "blog-one" | |
| 45 | 49 | And I press "Save" |
| 46 | 50 | Then I go to joaosilva's control panel |
| 47 | 51 | And I follow "Manage Content" |
| 48 | 52 | And I follow "New content" |
| 49 | 53 | And I follow "Blog" |
| 50 | 54 | And I fill in "Title" with "Blog Two" |
| 55 | + And I fill in "Address" with "blog-two" | |
| 51 | 56 | And I press "Save" |
| 52 | 57 | Then I should not see "error" |
| 53 | 58 | And I should be on /joaosilva/blog-two |
| ... | ... | @@ -109,3 +114,24 @@ Feature: blog |
| 109 | 114 | And I follow "New content" |
| 110 | 115 | When I follow "Blog" |
| 111 | 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 | 243 | # * https://github.com/jnicklas/capybara/issues/76 |
| 244 | 244 | evaluate_script("jQuery('#{element}').show() && false;") |
| 245 | 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 | 932 | #article-actions a{ |
| 933 | 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 | 947 | #article-tags { |
| 936 | 948 | font-size: 10px; |
| 937 | 949 | text-align: right; |
| ... | ... | @@ -6441,3 +6453,4 @@ li.profile-activity-item.upload_image .activity-gallery-images-count-1 img { |
| 6441 | 6453 | right: 2px; |
| 6442 | 6454 | z-index: 1; |
| 6443 | 6455 | } |
| 6456 | + | ... | ... |
test/functional/cms_controller_test.rb
| ... | ... | @@ -900,6 +900,15 @@ class CmsControllerTest < ActionController::TestCase |
| 900 | 900 | assert_no_tag :tag => 'a', :attributes => { :href => "/myprofile/#{profile.identifier}/cms/edit/#{profile.blog.feed.id}" } |
| 901 | 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 | 912 | should 'update feed options by edit blog form' do |
| 904 | 913 | profile.articles << Blog.new(:name => 'Blog for test', :profile => profile) |
| 905 | 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 | 218 | assert ! blog.empty? |
| 219 | 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 | 253 | end | ... | ... |