Sha256: 8f7cc82399760b59eacca432d78cb5d6a071dea11fb0183cc41e7dad73ef30c2

Contents?: true

Size: 1.03 KB

Versions: 17

Compression:

Stored size: 1.03 KB

Contents

module Lipsiadmin
  module Ext
    # Ext configuration used by components
    # 
    #   Generates: { name: 'name', handler: function(){ alert('Hello World') } }
    #
    class Configuration < Hash
      
      def initialize(hash)#:nodoc:
        hash.each { |k,v| self[k] = v }
      end
      
      # Returns the configuration as a string.
      # Optionally you can specify the indentation spaces.
      def to_s(indent=1)
        return if self.empty?
        i = ("  "*indent)
        s = self.size > 0 ? "\n" : "  "
        "{#{s}" + self.collect { |k,v| "#{i*2}#{k}: #{s(v)}" if k != :var }.join(",#{s}") + "#{s}#{i}}"
      end
      
      private
        def javascript_object_for(object)
          case object
            when Configuration
              object.to_s(2)
            when Array
              "[" + object.collect { |o| s(o) }.join(",") + "]"
            else
              object.respond_to?(:to_json) ? object.to_json : object.inspect
          end
        end
        alias_method :s, :javascript_object_for
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
lipsiadmin-3.1 lib/view/helpers/ext/configuration.rb
lipsiadmin-2.9 lib/view/helpers/ext/configuration.rb
lipsiadmin-3.3.1 lib/view/helpers/ext/configuration.rb
lipsiadmin-3.0 lib/view/helpers/ext/configuration.rb
lipsiadmin-3.2 lib/view/helpers/ext/configuration.rb
lipsiadmin-3.3.3 lib/view/helpers/ext/configuration.rb
lipsiadmin-3.3.2 lib/view/helpers/ext/configuration.rb
lipsiadmin-3.3.4 lib/view/helpers/ext/configuration.rb
lipsiadmin-3.3 lib/view/helpers/ext/configuration.rb
lipsiadmin-3.4.0 lib/view/helpers/ext/configuration.rb
lipsiadmin-3.4.1 lib/view/helpers/ext/configuration.rb
lipsiadmin-3.4.2 lib/view/helpers/ext/configuration.rb
lipsiadmin-4.0.0 lib/view/helpers/ext/configuration.rb
lipsiadmin-4.1.0 lib/view/helpers/ext/configuration.rb
lipsiadmin-4.1.1 lib/view/helpers/ext/configuration.rb
lipsiadmin-4.1.2 lib/view/helpers/ext/configuration.rb
lipsiadmin-4.1.3 lib/view/helpers/ext/configuration.rb