jekyll-default-layout 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/lib/jekyll-default-layout.rb +5 -0
- data/lib/jekyll-default-layout/generator.rb +66 -0
- data/lib/jekyll-default-layout/version.rb +3 -0
- metadata +89 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c3e0dc75157991dbdbb935c51815ebf3f94037f4
|
4
|
+
data.tar.gz: 71ca7a1e4aedae982caff20fecc2a52a5f98f6c9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8e68889b6595acd4986fcfbca2ee5f1395f9a2211c1831b5073799b7dbfca6b75dac9dcd0e510f6fd57233de9bbcd874bc8120b66f4429d825d69516acfdb8e6
|
7
|
+
data.tar.gz: a93cea1445dd937c707c6138188cd73eb3178b095383c443ee925e15f498d5cac9aa915a5c173df237ccf0dd3a0d97d10b96dcbaa1a92e4aee2e883d58c4eacb
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module JekyllDefaultLayout
|
2
|
+
# Injects front matter defaults to set default layouts, if they exist
|
3
|
+
class Generator < Jekyll::Generator
|
4
|
+
attr_accessor :site
|
5
|
+
|
6
|
+
safe true
|
7
|
+
priority :low
|
8
|
+
|
9
|
+
def initialize(site)
|
10
|
+
@site = site
|
11
|
+
end
|
12
|
+
|
13
|
+
def generate(site)
|
14
|
+
@site = site
|
15
|
+
documents.each do |document|
|
16
|
+
next unless should_set_layout?(document)
|
17
|
+
document.data["layout"] = layout_for(document)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def should_set_layout?(document)
|
22
|
+
markdown?(document) && !layout_specified?(document)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Does the given layout exist for the site?
|
26
|
+
def layout_exists?(layout)
|
27
|
+
!site.layouts[layout].nil?
|
28
|
+
end
|
29
|
+
|
30
|
+
# Has the user already specified a default for this layout?
|
31
|
+
def layout_specified?(document)
|
32
|
+
document.data.key? "layout"
|
33
|
+
end
|
34
|
+
|
35
|
+
def markdown?(document)
|
36
|
+
markdown_converter.matches(document.extname)
|
37
|
+
end
|
38
|
+
|
39
|
+
# What layout is appropriate for this document, if any
|
40
|
+
def layout_for(document)
|
41
|
+
if page?(document) && layout_exists?("page")
|
42
|
+
"page"
|
43
|
+
elsif post?(document) && layout_exists?("post")
|
44
|
+
"post"
|
45
|
+
elsif layout_exists?("default")
|
46
|
+
"default"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def documents
|
51
|
+
[site.pages, site.posts.docs].flatten
|
52
|
+
end
|
53
|
+
|
54
|
+
def markdown_converter
|
55
|
+
@markdown_converter ||= site.find_converter_instance(Jekyll::Converters::Markdown)
|
56
|
+
end
|
57
|
+
|
58
|
+
def post?(document)
|
59
|
+
document.is_a?(Jekyll::Document) && document.collection.label == "posts"
|
60
|
+
end
|
61
|
+
|
62
|
+
def page?(document)
|
63
|
+
document.is_a?(Jekyll::Page)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll-default-layout
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ben Balter
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-10-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: jekyll
|
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: rubocop
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.43'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.43'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.5'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.5'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- ben.balter@github.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- lib/jekyll-default-layout.rb
|
63
|
+
- lib/jekyll-default-layout/generator.rb
|
64
|
+
- lib/jekyll-default-layout/version.rb
|
65
|
+
homepage: https://github.com/benbalter/jekyll-default-layout
|
66
|
+
licenses:
|
67
|
+
- MIT
|
68
|
+
metadata: {}
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options: []
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
requirements: []
|
84
|
+
rubyforge_project:
|
85
|
+
rubygems_version: 2.6.7
|
86
|
+
signing_key:
|
87
|
+
specification_version: 4
|
88
|
+
summary: Silently sets default layouts for Jekyll pages and posts
|
89
|
+
test_files: []
|