Sha256: 2add10ec2fbbb7ca68810d4a70df4260b53638e4c4f98a183375248d83c7cb76

Contents?: true

Size: 1.01 KB

Versions: 2

Compression:

Stored size: 1.01 KB

Contents

require 'middleman-blog-similar/blog_article_extensions'
require 'middleman-blog-similar/helpers'
require 'middleman-blog-similar/algorithm'

module Middleman
  module Blog
    class SimilarExtension < ::Middleman::Extension

      option :algorithm, :word_frequency, 'Similar lookup algorithm'

      self.defined_helpers = [ Middleman::Blog::Similar::Helpers ]

      def after_configuration
        require 'middleman-blog/blog_article'
        ::Middleman::Sitemap::Resource.send :include, Middleman::Blog::Similar::BlogArticleExtensions
        algorithm = options[:algorithm].to_s
        begin
          require "middleman-blog-similar/algorithm/#{algorithm}"
          ns = ::Middleman::Blog::Similar::Algorithm
          algorithm.split('/').each do|n|
            ns = ns.const_get n.camelize
          end
          app.set :similarity_algorithm, ns
        rescue LoadError => e
          app.logger.error "Requested similar algorithm '#{algorithm}' not found."
          raise e
        end
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
middleman-blog-similar-1.1.1 lib/middleman-blog-similar/extension.rb
middleman-blog-similar-1.1.0 lib/middleman-blog-similar/extension.rb