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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d7a1eb9731c22637a2e63d07314c62301f14dbd9
4
- data.tar.gz: ad2ee24cb9e540a07e2c5394a249c87804d88bc3
3
+ metadata.gz: 03549c58c4562c87f8cd15ac4e77470ddf764295
4
+ data.tar.gz: d790afdfb814d2e87174eb5891c22f5964c88d70
5
5
  SHA512:
6
- metadata.gz: b50a57b7dfdd3e95e6ad51387a5a04d584dea262f29d9d7aab02799874a33714e21b17aa42aa0e621b68f5287a49f6681957a030b2d1477de0c5b52a5b869389
7
- data.tar.gz: 3d4515c852bdfb5ee6aea0be22dd5e19419fd9ef1f614c2abdc8cb1592f5f4fe9595545754061737a992c6f01e1aee688188aebc723fd7183b867810b3d82d39
6
+ metadata.gz: f1a1056e268c4df190f8db75dd6e3cf115da9816539b94730d962c87e8f445230d3b49f187d6c37f65e496a3f2c5672fae7e145382644b359ae5f5d91b202b27
7
+ data.tar.gz: 52eddae1fe00e1492cbeb09f4261eef7b7a5503eb6c22e92808395f398be3307e0b5812742f0e6e6839f63f06340687d12daefb5d45f20bd64d2d306d029b731
data/.gitignore CHANGED
@@ -20,3 +20,4 @@ tmp
20
20
  *.o
21
21
  *.a
22
22
  mkmf.log
23
+ .jekyll-metadata
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ### 1.1.2 - 2015-05-12
4
+ - Fix: Liquid 3 support improved
5
+ - Minor: Now supports Jekyll 2 and 3.
6
+
3
7
  ### 1.1.1 - 2015-05-11
4
8
 
5
9
  - Minor: loosened Jekyll dependency version for Jekyll 3 support.
@@ -5,50 +5,67 @@ require "jekyll"
5
5
  module Octopress
6
6
  module Tags
7
7
  module Include
8
- class Tag < Liquid::Tag
9
- PLUGIN_SYNTAX = /(.+?):(\S+)/
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
- super
13
- @og_markup = @markup = markup
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
- def render(context)
17
- return unless markup = TagHelpers::Conditional.parse(@markup, context)
18
- if markup =~ TagHelpers::Var::HAS_FILTERS
19
- markup = $1
20
- filters = $2
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
- include_tag = Jekyll::Tags::IncludeTag.new('include', markup, [])
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
- if markup.strip =~ PLUGIN_SYNTAX
29
- plugin = $1
30
- path = $2
31
- begin
32
- content = Octopress::Ink::Plugins.include(plugin, path).read
33
- rescue => error
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
- content = include_tag.render(context).strip
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
@@ -1,7 +1,7 @@
1
1
  module Octopress
2
2
  module Tags
3
3
  module Include
4
- VERSION = "1.1.1"
4
+ VERSION = "1.1.2"
5
5
  end
6
6
  end
7
7
  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
@@ -5,6 +5,7 @@ Testing Include → Testing Include
5
5
 
6
6
  ## Include from var
7
7
  Testing Include → Testing Include
8
+ Testing Include → Testing Include
8
9
 
9
10
  ## Local var passing
10
11
  Testing Include var_test → Testing Include var_test
@@ -3,6 +3,7 @@ require 'octopress-ink'
3
3
  Octopress::Ink.add_plugin({
4
4
  name: 'Test Plugin',
5
5
  slug: 'test-plugin',
6
+ type: 'plugin',
6
7
  assets_path: File.expand_path(File.dirname(__FILE__)),
7
8
  description: "Test some plugins y'all"
8
9
  })
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 : theme:greet.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.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-12 00:00:00.000000000 Z
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