lib/middleman-prismic/commands/prismic.rb
# Path where Middleman expects the local data to be stored
Path where Middleman expects the local data to be stored
Path where Middleman expects the local data to be stored
def prismic
        ::Middleman::Application.server.inst
        reference = MiddlemanPrismic.options.release
        Dir.mkdir('data') unless File.exists?('data')
        FileUtils.rm_rf(Dir.glob('data/prismic_*'))
        api = ::Prismic.api(MiddlemanPrismic.options.api_url)
        response = api.form('everything').submit(api.ref(reference))
        available_documents = []
        response.each {|d| available_documents << d.type}
        available_documents.uniq!
        available_documents.each do |document_type|
          documents = response.select{|d| d.type == document_type}
          File.open("data/prismic_#{document_type.pluralize}", 'w') do |f|
            f.write(Hash[[*documents.map.with_index]].invert.to_yaml)
          end
        end
        File.open('data/prismic_reference', 'w') do |f|
          f.write(api.master_ref.to_yaml)
        end
        MiddlemanPrismic.options.custom_queries.each do |k, v|
          response = api.form('everything').query(*v).submit(api.master_ref)
          File.open("data/prismic_custom_#{k}", 'w') do |f|
            f.write(Hash[[*response.map.with_index]].invert.to_yaml)
          end
        end
      end
def prismic :: Middleman :: Application . server . inst reference = MiddlemanPrismic . options . release Dir . mkdir ( 'data' ) unless File . exists? ( 'data' ) FileUtils . rm_rf ( Dir . glob ( 'data/prismic_*' ) ) api = :: Prismic . api ( MiddlemanPrismic . options . api_url ) response = api . form ( 'everything' ) . submit ( api . ref ( reference ) ) available_documents = [ ] response . each { | d | available_documents << d . type } available_documents . uniq! available_documents . each do | document_type | documents = response . select { | d | d . type == document_type } File . open ( "data/prismic_#{document_type.pluralize}" , 'w' ) do | f | f . write ( Hash [ [ * documents . map . with_index ] ] . invert . to_yaml ) end end File . open ( 'data/prismic_reference' , 'w' ) do | f | f . write ( api . master_ref . to_yaml ) end MiddlemanPrismic . options . custom_queries . each do | k , v | response = api . form ( 'everything' ) . query ( * v ) . submit ( api . master_ref ) File . open ( "data/prismic_custom_#{k}" , 'w' ) do | f | f . write ( Hash [ [ * response . map . with_index ] ] . invert . to_yaml ) end end end
Path where Middleman expects the local data to be stored
Path where Middleman expects the local data to be stored