class WCC::Contentful::Middleman::Extension

Public Class Methods

new(app, options_hash = {}, &block) click to toggle source
Calls superclass method
# File lib/wcc/contentful/middleman/extension.rb, line 20
def initialize(app, options_hash = {}, &block)
  # don't pass block to super b/c we use it to configure WCC::Contentful
  super(app, options_hash) {}

  # Require libraries only when activated
  require 'wcc/contentful'

  # set up your extension
  return if WCC::Contentful.initialized

  WCC::Contentful.configure do |config|
    config.store :eager_sync, :memory

    options.to_h.each do |(k, v)|
      config.public_send("#{k}=", v) if config.respond_to?("#{k}=")
    end

    instance_exec(config, &block) if block_given?
  end

  WCC::Contentful.init!
  model_glob = File.join(Middleman::Application.root, 'lib/models/**/*.rb')
  Dir[model_glob].sort.each { |f| require f }

  # Sync the latest data from Contentful
  WCC::Contentful::Services.instance.sync_engine&.next
end

Public Instance Methods

ready() click to toggle source

helpers do

def a_helper
end

end

# File lib/wcc/contentful/middleman/extension.rb, line 53
def ready
  # resync every page load in development & test mode only
  app.use ContentfulSyncUpdate if app.server?
end