jekyll-fridge 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +22 -0
- data/README.md +94 -0
- data/Rakefile +2 -0
- data/jekyll-fridge.gemspec +22 -0
- data/lib/jekyll-fridge.rb +183 -0
- data/lib/jekyll-fridge/version.rb +5 -0
- metadata +92 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 939432cda4f1442fdbfd37072c04c7bbba0b1a25
|
4
|
+
data.tar.gz: 39ad6c1cd25514568c639b94ab878aff51e8ec43
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d92843a7b035d6a9fdc06c1fe1f50b41b41251c1aae6f66fee96c4984e720aa90b60aa62ac11d9b96dbee4e383d605e509e38f1baab7c221fbc663cbaebcb0ed
|
7
|
+
data.tar.gz: 7474db8469eb952ef6ba91adb97fc79506c6a2fd06ae9d26be5fc8466fe52aae6e3321a1a67a82425cb73e7e300aa8487b5f47661c5b63aa97e7c61c69b0407b
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Ripeworks
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
jekyll-fridge
|
2
|
+
=============
|
3
|
+
|
4
|
+
Jekyll helper for adding Fridge content to your Jekyll site.
|
5
|
+
|
6
|
+
Installation
|
7
|
+
----
|
8
|
+
|
9
|
+
* Add `jekyll-fridge` to your `Gemfile`:
|
10
|
+
|
11
|
+
```Gemfile
|
12
|
+
group :jekyll_plugins do
|
13
|
+
gem "jekyll-fridge"
|
14
|
+
end
|
15
|
+
```
|
16
|
+
|
17
|
+
* Read on to configure the plugin.
|
18
|
+
|
19
|
+
_[Not using Bundler? There are other ways..](http://jekyllrb.com/docs/plugins/)_
|
20
|
+
|
21
|
+
Usage
|
22
|
+
----
|
23
|
+
|
24
|
+
In `_config.yml`
|
25
|
+
|
26
|
+
```yaml
|
27
|
+
fridge:
|
28
|
+
client_id: sk_xxxxxxxxxx
|
29
|
+
client_secret: xxxxxxxxxxxx
|
30
|
+
```
|
31
|
+
|
32
|
+
In your templates
|
33
|
+
|
34
|
+
```liquid
|
35
|
+
<h1>{{site.fridge.settings.home.title}}</h1>
|
36
|
+
|
37
|
+
<nav>
|
38
|
+
{% for item in site.fridge.navigation.content %}
|
39
|
+
<li>{{item.title}}</li>
|
40
|
+
{% endfor %}
|
41
|
+
</nav>
|
42
|
+
|
43
|
+
{{site.fridge.content.15.body | markdownify }}
|
44
|
+
|
45
|
+
{% for posts in site.fridge.content.blog_post %}
|
46
|
+
<li>Post: {{post.title}}</li>
|
47
|
+
{% endfor %}
|
48
|
+
```
|
49
|
+
|
50
|
+
Using Jekyll filters
|
51
|
+
|
52
|
+
```liquid
|
53
|
+
{% assign firefoxes = site.fridge.browser.content | where:"title", "Firefox" %}
|
54
|
+
{% for browser in firefoxes %}
|
55
|
+
<li>{{browser.title}}</li>
|
56
|
+
{% endfor %}
|
57
|
+
|
58
|
+
{% assign pages = site.fridge.content.page | sort:"title" %}
|
59
|
+
{% for page in pages %}
|
60
|
+
<li>{{page.title}}</li>
|
61
|
+
{% endfor %}
|
62
|
+
```
|
63
|
+
|
64
|
+
~~`where` filter currently depends on https://github.com/jekyll/jekyll/pull/2986~~
|
65
|
+
|
66
|
+
Filters
|
67
|
+
------
|
68
|
+
|
69
|
+
`fridge_asset`
|
70
|
+
|
71
|
+
Finds Fridge asset based on file name. Downloads asset to `asset_dir` _(configurable. defaults to `assets`)_ and
|
72
|
+
returns a url for the file.
|
73
|
+
|
74
|
+
```liquid
|
75
|
+
{% for image in site.fridge.content.photo %}
|
76
|
+
<img src="{{ image.name | fridge_asset }}" />
|
77
|
+
{% endfor %}
|
78
|
+
```
|
79
|
+
|
80
|
+
`fridge_choices`
|
81
|
+
|
82
|
+
Parses choices from a select/radio/checkbox content type.
|
83
|
+
|
84
|
+
```liquid
|
85
|
+
{% assign choices = site.fridge.types.blog.categories.choices %}
|
86
|
+
{% for category in choices %}
|
87
|
+
{{category}}
|
88
|
+
{% endfor %}
|
89
|
+
```
|
90
|
+
|
91
|
+
Reference
|
92
|
+
----
|
93
|
+
|
94
|
+
* [Liquid](https://github.com/Shopify/liquid/wiki/Liquid-for-Designers)
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'jekyll-fridge/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.add_development_dependency 'bundler', '~> 1.0'
|
7
|
+
spec.add_dependency 'jekyll', '~> 2.0'
|
8
|
+
spec.add_dependency 'fridge_api', '~> 0.1.3'
|
9
|
+
spec.authors = ["Mike Kruk"]
|
10
|
+
spec.email = ['mike@ripeworks.com']
|
11
|
+
spec.summary = %q{Jekyll plugin for building sites using Fridge content}
|
12
|
+
spec.description = %q{Jekyll plugin for building sites using Fridge content}
|
13
|
+
spec.files = %w(Rakefile LICENSE README.md jekyll-fridge.gemspec)
|
14
|
+
spec.files += Dir.glob("lib/**/*.rb")
|
15
|
+
spec.homepage = 'https://github.com/fridge-cms/jekyll-fridge'
|
16
|
+
spec.licenses = ['MIT']
|
17
|
+
spec.name = 'jekyll-fridge'
|
18
|
+
spec.require_paths = ['lib']
|
19
|
+
spec.required_ruby_version = '>= 1.9.2'
|
20
|
+
spec.required_rubygems_version = '>= 1.3.5'
|
21
|
+
spec.version = Jekyll::Fridge::VERSION.dup
|
22
|
+
end
|
@@ -0,0 +1,183 @@
|
|
1
|
+
require 'fridge_api'
|
2
|
+
require 'ostruct'
|
3
|
+
|
4
|
+
module Jekyll
|
5
|
+
|
6
|
+
# Recursively convert hash keys to strings
|
7
|
+
def self.stringify_keys_deep(h)
|
8
|
+
case h
|
9
|
+
when Hash
|
10
|
+
Hash[
|
11
|
+
h.map do |k, v|
|
12
|
+
[ k.respond_to?(:to_s) ? k.to_s : k, self.stringify_keys_deep(v) ]
|
13
|
+
end
|
14
|
+
]
|
15
|
+
when Sawyer::Resource
|
16
|
+
self.stringify_keys_deep(h.to_h)
|
17
|
+
when Enumerable
|
18
|
+
h.map { |v| self.stringify_keys_deep(v) }
|
19
|
+
else
|
20
|
+
h
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class Fridge < Generator
|
25
|
+
safe true
|
26
|
+
priority :low
|
27
|
+
|
28
|
+
def generate(site)
|
29
|
+
# get api configuration from _config.yml
|
30
|
+
#
|
31
|
+
# fridge:
|
32
|
+
# client_id: sk_xxxx
|
33
|
+
# client_secret: xxxx
|
34
|
+
api_config = site.config['fridge']
|
35
|
+
api_config['asset_dir'] ||= 'assets'
|
36
|
+
|
37
|
+
# set site.fridge as plugin entry
|
38
|
+
site.config['fridge'] = Client.new api_config
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class Client < Liquid::Drop
|
43
|
+
|
44
|
+
attr_reader :client, :config
|
45
|
+
|
46
|
+
def initialize(config)
|
47
|
+
@client = FridgeApi.client({
|
48
|
+
:client_id => config['client_id'],
|
49
|
+
:client_secret => config['client_secret']
|
50
|
+
})
|
51
|
+
@config = config.delete_if { |k, v| k.to_s.match(/client/) }
|
52
|
+
end
|
53
|
+
|
54
|
+
def before_method(method)
|
55
|
+
# try content type
|
56
|
+
type = @client.get("types/#{method}")
|
57
|
+
if type && type.kind_of?(FridgeApi::Model)
|
58
|
+
return Jekyll.stringify_keys_deep(type.attrs.merge({
|
59
|
+
'content' => ContentDrop.new(@client, "content", "type=#{type.slug}")
|
60
|
+
}))
|
61
|
+
end
|
62
|
+
|
63
|
+
# try user role
|
64
|
+
role = @client.get("roles/#{method}")
|
65
|
+
if role && role.kind_of?(FridgeApi::Model)
|
66
|
+
return Jekyll.stringify_keys_deep(role.attrs.merge({
|
67
|
+
'users' => ContentDrop.new(@client, "users", "role=#{role.slug}")
|
68
|
+
}))
|
69
|
+
end
|
70
|
+
|
71
|
+
nil
|
72
|
+
end
|
73
|
+
|
74
|
+
def content
|
75
|
+
ContentDrop.new(@client, "content")
|
76
|
+
end
|
77
|
+
|
78
|
+
def collections
|
79
|
+
ContentDrop.new(@client, "collections")
|
80
|
+
end
|
81
|
+
|
82
|
+
def settings
|
83
|
+
ContentDrop.new(@client, "settings")
|
84
|
+
end
|
85
|
+
|
86
|
+
def types
|
87
|
+
ContentDrop.new(@client, "types")
|
88
|
+
end
|
89
|
+
|
90
|
+
def users
|
91
|
+
ContentDrop.new(@client, "users")
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
class ContentDrop < Liquid::Drop
|
97
|
+
include Enumerable
|
98
|
+
|
99
|
+
def initialize(client, base, query = "", data = nil)
|
100
|
+
@client = client
|
101
|
+
@base = base
|
102
|
+
@query = query
|
103
|
+
@data = data
|
104
|
+
end
|
105
|
+
|
106
|
+
def before_method(method)
|
107
|
+
# check for single content item
|
108
|
+
item = @client.get("#{@base}/#{method}?#{@query}")
|
109
|
+
return Model.new(item) if item && item.kind_of?(FridgeApi::Model)
|
110
|
+
|
111
|
+
# filter by content type
|
112
|
+
if @base == "content" && @query.empty?
|
113
|
+
types = @client.get("#{@base}?type=#{method}")
|
114
|
+
return ContentDrop.new(@client, @base, "type=#{method}", types) if types
|
115
|
+
end
|
116
|
+
|
117
|
+
# filter by user role
|
118
|
+
if @base == "users" && @query.empty?
|
119
|
+
roles = @client.get("#{@base}?role=#{method}")
|
120
|
+
return ContentDrop.new(@client, @base, "role=#{method}", roles) if roles
|
121
|
+
end
|
122
|
+
|
123
|
+
nil
|
124
|
+
end
|
125
|
+
|
126
|
+
def each &block
|
127
|
+
@data ||= @client.get(@base)
|
128
|
+
@data.each do |v|
|
129
|
+
m = Model.new v
|
130
|
+
if block_given?
|
131
|
+
block.call m
|
132
|
+
else
|
133
|
+
yield m
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
end
|
139
|
+
|
140
|
+
class Model
|
141
|
+
def initialize(model)
|
142
|
+
@model = model
|
143
|
+
end
|
144
|
+
|
145
|
+
def inspect
|
146
|
+
@data
|
147
|
+
end
|
148
|
+
|
149
|
+
def to_liquid
|
150
|
+
@data ||= Jekyll.stringify_keys_deep(@model.attrs)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
module FridgeFilters
|
155
|
+
# Filter for fetching assets
|
156
|
+
# Writes static file to asset_dir and returns absolute file path
|
157
|
+
def fridge_asset(input)
|
158
|
+
site = @context.registers[:site]
|
159
|
+
asset_dir = site.config['fridge'].config['asset_dir']
|
160
|
+
dest_path = File.join(site.dest, asset_dir, input)
|
161
|
+
|
162
|
+
asset = site.config['fridge'].client.get("content/upload/#{input}")
|
163
|
+
return input unless asset
|
164
|
+
|
165
|
+
path = File.join(asset_dir, input)
|
166
|
+
# play for keeps
|
167
|
+
# this is so jekyll won't clean up the file
|
168
|
+
site.keep_files << path
|
169
|
+
|
170
|
+
# write file to destination
|
171
|
+
FileUtils.mkdir_p(File.dirname(dest_path))
|
172
|
+
File.write(dest_path, asset)
|
173
|
+
"/#{path}"
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
def fridge_choices(input)
|
178
|
+
input.lines
|
179
|
+
end
|
180
|
+
|
181
|
+
end
|
182
|
+
|
183
|
+
Liquid::Template.register_filter(Jekyll::FridgeFilters)
|
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll-fridge
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mike Kruk
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-02-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: jekyll
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: fridge_api
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.1.3
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.1.3
|
55
|
+
description: Jekyll plugin for building sites using Fridge content
|
56
|
+
email:
|
57
|
+
- mike@ripeworks.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- LICENSE
|
63
|
+
- README.md
|
64
|
+
- Rakefile
|
65
|
+
- jekyll-fridge.gemspec
|
66
|
+
- lib/jekyll-fridge.rb
|
67
|
+
- lib/jekyll-fridge/version.rb
|
68
|
+
homepage: https://github.com/fridge-cms/jekyll-fridge
|
69
|
+
licenses:
|
70
|
+
- MIT
|
71
|
+
metadata: {}
|
72
|
+
post_install_message:
|
73
|
+
rdoc_options: []
|
74
|
+
require_paths:
|
75
|
+
- lib
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: 1.9.2
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 1.3.5
|
86
|
+
requirements: []
|
87
|
+
rubyforge_project:
|
88
|
+
rubygems_version: 2.4.5
|
89
|
+
signing_key:
|
90
|
+
specification_version: 4
|
91
|
+
summary: Jekyll plugin for building sites using Fridge content
|
92
|
+
test_files: []
|