Sha256: fc79e2136ff1c153848a6b1936ba67665bd04a29c3b94ac66aff19a7d54d8912

Contents?: true

Size: 694 Bytes

Versions: 1

Compression:

Stored size: 694 Bytes

Contents

require "jekyll/languages/version"

module Jekyll
  module Languages
    
    def sentencize_array(array)
      connector = strings[:connector]
      
      case array.length
      when 0
        ""
      when 1
        array[0].to_s
      when 2
        "#{array[0]} #{connector} #{array[1]}"
      else
        "#{array[0...-1].join(', ')} #{connector} #{array[-1]}"
      end
    end
    
    private
    
    def config
      @config ||= Jekyll.configuration({}).fetch('jekyll_languages', {})
    end
    
    def strings
      {
        :connector => config['array_connector'] || 'and'
      }
    end
    
  end
end

Liquid::Template.register_filter(Jekyll::Languages) if defined?(Liquid)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jekyll-languages-0.0.1 lib/jekyll/languages.rb