| 1 | # |
|---|
| 2 | # retweet.rb - show retweet count in each section |
|---|
| 3 | # This plugin uses a Topsy Retweet Button for Web Sites powered by Topsy.com |
|---|
| 4 | # |
|---|
| 5 | # Copyright (C) 2010, MATSUOKA Kohei <http://www.machu.jp/diary/> |
|---|
| 6 | # You can redistribute it and/or modify it under GPL2. |
|---|
| 7 | # |
|---|
| 8 | |
|---|
| 9 | # |
|---|
| 10 | # settings for Topsy Retweet Button. |
|---|
| 11 | # see: http://labs.topsy.com/button/retweet-button/#global_settings |
|---|
| 12 | # |
|---|
| 13 | # your Twitter nickname |
|---|
| 14 | @topsy_nick = "your_twitter_account" |
|---|
| 15 | # retweet button color |
|---|
| 16 | #@topsy_theme = "blue" |
|---|
| 17 | # retweet button text |
|---|
| 18 | #@topsy_retweet_text = "retweet" |
|---|
| 19 | |
|---|
| 20 | unless defined?(permalink) |
|---|
| 21 | def permalink( date, index, escape = true ) |
|---|
| 22 | ymd = date.strftime( "%Y%m%d" ) |
|---|
| 23 | uri = @conf.index.dup |
|---|
| 24 | uri.sub!( %r|\A(?!https?://)|i, @conf.base_url ) |
|---|
| 25 | uri.tr!( ".", "/" ) |
|---|
| 26 | link = uri + anchor( "#{ymd}p%02d" % index ) |
|---|
| 27 | link.sub!( "#", "%23" ) if escape |
|---|
| 28 | link |
|---|
| 29 | end |
|---|
| 30 | end |
|---|
| 31 | |
|---|
| 32 | unless defined?(subtitle) |
|---|
| 33 | def subtitle( date, index, escape = true ) |
|---|
| 34 | diary = @diaries[date.strftime( "%Y%m%d" )] |
|---|
| 35 | return "" unless diary |
|---|
| 36 | sn = 1 |
|---|
| 37 | diary.each_section do |section| |
|---|
| 38 | if sn == index |
|---|
| 39 | old_apply_plugin = @options["apply_plugin"] |
|---|
| 40 | @options["apply_plugin"] = true |
|---|
| 41 | title = apply_plugin( section.subtitle_to_html, true ) |
|---|
| 42 | @options["apply_plugin"] = old_apply_plugin |
|---|
| 43 | title.gsub!( /(?=")/, "\\" ) if escape |
|---|
| 44 | return title |
|---|
| 45 | end |
|---|
| 46 | sn += 1 |
|---|
| 47 | end |
|---|
| 48 | end |
|---|
| 49 | end |
|---|
| 50 | |
|---|
| 51 | # load Tospy's script and initialize |
|---|
| 52 | add_header_proc do |
|---|
| 53 | r = "" |
|---|
| 54 | r << %Q|<script type="text/javascript" src="http://cdn.topsy.com/topsy.js?init=topsyWidgetCreator"></script>\n| |
|---|
| 55 | return r unless @topsy_theme or @topsy_nick or @topsy_retweet_text |
|---|
| 56 | r << %Q|<script type="text/javascript" id="topsy_global_settings"><!--\n| |
|---|
| 57 | r << %Q| var topsy_theme = "#{@topsy_theme}";\n| if @topsy_theme |
|---|
| 58 | r << %Q| var topsy_nick = "#{@topsy_nick}";\n| if @topsy_nick |
|---|
| 59 | r << %Q| var topsy_retweet_text = "#{@topsy_retweet_text}";\n| if @topsy_retweet_text |
|---|
| 60 | r << %Q|//--></script>\n| |
|---|
| 61 | end |
|---|
| 62 | |
|---|
| 63 | # show retweet button in top of section |
|---|
| 64 | add_section_enter_proc do |date, index| |
|---|
| 65 | <<-"EOS" |
|---|
| 66 | <div class="topsy_widget_data" style="float: right; margin-left: 1em;"><!-- { |
|---|
| 67 | "url": "#{permalink(date, index)}", |
|---|
| 68 | "title": "#{subtitle(date, index)}", |
|---|
| 69 | "style": "big" |
|---|
| 70 | } --></div> |
|---|
| 71 | EOS |
|---|
| 72 | end |
|---|
| 73 | |
|---|
| 74 | # show retweet button in end of section |
|---|
| 75 | add_section_leave_proc do |date, index| |
|---|
| 76 | <<-"EOS" |
|---|
| 77 | <div class="tags"> |
|---|
| 78 | <img src="http://www.machu.jp/diary/twitter_logo_small.png" height="16" width="62" alt="Twitter">: |
|---|
| 79 | <div class="topsy_widget_data" style="float: right; margin-left: 1em;"><!-- { |
|---|
| 80 | "url": "#{permalink(date, index)}", |
|---|
| 81 | "title": "#{subtitle(date, index)}", |
|---|
| 82 | "style": "small" |
|---|
| 83 | } --></div> |
|---|
| 84 | </div> |
|---|
| 85 | EOS |
|---|
| 86 | end |
|---|