Sha256: 6c4b0f2b272401859347edb222d53bc04280c6f9904118d50a0364ae2e01d71c

Contents?: true

Size: 788 Bytes

Versions: 1

Compression:

Stored size: 788 Bytes

Contents

module Middleman
  module GeneratorTag
    class Extension < ::Middleman::Extension
      def initialize(app, options_hash = {}, &block)
        super

        extension = self
        app.after_render do |content, path, locs|
          if /<html>/ =~ content
            html = Nokogiri::HTML(content)
            if html.css("meta[name='generator']").length == 0
              content = extension.insert_tag(html)
            end
            content
          end
        end
      end

      def insert_tag(html)
        title = html.at_css('title')
        meta  = Nokogiri::XML::Node.new "meta", html
        meta[:name]    = 'generator'
        meta[:content] = "Middleman v#{::Middleman::VERSION}"
        title.add_next_sibling(meta)
        html.to_s
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
middleman-generator-tag-0.1.0 lib/middleman-generator-tag/extension.rb