Sha256: 1c5599c7415ffc4b6e5719e5f5a680d964856e85fe15d1d73faf262a0cb21233

Contents?: true

Size: 1.18 KB

Versions: 1

Compression:

Stored size: 1.18 KB

Contents

module MobileEnhancements
  class Configuration
    def self.default
      new do
        mobile do
          prefix "mobile"
          layout "application"
          format "mobile"
        end
        
        desktop do
          layout "application"
        end
      end
    end
    
    def initialize(&block)
      instance_eval(&block) if block_given?
    end
    
    def mobile(&block)
      @options ||= {}
      @options[__method__] ||= Options.new
      if block_given?
        @options[__method__].instance_eval(&block)
      end
      @options[__method__]
    end
    alias_method :desktop, :mobile
    
    def mobile_path_prefix
      mobile.prefix.gsub(/^\/|\/$/, "")
    end
    
    def mobile_layout
      mobile.layout
    end
    
    def desktop_layout
      desktop.layout
    end
    
    def mobile_format
      if mobile.format && mobile.format.to_sym != :html
        mobile.format.to_sym
      end
    end
    
    class Options
      def method_missing(name, *args, &block)
        case args.size
        when 0
          (@properties ||= {})[name]
        when 1
          (@properties ||= {})[name] = args.first
        else
          super
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mobile-enhancements-0.0.1 lib/mobile_enhancements/configuration.rb