Sha256: 92a6dcbc04fc35d2f2532f8dcd34dd36de6db4caff4fbcda6878b52ed33bc909

Contents?: true

Size: 837 Bytes

Versions: 2

Compression:

Stored size: 837 Bytes

Contents

module Munge
  module Helpers
    module Tag
      def empty_tag(name, options = {})
        options_str = options.map { |k, v| %(#{k}="#{h(v)}") }.join(" ")

        if options_str == ""
          "<#{name} />"
        else
          "<#{name} #{options_str} />"
        end
      end

      def content_tag(name, content = nil, options = {}, &block)
        if content.is_a?(Hash)
          options = content
          content = nil
        end

        options_str = options.map { |k, v| %(#{k}="#{h(v)}") }.join(" ")

        content_str =
          if content
            content
          elsif block_given?
            capture(&block)
          else
            ""
          end

        "<#{name} #{options_str}>#{content_str}</#{name}>"
      end

      def h(string)
        CGI.escape_html(string)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
munge-0.11.1 lib/munge/helpers/tag.rb
munge-0.11.0 lib/munge/helpers/tag.rb