diff --git a/public/plugin/lokka-tweet_button/README.ja.markdown b/public/plugin/lokka-tweet_button/README.ja.markdown new file mode 100644 index 00000000..164c31b6 --- /dev/null +++ b/public/plugin/lokka-tweet_button/README.ja.markdown @@ -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."というメッセージを表示します。 diff --git a/public/plugin/lokka-tweet_button/README.markdown b/public/plugin/lokka-tweet_button/README.markdown new file mode 100644 index 00000000..1c901677 --- /dev/null +++ b/public/plugin/lokka-tweet_button/README.markdown @@ -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. diff --git a/public/plugin/lokka-tweet_button/i18n/en.yml b/public/plugin/lokka-tweet_button/i18n/en.yml new file mode 100644 index 00000000..bf895d2c --- /dev/null +++ b/public/plugin/lokka-tweet_button/i18n/en.yml @@ -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 diff --git a/public/plugin/lokka-tweet_button/i18n/ja.yml b/public/plugin/lokka-tweet_button/i18n/ja.yml new file mode 100644 index 00000000..ccbc5bd4 --- /dev/null +++ b/public/plugin/lokka-tweet_button/i18n/ja.yml @@ -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: 日本語 diff --git a/public/plugin/lokka-tweet_button/lib/lokka/tweet_button.rb b/public/plugin/lokka-tweet_button/lib/lokka/tweet_button.rb new file mode 100644 index 00000000..c123078d --- /dev/null +++ b/public/plugin/lokka-tweet_button/lib/lokka/tweet_button.rb @@ -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(Tweet) + end + end +end diff --git a/public/plugin/lokka-tweet_button/views/index.haml b/public/plugin/lokka-tweet_button/views/index.haml new file mode 100644 index 00000000..d1aae1c3 --- /dev/null +++ b/public/plugin/lokka-tweet_button/views/index.haml @@ -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}