middleman-prismic 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +69 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/middleman-prismic.rb +47 -0
- data/lib/middleman-prismic/commands/prismic.rb +68 -0
- data/lib/middleman-prismic/version.rb +3 -0
- data/middleman-prismic.gemspec +27 -0
- metadata +128 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9f736c2a97835b9aad9c6bd91fa2cdbd78c719c1
|
4
|
+
data.tar.gz: e9129af75a42538d8ab264f1a34c7ae17c68c743
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5a76611dba3fbbdc751b40222fd4cb88dd8b185b853ddcd86051dcb99891bb70b2c635148a745277fbd0482de505094acf9b99def96c2e90c3b4414f2cd79277
|
7
|
+
data.tar.gz: 52268bf6060956baf8ffb1013a3e7f2fe50bad2a1a0c583db10c94487cf84e2ed865760ab5e6eff4971c53efb971d81a5bc4da1c0a180a71b2e48a7db4bdbbe2
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Kollegorna
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
# Middleman Prismic
|
2
|
+
|
3
|
+
|
4
|
+
## Installation
|
5
|
+
|
6
|
+
Add this line to your application's Gemfile:
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
gem 'middleman-prismic'
|
10
|
+
```
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install middleman-prismic
|
19
|
+
i
|
20
|
+
## Configuration
|
21
|
+
|
22
|
+
To configure the extension, add the following configuration block to Middleman's config.rb:
|
23
|
+
|
24
|
+
|
25
|
+
Parameter |i Description
|
26
|
+
---------- |------------
|
27
|
+
api_url | the single endpoint of your content repository
|
28
|
+
access_token | Prismic API OAuth2 based access token (optional)
|
29
|
+
release | The content release (optional, defaults to `master`)
|
30
|
+
link_resolver | A link resolver. Expects a proc with one param, which is an object of type [Prismic::Fragments::DocumentLink](http://www.rubydoc.info/github/prismicio/ruby-kit/master/Prismic/Fragments/DocumentLink) (optional)
|
31
|
+
|
32
|
+
For instance:
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
activate :prismic do |f|
|
36
|
+
f.api_url = 'https://testrepositorymiddleman.prismic.io/api'
|
37
|
+
f.release = 'master'
|
38
|
+
f.link_resolver = ->(link) { binding.pry; "#{link.type.pluralize}/#{link.slug}"}
|
39
|
+
f.custom_queries = { test: [Prismic::Predicates::at('document.type', 'product')] }
|
40
|
+
end
|
41
|
+
```
|
42
|
+
|
43
|
+
## Usage
|
44
|
+
Run `bundle exec middleman prismic` in your terminal. This will fetch entries for the configured
|
45
|
+
spaces and content types and put the resulting data in the [local data folder](https://middlemanapp.com/advanced/local-data/) as yaml files.
|
46
|
+
|
47
|
+
For each document mask you have, you will get a file named `prismic_{document-name}` under `/data`.
|
48
|
+
So for instance if you have article and product document masks, you will get 2 files: `prismic_articles`, `prismic_products`.
|
49
|
+
Each file will contain all your documents of the specified document mask in an array.
|
50
|
+
|
51
|
+
|
52
|
+
In your templates, you get for free helper methods named after your document mask that return the Prismic equivelant object.
|
53
|
+
For instance for articles, if you run `<%= articles %>` you get back a `Prismic::Document`.
|
54
|
+
|
55
|
+
If at any time need access to `Prismic::Ref` you can do it using the `reference` helper.
|
56
|
+
|
57
|
+
## Development
|
58
|
+
|
59
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
60
|
+
|
61
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
62
|
+
|
63
|
+
## Contributing
|
64
|
+
|
65
|
+
1. Fork it ( https://github.com/[my-github-username]/middleman-prismic/fork )
|
66
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
67
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
68
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
69
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "middleman-prismic"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'prismic'
|
2
|
+
require 'middleman-prismic/version'
|
3
|
+
require 'middleman-prismic/commands/prismic'
|
4
|
+
|
5
|
+
module MiddlemanPrismic
|
6
|
+
class << self
|
7
|
+
attr_reader :options
|
8
|
+
end
|
9
|
+
|
10
|
+
class Core < Middleman::Extension
|
11
|
+
|
12
|
+
option :api_url, nil, 'The prismic api url'
|
13
|
+
option :release, 'master', 'Content release'
|
14
|
+
option(
|
15
|
+
:link_resolver,
|
16
|
+
->(link) {"http://www.example.com/#{link.type.pluralize}/#{link.slug}"},
|
17
|
+
'The link resolver'
|
18
|
+
)
|
19
|
+
option :custom_queries, {}, 'Custom queries'
|
20
|
+
|
21
|
+
def initialize(app, options_hash={}, &block)
|
22
|
+
super
|
23
|
+
|
24
|
+
MiddlemanPrismic.instance_variable_set('@options', options)
|
25
|
+
end
|
26
|
+
|
27
|
+
helpers do
|
28
|
+
Dir["data/prismic_*"].each do |file|
|
29
|
+
define_method(file.gsub('data/prismic_','')) do
|
30
|
+
YAML::load(File.read(file)).values
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def reference
|
35
|
+
ref = YAML::load(File.read('data/prismic_reference'))
|
36
|
+
ref.class.send(
|
37
|
+
:define_method, :link_to, MiddlemanPrismic.options.link_resolver
|
38
|
+
)
|
39
|
+
|
40
|
+
return ref
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
::Middleman::Extensions.register(:prismic, MiddlemanPrismic::Core)
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
module Middleman
|
5
|
+
module Cli
|
6
|
+
|
7
|
+
class Prismic < Thor
|
8
|
+
# Path where Middleman expects the local data to be stored
|
9
|
+
MIDDLEMAN_LOCAL_DATA_FOLDER = 'data'
|
10
|
+
|
11
|
+
check_unknown_options!
|
12
|
+
|
13
|
+
namespace :prismic
|
14
|
+
desc 'prismic', 'Import data from Prismic'
|
15
|
+
|
16
|
+
=begin
|
17
|
+
method_option "refetch",
|
18
|
+
aliases: "-r",
|
19
|
+
desc: "Refetches the data from Prismic"
|
20
|
+
=end
|
21
|
+
|
22
|
+
def self.source_root
|
23
|
+
ENV['MM_ROOT']
|
24
|
+
end
|
25
|
+
|
26
|
+
# Tell Thor to exit with a nonzero exit code on failure
|
27
|
+
def self.exit_on_failure?
|
28
|
+
true
|
29
|
+
end
|
30
|
+
|
31
|
+
def prismic
|
32
|
+
::Middleman::Application.server.inst
|
33
|
+
reference = MiddlemanPrismic.options.release
|
34
|
+
|
35
|
+
Dir.mkdir('data') unless File.exists?('data')
|
36
|
+
|
37
|
+
FileUtils.rm_rf(Dir.glob('data/prismic_*'))
|
38
|
+
|
39
|
+
api = ::Prismic.api(MiddlemanPrismic.options.api_url)
|
40
|
+
response = api.form('everything').submit(api.ref(reference))
|
41
|
+
|
42
|
+
available_documents = []
|
43
|
+
response.each {|d| available_documents << d.type}
|
44
|
+
|
45
|
+
available_documents.uniq!
|
46
|
+
|
47
|
+
available_documents.each do |document_type|
|
48
|
+
documents = response.select{|d| d.type == document_type}
|
49
|
+
File.open("data/prismic_#{document_type.pluralize}", 'w') do |f|
|
50
|
+
f.write(Hash[[*documents.map.with_index]].invert.to_yaml)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
File.open('data/prismic_reference', 'w') do |f|
|
55
|
+
f.write(api.master_ref.to_yaml)
|
56
|
+
end
|
57
|
+
|
58
|
+
MiddlemanPrismic.options.custom_queries.each do |k, v|
|
59
|
+
response = api.form('everything').query(*v).submit(api.master_ref)
|
60
|
+
File.open("data/prismic_custom_#{k}", 'w') do |f|
|
61
|
+
f.write(Hash[[*response.map.with_index]].invert.to_yaml)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'middleman-prismic/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "middleman-prismic"
|
8
|
+
spec.version = MiddlemanPrismic::VERSION
|
9
|
+
spec.authors = ["Filippos Vasilakis"]
|
10
|
+
spec.email = ["vasilakisfil@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Middleman extension for Prismic}
|
13
|
+
spec.description = %q{Middleman extension for Prismic}
|
14
|
+
spec.homepage = "https://github.com/kollegorna/middleman-prismic"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "middleman", "~> 3.3"
|
22
|
+
spec.add_dependency "middleman-core", "~> 3.3"
|
23
|
+
spec.add_dependency "prismic.io", "~> 1.1"
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.8"
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: middleman-prismic
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Filippos Vasilakis
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: middleman
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.3'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: middleman-core
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.3'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: prismic.io
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.1'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.8'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.8'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
description: Middleman extension for Prismic
|
84
|
+
email:
|
85
|
+
- vasilakisfil@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".travis.yml"
|
93
|
+
- CODE_OF_CONDUCT.md
|
94
|
+
- Gemfile
|
95
|
+
- LICENSE.txt
|
96
|
+
- README.md
|
97
|
+
- Rakefile
|
98
|
+
- bin/console
|
99
|
+
- bin/setup
|
100
|
+
- lib/middleman-prismic.rb
|
101
|
+
- lib/middleman-prismic/commands/prismic.rb
|
102
|
+
- lib/middleman-prismic/version.rb
|
103
|
+
- middleman-prismic.gemspec
|
104
|
+
homepage: https://github.com/kollegorna/middleman-prismic
|
105
|
+
licenses:
|
106
|
+
- MIT
|
107
|
+
metadata: {}
|
108
|
+
post_install_message:
|
109
|
+
rdoc_options: []
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
requirements: []
|
123
|
+
rubyforge_project:
|
124
|
+
rubygems_version: 2.4.5
|
125
|
+
signing_key:
|
126
|
+
specification_version: 4
|
127
|
+
summary: Middleman extension for Prismic
|
128
|
+
test_files: []
|