Class: Decidim::SocialShareServiceManifest

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations, AttributeObject::Model
Defined in:
decidim-core/lib/decidim/social_share_service_manifest.rb

Overview

This class represents an abstract social network to be used for sharing URLs Serves as a replacement for our usage of the social-share-button gem

Constant Summary

Constants included from AttributeObject::TypeMap

AttributeObject::TypeMap::Boolean, AttributeObject::TypeMap::Decimal

Instance Method Summary collapse

Methods included from AttributeObject::Model

#[], #[]=, #attributes, #attributes_with_values, #initialize, #to_h

Instance Method Details

#formatted_share_uri(title, args) ⇒ String?

Format a given URL to be shareable All the services gives us a controller that accepts different get parameters. As this parameters are used in an URL we need to escape them

Parameters:

  • title (String)

    the title of the resource that we want to share

  • args (Hash)

    all the parameters that will be added on the url

Returns:

  • (String, nil)

    The formatted URL or nil when some or one of the required parameters is missing



29
30
31
32
33
34
35
36
37
38
39
# File 'decidim-core/lib/decidim/social_share_service_manifest.rb', line 29

def formatted_share_uri(title, args)
  formatted_args = escape_args(args.compact)
  format(full_share_uri(formatted_args.keys), title: url_escape(title), **formatted_args)
rescue KeyError
  # This happens when all the arguments needed for the `format()` call are
  # not provided in the `formatted_args` array. E.g. the URL of the page
  # can be nil in some dummy views during the tests when they do not define
  # the meta URL, i.e. `add_decidim_meta_tags` has not been called in these
  # views or it has been called with an empty URL.
  nil
end

#icon_pathString

Path of the icon file

Returns:

  • (String)


44
45
46
# File 'decidim-core/lib/decidim/social_share_service_manifest.rb', line 44

def icon_path
  ActionController::Base.helpers.asset_pack_path("media/images/#{icon}")
end