Module: GooglePlusHelper
- Defined in:
- lib/google_plus_helper.rb,
lib/google_plus_helper/engine.rb,
lib/google_plus_helper/helper.rb,
lib/google_plus_helper/railtie.rb,
lib/google_plus_helper/version.rb,
lib/google_plus_helper/settings.rb
Overview
:nodoc: all
Defined Under Namespace
Modules: Rails Classes: Engine, Railtie, Settings
Constant Summary collapse
- VERSION =
"0.0.3"
Class Method Summary collapse
Instance Method Summary collapse
-
#google_plusone_button(url, *args) ⇒ Object
Generates the +1 button for specific URL.
-
#google_plusone_javascript_include_tag(*args) ⇒ Object
Generates a
<script>tag to load Google Plusone JavaScript file. -
#google_share_button(url, *args) ⇒ Object
Generates the “Share on Google+” button for specific URL.
-
#google_social_plugin(plugin_name, options, html_options = {}) ⇒ Object
Generates Google+ Social Plugin html structure.
Class Method Details
.config {|settings| ... } ⇒ Object
19 20 21 |
# File 'lib/google_plus_helper.rb', line 19 def self.config yield(settings) end |
Instance Method Details
#google_plusone_button(url, *args) ⇒ Object
Generates the +1 button for specific URL.
Arguments:
-
url: the URL to +1. -
options: (optional) a hash that is identical to the 1 Button attributes listed here.
Example - A +1 button in medium size and without annotation:
<%= google_plusone_button("http://example.com", :size => :medium, :annotation => :none)
78 79 80 81 82 83 84 |
# File 'lib/google_plus_helper/helper.rb', line 78 def (url, *args) = args. [:href] = url = .delete(:html_options) || {} (:plusone, , ) end |
#google_plusone_javascript_include_tag(*args) ⇒ Object
Generates a <script> tag to load Google Plusone JavaScript file.
The trivial usage is to load synchonously:
<%= google_plusone_javascript_include_tag %> #=> <script src="..."></script>
To load the script asynchronously, use:
<%= google_plusone_javascript_include_tag(:async => true)
By default it takes “en-US” as display language. Add :lang option to change, e.g. :lang => "zh-TW"
To load in explicit mode, add :explicit => true option.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/google_plus_helper/helper.rb', line 24 def google_plusone_javascript_include_tag(*args) = { :async => false, :lang => "en-US", :explicit => false }.merge(args.) explicit = .delete(:explicit) .merge!(:parsetags => "explicit") if explicit # explicit parsing can only be applied to synchronized loading async = .delete(:async) && !explicit params = .to_json if async javascript_tag <<-EOJS window.___gcfg = #{.to_json}; (function() { var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true; po.src = 'https://apis.google.com/js/plusone.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s); })(); EOJS else javascript_tag .to_json, :src => "https://apis.google.com/js/plusone.js" end end |
#google_share_button(url, *args) ⇒ Object
Generates the “Share on Google+” button for specific URL.
Arguments:
-
url: the URL to +1. -
options: (optional) a hash that is identical to the Share Button attributes listed here.
Example - A Share button aligned to right and with vertical-bubble annotation:
<%= google_share_button("http://example.com", :align => :right, :annotation => "vertical-bubble")
96 97 98 99 100 101 102 |
# File 'lib/google_plus_helper/helper.rb', line 96 def (url, *args) = args. .merge! :href => url, :action => :share = .delete(:html_options) || {} (:plus, , ) end |
#google_social_plugin(plugin_name, options, html_options = {}) ⇒ Object
Generates Google+ Social Plugin html structure.
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/google_plus_helper/helper.rb', line 55 def (plugin_name, , ={}) #:nodoc: case GooglePlusHelper.settings. when :html5 .merge! :class => "g-#{plugin_name.to_s}", :data => content_tag "div", "", when :xml .merge! content_tag "g:#{plugin_name.to_s}", "", else raise "Unknown Social Plugin Version: #{GooglePlusHelper.settings.}" end end |