Class MiscPlugins::SmileyReplacer
In: lib/webgen/plugins/miscplugins/smileyreplacer.rb
Parent: Webgen::Plugin
Webgen::Plugin RenderedFilesPlugin SmileyReplacer SyntaxHighlighter lib/webgen/plugins/miscplugins/smileyreplacer.rb lib/webgen/plugins/miscplugins/syntax_highlighter.rb lib/webgen/plugins/miscplugins/rendered_files.rb MiscPlugins dot/m_53_0.png

Methods

Constants

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)}/ } )

Public Class methods

[Source]

    # 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

Private Instance methods

[Source]

    # 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

[Source]

    # File lib/webgen/plugins/miscplugins/smileyreplacer.rb, line 81
81:     def smiley_pack( node )
82:       node.meta_info.has_key?( 'emoticonPack' ) && node['emoticonPack'].nil? ? nil : node['emoticonPack'] || param( 'emoticonPack' )
83:     end

[Validate]