Sha256: 16b3f43c4894bdbd5333264fa370612bf5c347bbc0ba64dc506795a6203557cc

Contents?: true

Size: 774 Bytes

Versions: 7

Compression:

Stored size: 774 Bytes

Contents

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

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

7 entries across 7 versions & 1 rubygems

Version Path
middleman-generator-tag-0.2.4 lib/middleman-generator-tag/extension.rb
middleman-generator-tag-0.2.3 lib/middleman-generator-tag/extension.rb
middleman-generator-tag-0.2.2 lib/middleman-generator-tag/extension.rb
middleman-generator-tag-0.2.1 lib/middleman-generator-tag/extension.rb
middleman-generator-tag-0.2.0 lib/middleman-generator-tag/extension.rb
middleman-generator-tag-0.1.2 lib/middleman-generator-tag/extension.rb
middleman-generator-tag-0.1.1 lib/middleman-generator-tag/extension.rb