Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
投稿文字列の3文字以上のアルファベット文字列(internationalizationとか)を縮めて(i18nとか)ツイートするmikutterプラグイン
# -*- coding: utf-8 -*-
Plugin.create :shrink_words do
def shrink_words(src)
str = src
src.scan(/[a-zA-Z_]+/).map{ |s|
if s.size > 3
[s, s[0] + (s.size - 2).to_s + s[-1]]
else
[s, s]
end
}.each{ |pair|
str.sub!(pair[0], pair[1])
}
str
end
filter_gui_postbox_post do |gui_postbox|
src = Plugin.create(:gtk).widgetof(gui_postbox).widget_post.buffer.text
text = shrink_words(src)
Service.primary.post :message => text
Plugin.call(:before_postbox_post, text)
Plugin.create(:gtk).widgetof(gui_postbox).widget_post.buffer.text = ''
Plugin.filter_cancel!
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment