jekyll-contentblocks 1.0.1 → 1.1.0

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: d4fb4909712a67d92748bbfbc282d1b3f89b991c
4
- data.tar.gz: dfd1945707d8649f2e43f3672f224ae78927b303
3
+ metadata.gz: c5fa5ab18f418d6455911cf33dbb9ad6d8e08c52
4
+ data.tar.gz: 8da924d203b87c0afb2767872386287b7ad9e4a8
5
5
  SHA512:
6
- metadata.gz: 97972d1f3a4f9f3d9f0eaddec302ec71d5f9e5bd2d8b92f4e3f6b84ecc59592001bf86fc4a434fc8558d30fb75ad44bc1bc42a2a6de81d5b9c92125cc5724300
7
- data.tar.gz: 24c856f8e881109a48024c7eb2818750b9d3956a1a46653d99779b0a7b42336a4136417af0f4737e2fc365e80bf42427c3a6a615f8c392047b39a628f93f7076
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 layouts. It's kind of like having Rails' content_for available for Jekyll.
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 end up. For example, say the file `_layouts/default.html` looks like this:
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, content blocks without any content will be ignored.
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 it in our template.
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
- def initialize(tag_name, block_name, tokens)
4
+ attr_accessor :content_block_name
5
+ attr_accessor :content_block_options
6
+
7
+ def initialize(tag_name, markup, tokens)
5
8
  super
6
- @block_name = get_content_block_name(tag_name, block_name)
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 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
+ 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['contentblocks'] ||= {}
26
- context.environments.first['contentblocks'][@block_name] ||= []
29
+ environment = context.environments.first
30
+ environment['contentblocks'] ||= {}
31
+ environment['contentblocks'][content_block_name] ||= []
27
32
  end
28
33
  end
29
34
  end
@@ -1,6 +1,6 @@
1
1
  module Jekyll
2
2
  module ContentBlocks
3
- VERSION = "1.0.1"
3
+ VERSION = "1.1.0"
4
4
  end
5
5
  end
6
6
 
@@ -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
- expect(page.css('style p')).to be_empty
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
@@ -1,5 +1,6 @@
1
1
  require 'nokogiri'
2
2
  require 'jekyll-contentblocks'
3
+ require 'pry-byebug'
3
4
 
4
5
  module SpecHelpers
5
6
  def jekyll_version
@@ -3,7 +3,7 @@
3
3
  <head>
4
4
  {% ifhascontent css %}
5
5
  <style type="text/css">
6
- {% contentblock css %}
6
+ {% contentblock css no-convert %}
7
7
  </style>
8
8
  {% endifhascontent %}
9
9
  </head>
data/test/page.md CHANGED
@@ -4,9 +4,11 @@ layout: default
4
4
  ---
5
5
 
6
6
  {% contentfor css %}
7
+
7
8
  div {
8
9
  font-weight: bold;
9
10
  }
11
+
10
12
  {% endcontentfor %}
11
13
 
12
14
  This page is here to test the opposite of index.md
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.1
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 00:00:00.000000000 Z
11
+ date: 2015-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll