Class: WCC::Contentful::Middleman::Extension

Inherits:
Middleman::Extension
  • Object
show all
Defined in:
lib/wcc/contentful/middleman/extension.rb

Defined Under Namespace

Classes: ContentfulSyncUpdate

Instance Method Summary collapse

Constructor Details

#initialize(app, options_hash = {}, &block) ⇒ Extension

Returns a new instance of Extension.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# 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

Instance Method Details

#readyObject

helpers do

def a_helper
end

end



53
54
55
56
# 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