Class: MiddlemanDato::MiddlemanExtension
- Inherits:
-
Middleman::Extension
- Object
- Middleman::Extension
- MiddlemanDato::MiddlemanExtension
- Defined in:
- lib/middleman_dato/middleman_extension.rb
Defined Under Namespace
Modules: InstanceMethods
Instance Attribute Summary collapse
-
#loader ⇒ Object
readonly
Returns the value of attribute loader.
Instance Method Summary collapse
- #client ⇒ Object
- #dato_collector ⇒ Object
-
#initialize(app, options_hash = {}, &block) ⇒ MiddlemanExtension
constructor
A new instance of MiddlemanExtension.
- #items_repo ⇒ Object
Constructor Details
#initialize(app, options_hash = {}, &block) ⇒ MiddlemanExtension
Returns a new instance of MiddlemanExtension.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/middleman_dato/middleman_extension.rb', line 27 def initialize(app, = {}, &block) super return if app.mode?(:config) @loader = loader = Dato::Local::Loader.new( client, [:preview] ) loader.load app.after_configuration do if [:live_reload] && !app.build? loader.watch do puts "DatoCMS content changed!" app.sitemap.rebuild_resource_list!(:touched_dato_content) end end end end |
Instance Attribute Details
#loader ⇒ Object (readonly)
Returns the value of attribute loader.
13 14 15 |
# File 'lib/middleman_dato/middleman_extension.rb', line 13 def loader @loader end |
Instance Method Details
#client ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/middleman_dato/middleman_extension.rb', line 49 def client token = [:token] if token.blank? && File.exist?('.env') token = Dotenv::Environment.new('.env')['DATO_API_TOKEN'] end if token.blank? raise RuntimeError, 'Missing DatoCMS site API token!' end @client ||= Dato::Site::Client.new( token, base_url: [:api_base_url], environment: [:environment], extra_headers: { 'X-Reason' => 'dump', 'X-SSG' => 'middleman' } ) end |
#dato_collector ⇒ Object
71 72 73 74 75 |
# File 'lib/middleman_dato/middleman_extension.rb', line 71 def dato_collector app.extensions[:collections].live_collector do |app, resources| app.dato_items_repo end end |
#items_repo ⇒ Object
77 78 79 |
# File 'lib/middleman_dato/middleman_extension.rb', line 77 def items_repo loader.items_repo end |