Sha256: 210e90df5a4db6b8607cadffece7f05cb1bed4d89cb17b540ed04f4459c2ba7c

Contents?: true

Size: 951 Bytes

Versions: 4

Compression:

Stored size: 951 Bytes

Contents

require 'rack/dev-mark/theme/base'

module Rack
  module DevMark
    module Theme
      class Tag < Base
        def initialize(options = {})
          @options = options
          super
        end

        def insert_into(html)
          name = @options[:name]

          if name
            html = gsub_tag_content html, name do |value|
              env_with(value)
            end
          end

          if attribute = @options[:attribute]
            Array(attribute).each do |attr|
              html = gsub_tag_attribute html, name, attr do |value|
                env_with(value)
              end
            end
          end

          html
        end

        private

        def env_with(org)
          s = env.to_s
          s = s.upcase if @options[:upcase]

          if @options[:type].to_s == 'postfix'
            "#{org} (#{s})"
          else
            "(#{s}) #{org}"
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rack-dev-mark-0.6.4 lib/rack/dev-mark/theme/tag.rb
rack-dev-mark-0.6.3 lib/rack/dev-mark/theme/tag.rb
rack-dev-mark-0.6.2 lib/rack/dev-mark/theme/tag.rb
rack-dev-mark-0.6.0 lib/rack/dev-mark/theme/tag.rb