jekyll-contentblocks 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ddeace684edb5376fdab5c280c88ced16731264b
4
- data.tar.gz: d770dffb2fb6b82e75888a2d502e02177a713864
3
+ metadata.gz: d4fb4909712a67d92748bbfbc282d1b3f89b991c
4
+ data.tar.gz: dfd1945707d8649f2e43f3672f224ae78927b303
5
5
  SHA512:
6
- metadata.gz: 06022becaeac04a221c70de8c345612cabbd96c61832faefb965085514a56265bfe916aa2476c54c7e8613de3a97db53d4032bc71b5a14e8e8441ab64bb07d1b
7
- data.tar.gz: 0e8281ad795ef26b00cd522c73603a7b5adb37a2f6d1a0aaa54b5c4308ecf17975db901f2ed8b8c54e450c702d47016656ed6f78791ee00759314a978cf9e9af
6
+ metadata.gz: 97972d1f3a4f9f3d9f0eaddec302ec71d5f9e5bd2d8b92f4e3f6b84ecc59592001bf86fc4a434fc8558d30fb75ad44bc1bc42a2a6de81d5b9c92125cc5724300
7
+ data.tar.gz: 24c856f8e881109a48024c7eb2818750b9d3956a1a46653d99779b0a7b42336a4136417af0f4737e2fc365e80bf42427c3a6a615f8c392047b39a628f93f7076
data/Gemfile CHANGED
@@ -4,6 +4,7 @@ gem 'jekyll', '> 1.0.0'
4
4
  gem 'appraisal', '1.0.2'
5
5
 
6
6
  gem 'pry'
7
+ gem 'pry-byebug'
7
8
  gem 'rspec', '~> 3.3.0'
8
9
  gem 'nokogiri', '~> 1.6.6.0'
9
10
 
@@ -5,6 +5,7 @@ source "https://rubygems.org"
5
5
  gem "jekyll", "1.0.4"
6
6
  gem "appraisal", "1.0.2"
7
7
  gem "pry"
8
+ gem "pry-byebug"
8
9
  gem "rspec", "~> 3.3.0"
9
10
  gem "nokogiri", "~> 1.6.6.0"
10
11
 
@@ -5,6 +5,7 @@ source "https://rubygems.org"
5
5
  gem "jekyll", "1.1.2"
6
6
  gem "appraisal", "1.0.2"
7
7
  gem "pry"
8
+ gem "pry-byebug"
8
9
  gem "rspec", "~> 3.3.0"
9
10
  gem "nokogiri", "~> 1.6.6.0"
10
11
 
@@ -5,6 +5,7 @@ source "https://rubygems.org"
5
5
  gem "jekyll", "1.2.1"
6
6
  gem "appraisal", "1.0.2"
7
7
  gem "pry"
8
+ gem "pry-byebug"
8
9
  gem "rspec", "~> 3.3.0"
9
10
  gem "nokogiri", "~> 1.6.6.0"
10
11
 
@@ -5,6 +5,7 @@ source "https://rubygems.org"
5
5
  gem "jekyll", "1.3.1"
6
6
  gem "appraisal", "1.0.2"
7
7
  gem "pry"
8
+ gem "pry-byebug"
8
9
  gem "rspec", "~> 3.3.0"
9
10
  gem "nokogiri", "~> 1.6.6.0"
10
11
 
@@ -5,6 +5,7 @@ source "https://rubygems.org"
5
5
  gem "jekyll", "1.4.3"
6
6
  gem "appraisal", "1.0.2"
7
7
  gem "pry"
8
+ gem "pry-byebug"
8
9
  gem "rspec", "~> 3.3.0"
9
10
  gem "nokogiri", "~> 1.6.6.0"
10
11
 
@@ -5,6 +5,7 @@ source "https://rubygems.org"
5
5
  gem "jekyll", "1.5.1"
6
6
  gem "appraisal", "1.0.2"
7
7
  gem "pry"
8
+ gem "pry-byebug"
8
9
  gem "rspec", "~> 3.3.0"
9
10
  gem "nokogiri", "~> 1.6.6.0"
10
11
 
@@ -5,6 +5,7 @@ source "https://rubygems.org"
5
5
  gem "jekyll", "2.0.3"
6
6
  gem "appraisal", "1.0.2"
7
7
  gem "pry"
8
+ gem "pry-byebug"
8
9
  gem "rspec", "~> 3.3.0"
9
10
  gem "nokogiri", "~> 1.6.6.0"
10
11
 
@@ -5,6 +5,7 @@ source "https://rubygems.org"
5
5
  gem "jekyll", "2.1.1"
6
6
  gem "appraisal", "1.0.2"
7
7
  gem "pry"
8
+ gem "pry-byebug"
8
9
  gem "rspec", "~> 3.3.0"
9
10
  gem "nokogiri", "~> 1.6.6.0"
10
11
 
@@ -5,6 +5,7 @@ source "https://rubygems.org"
5
5
  gem "jekyll", "2.2.0"
6
6
  gem "appraisal", "1.0.2"
7
7
  gem "pry"
8
+ gem "pry-byebug"
8
9
  gem "rspec", "~> 3.3.0"
9
10
  gem "nokogiri", "~> 1.6.6.0"
10
11
 
