jekyll-contentblocks 1.0.1 → 1.1.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/README.md +24 -5
- data/lib/jekyll/content_blocks/content_block_tag.rb +15 -10
- data/lib/jekyll/content_blocks/version.rb +1 -1
- data/lib/jekyll/tags/content_block.rb +14 -1
- data/spec/jekyll_content_blocks_spec.rb +2 -1
- data/spec/spec_helper.rb +1 -0
- data/test/_layouts/default.html +1 -1
- data/test/page.md +2 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c5fa5ab18f418d6455911cf33dbb9ad6d8e08c52
|
4
|
+
data.tar.gz: 8da924d203b87c0afb2767872386287b7ad9e4a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7247b7a4107c6d88be63576b06ea8dcd320c19e5b8a54509ebd3b2b1aef62bc3e5e756d1eb5269554e1e0c65d71d02bd4ff2238ad74b21a28256883808592112
|
7
|
+
data.tar.gz: 977e960485aabbc1f811a34561e805ea8fb4cabccab90d70258967b3d73d17e66268a595846c9f1012e1bd8b40ec5418da7bc639365b96fff43d3fb8c8e4374a
|
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# jekyll-contentblocks
|
2
2
|
|
3
|
-
Gives you a mechanism in Jekyll to pass content up from pages into their parent
|
3
|
+
Gives you a mechanism in Jekyll to pass content up from pages into their parent
|
4
|
+
layouts. It's kind of like having Rails' content_for available for Jekyll.
|
4
5
|
|
5
6
|
## Installation
|
6
7
|
|
@@ -39,7 +40,9 @@ require "jekyll-contentblocks"
|
|
39
40
|
|
40
41
|
## Usage
|
41
42
|
|
42
|
-
In your layout files, define `contentblock` blocks that say where content will
|
43
|
+
In your layout files, define `contentblock` blocks that say where content will
|
44
|
+
end up. For example, say the file `_layouts/default.html` looks like this:
|
45
|
+
|
43
46
|
```html
|
44
47
|
<html>
|
45
48
|
<head>
|
@@ -72,12 +75,28 @@ Here is my post content.
|
|
72
75
|
{% endcontentfor %}
|
73
76
|
```
|
74
77
|
|
75
|
-
Note that we didn't add anything to the `scripts` block in the post. That's OK,
|
78
|
+
Note that we didn't add anything to the `scripts` block in the post. That's OK,
|
79
|
+
content blocks without any content will be ignored.
|
80
|
+
|
81
|
+
### Skipping content conversion in a block
|
82
|
+
|
83
|
+
By default, a content block will be run through the converter for the current
|
84
|
+
file (Markdown, for instance). Sometimes this is not desirable, such as for
|
85
|
+
blocks containing code that shouldn't be modified. In the example above, content
|
86
|
+
in the `scripts` block will be converted by default. To prevent this, add the
|
87
|
+
`no-convert` option to the block, like this:
|
88
|
+
|
89
|
+
```
|
90
|
+
{% contentblock scripts no-convert %}
|
91
|
+
```
|
92
|
+
|
93
|
+
Now any content added to `scripts` will be placed in the block without any
|
94
|
+
formatting applied.
|
76
95
|
|
77
96
|
### Checking if a block has content
|
78
97
|
|
79
|
-
We might want to check if the particular contentblock has content before using
|
80
|
-
To do this, use the `ifhascontent` tag:
|
98
|
+
We might want to check if the particular contentblock has content before using
|
99
|
+
it in our template. To do this, use the `ifhascontent` tag:
|
81
100
|
|
82
101
|
```liquid
|
83
102
|
{% ifhascontent javascripts %}
|
@@ -1,19 +1,23 @@
|
|
1
1
|
module Jekyll
|
2
2
|
module ContentBlocks
|
3
3
|
module ContentBlockTag
|
4
|
-
|
4
|
+
attr_accessor :content_block_name
|
5
|
+
attr_accessor :content_block_options
|
6
|
+
|
7
|
+
def initialize(tag_name, markup, tokens)
|
5
8
|
super
|
6
|
-
|
9
|
+
parse_options(markup)
|
10
|
+
if content_block_name == ''
|
11
|
+
raise SyntaxError.new("No block name given in #{tag_name} tag")
|
12
|
+
end
|
7
13
|
end
|
8
14
|
|
9
15
|
private
|
10
16
|
|
11
|
-
def
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
end
|
16
|
-
block_name
|
17
|
+
def parse_options(markup)
|
18
|
+
options = (markup || '').split(' ').map(&:strip)
|
19
|
+
self.content_block_name = options.shift
|
20
|
+
self.content_block_options = options
|
17
21
|
end
|
18
22
|
|
19
23
|
def block_has_content?(context)
|
@@ -22,8 +26,9 @@ module Jekyll
|
|
22
26
|
end
|
23
27
|
|
24
28
|
def content_for_block(context)
|
25
|
-
context.environments.first
|
26
|
-
|
29
|
+
environment = context.environments.first
|
30
|
+
environment['contentblocks'] ||= {}
|
31
|
+
environment['contentblocks'][content_block_name] ||= []
|
27
32
|
end
|
28
33
|
end
|
29
34
|
end
|
@@ -5,6 +5,20 @@ module Jekyll
|
|
5
5
|
|
6
6
|
def render(context)
|
7
7
|
block_content = content_for_block(context).join
|
8
|
+
if convert_content?
|
9
|
+
converted_content(block_content, context)
|
10
|
+
else
|
11
|
+
block_content
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def convert_content?
|
18
|
+
!content_block_options.include?('no-convert')
|
19
|
+
end
|
20
|
+
|
21
|
+
def converted_content(block_content, context)
|
8
22
|
converters = context.environments.first['converters']
|
9
23
|
Array(converters).reduce(block_content) do |content, converter|
|
10
24
|
converter.convert(content)
|
@@ -13,4 +27,3 @@ module Jekyll
|
|
13
27
|
end
|
14
28
|
end
|
15
29
|
end
|
16
|
-
|
@@ -47,7 +47,8 @@ describe Jekyll::ContentBlocks do
|
|
47
47
|
end
|
48
48
|
|
49
49
|
it 'does not process Markdown in the CSS block' do
|
50
|
-
|
50
|
+
styles = page.css('style').text.gsub(/\s/, '')
|
51
|
+
expect(styles).to eq 'div{font-weight:bold;}'
|
51
52
|
end
|
52
53
|
|
53
54
|
it 'renders the custom footer' do
|
data/spec/spec_helper.rb
CHANGED
data/test/_layouts/default.html
CHANGED
data/test/page.md
CHANGED
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.1.0
|
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-10-
|
11
|
+
date: 2015-10-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|