Created
January 11, 2012 12:38
-
-
Save dmedvinsky/1594470 to your computer and use it in GitHub Desktop.
Earthquake Twitter client: align plugin
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
# -*- coding: utf-8 -*- | |
# align plugin | |
# | |
# For now only aligns usernames. | |
# | |
# Configure like this: | |
# | |
# Earthquake.config[:plugin_align] = { | |
# :name_maxlen => 10, | |
# :more_char => '…' | |
# } | |
Earthquake.init do | |
cfg = config[:plugin_align] ||= {} | |
cfg[:name_maxlen] ||= 12 | |
cfg[:more_char] ||= '…' | |
maxlen = cfg[:name_maxlen] | |
output_filter do |item| | |
next unless item['user'] | |
username = item['user']['screen_name'] | |
if username.length > maxlen | |
username = username[0..maxlen-2] + cfg[:more_char] | |
end | |
username = username.ljust(maxlen) | |
item['user']['screen_name'] = username | |
true | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment