octopress-render-tag 1.0.6 → 1.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/octopress-render-tag.rb +69 -29
- data/lib/octopress-render-tag/hooks.rb +0 -22
- data/lib/octopress-render-tag/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c5ef7d0ef6809c3c9599cd1c8b6e1f0585c14951
|
4
|
+
data.tar.gz: acdee57684c595f41d094d9effeba9bfe0d73f81
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1aa31ae5348cccbf9b48605143703628aacc6dc0e482db7313866a70cef8c5c07ca180472d28b8d664edf2da6894c0649265505ae8e99137cfa95f295b9e481a
|
7
|
+
data.tar.gz: 297acda1204b6a681d580f54e681d4e236332da64af38437a46c064cc5a11633bfa77fcc4ea9b9abe9d150cfbf6002619ff5acc618a10e2435cb6e9c8c926e22
|
data/CHANGELOG.md
CHANGED
data/lib/octopress-render-tag.rb
CHANGED
@@ -9,54 +9,93 @@ module Octopress
|
|
9
9
|
class Tag < Liquid::Tag
|
10
10
|
SYNTAX = /(\S+)(.+)?/
|
11
11
|
|
12
|
+
attr_reader :tag_markup
|
13
|
+
attr_reader :tag_name
|
14
|
+
attr_reader :raw
|
15
|
+
attr_accessor :filters
|
16
|
+
|
12
17
|
def initialize(tag_name, markup, tokens)
|
13
18
|
super
|
14
|
-
|
15
|
-
|
16
|
-
|
19
|
+
|
20
|
+
@tag_markup = markup
|
21
|
+
@tag_name = tag_name
|
22
|
+
|
23
|
+
if matched = markup.strip.match(/^(\s*raw\s)?(.+?)(\sraw\s*)?$/)
|
24
|
+
@tag_markup = $2
|
17
25
|
@raw = true unless $1.nil? and $3.nil?
|
18
26
|
end
|
19
27
|
end
|
20
28
|
|
21
29
|
def render(context)
|
22
|
-
return unless markup =
|
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)
|
30
|
+
return unless @markup = parse_markup(context)
|
29
31
|
|
30
|
-
content = read(markup, context)
|
32
|
+
content = read(@markup, context)
|
31
33
|
|
32
|
-
if
|
33
|
-
local_vars = SafeYAML.load(
|
34
|
-
content =
|
34
|
+
if matched = content.match(/\A-{3}(?<vars>.+[^\A])-{3}\n(?<content>.+)/m)
|
35
|
+
local_vars = SafeYAML.load(matched['vars'].strip)
|
36
|
+
content = matched['content'].strip
|
35
37
|
end
|
36
38
|
|
37
|
-
|
39
|
+
if raw
|
40
|
+
content
|
41
|
+
else
|
42
|
+
|
43
|
+
content = strip_raw(content)
|
38
44
|
|
39
|
-
|
40
|
-
|
45
|
+
partial = Liquid::Template.parse(content)
|
46
|
+
content = context.stack {
|
47
|
+
context['include'] = parse_params(context)
|
48
|
+
if local_vars
|
49
|
+
context['page'] = Jekyll::Utils.deep_merge_hashes(context['page'], local_vars)
|
50
|
+
end
|
51
|
+
partial.render!(context)
|
52
|
+
}.strip
|
41
53
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
54
|
+
content = replace_raw(content)
|
55
|
+
content = parse_convertible(content, context).strip
|
56
|
+
|
57
|
+
unless content.nil? || filters.nil?
|
58
|
+
content = TagHelpers::Var.render_filters(content, filters, context)
|
47
59
|
end
|
48
|
-
partial.render!(context)
|
49
|
-
}.strip
|
50
60
|
|
51
|
-
|
61
|
+
content
|
62
|
+
end
|
63
|
+
end
|
52
64
|
|
53
|
-
|
65
|
+
def parse_params(context)
|
66
|
+
if Jekyll::Tags::IncludeTag.respond_to?(:parse)
|
67
|
+
include_tag = Jekyll::Tags::IncludeTag.parse('include', @markup, [], {})
|
68
|
+
else
|
69
|
+
include_tag = Jekyll::Tags::IncludeTag.new('include', @markup, [])
|
70
|
+
end
|
71
|
+
include_tag.parse_params(context)
|
72
|
+
end
|
54
73
|
|
55
|
-
|
56
|
-
|
74
|
+
# Parses special markup, handling vars, conditions, and filters
|
75
|
+
# Returns:
|
76
|
+
# - render tag path or nil if markup conditionals evaluate false
|
77
|
+
#
|
78
|
+
def parse_markup(context)
|
79
|
+
# If conditional statements are present, only continue if they are true
|
80
|
+
#
|
81
|
+
return unless markup = TagHelpers::Conditional.parse(tag_markup, context)
|
82
|
+
|
83
|
+
# If there are filters, store them for use later and strip them out of markup
|
84
|
+
#
|
85
|
+
if matched = markup.match(TagHelpers::Var::HAS_FILTERS)
|
86
|
+
markup = matched['markup']
|
87
|
+
@filters = matched['filters']
|
57
88
|
end
|
58
89
|
|
59
|
-
|
90
|
+
# If there is a ternary expression, replace it with the true result
|
91
|
+
#
|
92
|
+
markup = TagHelpers::Var.evaluate_ternary(markup, context)
|
93
|
+
|
94
|
+
# Paths may be variables, check context to retrieve proper path
|
95
|
+
#
|
96
|
+
markup = TagHelpers::Path.parse(markup, context)
|
97
|
+
|
98
|
+
markup
|
60
99
|
end
|
61
100
|
|
62
101
|
def strip_raw(content)
|
@@ -101,6 +140,7 @@ Liquid::Template.register_tag('render_partial', Octopress::Tags::Render::Tag)
|
|
101
140
|
if defined? Octopress::Docs
|
102
141
|
Octopress::Docs.add({
|
103
142
|
name: "Octopress Render Tag",
|
143
|
+
gem_name: "octopress-render-tag",
|
104
144
|
description: "Embed files directly from the file system. This tag also supports conditional rendering, in-line filters.",
|
105
145
|
path: File.expand_path(File.join(File.dirname(__FILE__), "../")),
|
106
146
|
type: "tag",
|
@@ -19,29 +19,7 @@ module Octopress
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def render(payload)
|
22
|
-
pre_render
|
23
22
|
do_layout(payload, { no_layout: nil })
|
24
|
-
post_render
|
25
|
-
end
|
26
|
-
|
27
|
-
def hooks
|
28
|
-
if self.site.respond_to? :page_hooks
|
29
|
-
self.site.page_hooks
|
30
|
-
else
|
31
|
-
[]
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def pre_render
|
36
|
-
self.hooks.each do |hook|
|
37
|
-
hook.pre_render(self)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def post_render
|
42
|
-
self.hooks.each do |hook|
|
43
|
-
hook.post_render(self)
|
44
|
-
end
|
45
23
|
end
|
46
24
|
end
|
47
25
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: octopress-render-tag
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandon Mathis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-05-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: octopress-tag-helpers
|
@@ -28,14 +28,14 @@ dependencies:
|
|
28
28
|
name: jekyll
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '2.0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '2.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
@@ -94,7 +94,7 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
-
description:
|
97
|
+
description:
|
98
98
|
email:
|
99
99
|
- brandon@imathis.com
|
100
100
|
executables: []
|
@@ -127,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
127
127
|
version: '0'
|
128
128
|
requirements: []
|
129
129
|
rubyforge_project:
|
130
|
-
rubygems_version: 2.
|
130
|
+
rubygems_version: 2.4.6
|
131
131
|
signing_key:
|
132
132
|
specification_version: 4
|
133
133
|
summary: Render files inline on any Jekyll page or post
|