Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

before pull request

  • Loading branch information...
commit 5c35f6c3ae11dadfdc7e715c675c94a121eb894f 1 parent 47c4b9f
@artemasmith artemasmith authored
View
45 lib/social_buttons/view_helpers/vkontakte.rb
@@ -0,0 +1,45 @@
+module SocialButtons
+ module Vkontakte
+ include SocialButtons::Assistant
+ CLASS = "vk_like"
+
+ def vkontakte_like appId, *args
+ clazz = SocialButtons::Vkontakte
+ options = args.extract_options!
+
+ clazz.default_options.each { |k,v| options[k] ||= v }
+
+ html = "".html_safe
+ html << clazz::Scripter.new(self).init_js(appId)
+ html << content_tag(:div, nil, id: "vk_like")
+ html << clazz::Scripter.new(self).script(options)
+ #html << content_tag(:div, nil, params)
+ html
+ end
+
+ class << self
+ def default_options
+ @default_options ||= {
+ width: '350',
+ type: 'vertical',
+ verb: '0',
+ height: '22',
+ verb: '0'
+ }
+ end
+ end
+
+ class Scripter < SocialButtons::Scripter
+ def init_js appId
+ "<script type=\"text/javascript\"> VK.init({apiId: #{appId}, onlyWidgets: true}); </script>".html_safe
+ end
+ def script options = {}
+ [
+ "<script type=\"text/javascript\">",
+ "VK.Widgets.Like(\"vk_like\", { type: \"#{options[:type]}\", width: '#{options[:width]}', verb: '#{options[:verb] }'});",
+ "</script>"
+ ].join.html_safe
+ end
+ end
+ end
+end
View
BIN  social-buttons-0.3.8.gem
Binary file not shown
View
29 spec/social_buttons/vkontakte_spec.rb
@@ -0,0 +1,29 @@
+require 'view_helper_config'
+
+describe SocialButtons::ViewHelper do
+ include ControllerTestHelpers, SocialButtons::ViewHelper
+ describe "vk like button" do
+ context 'with app_id' do
+ it "should require a Facebook app id" do
+ expect { vkontakte_like('4138567') }.not_to raise_error
+ end
+ it "should require a Facebook app id" do
+ expect { vkontakte_like() }.to raise_error
+ end
+ end
+
+ context 'with options' do
+ it "should set width using option" do
+ output = vkontakte_like('4138567', :width => '400')
+ output.should match(/width: '400'/)
+ output.should match(/<script/)
+ end
+ it "should print type" do
+ output = vkontakte_like('4138567', :type => 1 )
+ output.should match(/type: "1"/)
+ end
+ end
+ end
+end
+
+
Please sign in to comment.
Something went wrong with that request. Please try again.