forked from lokka/lokka
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
169 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
Lokka Tweet Button | ||
=============== | ||
|
||
これは、[ツイートボタン](http://twitter.com/goodies/tweetbutton)を作成する[Lokka](http://lokka.org)用のプラグインです。 | ||
|
||
インストール | ||
------------ | ||
|
||
$ cd public/plugin | ||
$ git clone git://github.com/nkmrshn/lokka-tweet_button.git | ||
|
||
使い方 | ||
------ | ||
|
||
管理画面の[プラグイン]->[Tweet Button]でオプションを設定することができます。 | ||
|
||
ヘルパーメソッドとして、「tweet_button」があります。テーマのテンプレートを変更することをお忘れずにお願いします。tweet_buttonメソッドは、引数が与えられていない場合、表示しているページのURLをツイートします。URLを指定したい場合は、文字列引数としてメソッドに指定してください。 | ||
|
||
<%= tweet_button("http://example.com/foo/bar/") %> | ||
|
||
注意点 | ||
-------- | ||
|
||
URLが"http://localhost"で始まり、ツイートボタンをクリックすると、Twitterは"URL required - 'url' parameter does not contain a valid URL."というメッセージを表示します。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
Lokka Tweet Button | ||
================== | ||
|
||
This is a [Lokka](http://lokka.org) plugin to add ["Tweet Button"](http://twitter.com/goodies/tweetbutton) link. | ||
|
||
Installation | ||
------------ | ||
|
||
Run these commands: | ||
|
||
$ cd public/plugin | ||
$ git clone git://github.com/nkmrshn/lokka-tweet_button.git | ||
|
||
Usage | ||
----- | ||
|
||
You can set options in the admin page [Plugins]->[Tweet Button]. | ||
|
||
The helper method is "tweet_button". Don't forget to modify the theme template. If the tweet_button method called without any parameter, current page URL will be tweeted. If you want to specify the URL, call the method with String parameter like: | ||
|
||
<%= tweet_button("http://example.com/foo/bar/") %> | ||
|
||
Notice | ||
------ | ||
|
||
When the URL starts with "http://localhost" and clicked the Tweet button, you will get "URL required - 'url' parameter does not contain a valid URL." message from Twitter. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
en: | ||
tweet_button: Tweet Button | ||
tweet_button_updated: Updated. | ||
tweet_button_count: Button | ||
tweet_button_count_vertical: Vertical count | ||
tweet_button_count_horizontal: Horizontal count | ||
tweet_button_count_none: No count | ||
tweet_button_optional: Optional | ||
tweet_button_via: Recommend people to follow | ||
tweet_button_related_account: Related account | ||
tweet_button_related_description: Related account description | ||
tweet_button_lang: Language | ||
tweet_button_lang_english: English | ||
tweet_button_lang_french: French | ||
tweet_button_lang_german: German | ||
tweet_button_lang_spanish: Spanish | ||
tweet_button_lang_japanese: Japanese |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
ja: | ||
tweet_button: ツイートボタン | ||
tweet_button_updated: 更新しました。 | ||
tweet_button_count: ボタン | ||
tweet_button_count_vertical: 垂直方向にカウント数を表示 | ||
tweet_button_count_horizontal: 水平方向にカウント数を表示 | ||
tweet_button_count_none: カウント数の表示なし | ||
tweet_button_optional: 任意 | ||
tweet_button_via: フォローするのにおすすめのユーザー | ||
tweet_button_related_account: 関連アカウント | ||
tweet_button_related_description: 関連アカウントの説明 | ||
tweet_button_lang: 言語 | ||
tweet_button_lang_english: 英語 | ||
tweet_button_lang_french: フランス語 | ||
tweet_button_lang_german: ドイツ語 | ||
tweet_button_lang_spanish: スペイン語 | ||
tweet_button_lang_japanese: 日本語 |
50 changes: 50 additions & 0 deletions
50
public/plugin/lokka-tweet_button/lib/lokka/tweet_button.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
module Lokka | ||
module TweetButton | ||
def self.registered(app) | ||
app.get '/admin/plugins/tweet_button' do | ||
haml :"plugin/lokka-tweet_button/views/index", :layout => :"admin/layout" | ||
end | ||
|
||
app.put '/admin/plugins/tweet_button' do | ||
params.each_pair do |key, value| | ||
eval("Option.#{key}='#{value}'") if key != '_method' | ||
end | ||
flash[:notice] = t.tweet_button_updated | ||
redirect '/admin/plugins/tweet_button' | ||
end | ||
end | ||
end | ||
|
||
module Helpers | ||
def tweet_button(url = nil) | ||
url = "#{request.env['rack.url_scheme']}://#{request.env['HTTP_HOST']}#{request.env['SCRIPT_NAME']}#{request.env['PATH_INFO']}" if url.blank? | ||
|
||
count = Option.tweet_button_count | ||
count = 'vertical' if count.blank? | ||
|
||
via = Option.tweet_button_via | ||
|
||
related = Option.tweet_button_related_account | ||
unless related.blank? | ||
description = Option.tweet_button_related_description | ||
related += ':' + description unless description.blank? | ||
end | ||
|
||
lang = Option.tweet_button_lang | ||
lang = '' if lang == 'en' | ||
|
||
opts = {'data-count' => count} | ||
opts['data-via'] = via unless via.blank? | ||
opts['data-related'] = related unless related.blank? | ||
opts['data-lang'] = lang unless lang.blank? | ||
opts['data-url'] = url unless url.blank? | ||
|
||
data = [] | ||
opts.each {|opt| data << opt.join('="') + '"'} | ||
|
||
code = %Q(<a href="http://twitter.com/share" class="twitter-share-button") | ||
code += ' ' + data.join(' ') | ||
code += %Q(>Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
%h2= t.tweet_button | ||
%form{:action => '/admin/plugins/tweet_button', :method => 'post'} | ||
%input{:type => 'hidden', :name => '_method', :value => 'put'} | ||
.field | ||
%label{:for => 'tweet_button_count'}= t.tweet_button_count | ||
%br | ||
%input{:type => 'radio', :id => 'tweet_button_count_vertical', :name => 'tweet_button_count', :value => 'vertical', :checked => Option.tweet_button_count == 'vertical'} | ||
%label{:for => 'tweet_button_count_vertical'}= t.tweet_button_count_vertical | ||
%input{:type => 'radio', :id => 'tweet_button_count_horizontal', :name => 'tweet_button_count', :value => 'horizontal', :checked => Option.tweet_button_count == 'horizontal'} | ||
%label{:for => 'tweet_button_count_horizontal'}= t.tweet_button_count_horizontal | ||
%input{:type => 'radio', :id => 'tweet_button_count_none', :name => 'tweet_button_count', :value => 'none', :checked => Option.tweet_button_count == 'none'} | ||
%label{:for => 'tweet_button_count_none'}= t.tweet_button_count_none | ||
.field | ||
%label{:for => 'tweet_button_via'}= t.tweet_button_via + " (#{t.tweet_button_optional})" | ||
%br | ||
%input{:type => 'text', :id => 'tweet_button_via', :name => 'tweet_button_via', :value => Option.tweet_button_via} | ||
.field | ||
%label{:for => 'tweet_button_related_account'}= t.tweet_button_related_account + " (#{t.tweet_button_optional})" | ||
%br | ||
%input{:type => 'text', :id => 'tweet_button_related_account', :name => 'tweet_button_related_account', :value => Option.tweet_button_related_account} | ||
.field | ||
%label{:for => 'tweet_button_related_description'}= t.tweet_button_related_description + " (#{t.tweet_button_optional})" | ||
%br | ||
%input{:type => 'text', :id => 'tweet_button_related_description', :name => 'tweet_button_related_description', :value => Option.tweet_button_related_description} | ||
.field | ||
%label{:for => 'tweet_button_lang'}= t.tweet_button_lang + " (#{t.tweet_button_optional})" | ||
%br | ||
%select{:id => 'tweet_button_lang', :name => 'tweet_button_lang'} | ||
%option{:value => 'en', :selected => Option.tweet_button_lang == 'en'}= t.tweet_button_lang_english | ||
%option{:value => 'fr', :selected => Option.tweet_button_lang == 'fr'}= t.tweet_button_lang_french | ||
%option{:value => 'de', :selected => Option.tweet_button_lang == 'de'}= t.tweet_button_lang_german | ||
%option{:value => 'es', :selected => Option.tweet_button_lang == 'es'}= t.tweet_button_lang_spanish | ||
%option{:value => 'ja', :selected => Option.tweet_button_lang == 'ja'}= t.tweet_button_lang_japanese | ||
.field | ||
%input{:type => 'submit', :value => t.edit} |