Module: Faces::Public
- Defined in:
- lib/faces.rb
Class Method Summary collapse
-
.avatar_default_html(configuration = {}) ⇒ Object
Returns the default avatar in an <img /> HTML tag.
-
.avatar_default_url(configuration = {}) ⇒ Object
Returns the default avatar as a url.
-
.avatar_exists?(identifier, provider, configuration = {}) ⇒ Boolean
Returns true if avatar exists, false if not.
-
.avatar_html(identifier, provider, configuration = {}) ⇒ Object
Returns the avatar in an <img /> HTML tag based on identifier, provider and configuration Uses local provider classes to generate the result Does not check for existance of Avatar, this is the responsibility of the developer.
-
.avatar_url(identifier, provider, configuration = {}) ⇒ Object
Returns avatar url based on identifier, provider and configuration Uses local provider classes to generate the result Does not check for existance of Avatar, this is the responsibility of the developer.
-
.generate_html(url, configuration = {}) ⇒ Object
Generates a HTML <img /> tag for the given url.
-
.provider_exists?(provider) ⇒ Boolean
Returns true if provider exists, false if not.
-
.provider_method_exists?(method, provider) ⇒ Boolean
Returns true if provider method exists, false if not.
-
.provider_supports_ssl?(provider) ⇒ Boolean
Returns true if the provider has SSL available, else false.
Class Method Details
.avatar_default_html(configuration = {}) ⇒ Object
Returns the default avatar in an <img /> HTML tag
59 60 61 62 |
# File 'lib/faces.rb', line 59 def avatar_default_html(configuration = {}) url = configuration[:default].present? ? configuration[:default] : ::Faces::Configuration::UNIVERSAL[:default] generate_html(url, configuration) end |
.avatar_default_url(configuration = {}) ⇒ Object
Returns the default avatar as a url
64 65 66 |
# File 'lib/faces.rb', line 64 def avatar_default_url(configuration = {}) configuration[:default].present? ? configuration[:default] : ::Faces::Configuration::UNIVERSAL[:default] end |
.avatar_exists?(identifier, provider, configuration = {}) ⇒ Boolean
Returns true if avatar exists, false if not
49 50 51 52 |
# File 'lib/faces.rb', line 49 def avatar_exists?(identifier, provider, configuration = {}) obj = "::Faces::Providers::#{provider.to_s.classify}".constantize.new obj.exists?(identifier, configuration) end |
.avatar_html(identifier, provider, configuration = {}) ⇒ Object
Returns the avatar in an <img /> HTML tag based on identifier, provider and configuration Uses local provider classes to generate the result Does not check for existance of Avatar, this is the responsibility of the developer
29 30 31 32 33 34 35 36 |
# File 'lib/faces.rb', line 29 def avatar_html(identifier, provider, configuration = {}) if provider_method_exists?('html', provider) obj = "::Faces::Providers::#{provider.to_s.classify}".constantize.new obj.html(identifier, configuration) else avatar_default_html(configuration) end end |
.avatar_url(identifier, provider, configuration = {}) ⇒ Object
Returns avatar url based on identifier, provider and configuration Uses local provider classes to generate the result Does not check for existance of Avatar, this is the responsibility of the developer
40 41 42 43 44 45 46 47 |
# File 'lib/faces.rb', line 40 def avatar_url(identifier, provider, configuration = {}) if provider_method_exists?('url', provider) obj = "::Faces::Providers::#{provider.to_s.classify}".constantize.new obj.url(identifier, configuration) else avatar_default_url(configuration) end end |
.generate_html(url, configuration = {}) ⇒ Object
Generates a HTML <img /> tag for the given url
83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/faces.rb', line 83 def generate_html(url, configuration = {}) m_configuration = Faces::Common.merge_configurations([Faces::Configuration::UNIVERSAL, configuration]) combined_classes = m_configuration[:html_provider_classes].present? ? m_configuration[:html_classes] + ' ' + m_configuration[:html_provider_classes] : m_configuration[:html_classes] html = '<img src="' + url + '" class="' + combined_classes + '"' html += " id=\"#{m_configuration[:id]}\"" if m_configuration[:id].present? html += " width=\"#{m_configuration[:width]}\"" if m_configuration[:width].present? html += " height=\"#{m_configuration[:height]}\"" if m_configuration[:height].present? html += " alt=\"#{m_configuration[:alt]}\"" if m_configuration[:alt].present? html += ' />' end |
.provider_exists?(provider) ⇒ Boolean
Returns true if provider exists, false if not
68 69 70 71 72 |
# File 'lib/faces.rb', line 68 def provider_exists?(provider) true if ::Faces::Providers.const_get("#{provider.to_s.classify}") rescue NameError false end |
.provider_method_exists?(method, provider) ⇒ Boolean
Returns true if provider method exists, false if not
74 75 76 77 78 79 80 81 |
# File 'lib/faces.rb', line 74 def provider_method_exists?(method, provider) if ::Faces::Providers.const_get("#{provider.to_s.classify}") obj = "::Faces::Providers::#{provider.to_s.classify}".constantize.new obj.respond_to?(method) end rescue NameError false end |
.provider_supports_ssl?(provider) ⇒ Boolean
Returns true if the provider has SSL available, else false
54 55 56 57 |
# File 'lib/faces.rb', line 54 def provider_supports_ssl?(provider) obj = "::Faces::Providers::#{provider.to_s.classify}".constantize.new obj.respond_to?('ssl?') ? obj.ssl? : false end |