@@ -5,6 +5,7 @@ source "https://rubygems.org"
5
5
  gem "jekyll", "2.3.0"
6
6
  gem "appraisal", "1.0.2"
7
7
  gem "pry"
8
+ gem "pry-byebug"
8
9
  gem "rspec", "~> 3.3.0"
9
10
  gem "nokogiri", "~> 1.6.6.0"
10
11
 
@@ -5,6 +5,7 @@ source "https://rubygems.org"
5
5
  gem "jekyll", "2.4.0"
6
6
  gem "appraisal", "1.0.2"
7
7
  gem "pry"
8
+ gem "pry-byebug"
8
9
  gem "rspec", "~> 3.3.0"
9
10
  gem "nokogiri", "~> 1.6.6.0"
10
11
 
@@ -5,6 +5,7 @@ source "https://rubygems.org"
5
5
  gem "jekyll", "2.5.3"
6
6
  gem "appraisal", "1.0.2"
7
7
  gem "pry"
8
+ gem "pry-byebug"
8
9
  gem "rspec", "~> 3.3.0"
9
10
  gem "nokogiri", "~> 1.6.6.0"
10
11
 
@@ -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/contentblocks/version'
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
@@ -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
@@ -1,6 +1,6 @@
1
1
  module Jekyll
2
2
  module ContentBlocks
3
- VERSION = "1.0.0"
3
+ VERSION = "1.0.1"
4
4
  end
5
5
  end
6
6
 
@@ -1,7 +1,7 @@
1
1
  module Jekyll
2
2
  module Tags
3
3
  class ContentBlock < Liquid::Tag
4
- include ::Jekyll::ContentBlockTag
4
+ include ::Jekyll::ContentBlocks::ContentBlockTag
5
5
 
6
6
  def render(context)
7
7
  block_content = content_for_block(context).join
@@ -1,7 +1,7 @@
1
1
  module Jekyll
2
2
  module Tags
3
3
  class ContentFor < Liquid::Block
4
- include ::Jekyll::ContentBlockTag
4
+ include ::Jekyll::ContentBlocks::ContentBlockTag
5
5
  alias_method :render_block, :render
6
6
 
7
7
  def render(context)
@@ -1,7 +1,7 @@
1
1
  module Jekyll
2
2
  module Tags
3
3
  class IfHasContent < Liquid::Block
4
- include ::Jekyll::ContentBlockTag
4
+ include ::Jekyll::ContentBlocks::ContentBlockTag
5
5
  alias_method :render_block, :render
6
6
 
7
7
  def render(context)
@@ -1,7 +1,7 @@
1
1
  module Jekyll
2
2
  module Tags
3
3
  class IfNotHasContent < Liquid::Block
4
- include ::Jekyll::ContentBlockTag
4
+ include ::Jekyll::ContentBlocks::ContentBlockTag
5
5
  alias_method :render_block, :render
6
6
 
7
7
  def render(context)
@@ -1,9 +1,22 @@
1
1
  require 'jekyll'
2
- require 'jekyll/convertible'
3
- require File.expand_path('../jekyll/convertible', __FILE__)
4
2
 
5
- require 'jekyll/contentblocks/version'
6
- require 'jekyll/content_block_tag'
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
- jekyll_version = `jekyll --version`.strip
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(:page) { load_index_html.html }
13
- let(:sidebar) { page.css('body > div > h2#sidebar').first }
11
+ let(:index) { load_html('index.html') }
14
12
 
15
- it 'renders the sidebar content block' do
16
- expect(sidebar).not_to be_nil
17
- expect(sidebar.text).to eq 'SIDEBAR'
18
- end
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
- it 'renders Liquid within a content block' do
21
- rendered_liquid = sidebar.css('+ p')
22
- expect(rendered_liquid).not_to be_nil
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
- it 'does not render a block without content' do
27
- expect(page.css('head > style')).to be_empty
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(page.css('div#footer')).not_to be_empty
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(page.css('div[class=sidebar-default]')).to be_empty
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 load_index_html
10
- index_html = File.read('test/_site/index.html')
11
- Nokogiri::Slop(index_html)
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
@@ -0,0 +1,5 @@
1
+ collections:
2
+ items:
3
+ output: true
4
+ permalink: /items/:path/
5
+
@@ -0,0 +1,14 @@
1
+ ---
2
+ layout: default
3
+ title: One
4
+ ---
5
+
6
+ ## From a collection.
7
+
8
+ {% contentfor sidebar %}
9
+
10
+ * Some content
11
+ * in a markdown list
12
+ * with some {{ 'liquid' }} tags too!
13
+
14
+ {% endcontentfor %}
@@ -0,0 +1,9 @@
1
+ ---
2
+ layout: default
3
+ title: Two
4
+ ---
5
+
6
+ ## From a collection.
7
+
8
+ I have no custom sidebar.
9
+
@@ -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
@@ -5,7 +5,6 @@ layout: default
5
5
 
6
6
  # CONTENT
7
7
 
8
-
9
8
  {% contentfor sidebar %}
10
9
  ## SIDEBAR
11
10
  {{ 'foo bar baz' | number_of_words }}
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.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-09-12 00:00:00.000000000 Z
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/contentblocks/version.rb
57
- - lib/jekyll/convertible.rb
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