Skip to content

Commit

Permalink
WIP: Add content_types
Browse files Browse the repository at this point in the history
  • Loading branch information
bricesanchez committed Nov 4, 2016
1 parent 576c05c commit a2f9fdb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ activate :refinery do |f|
f.release = 'master'
f.link_resolver = ->(link) { binding.pry; "#{link.type.pluralize}/#{link.slug}"}
f.custom_queries = { test: [Refinery::Predicates::at('document.type', 'product')] }
f.content_types = [
{ content_type: 'Blog::Posts', destination: 'source/data' },
{ content_type: 'Pages' }
]
end
```

Expand Down
1 change: 1 addition & 0 deletions lib/middleman-refinery.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Core < Middleman::Extension
option :api_token, nil, 'The Refinery CMS API token'
option :api_url, nil, 'The Refinery CMS API url'
option :api_path, '/api/v1', 'The Refinery CMS API path'
option :content_types, [], 'Content types'
option :release, 'master', 'Content release'
option(
:link_resolver,
Expand Down
25 changes: 16 additions & 9 deletions lib/middleman-refinery/commands/refinery.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require 'json'
require 'fileutils'
require 'logger'
require 'pry'

module Middleman
module Cli
Expand Down Expand Up @@ -47,18 +48,24 @@ def refinery
# api = ::Refinery::API.configure(MiddlemanRefinery.options.api_url)
# response = api.form('everything').submit(api.ref(reference))

client = ::Refinery::API::Pages.new
pages = client.index.body

File.open('data/refinery_page.yml', 'w') do |f|
f.write(JSON.parse(pages).to_yaml)
end
options.content_types.each do |ct|
content = eval("::Refinery::API::#{ct[:content_type]}.new")
content_body = content.index.body

content_type_param = ct[:content_type].parameterize
destination = "#{ct[:destination] || 'data'}/#{ct[:content_type].parameterize}"
FileUtils.mkdir_p destination

client = ::Refinery::API::Blog::Posts.new
posts = client.index.body
JSON.parse(content_body)[content_type_param].each do |content|
File.open("#{destination}/#{content["id"]}.yml", 'w') do |f|
f.write(content.to_yaml)
end
end

File.open('data/refinery_blog_post.yml', 'w') do |f|
f.write(JSON.parse(posts).to_yaml)
File.open("#{ct[:destination] || 'data'}/#{content_type_param}.yml", 'w') do |f|
f.write(JSON.parse(content_body).to_yaml)
end
end

Middleman::Cli::Build.new.build if options[:rebuild]
Expand Down

0 comments on commit a2f9fdb

Please sign in to comment.