| Class | MiscPlugins::SmileyReplacer |
| In: |
lib/webgen/plugins/miscplugins/smileyreplacer.rb
|
| Parent: | Webgen::Plugin |
| SMILEY_MAP | = | { ':-@' => 'angry', '8-)' => 'cool', ':\'-(' => 'cry', ':*)' => 'drunk', ':-D' => 'lol', ':-O' => 'oops', ':-(' => 'sad', '|-I' => 'sleep', ':-)' => 'smile', ':-P' => 'tongue', ';-)' => 'wink' |
| SMILEY_REGEXP | = | Regexp.union( *SMILEY_MAP.keys.collect {|t| /#{Regexp.escape(t)}/ } ) |
# File lib/webgen/plugins/miscplugins/smileyreplacer.rb, line 56
56: def initialize( plugin_manager )
57: super
58: @plugin_manager['File/PageHandler'].add_msg_listener( :after_node_rendered, method( :replace_smileys ) )
59: end
# File lib/webgen/plugins/miscplugins/smileyreplacer.rb, line 65
65: def replace_smileys( content, node )
66: pack = smiley_pack( node )
67: return content if pack.nil?
68:
69: log(:info) { "Replacing smileys in file <#{node.full_path}>..." }
70: content.gsub!( SMILEY_REGEXP ) do |match|
71: if res = @plugin_manager['Core/ResourceManager'].get_resource( "webgen-emoticons-#{pack}-#{SMILEY_MAP[match]}" )
72: res.referenced!
73: "<img src=\"#{res.route_from( node )}\" alt=\"smiley #{match}\" />"
74: else
75: log(:warn) { "Could not replace smiley '#{match}'(name: #{SMILEY_MAP[match]}, pack: #{pack}) in <#{node.full_path}>: resource not found!" }
76: match
77: end
78: end
79: end