assemblymade/coderwall

View on GitHub
app/views/protips/index.html.haml

Summary

Maintainability
Test Coverage
- content_for :content_wrapper do
  false

- content_for :head do
  = stylesheet_link_tag 'protip'

- content_for :footer_menu do
  %li= link_to 'Protips', by_tags_protips_path

- unless signed_in?
  %section.home-top.cf
    .home-top
      .left-panel
        %h1
          A community for developers to unlock and share new skills, join us
        = render partial: "sessions/join_buttons"

      %ul.features-list
        %li.achievements
          %h2 Earn achievements
          %p Unlock unique badges for your open-source contributions
        %li.connections
          %h2 Make connections
          %p Connect with your peers from around the world
        %li.protips
          %h2 Share protips
          %p Learn from experts or share your own tips, tricks and best practices
        %li.team
          %h2 Represent your team
          %p Gather your team mates from work to establish your team's geek cred

- else
  #upvoted-protips{'data-protips' => @upvoted_protips_public_ids}

%section.new-main-content#x-protips-grid.cf

  //following on
  .filter-bar#x-scopes-bar{class: display_scopes_class}
    .inside.cf
      %ul.filter-nav#x-scopes
        -if signed_in?
          %li
            = link_to "Fresh", fresh_protips_path(scope: params[:scope]), class: selected_search_context_class("fresh"), id: "x-scope-fresh"
        %li
          = link_to "Trending", trending_protips_path(scope: params[:scope]), class: selected_search_context_class("trending"), id: "x-scope-trending"
        %li
          = link_to "Popular", popular_protips_path(scope: params[:scope]), class: selected_search_context_class("popular"), id: "x-scope-popular"
        -if signed_in?
          %li
            = link_to "Liked", liked_protips_path(scope: params[:scope]), class: selected_search_context_class("liked"), id: "x-scope-liked"

      - if signed_in?
        %ul.toggle-nav
          %li
            %a.action.share-tip{href: new_protip_path, class: "track", 'data-action' => 'create protip', 'data-from' => 'homepage', 'data-properties' => {'context' => @context}.to_json}


  //search bar
  .filter-bar.search-bar#x-search{class: display_search_class}
    .inside.cf
      %form.search-bar{href: search_protips_path}
        %input{name: "search", type: "text", placeholder: "Type here to search, for example: Ruby on Rails", value: params[:search]}

      %ul.toggle-nav
        %li
          %a.action.search#x-hide-search{href: '/'}


  -if signed_in?
    //followings
    -cache(followings_fragment_cache_key(current_user.id), expires_in: 15.minutes) do
      .following-panel#x-followings.hide
        .inside
          %h1 Following

          .inside-panel
            %h2 Connections
            %ul.protips-grid.connections-list.cf
              - following_users = current_user.following_users
              #x-following-users.hide{'data-users' => following_users.map(&:username)}

              - following_users.limit(11).each do |user|
                %li
                  = link_to '', follow_user_path(user.username), class: 'unfollow followed', remote: true, method: :post, rel: 'nofollow'
                  %ul.author
                    %li.user
                      %a{href: profile_path(user.username)}= user.username
                    -if user.on_team?
                      %li.team
                        %a{href: friendly_team_path(user.team)}= user.team.name

                  %ul.avatars
                    %li.user
                      %a{href: profile_path(user.username)}
                        = image_tag(user.avatar_url)
                    -if user.on_team?
                      %li.team
                        %a{href: friendly_team_path(user.team)}
                          = image_tag(user.team.avatar_url)

              - if following_users.count > 11
                %li.plus-more
                  %a{href: following_path(current_user.username)}

                    %span.x-follow-count
                      = following_users.count - 11
                    more


            %h2 teams
            %ul.protips-grid.connections-list.cf
              - following_teams = current_user.teams_being_followed
              #x-following-teams.hide{'data-teams' => following_teams.map(&:name)}

              - following_teams.first(11).each do |team|
                %li
                  = link_to '', follow_team_path(team.slug), class: "unfollow followed", remote: true, method: :post, rel: "nofollow"
                  %ul.author
                    %li.user
                      %a{href: friendly_team_path(team)}= team.name
                    - team_protips_count = team.trending_protips(1000).count
                    - if team_protips_count > 0
                      %li.team
                        %a{href: team_protips_path(team)}== #{team_protips_count} Protips

                  %ul.avatars
                    %li.team
                      %a{href: friendly_team_path(team)}
                        = image_tag(team.avatar_url)
              - if following_teams.count > 11
                %li.plus-more
                  %a{href: teams_path}

                    %span.x-follow-count
                      = following_teams.count - 11
                    more


  .inside.cf
    -unless @suggested_networks.blank?
      .suggested
        .inside-panel
          %h2 Suggested networks to follow
          %ul.protips-grid.new-networks-list.cf
            - @suggested_networks.each do |name|
              - slug = name.parameterize
              %li{style: "border-color:##{color_signature(slug)}"}
                = link_to '', join_network_path(id: slug), class: "follow #{slug} #{signed_in? && current_user.following_networks.exists?(slug: slug) ? "followed" : ""}", remote: true, method: :post, rel: "nofollow"
                %a.new-network{href: network_path(id: slug)}
                  = name

    - if @protips && @protips.count == 0
      .no-tips
        %h1 No results
        %p You are not following anything yet. Follow people, teams or networks to see protips from them here. boom.
    - else
      = render partial: 'protips/grid', locals: { protips: @protips.respond_to?(:results) ? @protips.results : @protips, collection: @protips, url: :protips_path, hide_more: blur_protips?, width: 4, mode: protip_display_mode, opportunity: @job }