Skip to content

Commit 59b24a2

Browse files
committed
Merge pull request #168 from just3ws/grid_protip_gets_two_different_collection_types
Grid protip gets two different collection types
2 parents 7239764 + ec218d6 commit 59b24a2

File tree

4 files changed

+55
-56
lines changed

4 files changed

+55
-56
lines changed

app/helpers/protips_helper.rb

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
require 'cfm'
2+
23
module ProtipsHelper
34

5+
def protip_search_results_to_render(protips)
6+
(protips.results if protips.respond_to?(:results)) || protips.try(:all)
7+
end
8+
49
def protip_summary
510
"A protip by #{@protip.user.username} about #{@protip.topics.to_sentence}."
611
end
@@ -296,12 +301,12 @@ def protip_stat_class(protip)
296301

297302
def formatted_best_stat_value(protip)
298303
value =
299-
case best_stat_name(protip).to_sym
300-
when :views
301-
views_stat_value(protip)
302-
else
303-
best_stat_value(protip)
304-
end
304+
case best_stat_name(protip).to_sym
305+
when :views
306+
views_stat_value(protip)
307+
else
308+
best_stat_value(protip)
309+
end
305310
number_to_human(value, units: {unit: "", thousand: "k"})
306311
end
307312

app/views/protips/_grid.html.haml

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
1-
-reset_protip_result_index
2-
-show_job = defined?(opportunity) && !opportunity.nil?
1+
- reset_protip_result_index
2+
- show_job = defined?(opportunity) && opportunity.present?
33
- width = (defined?(width) && width) || 4
4-
- show_ad_every = width*2+width-2
5-
- items = show_job ? protips.each_slice(show_ad_every).map{|row| row.count == show_ad_every ? row.concat(['show-ad', nil]) : row }.flatten : protips
4+
- show_ad_every = width * 2 + width - 2
5+
- items = show_job ? protips.each_slice(show_ad_every).map{ |row| row.count == show_ad_every ? row.concat(['show-ad', nil]) : row }.flatten : protips
66

7-
- if collection.failure?
7+
- logger.ap(collection, :debug)
8+
- if collection.respond_to?(:failure?) && collection.failure?
89
.error
9-
="#{collection.error} Meanwhile you can "
10-
=link_to 'create a pro tip', new_protip_path
10+
= "#{collection.error} Meanwhile you can "
11+
= link_to 'create a pro tip', new_protip_path
1112
= "about #{@topic}" unless @topic.nil?
1213

13-
-items.in_groups_of(width, nil).each_with_index do |group, row|
14-
-if (row > 0) && blur_protips?
14+
- items.in_groups_of(width, nil).each_with_index do |group, row|
15+
- if (row > 0) && blur_protips?
1516
.blurred-tips
16-
=render :partial => "sessions/join_buttons", :locals => {:message => "Join to start earning badges for your open source contributions, discover protips and connect with other developers"}
17-
-break
17+
= render(partial: 'sessions/join_buttons', locals: { message: 'Join to start earning badges for your open source contributions, discover protips and connect with other developers' })
18+
- break
1819
%ul.protips-grid.cf
19-
-group.each do |protip|
20-
-if protip == 'show-ad'
21-
=render :partial => 'opportunities/mini', :locals => {:opportunity => opportunity}
22-
-elsif !protip.nil?
20+
- group.each do |protip|
21+
- if protip == 'show-ad'
22+
= render(partial: 'opportunities/mini', locals: { opportunity: opportunity })
23+
-elsif protip.present?
2324
- if protip = protip.load rescue nil # HACK: User deleted, protip no longer exists. Won't be found.
24-
%li{:class => (protip.kind == 'link' ? 'ext-link' : '') }
25-
= render :partial => 'protips/mini', :locals => {:protip => protip, :mode => mode}
25+
%li{ class: (protip.kind == 'link' ? 'ext-link' : '') }
26+
= render(partial: 'protips/mini', locals: { protip: protip, mode: mode })
2627

2728
- unless collection.nil? || !collection.respond_to?(:next_page) || collection.next_page.nil? || hide_more
28-
- next_url = url_for(params.merge(:tags=> params[:tags], :q => params[:q], :source => params[:action], :controller =>params[:controller], :page => collection.current_page + 1, :section => (defined?(section) ? section : nil), :width => width, :mode => mode ))
29-
%div{:class => ("#{number_to_word(width)}-cols-more" unless width.nil?)}
30-
#more=link_to 'More', next_url, :class => 'final-more track' , :rel => 'next', :remote => true, :method => (params[:action] == "search" ? :post : :get), 'data-action' => 'more protips', 'data-from' => params[:action]
29+
- next_url = url_for(params.merge(tags: params[:tags], q: params[:q], source: params[:action], controller:params[:controller], page: collection.current_page + 1, section: (defined?(section) ? section : nil), width: width, mode: mode ))
30+
%div{ class: ("#{number_to_word(width)}-cols-more" unless width.nil?) }
31+
#more= link_to('More', next_url, class: 'final-more track', rel: 'next', remote: true, method: (params[:action] == 'search' ? :post : :get), 'data-action' => 'more protips', 'data-from' => params[:action])

