app/helpers/extensions_helper.rb
#
# Return the correct state for an extension follow/unfollow button. If given a
# block, the result of the block will become the button's text.
#
# @example
#   <%= follow_button_for(@extension) %>
#   <%= follow_button_for(@extension) do |following| %>
#     <%= following ? 'Stop Following' : 'Follow' %>
#   <% end %>
#
# @param extension [Extension] the Extension to follow or unfollow
# @param params [Hash] any additional query params to add to the follow button
# @yieldparam following [Boolean] whether or not the +current_user+ is
#   following the given +Extension+
#
# @return [String] a link based on the following state for the current extension.
#
Return the correct state for an extension follow/unfollow button. If given a
block, the result of the block will become the button's text.
Return the correct state for an extension follow / unfollow button . If given a block the result of the block will become the button ' s text .
def follow_button_for(extension, params = {}, &block)
    fa_icon = content_tag(:i, '', class: 'fa fa-star')
    followers_count = extension.extension_followers_count.to_s
    followers_count_span = content_tag(
      :span,
      number_with_delimiter(followers_count),
      class: 'extension_follow_count'
    )
    follow_html = fa_icon + 'Star' + followers_count_span
    unfollow_html = fa_icon + 'Starred' + followers_count_span
    unless current_user
      return link_to(
        follow_extension_path(extension, params.merge(username: extension.owner_name)),
        method: 'put',
        rel: 'sign-in-to-follow',
        class: 'button radius tiny secondary follow',
        title: "You must be signed in to star #{t('indefinite_articles.extension')} #{t('nouns.extension')}.",
        'data-tooltip' => true
      ) do
        if block
          block.call(false)
        else
          follow_html
        end
      end
    end
    if extension.followed_by?(current_user)
      link_to(
        unfollow_extension_path(extension, params.merge(username: extension.owner_name)),
        method: 'delete',
        rel: 'unfollow',
        class: 'button radius tiny secondary follow',
        id: 'unfollow_extension',
        'data-extension' => extension.lowercase_name,
        remote: true
      ) do
        if block
          block.call(true)
        else
          unfollow_html
        end
      end
    else
      link_to(
        follow_extension_path(extension, params.merge(username: extension.owner_name)),
        method: 'put',
        rel: 'follow',
        class: 'button radius tiny follow',
        id: 'follow_extension',
        'data-extension' => extension.lowercase_name,
        remote: true
      ) do
        if block
          block.call(false)
        else
          follow_html
        end
      end
    end
  end
def follow_button_for ( extension , params = { } , & block ) fa_icon = content_tag ( :i , '' , class : 'fa fa-star' ) followers_count = extension . extension_followers_count . to_s followers_count_span = content_tag ( :span , number_with_delimiter ( followers_count ) , class : 'extension_follow_count' ) follow_html = fa_icon + 'Star' + followers_count_span unfollow_html = fa_icon + 'Starred' + followers_count_span unless current_user return link_to ( follow_extension_path ( extension , params . merge ( username : extension . owner_name ) ) , method : 'put' , rel : 'sign-in-to-follow' , class : 'button radius tiny secondary follow' , title : "You must be signed in to star #{t('indefinite_articles.extension')} #{t('nouns.extension')}." , 'data-tooltip' => true ) do if block block . call ( false ) else follow_html end end end if extension . followed_by? ( current_user ) link_to ( unfollow_extension_path ( extension , params . merge ( username : extension . owner_name ) ) , method : 'delete' , rel : 'unfollow' , class : 'button radius tiny secondary follow' , id : 'unfollow_extension' , 'data-extension' => extension . lowercase_name , remote : true ) do if block block . call ( true ) else unfollow_html end end else link_to ( follow_extension_path ( extension , params . merge ( username : extension . owner_name ) ) , method : 'put' , rel : 'follow' , class : 'button radius tiny follow' , id : 'follow_extension' , 'data-extension' => extension . lowercase_name , remote : true ) do if block block . call ( false ) else follow_html end end end end
Return the correct state for an extension follow/unfollow button.
Return the correct state for an extension follow / unfollow button .
a link based on the following state for the current extension.
a link based on the following state for the current extension .
String
extension
the Extension to follow or unfollow
the Extension to follow or unfollow
params
any additional query params to add to the follow button
any additional query params to add to the follow button
block
<not_specific>
following
<not_specific>
whether or not the +current_user+ is following the given +Extension+
whether or not the + current_user + is following the given + Extension +
example
<%= follow_button_for(@extension) %> <%= follow_button_for(@extension) do |following| %> <%= following . 'Stop Following' : 'Follow' %> <% end %>
<% = follow_button_for ( @extension ) % > <% = follow_button_for ( @extension ) do |following| % > <% = following . ' Stop Following ' : ' Follow ' % > <% end % >