Sha256: 270ac70d8d86bf6b0e3c08e8a7e04326effc6a41215e351033d346cb888e8ce7

Contents?: true

Size: 573 Bytes

Versions: 2

Compression:

Stored size: 573 Bytes

Contents

require "listless/version"
require "htmlentities"

module Listless
  extend self

  # Create a HTML unordered list from an array
  #
  # @param array [Array]
  # @return [String]
  #
  # @example
  #   Listless.ul ['foo', 'bar'] #=> "<ul><li>foo</li><li>bar</li></ul>"

  def ul(array)
    list = array.map { |x| tag(:li, escape(x)) }.join
    tag(:ul, list)
  end

  private

  def tag(element, string)
    "<#{ element }>#{ string }</#{ element }>"
  end

  def escape(string, entities = :named)
    coder = HTMLEntities.new
    coder.encode(string, entities)
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
listless-0.1.0 lib/listless.rb
listless-0.0.1 lib/listless.rb