-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from Paradem/tweaks
Bridgetown Builders
- Loading branch information
Showing
7 changed files
with
119 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
::Bridgetown.initializer :dato_cms_graphql do |config| | ||
config.builder DatoCmsGraphql::Bridgetown::Builder | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
module DatoCmsGraphql::Bridgetown | ||
class Builder < ::Bridgetown::Builder | ||
def build | ||
queries = DatoCmsGraphql.queries | ||
|
||
hook :site, :post_read do | ||
queries.each do |query| | ||
if query.single_instance? | ||
site.data[query.single_name.underscore] = query.get | ||
else | ||
results = query.all | ||
site.data[query.plural_name.underscore] = results | ||
|
||
if query.render? | ||
results.each do |item| | ||
add_resource query.plural_name.underscore, "#{item.id}.erb" do | ||
result item | ||
permalink "#{item.permalink}/" | ||
title item.title | ||
layout query.single_name.underscore | ||
content "" | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,37 @@ | ||
require "active_support/concern" | ||
|
||
module DatoCmsGraphql::Rails::CacheTable | ||
extend ActiveSupport::Concern | ||
module DatoCmsGraphql::Rails | ||
module CacheTable | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
enum :locale, I18n.available_locales | ||
end | ||
included do | ||
enum :locale, I18n.available_locales | ||
end | ||
|
||
class_methods do | ||
def allow?(type, request) | ||
permalink = request.params["permalink"] | ||
exists?(type: type, render: true, permalink: permalink) | ||
class_methods do | ||
def allow?(type, request) | ||
permalink = request.params["permalink"] | ||
exists?(type: type, render: true, permalink: permalink) | ||
end | ||
end | ||
end | ||
|
||
def cms_record | ||
@parsed ||= begin | ||
data = read_attribute(:cms_record) | ||
JSON.parse(data.to_json, object_class: OpenStruct) | ||
def cms_record | ||
@parsed ||= begin | ||
data = read_attribute(:cms_record) | ||
JSON.parse(data.to_json, object_class: OpenStruct) | ||
end | ||
end | ||
end | ||
|
||
def respond_to_missing?(method, *args) | ||
cms_record.respond_to?(method.to_s, *args) | ||
end | ||
def respond_to_missing?(method, *args) | ||
cms_record.respond_to?(method.to_s, *args) | ||
end | ||
|
||
def method_missing(method, *a, &block) | ||
if cms_record.respond_to?(method.to_s) | ||
cms_record.send(method, *a, &block) | ||
else | ||
super | ||
def method_missing(method, *a, &block) | ||
if cms_record.respond_to?(method.to_s) | ||
cms_record.send(method, *a, &block) | ||
else | ||
super | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters