octopress-include-tag 1.1.1 → 1.1.2
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/.gitignore +1 -0
- data/CHANGELOG.md +4 -0
- data/lib/octopress-include-tag.rb +102 -34
- data/lib/octopress-include-tag/version.rb +1 -1
- data/octopress-include-tag.gemspec +4 -0
- data/test/_expected/includes.html +1 -0
- data/test/_ink_plugins/test-plugin/test.rb +1 -0
- data/test/includes.html +2 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03549c58c4562c87f8cd15ac4e77470ddf764295
|
4
|
+
data.tar.gz: d790afdfb814d2e87174eb5891c22f5964c88d70
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1a1056e268c4df190f8db75dd6e3cf115da9816539b94730d962c87e8f445230d3b49f187d6c37f65e496a3f2c5672fae7e145382644b359ae5f5d91b202b27
|
7
|
+
data.tar.gz: 52eddae1fe00e1492cbeb09f4261eef7b7a5503eb6c22e92808395f398be3307e0b5812742f0e6e6839f63f06340687d12daefb5d45f20bd64d2d306d029b731
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -5,50 +5,67 @@ require "jekyll"
|
|
5
5
|
module Octopress
|
6
6
|
module Tags
|
7
7
|
module Include
|
8
|
-
class Tag <
|
9
|
-
PLUGIN_SYNTAX = /(
|
8
|
+
class Tag < Jekyll::Tags::IncludeTag
|
9
|
+
PLUGIN_SYNTAX = /(?<plugin>.+?):(?<path>\S+)\s?(?<other>.*)/
|
10
|
+
attr_accessor :path
|
11
|
+
attr_reader :tag_markup
|
12
|
+
attr_reader :tag_name
|
13
|
+
attr_accessor :filters
|
10
14
|
|
11
15
|
def initialize(tag_name, markup, tokens)
|
12
|
-
|
13
|
-
@
|
16
|
+
@tag_markup = markup
|
17
|
+
@tag_name = tag_name
|
18
|
+
|
19
|
+
if matched = markup.strip.match(PLUGIN_SYNTAX)
|
20
|
+
@plugin = matched['plugin'].strip
|
21
|
+
@path = matched['path'].strip
|
22
|
+
end
|
23
|
+
|
24
|
+
# Trigger Jekyll's Include tag with compatible markup
|
25
|
+
#
|
26
|
+
super(tag_name, safe_markup(markup).join(' '), tokens)
|
14
27
|
end
|
15
28
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
29
|
+
# Strip specials out of markup so that it is suitable for Jekyll include tag
|
30
|
+
#
|
31
|
+
def safe_markup(markup)
|
32
|
+
file = markup.strip.match(/\S+/)[0]
|
33
|
+
params = ''
|
34
|
+
|
35
|
+
if matched = markup.match(VALID_SYNTAX)
|
36
|
+
params = matched[0]
|
21
37
|
end
|
22
|
-
markup = TagHelpers::Var.evaluate_ternary(markup, context)
|
23
|
-
markup = TagHelpers::Path.parse(markup, context)
|
24
38
|
|
25
|
-
|
39
|
+
if matched = tag_markup.match(VARIABLE_SYNTAX)
|
40
|
+
file = matched['variable']
|
41
|
+
end
|
42
|
+
|
43
|
+
[file, params]
|
44
|
+
end
|
45
|
+
|
46
|
+
def render(context)
|
47
|
+
|
48
|
+
# Parse special markup until markup is simplified
|
49
|
+
return unless markup = parse_markup(context)
|
26
50
|
|
27
51
|
# If markup references a plugin e.g. plugin-name:include-file.html
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
msg = "Include failed: {% #{@tag_name} #{@og_markup}%}.\n"
|
35
|
-
if !defined?(Octopress::Ink)
|
36
|
-
msg += "To include plugin partials, first install Octopress Ink."
|
37
|
-
else
|
38
|
-
msg += "The plugin '#{plugin}' does not have an include named '#{path}'."
|
39
|
-
end
|
40
|
-
raise IOError.new(msg)
|
41
|
-
end
|
42
|
-
partial = Liquid::Template.parse(content)
|
43
|
-
content = context.stack {
|
44
|
-
context['include'] = include_tag.parse_params(context)
|
45
|
-
context['plugin'] = Octopress::Ink::Plugins.plugin(plugin).config(context['lang'])
|
46
|
-
partial.render!(context)
|
47
|
-
}.strip
|
52
|
+
#
|
53
|
+
if matched = markup.strip.match(PLUGIN_SYNTAX)
|
54
|
+
|
55
|
+
# Call Octopress Ink to render the plugin's include file
|
56
|
+
#
|
57
|
+
content = render_ink_include(matched['plugin'], matched['path'], context)
|
48
58
|
|
49
|
-
# Otherwise, use Jekyll's default include tag
|
50
59
|
else
|
51
|
-
|
60
|
+
|
61
|
+
# use Jekyll's default include tag
|
62
|
+
#
|
63
|
+
# Why safe_markup again? In initialize we didn't know what the path would be becuase
|
64
|
+
# we needed the context to parse vars and conditions. Now that we know them, we'll
|
65
|
+
# reset @file and @params as intended in order to render with Jekyll's include tag.
|
66
|
+
#
|
67
|
+
@file, @params = safe_markup(markup)
|
68
|
+
content = super(context).strip
|
52
69
|
end
|
53
70
|
|
54
71
|
unless content.nil? || filters.nil?
|
@@ -57,6 +74,57 @@ module Octopress
|
|
57
74
|
|
58
75
|
content
|
59
76
|
end
|
77
|
+
|
78
|
+
# Parses special markup, handling vars, conditions, and filters
|
79
|
+
# Returns:
|
80
|
+
# - include path or nil if markup conditionals evaluate false
|
81
|
+
#
|
82
|
+
def parse_markup(context)
|
83
|
+
# If conditional statements are present, only continue if they are true
|
84
|
+
#
|
85
|
+
return unless markup = TagHelpers::Conditional.parse(tag_markup, context)
|
86
|
+
|
87
|
+
# If there are filters, store them for use later and strip them out of markup
|
88
|
+
#
|
89
|
+
if matched = markup.match(TagHelpers::Var::HAS_FILTERS)
|
90
|
+
markup = matched['markup']
|
91
|
+
@filters = matched['filters']
|
92
|
+
end
|
93
|
+
|
94
|
+
# If there is a ternary expression, replace it with the true result
|
95
|
+
#
|
96
|
+
markup = TagHelpers::Var.evaluate_ternary(markup, context)
|
97
|
+
|
98
|
+
# Paths may be variables, check context to retrieve proper path
|
99
|
+
#
|
100
|
+
markup = TagHelpers::Path.parse(markup, context)
|
101
|
+
|
102
|
+
markup
|
103
|
+
end
|
104
|
+
|
105
|
+
# Call Octopress Ink to render the plugin's include file
|
106
|
+
#
|
107
|
+
def render_ink_include(plugin, file, context)
|
108
|
+
begin
|
109
|
+
content = Octopress::Ink::Plugins.include(plugin, path).read
|
110
|
+
rescue => error
|
111
|
+
msg = "Include failed: {% #{tag_name} #{tag_markup}%}.\n"
|
112
|
+
if !defined?(Octopress::Ink)
|
113
|
+
msg += "To include plugin partials, first install Octopress Ink."
|
114
|
+
else
|
115
|
+
msg += "The plugin '#{plugin}' does not have an include named '#{path}'."
|
116
|
+
end
|
117
|
+
raise IOError.new(msg)
|
118
|
+
end
|
119
|
+
|
120
|
+
partial = Liquid::Template.parse(content)
|
121
|
+
|
122
|
+
context.stack {
|
123
|
+
context['include'] = parse_params(context)
|
124
|
+
context['plugin'] = Octopress::Ink::Plugins.plugin(plugin).config(context['lang'])
|
125
|
+
partial.render!(context)
|
126
|
+
}.strip
|
127
|
+
end
|
60
128
|
end
|
61
129
|
end
|
62
130
|
end
|
@@ -25,4 +25,8 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.add_development_dependency "clash"
|
26
26
|
spec.add_development_dependency "octopress-ink"
|
27
27
|
spec.add_development_dependency "octopress"
|
28
|
+
|
29
|
+
if RUBY_VERSION >= "2"
|
30
|
+
spec.add_development_dependency "pry-byebug"
|
31
|
+
end
|
28
32
|
end
|
data/test/includes.html
CHANGED
@@ -8,6 +8,7 @@ Testing Include → {% include foo.html %}
|
|
8
8
|
|
9
9
|
## Include from var
|
10
10
|
Testing Include → {% include page.partial %}
|
11
|
+
Testing Include → {% include {{ page.partial }} %}
|
11
12
|
|
12
13
|
## Local var passing
|
13
14
|
Testing Include var_test → {% include foo.html some_var="var_test" %}
|
@@ -26,4 +27,4 @@ Testing Include var_test → {% include foo.html some_var="var_test" if some_boo
|
|
26
27
|
|
27
28
|
## Ternary include
|
28
29
|
Testing Include → {% include (false ? bar.html : foo.html ) %}
|
29
|
-
Testing Include → {% include (some_bool ? foo.html :
|
30
|
+
Testing Include → {% include (some_bool ? foo.html : test-plugin:greet.html) %}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: octopress-include-tag
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
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-05-
|
11
|
+
date: 2015-05-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: octopress-tag-helpers
|
@@ -108,6 +108,20 @@ dependencies:
|
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: pry-byebug
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
111
125
|
description:
|
112
126
|
email:
|
113
127
|
- brandon@imathis.com
|