Sha256: e9460c2ded47c8727d1aaa42abc1501a99721a20172ff144e51fa04761de7301

Contents?: true

Size: 1017 Bytes

Versions: 2

Compression:

Stored size: 1017 Bytes

Contents

module Jekyll
  module Maps
    class OptionsParser
      OPTIONS_SYNTAX     = %r!([^\s]+)\s*=\s*['"]+([^'"]+)['"]+!
      ALLOWED_FLAGS      = %w(
        no_cluster
      ).freeze
      ALLOWED_ATTRIBUTES = %w(
        id
        width
        height
        class
        show_marker
        show_popup
        zoom
      ).freeze

      class << self
        def parse(raw_options)
          options = {
            :attributes => {},
            :filters    => {},
            :flags      => {}
          }
          raw_options.scan(OPTIONS_SYNTAX).each do |key, value|
            value = value.split(",") if value.include?(",")
            if ALLOWED_ATTRIBUTES.include?(key)
              options[:attributes][key.to_sym] = value
            else
              options[:filters][key] = value
            end
          end
          ALLOWED_FLAGS.each do |key|
            options[:flags][key.to_sym] = true if raw_options.include?(key)
          end
          options
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
jekyll-maps-2.0.3 lib/jekyll-maps/options_parser.rb
jekyll-maps-2.0.2 lib/jekyll-maps/options_parser.rb