jekyll-contentblocks 1.0.0 → 1.0.1
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/Gemfile +1 -0
- data/gemfiles/jekyll_1.0.4.gemfile +1 -0
- data/gemfiles/jekyll_1.1.2.gemfile +1 -0
- data/gemfiles/jekyll_1.2.1.gemfile +1 -0
- data/gemfiles/jekyll_1.3.1.gemfile +1 -0
- data/gemfiles/jekyll_1.4.3.gemfile +1 -0
- data/gemfiles/jekyll_1.5.1.gemfile +1 -0
- data/gemfiles/jekyll_2.0.3.gemfile +1 -0
- data/gemfiles/jekyll_2.1.1.gemfile +1 -0
- data/gemfiles/jekyll_2.2.0.gemfile +1 -0
- data/gemfiles/jekyll_2.3.0.gemfile +1 -0
- data/gemfiles/jekyll_2.4.0.gemfile +1 -0
- data/gemfiles/jekyll_2.5.3.gemfile +1 -0
- data/jekyll-contentblocks.gemspec +1 -1
- data/lib/jekyll/content_blocks/content_block_tag.rb +30 -0
- data/lib/jekyll/{convertible.rb → content_blocks/convertible.rb} +0 -0
- data/lib/jekyll/content_blocks/renderer.rb +11 -0
- data/lib/jekyll/{contentblocks → content_blocks}/version.rb +1 -1
- data/lib/jekyll/tags/content_block.rb +1 -1
- data/lib/jekyll/tags/content_for.rb +1 -1
- data/lib/jekyll/tags/if_has_content.rb +1 -1
- data/lib/jekyll/tags/if_not_has_content.rb +1 -1
- data/lib/jekyll-contentblocks.rb +17 -4
- data/spec/jekyll_content_blocks_spec.rb +72 -17
- data/spec/spec_helper.rb +20 -3
- data/test/_config.yml +5 -0
- data/test/_items/one.md +14 -0
- data/test/_items/two.md +9 -0
- data/test/_layouts/default.html +7 -1
- data/test/index.md +0 -1
- data/test/page.md +18 -0
- metadata +14 -5
- data/lib/jekyll/content_block_tag.rb +0 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d4fb4909712a67d92748bbfbc282d1b3f89b991c
|
4
|
+
data.tar.gz: dfd1945707d8649f2e43f3672f224ae78927b303
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97972d1f3a4f9f3d9f0eaddec302ec71d5f9e5bd2d8b92f4e3f6b84ecc59592001bf86fc4a434fc8558d30fb75ad44bc1bc42a2a6de81d5b9c92125cc5724300
|
7
|
+
data.tar.gz: 24c856f8e881109a48024c7eb2818750b9d3956a1a46653d99779b0a7b42336a4136417af0f4737e2fc365e80bf42427c3a6a615f8c392047b39a628f93f7076
|
data/Gemfile
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'jekyll/
|
4
|
+
require 'jekyll/content_blocks/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |gem|
|
7
7
|
gem.name = "jekyll-contentblocks"
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Jekyll
|
2
|
+
module ContentBlocks
|
3
|
+
module ContentBlockTag
|
4
|
+
def initialize(tag_name, block_name, tokens)
|
5
|
+
super
|
6
|
+
@block_name = get_content_block_name(tag_name, block_name)
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def get_content_block_name(tag_name, block_name)
|
12
|
+
block_name = (block_name || '').strip
|
13
|
+
if block_name == ''
|
14
|
+
raise SyntaxError.new("No block name given in #{tag_name} tag")
|
15
|
+
end
|
16
|
+
block_name
|
17
|
+
end
|
18
|
+
|
19
|
+
def block_has_content?(context)
|
20
|
+
block_content = content_for_block(context).join
|
21
|
+
!(block_content.nil? || block_content.empty?)
|
22
|
+
end
|
23
|
+
|
24
|
+
def content_for_block(context)
|
25
|
+
context.environments.first['contentblocks'] ||= {}
|
26
|
+
context.environments.first['contentblocks'][@block_name] ||= []
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
File without changes
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Jekyll
|
2
|
+
class Renderer
|
3
|
+
alias_method :render_liquid_orig, :render_liquid
|
4
|
+
|
5
|
+
def render_liquid(content, payload, info, path = nil)
|
6
|
+
payload['converters'] ||= converters
|
7
|
+
payload['contentblocks'] ||= {}
|
8
|
+
render_liquid_orig(content, payload, info, path)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
data/lib/jekyll-contentblocks.rb
CHANGED
@@ -1,9 +1,22 @@
|
|
1
1
|
require 'jekyll'
|
2
|
-
require 'jekyll/convertible'
|
3
|
-
require File.expand_path('../jekyll/convertible', __FILE__)
|
4
2
|
|
5
|
-
|
6
|
-
|
3
|
+
module Jekyll
|
4
|
+
def self.version_less_than?(version)
|
5
|
+
Gem::Version.new(VERSION) < Gem::Version.new(version)
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.supports_collections?
|
9
|
+
!version_less_than?('2.0.0')
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
require 'jekyll/content_blocks/convertible'
|
14
|
+
unless Jekyll.version_less_than?('2.0.0')
|
15
|
+
require 'jekyll/content_blocks/renderer'
|
16
|
+
end
|
17
|
+
|
18
|
+
require 'jekyll/content_blocks/version'
|
19
|
+
require 'jekyll/content_blocks/content_block_tag'
|
7
20
|
require 'jekyll/tags/content_for'
|
8
21
|
require 'jekyll/tags/if_has_content'
|
9
22
|
require 'jekyll/tags/if_not_has_content'
|
@@ -1,39 +1,94 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Jekyll::ContentBlocks do
|
4
|
-
|
5
|
-
puts jekyll_version
|
4
|
+
puts "jekyll #{jekyll_version}"
|
6
5
|
|
7
|
-
context "against #{jekyll_version}" do
|
6
|
+
context "against jekyll #{jekyll_version}" do
|
8
7
|
before(:all) do
|
9
8
|
expect(generate_test_site).to be true
|
10
9
|
end
|
11
10
|
|
12
|
-
let(:
|
13
|
-
let(:sidebar) { page.css('body > div > h2#sidebar').first }
|
11
|
+
let(:index) { load_html('index.html') }
|
14
12
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
13
|
+
describe 'index.html' do
|
14
|
+
let(:sidebar) { index.css('body > div > h2#sidebar').first }
|
15
|
+
|
16
|
+
it 'does not render the css block' do
|
17
|
+
expect(index.css('style')).to be_empty
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'renders the custom sidebar' do
|
21
|
+
expect(index.css('div.custom-sidebar')).not_to be_empty
|
22
|
+
expect(index.css('div.sidebar-default')).to be_empty
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'renders the sidebar content block' do
|
26
|
+
expect(sidebar).not_to be_nil
|
27
|
+
expect(sidebar.text).to eq 'SIDEBAR'
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'renders Liquid within a content block' do
|
31
|
+
rendered_liquid = sidebar.css('+ p')
|
32
|
+
expect(rendered_liquid).not_to be_nil
|
33
|
+
expect(rendered_liquid.text).to eq '3'
|
34
|
+
end
|
19
35
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
expect(rendered_liquid.text).to eq '3'
|
36
|
+
it 'does not render a block without content' do
|
37
|
+
expect(index.css('head > style')).to be_empty
|
38
|
+
end
|
24
39
|
end
|
25
40
|
|
26
|
-
|
27
|
-
|
41
|
+
describe 'page.html' do
|
42
|
+
let(:page) { load_html('page.html') }
|
43
|
+
let(:sidebar) { index.css('body > div > h2#sidebar').first }
|
44
|
+
|
45
|
+
it 'renders the css block' do
|
46
|
+
expect(page.css('style')).not_to be_empty
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'does not process Markdown in the CSS block' do
|
50
|
+
expect(page.css('style p')).to be_empty
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'renders the custom footer' do
|
54
|
+
expect(page.css('div#footer')).to be_empty
|
55
|
+
expect(page.css('div#custom-footer')).not_to be_empty
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'renders the default sidebar' do
|
59
|
+
expect(page.css('div.sidebar-default')).not_to be_empty
|
60
|
+
expect(page.css('div.custom-sidebar')).to be_empty
|
61
|
+
end
|
28
62
|
end
|
29
63
|
|
30
64
|
describe 'ifnothascontent' do
|
31
65
|
it 'renders defaults when content is not supplied' do
|
32
|
-
expect(
|
66
|
+
expect(index.css('div#footer')).not_to be_empty
|
33
67
|
end
|
34
68
|
|
35
69
|
it 'does not render when there is content' do
|
36
|
-
expect(
|
70
|
+
expect(index.css('div[class=sidebar-default]')).to be_empty
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
if Jekyll.supports_collections?
|
75
|
+
describe 'content blocks in a collection' do
|
76
|
+
let(:item_one) { load_item_html('one') }
|
77
|
+
let(:item_two) { load_item_html('two') }
|
78
|
+
|
79
|
+
it 'should render the content block' do
|
80
|
+
expect(item_one.css('div[class=sidebar-default]')).to be_empty
|
81
|
+
expect(item_one.css('div[class=custom-sidebar]')).not_to be_empty
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'should skip a content block that was not defined' do
|
85
|
+
expect(item_two.css('div[class=sidebar-default]')).not_to be_empty
|
86
|
+
expect(item_two.css('div[class=custom-sidebar]')).to be_empty
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'should process Markdown inside the content block' do
|
90
|
+
expect(item_one.css('div[class=custom-sidebar] ul li')).not_to be_empty
|
91
|
+
end
|
37
92
|
end
|
38
93
|
end
|
39
94
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,17 +1,34 @@
|
|
1
1
|
require 'nokogiri'
|
2
|
+
require 'jekyll-contentblocks'
|
2
3
|
|
3
4
|
module SpecHelpers
|
5
|
+
def jekyll_version
|
6
|
+
@jekyll_version ||= `jekyll --version`.strip.gsub('jekyll ', '')
|
7
|
+
end
|
8
|
+
|
4
9
|
def generate_test_site
|
5
10
|
system 'rm -rf test/_site'
|
6
11
|
system 'jekyll build -s test/ -d test/_site &> /dev/null'
|
7
12
|
end
|
8
13
|
|
9
|
-
def
|
10
|
-
|
11
|
-
|
14
|
+
def load_html(file)
|
15
|
+
path = "test/_site/#{file}"
|
16
|
+
if File.exists?(path)
|
17
|
+
index_html = File.read(path)
|
18
|
+
Nokogiri::Slop(index_html).html
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def load_item_html(item)
|
23
|
+
if Jekyll.version_less_than?('2.1.0')
|
24
|
+
load_html("items/#{item}.html")
|
25
|
+
else
|
26
|
+
load_html("items/#{item}/index.html")
|
27
|
+
end
|
12
28
|
end
|
13
29
|
end
|
14
30
|
|
15
31
|
RSpec.configure do |config|
|
32
|
+
config.extend(SpecHelpers)
|
16
33
|
config.include(SpecHelpers)
|
17
34
|
end
|
data/test/_config.yml
ADDED
data/test/_items/one.md
ADDED
data/test/_items/two.md
ADDED
data/test/_layouts/default.html
CHANGED
@@ -9,10 +9,12 @@
|
|
9
9
|
</head>
|
10
10
|
|
11
11
|
<body>
|
12
|
+
<h1>{{ page.title }}</h1>
|
13
|
+
|
12
14
|
{{ content }}
|
13
15
|
|
14
16
|
{% ifhascontent sidebar %}
|
15
|
-
<div>
|
17
|
+
<div class="custom-sidebar">
|
16
18
|
{% contentblock sidebar %}
|
17
19
|
</div>
|
18
20
|
{% endifhascontent %}
|
@@ -23,6 +25,10 @@
|
|
23
25
|
</div>
|
24
26
|
{% endifnothascontent %}
|
25
27
|
|
28
|
+
{% ifhascontent footer %}
|
29
|
+
{% contentblock footer %}
|
30
|
+
{% endifhascontent %}
|
31
|
+
|
26
32
|
{% ifnothascontent footer %}
|
27
33
|
<div id="footer">
|
28
34
|
This is the default footer.
|
data/test/index.md
CHANGED
data/test/page.md
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
---
|
2
|
+
title: A test page
|
3
|
+
layout: default
|
4
|
+
---
|
5
|
+
|
6
|
+
{% contentfor css %}
|
7
|
+
div {
|
8
|
+
font-weight: bold;
|
9
|
+
}
|
10
|
+
{% endcontentfor %}
|
11
|
+
|
12
|
+
This page is here to test the opposite of index.md
|
13
|
+
|
14
|
+
{% contentfor footer %}
|
15
|
+
<div id="custom-footer">
|
16
|
+
This is the custom footer for hte page.
|
17
|
+
</div>
|
18
|
+
{% endcontentfor %}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-contentblocks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rusty Geldmacher
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -52,18 +52,23 @@ files:
|
|
52
52
|
- gemfiles/jekyll_2.5.3.gemfile
|
53
53
|
- jekyll-contentblocks.gemspec
|
54
54
|
- lib/jekyll-contentblocks.rb
|
55
|
-
- lib/jekyll/content_block_tag.rb
|
56
|
-
- lib/jekyll/
|
57
|
-
- lib/jekyll/
|
55
|
+
- lib/jekyll/content_blocks/content_block_tag.rb
|
56
|
+
- lib/jekyll/content_blocks/convertible.rb
|
57
|
+
- lib/jekyll/content_blocks/renderer.rb
|
58
|
+
- lib/jekyll/content_blocks/version.rb
|
58
59
|
- lib/jekyll/tags/content_block.rb
|
59
60
|
- lib/jekyll/tags/content_for.rb
|
60
61
|
- lib/jekyll/tags/if_has_content.rb
|
61
62
|
- lib/jekyll/tags/if_not_has_content.rb
|
62
63
|
- spec/jekyll_content_blocks_spec.rb
|
63
64
|
- spec/spec_helper.rb
|
65
|
+
- test/_config.yml
|
66
|
+
- test/_items/one.md
|
67
|
+
- test/_items/two.md
|
64
68
|
- test/_layouts/default.html
|
65
69
|
- test/_plugins/bundler.rb
|
66
70
|
- test/index.md
|
71
|
+
- test/page.md
|
67
72
|
homepage: https://github.com/rustygeldmacher/jekyll-contentblocks
|
68
73
|
licenses: []
|
69
74
|
metadata: {}
|
@@ -90,6 +95,10 @@ summary: A Jekyll plugin kind of like Rails' content_for
|
|
90
95
|
test_files:
|
91
96
|
- spec/jekyll_content_blocks_spec.rb
|
92
97
|
- spec/spec_helper.rb
|
98
|
+
- test/_config.yml
|
99
|
+
- test/_items/one.md
|
100
|
+
- test/_items/two.md
|
93
101
|
- test/_layouts/default.html
|
94
102
|
- test/_plugins/bundler.rb
|
95
103
|
- test/index.md
|
104
|
+
- test/page.md
|
@@ -1,28 +0,0 @@
|
|
1
|
-
module Jekyll
|
2
|
-
module ContentBlockTag
|
3
|
-
def initialize(tag_name, block_name, tokens)
|
4
|
-
super
|
5
|
-
@block_name = get_content_block_name(tag_name, block_name)
|
6
|
-
end
|
7
|
-
|
8
|
-
private
|
9
|
-
|
10
|
-
def get_content_block_name(tag_name, block_name)
|
11
|
-
block_name = (block_name || '').strip
|
12
|
-
if block_name == ''
|
13
|
-
raise SyntaxError.new("No block name given in #{tag_name} tag")
|
14
|
-
end
|
15
|
-
block_name
|
16
|
-
end
|
17
|
-
|
18
|
-
def block_has_content?(context)
|
19
|
-
block_content = content_for_block(context).join
|
20
|
-
!(block_content.nil? || block_content.empty?)
|
21
|
-
end
|
22
|
-
|
23
|
-
def content_for_block(context)
|
24
|
-
context.environments.first['contentblocks'] ||= {}
|
25
|
-
context.environments.first['contentblocks'][@block_name] ||= []
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|