Sha256: 28a1d94b12c52416de3f5a231f68945fb24f05f69b838ed97c5f4fc825e01b16

Contents?: true

Size: 1.17 KB

Versions: 4

Compression:

Stored size: 1.17 KB

Contents

# -*- encoding : utf-8 -*-

module PhraseApp
  module InContextEditor
    module Delegate
      class Base < String
        def to_s
          "#{decorated_key_name}"
        end
        alias :camelize :to_s
        alias :underscore :to_s
        alias :classify :to_s
        alias :dasherize :to_s
        alias :tableize :to_s

        # Delegate .html_safe from accessing Delegate object as if it was a hash,
        # but instead perform it on the resulting string
        delegate :html_safe, to: :to_s

        def self.log(message)
          message = "phrase: #{message}"
          if defined?(Rails) and Rails.respond_to?(:logger)
            Rails.logger.warn(message)
          else
            $stderr.puts message
          end
        end

      protected
        def decorated_key_name
          "#{PhraseApp::InContextEditor.prefix}phrase_#{normalized_display_key}#{PhraseApp::InContextEditor.suffix}"
        end

        def normalized_display_key
          unless @display_key.nil?
            @display_key.gsub("<", "[[[[[[html_open]]]]]]").gsub(">", "[[[[[[html_close]]]]]]")
          else
            @display_key
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
phraseapp-in-context-editor-ruby-1.4.0 lib/phraseapp-in-context-editor-ruby/delegate.rb
phraseapp-in-context-editor-ruby-1.3.1 lib/phraseapp-in-context-editor-ruby/delegate.rb
phraseapp-in-context-editor-ruby-1.3.0 lib/phraseapp-in-context-editor-ruby/delegate.rb
phraseapp-in-context-editor-ruby-1.2.1 lib/phraseapp-in-context-editor-ruby/delegate.rb