middleman-headless 0.3.5 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -4
- data/README.md +23 -1
- data/example/Gemfile +5 -0
- data/example/Gemfile.lock +138 -0
- data/example/config.rb +10 -0
- data/example/source/index.html.erb +27 -0
- data/lib/middleman-headless/extension.rb +40 -0
- data/lib/middleman-headless/interface.rb +17 -1
- data/middleman-headless.gemspec +3 -2
- metadata +24 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 02fde3f80d8802e683bcfd98cc2aaa59c49d668a
|
|
4
|
+
data.tar.gz: 33dfef11c36b4a22fa09e9aa8fe866c7343ff01b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a784d489c4ba026ec11f067b3858a4df3e29d1eae05065c5b2c18c4bfb96e2b31022a663dd44886c6219ce6087b3b796d18bd86dde2acd0aa974ed6d2f848fe3
|
|
7
|
+
data.tar.gz: 3b0c1fe73bb16ee698e48231a17d9810f69489be8a44ebd70ca44be67d51445a02ae443e0f251d83c7439da8ec0208fcd98187ccbbcbae84bdbda7855ad1e3c5
|
data/.gitignore
CHANGED
data/README.md
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
1
|
# middleman-headless
|
|
2
2
|
|
|
3
|
-
**Middleman extension to load content from the Headless Content Management System.**
|
|
3
|
+
**Middleman extension to load content from the Headless Content Management System.**
|
|
4
|
+
|
|
5
|
+
## Example
|
|
6
|
+
|
|
7
|
+
The example middleman site in `./example` shows how you can retrieve data from a headless instance.
|
|
8
|
+
|
|
9
|
+
First of all, you need to create a new space in your headless server with the slug `example`.
|
|
10
|
+
|
|
11
|
+
After that you need to create the following content types:
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
post:
|
|
15
|
+
title: string
|
|
16
|
+
body: string (multiline)
|
|
17
|
+
image: asset
|
|
18
|
+
author: reference (author)
|
|
19
|
+
|
|
20
|
+
author (has no fields)
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Now you need to add English as a language with the slug `en`.
|
|
24
|
+
|
|
25
|
+
Finally, you can create as many entries you like.
|
data/example/Gemfile
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: ../
|
|
3
|
+
specs:
|
|
4
|
+
middleman-headless (0.3.5)
|
|
5
|
+
middleman-core (~> 4.1)
|
|
6
|
+
mime-types (~> 3.1)
|
|
7
|
+
oauth2 (~> 1.4)
|
|
8
|
+
|
|
9
|
+
GEM
|
|
10
|
+
remote: https://rubygems.org/
|
|
11
|
+
specs:
|
|
12
|
+
activesupport (5.0.6)
|
|
13
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
14
|
+
i18n (~> 0.7)
|
|
15
|
+
minitest (~> 5.1)
|
|
16
|
+
tzinfo (~> 1.1)
|
|
17
|
+
addressable (2.5.2)
|
|
18
|
+
public_suffix (>= 2.0.2, < 4.0)
|
|
19
|
+
backports (3.10.3)
|
|
20
|
+
coffee-script (2.4.1)
|
|
21
|
+
coffee-script-source
|
|
22
|
+
execjs
|
|
23
|
+
coffee-script-source (1.12.2)
|
|
24
|
+
compass-import-once (1.0.5)
|
|
25
|
+
sass (>= 3.2, < 3.5)
|
|
26
|
+
concurrent-ruby (1.0.5)
|
|
27
|
+
contracts (0.13.0)
|
|
28
|
+
dotenv (2.2.1)
|
|
29
|
+
em-websocket (0.5.1)
|
|
30
|
+
eventmachine (>= 0.12.9)
|
|
31
|
+
http_parser.rb (~> 0.6.0)
|
|
32
|
+
erubis (2.7.0)
|
|
33
|
+
eventmachine (1.2.5)
|
|
34
|
+
execjs (2.7.0)
|
|
35
|
+
faraday (0.12.2)
|
|
36
|
+
multipart-post (>= 1.2, < 3)
|
|
37
|
+
fast_blank (1.0.0)
|
|
38
|
+
fastimage (2.1.0)
|
|
39
|
+
ffi (1.9.18)
|
|
40
|
+
haml (5.0.4)
|
|
41
|
+
temple (>= 0.8.0)
|
|
42
|
+
tilt
|
|
43
|
+
hamster (3.0.0)
|
|
44
|
+
concurrent-ruby (~> 1.0)
|
|
45
|
+
hashie (3.5.6)
|
|
46
|
+
http_parser.rb (0.6.0)
|
|
47
|
+
i18n (0.7.0)
|
|
48
|
+
jwt (1.5.6)
|
|
49
|
+
kramdown (1.15.0)
|
|
50
|
+
listen (3.0.8)
|
|
51
|
+
rb-fsevent (~> 0.9, >= 0.9.4)
|
|
52
|
+
rb-inotify (~> 0.9, >= 0.9.7)
|
|
53
|
+
memoist (0.16.0)
|
|
54
|
+
middleman (4.2.1)
|
|
55
|
+
coffee-script (~> 2.2)
|
|
56
|
+
compass-import-once (= 1.0.5)
|
|
57
|
+
haml (>= 4.0.5)
|
|
58
|
+
kramdown (~> 1.2)
|
|
59
|
+
middleman-cli (= 4.2.1)
|
|
60
|
+
middleman-core (= 4.2.1)
|
|
61
|
+
sass (>= 3.4.0, < 4.0)
|
|
62
|
+
middleman-cli (4.2.1)
|
|
63
|
+
thor (>= 0.17.0, < 2.0)
|
|
64
|
+
middleman-core (4.2.1)
|
|
65
|
+
activesupport (>= 4.2, < 5.1)
|
|
66
|
+
addressable (~> 2.3)
|
|
67
|
+
backports (~> 3.6)
|
|
68
|
+
bundler (~> 1.1)
|
|
69
|
+
contracts (~> 0.13.0)
|
|
70
|
+
dotenv
|
|
71
|
+
erubis
|
|
72
|
+
execjs (~> 2.0)
|
|
73
|
+
fast_blank
|
|
74
|
+
fastimage (~> 2.0)
|
|
75
|
+
hamster (~> 3.0)
|
|
76
|
+
hashie (~> 3.4)
|
|
77
|
+
i18n (~> 0.7.0)
|
|
78
|
+
listen (~> 3.0.0)
|
|
79
|
+
memoist (~> 0.14)
|
|
80
|
+
padrino-helpers (~> 0.13.0)
|
|
81
|
+
parallel
|
|
82
|
+
rack (>= 1.4.5, < 3)
|
|
83
|
+
sass (>= 3.4)
|
|
84
|
+
servolux
|
|
85
|
+
tilt (~> 2.0)
|
|
86
|
+
uglifier (~> 3.0)
|
|
87
|
+
middleman-livereload (3.4.6)
|
|
88
|
+
em-websocket (~> 0.5.1)
|
|
89
|
+
middleman-core (>= 3.3)
|
|
90
|
+
rack-livereload (~> 0.3.15)
|
|
91
|
+
mime-types (3.1)
|
|
92
|
+
mime-types-data (~> 3.2015)
|
|
93
|
+
mime-types-data (3.2016.0521)
|
|
94
|
+
minitest (5.10.3)
|
|
95
|
+
multi_json (1.12.2)
|
|
96
|
+
multi_xml (0.6.0)
|
|
97
|
+
multipart-post (2.0.0)
|
|
98
|
+
oauth2 (1.4.0)
|
|
99
|
+
faraday (>= 0.8, < 0.13)
|
|
100
|
+
jwt (~> 1.0)
|
|
101
|
+
multi_json (~> 1.3)
|
|
102
|
+
multi_xml (~> 0.5)
|
|
103
|
+
rack (>= 1.2, < 3)
|
|
104
|
+
padrino-helpers (0.13.3.4)
|
|
105
|
+
i18n (~> 0.6, >= 0.6.7)
|
|
106
|
+
padrino-support (= 0.13.3.4)
|
|
107
|
+
tilt (>= 1.4.1, < 3)
|
|
108
|
+
padrino-support (0.13.3.4)
|
|
109
|
+
activesupport (>= 3.1)
|
|
110
|
+
parallel (1.12.0)
|
|
111
|
+
public_suffix (3.0.0)
|
|
112
|
+
rack (2.0.3)
|
|
113
|
+
rack-livereload (0.3.16)
|
|
114
|
+
rack
|
|
115
|
+
rb-fsevent (0.10.2)
|
|
116
|
+
rb-inotify (0.9.10)
|
|
117
|
+
ffi (>= 0.5.0, < 2)
|
|
118
|
+
sass (3.4.25)
|
|
119
|
+
servolux (0.13.0)
|
|
120
|
+
temple (0.8.0)
|
|
121
|
+
thor (0.20.0)
|
|
122
|
+
thread_safe (0.3.6)
|
|
123
|
+
tilt (2.0.8)
|
|
124
|
+
tzinfo (1.2.3)
|
|
125
|
+
thread_safe (~> 0.1)
|
|
126
|
+
uglifier (3.2.0)
|
|
127
|
+
execjs (>= 0.3.0, < 3)
|
|
128
|
+
|
|
129
|
+
PLATFORMS
|
|
130
|
+
ruby
|
|
131
|
+
|
|
132
|
+
DEPENDENCIES
|
|
133
|
+
middleman (>= 4.0.0)
|
|
134
|
+
middleman-headless!
|
|
135
|
+
middleman-livereload
|
|
136
|
+
|
|
137
|
+
BUNDLED WITH
|
|
138
|
+
1.13.6
|
data/example/config.rb
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<title>Example</title>
|
|
6
|
+
|
|
7
|
+
<style>
|
|
8
|
+
body {
|
|
9
|
+
font-family: sans-serif;
|
|
10
|
+
font-size: 16px;
|
|
11
|
+
}
|
|
12
|
+
</style>
|
|
13
|
+
</head>
|
|
14
|
+
|
|
15
|
+
<body>
|
|
16
|
+
|
|
17
|
+
<h1><%= headless.space.name %></h1>
|
|
18
|
+
|
|
19
|
+
<% headless.posts.each do |post| %>
|
|
20
|
+
<h2><%= post.title %></h2>
|
|
21
|
+
<p><%= image_tag post.asset(:image).url(width: 400), alt: post.asset(:image).name %></p>
|
|
22
|
+
<p><%= post.body %></p>
|
|
23
|
+
<p>Written by <%= post.reference(:author).name %></p>
|
|
24
|
+
<% end %>
|
|
25
|
+
|
|
26
|
+
</body>
|
|
27
|
+
</html>
|
|
@@ -11,6 +11,10 @@ module MiddlemanHeadless
|
|
|
11
11
|
option :space, nil, 'The space to be used'
|
|
12
12
|
option :preview, false, 'Enable preview mode'
|
|
13
13
|
option :cache, false, 'Enable caching. You need to restart the middleman to get updated content.'
|
|
14
|
+
option :download_assets, false, 'Download assets and replace links during a build.'
|
|
15
|
+
option :assets_dir, 'assets', 'The directory to place downloaded assets in.'
|
|
16
|
+
option :process_exts, %w(.html .json), 'The extension of files to process for downloadable assets.'
|
|
17
|
+
option :assets_hash_length, 8, 'The length of the appended hash key to the asset filenames.'
|
|
14
18
|
|
|
15
19
|
expose_to_config :headless
|
|
16
20
|
expose_to_template :headless
|
|
@@ -25,11 +29,47 @@ module MiddlemanHeadless
|
|
|
25
29
|
end
|
|
26
30
|
|
|
27
31
|
def headless
|
|
32
|
+
if options.app_key.blank? or options.app_secret.blank? or options.address.blank?
|
|
33
|
+
raise 'missing app_key, app_secret or address'
|
|
34
|
+
end
|
|
35
|
+
|
|
28
36
|
@interface ||= Interface.new(options)
|
|
29
37
|
end
|
|
30
38
|
|
|
31
39
|
def clear
|
|
32
40
|
@interface = nil unless options.cache
|
|
33
41
|
end
|
|
42
|
+
|
|
43
|
+
def after_build(builder)
|
|
44
|
+
download_assets(builder) if options[:download_assets] and app.build?
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def download_assets(builder)
|
|
48
|
+
downloads = {}
|
|
49
|
+
builder.thor.say 'Downloading headless assets...'
|
|
50
|
+
|
|
51
|
+
Middleman::Util.all_files_under(app.config[:build_dir]).each do |file|
|
|
52
|
+
next unless options[:process_exts].include?(File.extname(file))
|
|
53
|
+
|
|
54
|
+
content = File.binread(file.expand_path)
|
|
55
|
+
|
|
56
|
+
content.gsub! /hldl:\/\/([A-z0-9=]+)\// do
|
|
57
|
+
data = JSON.parse(Base64.urlsafe_decode64($1))
|
|
58
|
+
hash = Digest::SHA1.hexdigest(data['addr'])[0..options[:assets_hash_length]]
|
|
59
|
+
id = "#{data['name']}-#{hash}.#{data['ext']}"
|
|
60
|
+
downloads[id] = data['addr']
|
|
61
|
+
"/#{options[:assets_dir]}/#{id}"
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
File.open(file.expand_path, 'wb') { |f| f.write(content) }
|
|
65
|
+
builder.thor.say_status :processed, file
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
downloads.each do |id, url|
|
|
69
|
+
dest = Pathname(app.config[:build_dir]).join(options[:assets_dir], id)
|
|
70
|
+
builder.thor.get url, dest, verbose: false
|
|
71
|
+
builder.thor.say_status :downloaded, dest
|
|
72
|
+
end
|
|
73
|
+
end
|
|
34
74
|
end
|
|
35
75
|
end
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
require 'mime/types'
|
|
1
2
|
require 'active_support/core_ext/hash/indifferent_access'
|
|
2
3
|
|
|
3
4
|
module MiddlemanHeadless
|
|
@@ -187,9 +188,24 @@ module MiddlemanHeadless
|
|
|
187
188
|
@data[:name]
|
|
188
189
|
end
|
|
189
190
|
|
|
191
|
+
def content_type
|
|
192
|
+
@data[:content_type]
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
def extension
|
|
196
|
+
MIME::Types[content_type].first.preferred_extension
|
|
197
|
+
end
|
|
198
|
+
|
|
190
199
|
def url(options={})
|
|
191
200
|
opts = options.length > 0 ? "?#{options.to_query}" : ''
|
|
192
|
-
"#{@interface.options.address}/content/file/#{key}#{opts}"
|
|
201
|
+
addr = "#{@interface.options.address}/content/file/#{key}#{opts}"
|
|
202
|
+
|
|
203
|
+
if @interface.options[:download_assets]
|
|
204
|
+
data = { addr: addr, ext: extension, name: name.parameterize }
|
|
205
|
+
"hldl://#{Base64.urlsafe_encode64(JSON.generate(data))}/"
|
|
206
|
+
else
|
|
207
|
+
addr
|
|
208
|
+
end
|
|
193
209
|
end
|
|
194
210
|
end
|
|
195
211
|
|
data/middleman-headless.gemspec
CHANGED
|
@@ -3,7 +3,7 @@ $:.push File.expand_path('../lib', __FILE__)
|
|
|
3
3
|
|
|
4
4
|
Gem::Specification.new do |s|
|
|
5
5
|
s.name = 'middleman-headless'
|
|
6
|
-
s.version = '0.
|
|
6
|
+
s.version = '0.4.0'
|
|
7
7
|
s.licenses = ['MIT']
|
|
8
8
|
s.platform = Gem::Platform::RUBY
|
|
9
9
|
s.authors = ['Joël Gähwiler']
|
|
@@ -17,5 +17,6 @@ Gem::Specification.new do |s|
|
|
|
17
17
|
s.require_paths = ['lib']
|
|
18
18
|
|
|
19
19
|
s.add_runtime_dependency('middleman-core', ['~> 4.1'])
|
|
20
|
-
s.add_runtime_dependency('oauth2')
|
|
20
|
+
s.add_runtime_dependency('oauth2', ['~> 1.4'])
|
|
21
|
+
s.add_runtime_dependency('mime-types', ['~> 3.1'])
|
|
21
22
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: middleman-headless
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Joël Gähwiler
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2017-
|
|
11
|
+
date: 2017-10-23 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: middleman-core
|
|
@@ -28,16 +28,30 @@ dependencies:
|
|
|
28
28
|
name: oauth2
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
30
30
|
requirements:
|
|
31
|
-
- - "
|
|
31
|
+
- - "~>"
|
|
32
32
|
- !ruby/object:Gem::Version
|
|
33
|
-
version: '
|
|
33
|
+
version: '1.4'
|
|
34
34
|
type: :runtime
|
|
35
35
|
prerelease: false
|
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
37
|
requirements:
|
|
38
|
-
- - "
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '1.4'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: mime-types
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '3.1'
|
|
48
|
+
type: :runtime
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
39
53
|
- !ruby/object:Gem::Version
|
|
40
|
-
version: '
|
|
54
|
+
version: '3.1'
|
|
41
55
|
description:
|
|
42
56
|
email:
|
|
43
57
|
- joel@twomanyprojects.com
|
|
@@ -49,6 +63,10 @@ files:
|
|
|
49
63
|
- Gemfile
|
|
50
64
|
- LICENSE.md
|
|
51
65
|
- README.md
|
|
66
|
+
- example/Gemfile
|
|
67
|
+
- example/Gemfile.lock
|
|
68
|
+
- example/config.rb
|
|
69
|
+
- example/source/index.html.erb
|
|
52
70
|
- lib/middleman-headless.rb
|
|
53
71
|
- lib/middleman-headless/extension.rb
|
|
54
72
|
- lib/middleman-headless/interface.rb
|