app/views/protips/topic.html.haml

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,25 @@
1-
-#-content_for :javascript do
2-
-# -if @topic_user
3-
-# %script="logUsage('viewed', 'users protips');"
4-
-# -else
5-
-# %script="logUsage('viewed', 'topics protips');"
6-
7-
= render :partial => "head", :locals => {:topic => @topic}
1+
= render(partial: 'head', locals: { topic: @topic })
82

93
.secondary-notice
104
%p
11-
-if @topic_user
12-
-if @topic_user && signed_in? && @topic_user == current_user
5+
- if @topic_user
6+
- if @topic_user && signed_in? && @topic_user == current_user
137
These are your links, code snippets, posts and other pro tips you have created or upvoted. Have a quick pro tip to
14-
=link_to('share?', new_protip_path, 'data-action' => 'create protip', 'data-from' => 'own protips page')
8+
= link_to('share?', new_protip_path, 'data-action' => 'create protip', 'data-from' => 'own protips page')
159
or
16-
=link_to('learn more', faq_path, :class => 'track', 'data-action' => 'view faq', 'data-from' => 'own protips page')
10+
= link_to('learn more', faq_path, class: 'track', 'data-action' => 'view faq', 'data-from' => 'own protips page')
1711
- if @topic_user.protips.reject(&:created_automagically?).count == 0
1812
%br Pro tips you currently see here are created automagically from repos you follow/consider useful or slideshares you've created
19-
-else
20-
==These are the links, code snippets, posts, and other pro tips #{@topic_user.display_name} has created. Have your own to
21-
=link_to('share?', new_protip_path, 'data-action' => 'create protip', 'data-from' => 'user protips page')
13+
- else
14+
== These are the links, code snippets, posts, and other pro tips #{@topic_user.display_name} has created. Have your own to
15+
= link_to('share?', new_protip_path, 'data-action' => 'create protip', 'data-from' => 'user protips page')
2216
or
23-
=link_to('learn more', faq_path, :class => 'track', 'data-action' => 'view faq', 'data-from' => 'user protips page')
24-
-elsif signed_in?
25-
%p
26-
=link_to('Share', new_protip_path(:topics => @topic), 'data-action' => 'create protip', 'data-from' => 'user protips page') + " a link, code snippet, post or other pro tip about #{@topic}"
27-
-else
28-
=link_to('Sign in', root_path)
29-
==to start sharing your #{@topic} pro tips or
30-
=link_to('learn more', faq_path, :class => 'track', 'data-action' => 'view faq', 'data-from' => 'user protips page')
17+
= link_to('learn more', faq_path, class: 'track', 'data-action' => 'view faq', 'data-from' => 'user protips page')
18+
- elsif signed_in?
19+
%p= link_to('Share', new_protip_path(topics: @topic), 'data-action' => 'create protip', 'data-from' => 'user protips page') + " a link, code snippet, post or other pro tip about #{@topic}"
20+
- else
21+
= link_to('Sign in', root_path)
22+
== to start sharing your #{@topic} pro tips or
23+
= link_to('learn more', faq_path, class: 'track', 'data-action' => 'view faq', 'data-from' => 'user protips page')
3124

32-
#browse-results
33-
= render :partial => "grid", :locals => {:protips => (@protips.results if @protips.respond_to?(:results)) || @protips.try(:all), :collection => @protips, :url => :tagged_protips_path, :hide_more => false, :mode => 'popup'}
25+
#browse-results= render(partial: 'grid', locals: { protips: protip_search_results_to_render(@protips), collection: @protips, url: :tagged_protips_path, hide_more: false, mode: 'popup' })

spec/helpers/protips_helper_spec.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
require 'spec_helper'
2-
3-
RSpec.describe ProtipsHelper, :type => :helper do
4-
5-
6-
end
1+
RSpec.describe ProtipsHelper, type: :helper do
2+
describe ".protip_search_results_to_render" do
3+
it 'has no protips to render' do
4+
expect(helper.protip_search_results_to_render(nil)).to be_nil
5+
end
6+
end
7+
end

0 commit comments

Comments
 (0)