google_plus_helper 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in google_plus_helper.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,133 @@
1
+ # GooglePlusHelper
2
+
3
+ GooglePlusHelper helps you generate Google Plus Social Plugins in your Rails application. Source code is available [on Github](https://github.com/techbang/google_plus_helper)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem "google_plus_helper"
10
+
11
+ or from Github:
12
+
13
+ gem "google_plus_helper", :github => "techbang/google_plus_helper"
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ ## Getting Started: Include the Google Plus JavaScript API
20
+
21
+ It is easy to include the javascript of Google Plusone:
22
+
23
+ <%= google_plusone_javascript_include_tag %>
24
+
25
+ This will yield a synchronized method (not recommended) of javascript include tag, with default language `en-US`:
26
+
27
+ <script src="https://apis.google.com/js/plusone.js" type="text/javascript">
28
+ //<![CDATA[
29
+ {"lang":"en-US"}
30
+ //]]>
31
+ </script>
32
+
33
+ ### Asynchrnoized loading (Recommended)
34
+
35
+ For best practice, it is recommended to use the **asynchronized method**:
36
+
37
+ <%= google_plusone_javascript_include_tag(:async => true) %>
38
+
39
+ which yields:
40
+
41
+ <script type="text/javascript">
42
+ //<![CDATA[
43
+ window.___gcfg = {"lang":"en-US"};
44
+ (function() {
45
+ var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
46
+ po.src = 'https://apis.google.com/js/plusone.js';
47
+ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
48
+ })();
49
+ //]]>
50
+ </script>
51
+
52
+ ### Language
53
+
54
+ To change then displaying language, specify `:lang` option:
55
+
56
+ <%= google_plusone_javascript_include_tag(:async => true, :lang => "zh-TW") %>
57
+
58
+ ### Explicit Loading / Rendering
59
+
60
+ To load Google Plusone javascript in [explicit mode](https://developers.google.com/+/plugins/+1button/#example-explicit-load), specify `:explicit => true` option:
61
+
62
+ <%= google_plusone_javascript_include_tag(:explicit => true) %>
63
+
64
+ and don't forget to invoke `gapi.plusone.go("container-id")`. See [Google Plusone JavaScript API](https://developers.google.com/+/plugins/+1button/#jsapi) for more details.
65
+
66
+ ## Render Social Plugins
67
+
68
+ Currently GooglePlusHelper supports **+1 button** and the **share button**.
69
+
70
+ Notes:
71
+
72
+ * By default it renders **HTML5 version** of tags. If you want to use XML version, see Configure GooglePlusHelper below.
73
+ * You **have to specify the URL** to +1 or share, even though Google's Social Plugins do not need it explicitly.
74
+ * If you want to control what to display on Google+, please specify [Open Graph tags](https://developers.facebook.com/docs/opengraphprotocol/). Currently there is no support to render [Snippet](https://developers.google.com/+/plugins/snippet/).
75
+
76
+ ### The +1 Button
77
+
78
+ <%= google_plusone_button("http://example.com") %>
79
+
80
+ Options are the same that listed in the [+1 Tag Document](https://developers.google.com/+/plugins/+1button/#plusonetag-parameters), except for `href` option, which is overriden by the URL you specified. For example:
81
+
82
+ <%= google_plusone_button("http://example.com", :size => :medium, :annotation => :inline) %>
83
+
84
+ ### Share Button
85
+
86
+ <%= google_share_button("http://example.com") %>
87
+
88
+ Options are the same that listed in the [Share Tag document](https://developers.google.com/+/plugins/share/#sharetag-parameters), except for `href` option, which is overriden by the URL you specified. For example:
89
+
90
+ <%= google_share_button("http://example.com", :align => :right, :annotation => :inline) %>
91
+
92
+ ## Configure GooglePlusHelper
93
+
94
+ GooglePlusHelper provides some configurable options. Put them in an initializer if you don't like the defaults:
95
+
96
+ GooglePlusHelper.config do |config|
97
+ config.social_plugin_version = :xml # default is :html5
98
+ end
99
+
100
+ *Hint*: You don't need this initializer if you want to use the default values.
101
+
102
+ ## Contributing
103
+
104
+ 1. Fork it
105
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
106
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
107
+ 4. Push to the branch (`git push origin my-new-feature`)
108
+ 5. Create new Pull Request
109
+
110
+ # License
111
+
112
+ Copyright (c) 2012 Techbang.com
113
+
114
+ MIT License
115
+
116
+ Permission is hereby granted, free of charge, to any person obtaining
117
+ a copy of this software and associated documentation files (the
118
+ "Software"), to deal in the Software without restriction, including
119
+ without limitation the rights to use, copy, modify, merge, publish,
120
+ distribute, sublicense, and/or sell copies of the Software, and to
121
+ permit persons to whom the Software is furnished to do so, subject to
122
+ the following conditions:
123
+
124
+ The above copyright notice and this permission notice shall be
125
+ included in all copies or substantial portions of the Software.
126
+
127
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
128
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
129
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
130
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
131
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
132
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
133
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/google_plus_helper/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["chitsaou"]
6
+ gem.email = ["chitsaou@techbang.com.tw"]
7
+ gem.description = %q{Google+ Social Plugins Helpers for Rails}
8
+ gem.summary = %q{Easily generate Google+ Social Plugins in Rails application}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "google_plus_helper"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = GooglePlusHelper::VERSION
17
+
18
+ gem.add_dependency("rails", ">= 3.0")
19
+ end
@@ -0,0 +1,22 @@
1
+ require 'google_plus_helper/settings'
2
+
3
+ module GooglePlusHelper
4
+ class << self
5
+ def settings
6
+ _settings ||= Settings.new
7
+ _settings
8
+ end
9
+ end
10
+
11
+ module Rails
12
+ if ::Rails.version < "3.1"
13
+ require "google_plus_helper/railtie"
14
+ else
15
+ require "google_plus_helper/engine"
16
+ end
17
+ end
18
+
19
+ def self.config
20
+ yield(settings)
21
+ end
22
+ end
@@ -0,0 +1,9 @@
1
+ require "google_plus_helper/helper"
2
+
3
+ module GooglePlusHelper
4
+ class Engine < ::Rails::Engine
5
+ initializer "google_plus_helper.view_helpers" do
6
+ ActionView::Base.send :include, GooglePlusHelper
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,68 @@
1
+ # https://developers.google.com/+/
2
+ # Currently there is no support for generating Schema.org meta tags.
3
+ # Please use Open Graph tags.
4
+ module GooglePlusHelper
5
+ # load google plusone javascript
6
+ def google_plusone_javascript_include_tag(*args)
7
+ options = {
8
+ :async => false,
9
+ :lang => "en-US",
10
+ :explicit => false
11
+ }.merge(args.extract_options!)
12
+
13
+ explicit = options.delete(:explicit)
14
+ options.merge!(:parsetags => "explicit") if explicit
15
+
16
+ # explicit parsing can only be applied to synchronized loading
17
+ async = options.delete(:async) && !explicit
18
+
19
+ params = options.to_json
20
+
21
+ if async
22
+ javascript_tag <<-EOJS
23
+ window.___gcfg = #{options.to_json};
24
+ (function() {
25
+ var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
26
+ po.src = 'https://apis.google.com/js/plusone.js';
27
+ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
28
+ })();
29
+ EOJS
30
+ else
31
+ javascript_tag options.to_json, :src => "https://apis.google.com/js/plusone.js"
32
+ end
33
+ end
34
+
35
+ def google_social_plugin(plugin_name, options, html_options={})
36
+ case GooglePlusHelper.settings.social_plugin_version
37
+ when :html5
38
+ html_options.merge! :class => "g-#{plugin_name.to_s}", :data => options
39
+ content_tag "div", "", html_options
40
+ when :xml
41
+ html_options.merge! options
42
+ content_tag "g:#{plugin_name.to_s}", "", html_options
43
+ else
44
+ raise "Unknown Social Plugin Version: #{GooglePlusHelper.settings.social_plugin_version}"
45
+ end
46
+ end
47
+
48
+ # google_plusone_button generates plusone button for specific URL
49
+ #
50
+ # default arguments: (implicitly assigned according to +1 button document)
51
+ # size: standard
52
+ # annotation: bubble
53
+ def google_plusone_button(url, *args)
54
+ options = args.extract_options!
55
+ options[:href] = url
56
+ html_options = options.delete(:html_options) || {}
57
+
58
+ google_social_plugin(:plusone, options, html_options)
59
+ end
60
+
61
+ def google_share_button(url, *args)
62
+ options = args.extract_options!
63
+ options.merge! :href => url, :action => :share
64
+ html_options = options.delete(:html_options) || {}
65
+
66
+ google_social_plugin(:plus, options, html_options)
67
+ end
68
+ end
@@ -0,0 +1,9 @@
1
+ require "google_plus_helper/helper"
2
+
3
+ module GooglePlusHelper
4
+ class Railtie < Rails::Railtie
5
+ initializer "google_plus_helper.view_helpers" do
6
+ ActionView::Base.send :include, GooglePlusHelper
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ module GooglePlusHelper
2
+ class Settings
3
+ attr_accessor :social_plugin_version
4
+
5
+ def initialize
6
+ self.social_plugin_version = :html5
7
+ end
8
+
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module GooglePlusHelper
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: google_plus_helper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - chitsaou
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: &2153199480 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '3.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *2153199480
25
+ description: Google+ Social Plugins Helpers for Rails
26
+ email:
27
+ - chitsaou@techbang.com.tw
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - .gitignore
33
+ - Gemfile
34
+ - README.md
35
+ - Rakefile
36
+ - google_plus_helper.gemspec
37
+ - lib/google_plus_helper.rb
38
+ - lib/google_plus_helper/engine.rb
39
+ - lib/google_plus_helper/helper.rb
40
+ - lib/google_plus_helper/railtie.rb
41
+ - lib/google_plus_helper/settings.rb
42
+ - lib/google_plus_helper/version.rb
43
+ homepage: ''
44
+ licenses: []
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubyforge_project:
63
+ rubygems_version: 1.8.17
64
+ signing_key:
65
+ specification_version: 3
66
+ summary: Easily generate Google+ Social Plugins in Rails application
67
+ test_files: []