Sha256: 95864833b82145bdd28c009571d629fba0c7c750dc96dc92f691c2c8a9d7a0e4

Contents?: true

Size: 1.1 KB

Versions: 1

Compression:

Stored size: 1.1 KB

Contents

require 'prismic'
require 'middleman-prismic/version'
require 'middleman-prismic/commands/prismic'

module MiddlemanPrismic
  class << self
    attr_reader :options
  end

  class Core < Middleman::Extension

    option :api_url, nil, 'The prismic api url'
    option :release, 'master', 'Content release'
    option(
      :link_resolver,
      ->(link) {"http://www.example.com/#{link.type.pluralize}/#{link.slug}"},
      'The link resolver'
    )
    option :custom_queries, {}, 'Custom queries'

    def initialize(app, options_hash={}, &block)
      super

      MiddlemanPrismic.instance_variable_set('@options', options)
    end

    helpers do
      Dir["data/prismic_*"].each do |file|
        define_method(file.gsub('data/prismic_','')) do
          YAML::load(File.read(file)).values
        end
      end

      def reference
        ref = YAML::load(File.read('data/prismic_reference'))
        ref.class.send(
          :define_method, :link_to, MiddlemanPrismic.options.link_resolver
        )

        return ref
      end
    end
  end

end

::Middleman::Extensions.register(:prismic, MiddlemanPrismic::Core)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
middleman-prismic-0.1.0 lib/middleman-prismic.rb