jekyll-contentblocks 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +83 -0
- data/Rakefile +1 -0
- data/jekyll-contentblocks.gemspec +21 -0
- data/lib/jekyll-contentblocks.rb +8 -0
- data/lib/jekyll-contentblocks/common.rb +20 -0
- data/lib/jekyll-contentblocks/content_block.rb +18 -0
- data/lib/jekyll-contentblocks/content_for.rb +20 -0
- data/lib/jekyll-contentblocks/convertible.rb +11 -0
- data/lib/jekyll-contentblocks/version.rb +5 -0
- metadata +73 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Rusty Geldmacher
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
# jekyll-contentblocks
|
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.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
### Bundler (recommended)
|
8
|
+
|
9
|
+
Add this line to your Jekyll project's `Gemfile`:
|
10
|
+
```ruby
|
11
|
+
gem 'jekyll-contentblocks'
|
12
|
+
```
|
13
|
+
|
14
|
+
Then execute:
|
15
|
+
```bash
|
16
|
+
$ bundle install
|
17
|
+
```
|
18
|
+
|
19
|
+
Make sure your have a plugin that initializes Bundler:
|
20
|
+
```ruby
|
21
|
+
# _plugins/bundler.rb
|
22
|
+
require "rubygems"
|
23
|
+
require "bundler/setup"
|
24
|
+
Bundler.require(:default)
|
25
|
+
```
|
26
|
+
|
27
|
+
### Standalone
|
28
|
+
Execute:
|
29
|
+
```bash
|
30
|
+
$ gem install jekyll-contentblocks
|
31
|
+
```
|
32
|
+
|
33
|
+
And initialize it in a plugin:
|
34
|
+
```ruby
|
35
|
+
# _plugins/ext.rb
|
36
|
+
require "rubygems"
|
37
|
+
require "jekyll-contentblocks"
|
38
|
+
```
|
39
|
+
|
40
|
+
## Usage
|
41
|
+
|
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
|
+
```html
|
44
|
+
<html>
|
45
|
+
<head>
|
46
|
+
{% contentblock scripts %}
|
47
|
+
</head>
|
48
|
+
<body>
|
49
|
+
<div class="main">
|
50
|
+
{{ content }}
|
51
|
+
</div>
|
52
|
+
<div class="sidebar">
|
53
|
+
{% contentblock sidebar %}
|
54
|
+
</div>
|
55
|
+
</body>
|
56
|
+
</html>
|
57
|
+
```
|
58
|
+
|
59
|
+
Now to add content to the sidebar from a post, you'd just need to do something like:
|
60
|
+
|
61
|
+
```html
|
62
|
+
---
|
63
|
+
layout: default
|
64
|
+
---
|
65
|
+
|
66
|
+
Here is my post content.
|
67
|
+
|
68
|
+
{% contentfor sidebar %}
|
69
|
+
* Some content
|
70
|
+
* in a markdown list
|
71
|
+
* with some {{ 'liquid' }} tags too!
|
72
|
+
{% endcontentfor %}
|
73
|
+
```
|
74
|
+
|
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.
|
76
|
+
|
77
|
+
## Contributing
|
78
|
+
|
79
|
+
1. Fork it
|
80
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
81
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
82
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
83
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'jekyll-contentblocks/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "jekyll-contentblocks"
|
8
|
+
gem.version = Jekyll::ContentBlocks::VERSION
|
9
|
+
gem.authors = ["Rusty Geldmacher"]
|
10
|
+
gem.email = ["russell.geldmacher@gmail.com"]
|
11
|
+
gem.description = %q{Provides a mechanism for passing content up to the layout}
|
12
|
+
gem.summary = %q{A Jekyll plugin kind of like Rails' content_for}
|
13
|
+
gem.homepage = "https://github.com/rustygeldmacher/jekyll-contentblocks"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_dependency('jekyll')
|
21
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
require "jekyll-contentblocks/version"
|
2
|
+
require "jekyll-contentblocks/convertible"
|
3
|
+
require "jekyll-contentblocks/common"
|
4
|
+
require "jekyll-contentblocks/content_for"
|
5
|
+
require "jekyll-contentblocks/content_block"
|
6
|
+
|
7
|
+
Liquid::Template.register_tag('contentfor', Jekyll::Tags::ContentFor)
|
8
|
+
Liquid::Template.register_tag('contentblock', Jekyll::Tags::ContentBlock)
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Jekyll
|
2
|
+
module ContentBlocks
|
3
|
+
module Common
|
4
|
+
# Extracts and verified the content block's name
|
5
|
+
def get_content_block_name(tag_name, block_name)
|
6
|
+
block_name = (block_name || '').strip
|
7
|
+
if block_name == ''
|
8
|
+
raise SyntaxError.new("No block name given in #{tag_name} tag")
|
9
|
+
end
|
10
|
+
block_name
|
11
|
+
end
|
12
|
+
|
13
|
+
# Gets the storage space for the content block
|
14
|
+
def content_for_block(context)
|
15
|
+
context.environments.first['contentblocks'] ||= {}
|
16
|
+
context.environments.first['contentblocks'][@block_name] ||= []
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Jekyll
|
2
|
+
module Tags
|
3
|
+
class ContentBlock < Liquid::Tag
|
4
|
+
include ::Jekyll::ContentBlocks::Common
|
5
|
+
|
6
|
+
def initialize(tag_name, block_name, tokens)
|
7
|
+
super
|
8
|
+
@block_name = get_content_block_name(tag_name, block_name)
|
9
|
+
end
|
10
|
+
|
11
|
+
def render(context)
|
12
|
+
converter = context.environments.first['converter']
|
13
|
+
content_for_block(context).map { |c| converter.convert(c || '') }.join
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Jekyll
|
2
|
+
module Tags
|
3
|
+
class ContentFor < Liquid::Block
|
4
|
+
include ::Jekyll::ContentBlocks::Common
|
5
|
+
alias_method :render_block, :render
|
6
|
+
|
7
|
+
def initialize(tag_name, block_name, tokens)
|
8
|
+
super
|
9
|
+
@block_name = get_content_block_name(tag_name, block_name)
|
10
|
+
end
|
11
|
+
|
12
|
+
def render(context)
|
13
|
+
content_for_block(context) << render_block(context)
|
14
|
+
# Render nothing right now
|
15
|
+
''
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Jekyll
|
2
|
+
module Convertible
|
3
|
+
alias_method :do_layout_orig, :do_layout
|
4
|
+
|
5
|
+
def do_layout(payload, layouts)
|
6
|
+
# The contentblock tags needs access to the converter to process it while rendering.
|
7
|
+
payload['converter'] = self.converter
|
8
|
+
do_layout_orig(payload, layouts)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll-contentblocks
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Rusty Geldmacher
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-03-05 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: jekyll
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: Provides a mechanism for passing content up to the layout
|
31
|
+
email:
|
32
|
+
- russell.geldmacher@gmail.com
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- Gemfile
|
39
|
+
- LICENSE.txt
|
40
|
+
- README.md
|
41
|
+
- Rakefile
|
42
|
+
- jekyll-contentblocks.gemspec
|
43
|
+
- lib/jekyll-contentblocks.rb
|
44
|
+
- lib/jekyll-contentblocks/common.rb
|
45
|
+
- lib/jekyll-contentblocks/content_block.rb
|
46
|
+
- lib/jekyll-contentblocks/content_for.rb
|
47
|
+
- lib/jekyll-contentblocks/convertible.rb
|
48
|
+
- lib/jekyll-contentblocks/version.rb
|
49
|
+
homepage: https://github.com/rustygeldmacher/jekyll-contentblocks
|
50
|
+
licenses: []
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options: []
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ! '>='
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
requirements: []
|
68
|
+
rubyforge_project:
|
69
|
+
rubygems_version: 1.8.24
|
70
|
+
signing_key:
|
71
|
+
specification_version: 3
|
72
|
+
summary: A Jekyll plugin kind of like Rails' content_for
|
73
|
+
test_files: []
|