octopress-render-tag 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/lib/octopress-render-tag.rb +101 -0
- data/lib/octopress-render-tag/version.rb +7 -0
- data/octopress-render-tag.gemspec +27 -0
- data/test/.gitignore +1 -0
- data/test/Gemfile +3 -0
- data/test/_config.yml +20 -0
- data/test/_test_render.md +4 -0
- data/test/expected.html +34 -0
- data/test/index.html +35 -0
- data/test/test.rb +11 -0
- data/test/test_render/_f.html +1 -0
- data/test/test_render/_var.html +1 -0
- metadata +141 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7521e258881ed59759ca566d6312602228b9c452
|
4
|
+
data.tar.gz: 06101030a8b925ce0ecd587ccea896b0799d36fb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 61ab181f1c0b9d656cc1bd9eebf1f33f2d0cd6940a2c78a940cd291bd798a378e32b60f19423b45fd820d6f104287fc6edc587de45f83c460f5c85c92cbd4b4d
|
7
|
+
data.tar.gz: 5f2a6f6ea3e6368e8f7b4e2074f77cc304b84ca834ff67f572ff4223b41ca1e2e121199c6ba88d6172be8ab00771e31586f25efe6110148bb7e80dcb533e882d
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Brandon Mathis
|
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,29 @@
|
|
1
|
+
# OctopressRenderTag
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'octopress_render_tag'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install octopress_render_tag
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( https://github.com/[my-github-username]/octopress_render_tag/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
require "octopress-render-tag/version"
|
2
|
+
require "octopress-tag-helpers"
|
3
|
+
require "jekyll-page-hooks"
|
4
|
+
require "jekyll"
|
5
|
+
|
6
|
+
module Octopress
|
7
|
+
module Tags
|
8
|
+
module RenderTag
|
9
|
+
class Tag < Liquid::Tag
|
10
|
+
SYNTAX = /(\S+)(.+)?/
|
11
|
+
|
12
|
+
def initialize(tag_name, markup, tokens)
|
13
|
+
super
|
14
|
+
@og_markup = @markup = markup
|
15
|
+
if markup =~ /^(\s*raw\s)?(.+?)(\sraw\s*)?$/
|
16
|
+
@markup = $2
|
17
|
+
@raw = true unless $1.nil? and $3.nil?
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def render(context)
|
22
|
+
return unless markup = TagHelpers::Conditional.parse(@markup, context)
|
23
|
+
if markup =~ TagHelpers::Var::HAS_FILTERS
|
24
|
+
markup = $1
|
25
|
+
filters = $2
|
26
|
+
end
|
27
|
+
markup = TagHelpers::Var.evaluate_ternary(markup, context)
|
28
|
+
markup = TagHelpers::Path.parse(markup, context)
|
29
|
+
|
30
|
+
content = read(markup, context)
|
31
|
+
|
32
|
+
if content =~ /\A-{3}(.+[^\A])-{3}\n(.+)/m
|
33
|
+
local_vars = SafeYAML.load($1.strip)
|
34
|
+
content = $2.strip
|
35
|
+
end
|
36
|
+
|
37
|
+
return content if @raw
|
38
|
+
|
39
|
+
content = strip_raw(content)
|
40
|
+
include_tag = Jekyll::Tags::IncludeTag.new('include', markup, [])
|
41
|
+
|
42
|
+
partial = Liquid::Template.parse(content)
|
43
|
+
content = context.stack {
|
44
|
+
context['include'] = include_tag.parse_params(context)
|
45
|
+
if local_vars
|
46
|
+
context['page'] = Jekyll::Utils.deep_merge_hashes(context['page'], local_vars)
|
47
|
+
end
|
48
|
+
partial.render!(context)
|
49
|
+
}.strip
|
50
|
+
|
51
|
+
content = replace_raw(content)
|
52
|
+
|
53
|
+
if defined?(Jekyll::ConvertiblePartial)
|
54
|
+
content = parse_convertible(content, context).strip
|
55
|
+
end
|
56
|
+
|
57
|
+
unless content.nil? || filters.nil?
|
58
|
+
content = TagHelpers::Var.render_filters(content, filters, context)
|
59
|
+
end
|
60
|
+
|
61
|
+
content
|
62
|
+
end
|
63
|
+
|
64
|
+
def strip_raw(content)
|
65
|
+
@raw_content = {}
|
66
|
+
content.gsub /{%\s*raw\s*%}(.+?){% endraw %}/m do
|
67
|
+
data = $1
|
68
|
+
key = Digest::MD5.hexdigest(data)
|
69
|
+
@raw_content[key] = "{% raw %}#{data}{% endraw %}"
|
70
|
+
key
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def replace_raw(content)
|
75
|
+
@raw_content.each { |k, v| content.sub!(k, v) }
|
76
|
+
content
|
77
|
+
end
|
78
|
+
|
79
|
+
def read(markup, context)
|
80
|
+
path = markup.match(SYNTAX)[1]
|
81
|
+
@path = TagHelpers::Path.expand(path, context)
|
82
|
+
begin
|
83
|
+
File.open(@path).read
|
84
|
+
rescue
|
85
|
+
raise IOError.new "Render failed: {% #{@tag_name} #{@og_markup}%}. The file '#{path}' could not be found at #{@path}."
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def parse_convertible(content, context)
|
90
|
+
page = Jekyll::ConvertiblePartial.new(context.registers[:site], @path, content)
|
91
|
+
page.render({})
|
92
|
+
page.output.strip
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
Liquid::Template.register_tag('render', Octopress::Tags::RenderTag::Tag)
|
101
|
+
Liquid::Template.register_tag('render_partial', Octopress::Tags::RenderTag::Tag)
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'octopress-render-tag/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "octopress-render-tag"
|
8
|
+
spec.version = Octopress::Tags::RenderTag::VERSION
|
9
|
+
spec.authors = ["Brandon Mathis"]
|
10
|
+
spec.email = ["brandon@imathis.com"]
|
11
|
+
spec.summary = %q{Render files inline on any Jekyll page or post}
|
12
|
+
spec.description = %q{Render files inline on any Jekyll page or post}
|
13
|
+
spec.homepage = "https://github.com/octopress/render-tag"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency "octopress-tag-helpers", "~> 1.0"
|
22
|
+
spec.add_runtime_dependency "jekyll-page-hooks", "~> 1.0"
|
23
|
+
spec.add_runtime_dependency "jekyll", "~> 2.0"
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
26
|
+
spec.add_development_dependency "rake"
|
27
|
+
end
|
data/test/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
_site
|
data/test/Gemfile
ADDED
data/test/_config.yml
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# Site settings
|
2
|
+
title: Your awesome title
|
3
|
+
email: your-email@domain.com
|
4
|
+
description: "Write an awesome description for your new site here. You can edit this line in _config.yml. It will appear in your document head meta (for Google search results) and in your feed.xml site description."
|
5
|
+
baseurl: ""
|
6
|
+
url: "http://yourdomain.com"
|
7
|
+
twitter_username: jekyllrb
|
8
|
+
github_username: jekyll
|
9
|
+
|
10
|
+
exclude:
|
11
|
+
- Gemfile*
|
12
|
+
- expected.html
|
13
|
+
- test.rb
|
14
|
+
|
15
|
+
render_test: kittens
|
16
|
+
# Build settings
|
17
|
+
markdown: kramdown
|
18
|
+
permalink: pretty
|
19
|
+
gems:
|
20
|
+
- octopress-render-tag
|
data/test/expected.html
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
## Simple render
|
8
|
+
Testing Render → Testing Render
|
9
|
+
Testing Render whatever → Testing Render whatever
|
10
|
+
|
11
|
+
## File name stored in variable
|
12
|
+
Testing Render → Testing Render
|
13
|
+
|
14
|
+
## Post conditional render
|
15
|
+
'' → ''
|
16
|
+
Testing Render → Testing Render
|
17
|
+
|
18
|
+
## Test Variables
|
19
|
+
kittens → kittens
|
20
|
+
|
21
|
+
## Test Filters
|
22
|
+
KITTENS → KITTENS
|
23
|
+
MITTENS → MITTENS
|
24
|
+
|
25
|
+
## Ternary include
|
26
|
+
kittens → kittens
|
27
|
+
Testing Render → Testing Render
|
28
|
+
|
29
|
+
## Render markdown with local vars
|
30
|
+
<p><strong>page vars</strong></p> → <p><strong>page vars</strong></p>
|
31
|
+
|
32
|
+
## Render raw
|
33
|
+
Testing Render {{ include.var }} → Testing Render {{ include.var }}
|
34
|
+
|
data/test/index.html
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
---
|
2
|
+
---
|
3
|
+
{% assign file = 'test_render/_f.html' %}
|
4
|
+
{% assign file2 = 'test_render/_var.html' %}
|
5
|
+
{% assign relative = './_test_render.md' %}
|
6
|
+
{% assign some_bool = true %}
|
7
|
+
{% assign test_var = 'variable' %}
|
8
|
+
|
9
|
+
## Simple render
|
10
|
+
Testing Render → {% render test_render/_f.html %}
|
11
|
+
Testing Render whatever → {% render test_render/_f.html var="whatever" %}
|
12
|
+
|
13
|
+
## File name stored in variable
|
14
|
+
Testing Render → {% render file %}
|
15
|
+
|
16
|
+
## Post conditional render
|
17
|
+
'' → '{% render file unless true %}'
|
18
|
+
Testing Render → {% render file if some_bool %}
|
19
|
+
|
20
|
+
## Test Variables
|
21
|
+
kittens → {% render test_render/_var.html %}
|
22
|
+
|
23
|
+
## Test Filters
|
24
|
+
KITTENS → {% render test_render/_var.html | upcase %}
|
25
|
+
MITTENS → {% render test_render/_var.html | replace:"k","m" | upcase %}
|
26
|
+
|
27
|
+
## Ternary include
|
28
|
+
kittens → {% render (false ? file : file2) %}
|
29
|
+
Testing Render → {% render (some_bool ? file : file2) %}
|
30
|
+
|
31
|
+
## Render markdown with local vars
|
32
|
+
<p><strong>page vars</strong></p> → {% render relative %}
|
33
|
+
|
34
|
+
## Render raw
|
35
|
+
{% raw %}Testing Render {{ include.var }}{% endraw %} → {% render raw file %}
|
data/test/test.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Testing Render {{ include.var }}
|
@@ -0,0 +1 @@
|
|
1
|
+
{% assign bar = site.render_test %}{{ bar }}
|
metadata
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: octopress-render-tag
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brandon Mathis
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: octopress-tag-helpers
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: jekyll-page-hooks
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: jekyll
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.6'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.6'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Render files inline on any Jekyll page or post
|
84
|
+
email:
|
85
|
+
- brandon@imathis.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".travis.yml"
|
92
|
+
- Gemfile
|
93
|
+
- LICENSE.txt
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- lib/octopress-render-tag.rb
|
97
|
+
- lib/octopress-render-tag/version.rb
|
98
|
+
- octopress-render-tag.gemspec
|
99
|
+
- test/.gitignore
|
100
|
+
- test/Gemfile
|
101
|
+
- test/_config.yml
|
102
|
+
- test/_test_render.md
|
103
|
+
- test/expected.html
|
104
|
+
- test/index.html
|
105
|
+
- test/test.rb
|
106
|
+
- test/test_render/_f.html
|
107
|
+
- test/test_render/_var.html
|
108
|
+
homepage: https://github.com/octopress/render-tag
|
109
|
+
licenses:
|
110
|
+
- MIT
|
111
|
+
metadata: {}
|
112
|
+
post_install_message:
|
113
|
+
rdoc_options: []
|
114
|
+
require_paths:
|
115
|
+
- lib
|
116
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
requirements: []
|
127
|
+
rubyforge_project:
|
128
|
+
rubygems_version: 2.2.2
|
129
|
+
signing_key:
|
130
|
+
specification_version: 4
|
131
|
+
summary: Render files inline on any Jekyll page or post
|
132
|
+
test_files:
|
133
|
+
- test/.gitignore
|
134
|
+
- test/Gemfile
|
135
|
+
- test/_config.yml
|
136
|
+
- test/_test_render.md
|
137
|
+
- test/expected.html
|
138
|
+
- test/index.html
|
139
|
+
- test/test.rb
|
140
|
+
- test/test_render/_f.html
|
141
|
+
- test/test_render/_var.html
|