jekyll-liquid-plus 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: de976d38b8549a3022f3178705c3981e3638c9d0
4
- data.tar.gz: 993189b53393131442fe4ebf8c486c3be17bcd40
3
+ metadata.gz: 050beadf8660b7b1e2067aa1ff5153d06bf8e85e
4
+ data.tar.gz: 9b2d3e942011d756f602a51bb63f412c36c814f8
5
5
  SHA512:
6
- metadata.gz: eaad7e1bad7865cb335d33753847146990891cc537e2e484c4a181a8a51c3e3224eebc2be69b76a76214736db3d743e6f0d7e7d223ecb8f7ab4b60a1e3b9ec29
7
- data.tar.gz: 03d2e10cde1244326eec35df1b974e4846305523940f2fdb803398ef43e5e6bf80af7cc17463ddadd7cc980c8b89147600ac716eb80716b5f1d78b750091e368
6
+ metadata.gz: 86414e474bc4521e42a450e3a315e501c95bcba4927832efce95403f6d13e1623e8aae3b15bab40719bcb182ff960f2c03578dc8c25fbc9bdb45824d56a29749
7
+ data.tar.gz: 42f11dbbbdfa82f461e68f602ef7ffe35ee979d0a11b09f712acbbd2228a54b31f0f830d4b486ecf6ee6c39034d517e66e0696b53d407eabd087ddb72e687784
@@ -1,5 +1,8 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.2.0 (2013-11-03)
4
+ - Fix: Render tag now properly renders {{ content }}.
5
+
3
6
  ## 1.1.0 (2013-11-03)
4
7
  - New: Render tag works with absolute paths and user relative paths.
5
8
 
@@ -16,7 +16,7 @@ Gem::Specification.new do |spec|
16
16
  spec.files = `git ls-files`.split($/)
17
17
  spec.require_paths = ["lib"]
18
18
 
19
- spec.add_runtime_dependency "jekyll", "~> 1.1.2"
19
+ spec.add_runtime_dependency "jekyll", "~> 1.3.0"
20
20
  spec.add_runtime_dependency "liquid", "~> 2.5.1"
21
21
 
22
22
  spec.add_development_dependency "bundler", "~> 1.3"
@@ -1,4 +1,5 @@
1
1
  require 'liquid'
2
+ require 'jekyll'
2
3
 
3
4
  $:.unshift File.dirname(__FILE__)
4
5
 
@@ -8,17 +9,16 @@ module LiquidPlus
8
9
  autoload :Cache, 'jekyll-liquid-plus/helpers/cache'
9
10
  autoload :IncludeTag, 'jekyll-liquid-plus/tags/include'
10
11
  autoload :WrapTag, 'jekyll-liquid-plus/tags/wrap'
11
- autoload :RenderTag, 'jekyll-liquid-plus/tags/render'
12
12
  autoload :AssignTag, 'jekyll-liquid-plus/tags/assign'
13
13
  autoload :CaptureTag, 'jekyll-liquid-plus/tags/capture'
14
14
  autoload :ReturnTag, 'jekyll-liquid-plus/tags/return'
15
15
  end
16
16
 
17
17
  Liquid::Template.register_tag('include', LiquidPlus::IncludeTag)
18
+ Liquid::Template.register_tag('render', LiquidPlus::IncludeTag)
18
19
  Liquid::Template.register_tag('wrap', LiquidPlus::WrapTag)
19
20
  Liquid::Template.register_tag('wrap_include', LiquidPlus::WrapTag)
20
- Liquid::Template.register_tag('render', LiquidPlus::RenderTag)
21
- Liquid::Template.register_tag('render_partial', LiquidPlus::RenderTag)
21
+ Liquid::Template.register_tag('render_partial', LiquidPlus::IncludeTag)
22
22
  Liquid::Template.register_tag('assign', LiquidPlus::AssignTag)
23
23
  Liquid::Template.register_tag('capture', LiquidPlus::CaptureTag)
24
24
  Liquid::Template.register_tag('return', LiquidPlus::ReturnTag)
@@ -3,32 +3,11 @@ require File.join File.expand_path('../../', __FILE__), 'helpers/path'
3
3
  module LiquidPlus
4
4
  class Include
5
5
  LOCALS = /(.*?)(([\w-]+)\s*=\s*(?:"([^"\\]*(?:\\.[^"\\]*)*)"|'([^'\\]*(?:\\.[^'\\]*)*)'|([\w\.-]+)))(.*)?/
6
-
7
6
  class << self
8
7
 
9
8
  def render(markup, context)
10
-
11
- markup, params = split_params markup
12
- file = Path.parse(markup, context, '_includes')
13
-
14
- if file
15
- if File.exist? Path.expand(File.join('_includes', file), context)
16
- markup = file
17
- markup += params if params
18
- tag = Jekyll::Tags::IncludeTag.new('', markup, [])
19
- tag.render(context)
20
- else
21
- dir = '_includes'
22
- dir = File.join dir, File.dirname(file) unless File.dirname(file) == '.'
23
-
24
- msg = "From #{context.registers[:page]['path']}: "
25
- msg += "File '#{file}' not found"
26
- msg += " in '#{dir}/' directory"
27
-
28
- puts msg.red
29
- return msg
30
- end
31
- end
9
+ tag = IncludeTag.new('include', markup, [])
10
+ tag.render(context)
32
11
  end
33
12
 
34
13
  def split_params(markup)
@@ -1,16 +1,138 @@
1
- require File.join File.expand_path('../../', __FILE__), 'helpers/include'
1
+ require File.join File.expand_path('../../', __FILE__), 'helpers/path'
2
+ require File.join File.expand_path('../../', __FILE__), 'helpers/cache'
3
+
4
+ module Jekyll
5
+
6
+ # Create a new page class to allow partials to trigger Jekyll Page Hooks.
7
+ class ConvertiblePage
8
+ include Convertible
9
+
10
+ attr_accessor :name, :content, :site, :ext, :output, :data
11
+
12
+ def initialize(site, name, content)
13
+ @site = site
14
+ @name = name
15
+ @ext = File.extname(name)
16
+ @content = content
17
+ @data = { layout: "no_layout" } # hack
18
+
19
+ end
20
+
21
+ def render(payload)
22
+ do_layout(payload, { no_layout: nil })
23
+ end
24
+ end
25
+ end
2
26
 
3
27
  module LiquidPlus
4
- class IncludeTag < Liquid::Tag
28
+ class IncludeTag < Jekyll::Tags::IncludeTag
29
+ LOCALS = /(.*?)(([\w-]+)\s*=\s*(?:"([^"\\]*(?:\\.[^"\\]*)*)"|'([^'\\]*(?:\\.[^'\\]*)*)'|([\w\.-]+)))(.*)?/
30
+
31
+ alias_method :default_render, :render
32
+
5
33
 
6
34
  def initialize(tag_name, markup, tokens)
35
+ @tag = tag_name.strip
7
36
  @markup = markup.strip
8
- super
9
- end
37
+ # If raw, strip from the markup as not to confuse the Path syntax parsing
38
+ if @markup =~ /^(\s*raw\s)?(.+?)(\sraw\s*)?$/
39
+ @markup = $2.strip
40
+ @raw = true unless $1.nil? and $3.nil?
41
+ end
10
42
 
43
+ split_params
44
+ end
45
+
11
46
  def render(context)
12
- Include.render(@markup, context)
47
+ validate_params if @params
48
+ @file = get_path(context)
49
+ if @tag == 'include' && @file && Cache.exists(Path.expand(File.join(INCLUDES_DIR, @file), context))
50
+ include_tag(context)
51
+ elsif @tag =~ /render/ && @file && Cache.exists(@file)
52
+ render_tag(context)
53
+ elsif @file
54
+ not_found(context)
55
+ end
56
+ end
57
+
58
+ def include_tag(context)
59
+ @markup = @file
60
+ @markup += @params if @params
61
+ @page = context.registers[:page]['path']
62
+ content = default_render(context)
63
+ parse_convertible(content, context)
64
+ end
65
+
66
+ def render_tag(context)
67
+ @markup = @file
68
+ @markup += @params if @params
69
+ content = read_raw
70
+
71
+ unless @raw
72
+ partial = Liquid::Template.parse(content)
73
+
74
+ content = context.stack do
75
+ context['render'] = Jekyll::Tags::IncludeTag.new('include', @markup, []).parse_params(context) if @params
76
+ context['page'] = context['page'].deep_merge(@local_vars) if @local_vars and @local_vars.keys.size > 0
77
+ partial.render!(context)
78
+ end
79
+ content = parse_convertible(content, context)
80
+ end
81
+ content
82
+ end
83
+
84
+ def not_found(context)
85
+ @file = File.join(INCLUDES_DIR, @file) if @tag == 'include'
86
+ name = File.basename(@file)
87
+ dir = @file.to_s.sub(context.registers[:site].source + '/', '').sub(name, '')
88
+ msg = "File '#{name}' not found"
89
+ msg += " in '#{dir}'" if dir.length > 0 && name != dir
90
+ raise IOError.new msg
91
+ end
92
+
93
+ def parse_convertible(content, context)
94
+ page = Jekyll::ConvertiblePage.new(context.registers[:site], @file, content)
95
+ page.render({})
96
+ content = page.output.strip
97
+ end
98
+
99
+ def split_params
100
+ if @markup =~ LOCALS
101
+ @params = ' ' + $2
102
+ @markup = $1 + $7
103
+ end
104
+ end
105
+
106
+ def get_path(context)
107
+ root = (@tag == 'include') ? INCLUDES_DIR : nil
108
+ if file = Path.parse(@markup, context, root)
109
+ file = Path.expand(file, context) if @tag =~ /render/
110
+ @markup = file
111
+ file
112
+ end
113
+ end
114
+
115
+ #Strip out yaml header from partials
116
+ def strip_yaml(content)
117
+ if content =~ /\A-{3}(.+[^\A])-{3}\n(.+)/m
118
+ $2.strip
119
+ end
120
+ content
121
+ end
122
+
123
+ def read_raw
124
+ path = Pathname.new @file
125
+ Dir.chdir(File.dirname(path)) do
126
+ content = path.read
127
+ if content =~ /\A-{3}(.+[^\A])-{3}\n(.+)/m
128
+ @local_vars = YAML.safe_load($1.strip)
129
+ content = $2.strip
130
+ end
131
+ content
132
+ end
13
133
  end
14
134
  end
15
135
  end
16
136
 
137
+
138
+
@@ -1,5 +1,4 @@
1
1
  require File.join File.expand_path('../../', __FILE__), 'helpers/include'
2
- require File.join File.expand_path('../../', __FILE__), 'tags/render'
3
2
 
4
3
  module LiquidPlus
5
4
  class WrapTag < Liquid::Block
@@ -17,7 +16,8 @@ module LiquidPlus
17
16
  back = $3
18
17
 
19
18
  partial = if @tag == 'wrap'
20
- RenderTag.new('', @markup, []).render(context)
19
+ tag = IncludeTag.new('render', @markup, [])
20
+ tag.render(context)
21
21
  elsif @tag == 'wrap_include'
22
22
  Include.render(@markup, context)
23
23
  end
@@ -1,3 +1,3 @@
1
1
  module LiquidPlus
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -0,0 +1 @@
1
+ *{{ content }}*
@@ -0,0 +1 @@
1
+ *{{ content }}*
@@ -0,0 +1 @@
1
+ {% include custom/include_layout.html %}
@@ -0,0 +1 @@
1
+ {% render _layouts/custom/render_layout.html %}
@@ -23,7 +23,6 @@ file.html → {% include (some_bool ? file.html : file2.html) %}
23
23
  ## Cascading include
24
24
  file.html → {% include not_there.html || file.html %}
25
25
  '' → '{% include not_there.html || none %}'
26
- From include.html: File 'not_there.html' not found in '_includes/' directory → {% include nothing || not_there.html %}
27
26
 
28
27
  ## Complex includes
29
28
  file2.html and variable → {% include (some_bool ? not_here : file.html) || file2.html var='variable' %}
@@ -0,0 +1,4 @@
1
+ ---
2
+ layout: include
3
+ ---
4
+ success
@@ -27,7 +27,6 @@ file.html → {% render (some_bool ? f/file.html : f/file2.html) %}
27
27
  ## Cascading include
28
28
  file.html → {% render not_there.html || f/file.html %}
29
29
  '' → '{% render not_there.html or none %}'
30
- From render.html: File 'not_there.html' not found → {% render nothing || not_there.html %}
31
30
 
32
31
  ## Complex includes
33
32
  file2.html and variable → {% render (some_bool ? not_here : f/file.html) || f/file2.html var='variable' %}
@@ -39,3 +38,4 @@ file2.html and variable → {% render (some_bool ? not_here : f/file.html) || f/
39
38
 
40
39
  ## Render raw
41
40
  {% raw %}**{{ page.test_var }}{{ render.foo }}**{% endraw %} → {% render raw f/file3.md %}
41
+
@@ -0,0 +1,4 @@
1
+ ---
2
+ layout: render
3
+ ---
4
+ success
@@ -20,7 +20,6 @@ layout: nil
20
20
  ## Cascading wrap
21
21
  [- file.html -] → {% wrap not_there.html || f/file.html %}[- {=yield} -]{% endwrap %}
22
22
  '' → '{% wrap not_there.html || none %}[- {=yield} -]{% endwrap %}'
23
- [- From wrap.html: File 'not_there.html' not found in '_includes/' directory -] → {% wrap_include nothing || not_there.html %}[- {=yield} -]{% endwrap_include %}
24
23
 
25
24
  ## Complex wraps
26
25
  [- file2.html and variable -] → {% wrap (some_bool ? not_here : f/file.html) || f/file2.html var='variable' %}[- {=yield} -]{% endwrap %}
@@ -7,7 +7,10 @@ has_failed = false
7
7
  def test(path)
8
8
  path = Pathname.new path + '.html'
9
9
  failure = []
10
- start = 0
10
+ start = 1
11
+ tests = ''
12
+ passed = 0
13
+ failed = 0
11
14
 
12
15
  f = File.new("source/#{path}")
13
16
  # Get the starting line (after the YAML FM) for source map
@@ -16,25 +19,57 @@ def test(path)
16
19
  break start = f.lineno + 1
17
20
  end
18
21
  end
22
+ total = f.read.count('→')
19
23
 
20
24
  Dir.chdir('_site') do
21
25
  File.readlines(path).each_with_index do |line, i|
22
26
  if line =~ /(.+?)→(.+)/
23
27
  if $1.strip != $2.strip
28
+ failed += 1
29
+ tests << 'F'.red
24
30
  failure << " - line #{i+start}: #{$1}!=#{$2}"
31
+ else
32
+ passed += 1
33
+ tests << '.'.green
25
34
  end
26
35
  end
27
36
  end
28
37
  end
29
- if failure.size > 0
30
- puts "failed".red + ": #{path}"
38
+ if failed < 1 && passed < 1
39
+ puts "missed".yellow + ": #{path} " + "0/#{total}".yellow
40
+ has_failed = true
41
+ elsif failure.size > 0
42
+ puts "failed".red + ": #{path} #{tests} " + "#{passed}/#{total}".red
31
43
  puts failure.join "\n"
32
44
  has_failed = true
33
45
  else
34
- puts "passed".green + ": #{path}"
46
+ puts "passed".green + ": #{path} #{tests} " + "#{passed}/#{total}".green
47
+ end
48
+ end
49
+
50
+ def test_layout(path)
51
+ path = Pathname.new path + '.html'
52
+ failure = []
53
+ start = 0
54
+
55
+ f = File.new("source/#{path}")
56
+ # Get the starting line (after the YAML FM) for source map
57
+ f.each do |line|
58
+ if line =~ /---/ and f.lineno > 1
59
+ break start = f.lineno + 1
60
+ end
61
+ end
62
+ Dir.chdir('_site') do
63
+ if path.read !~ /success/
64
+ puts "failed".red + ": #{path} 1/1".red
65
+ has_failed = true
66
+ else
67
+ puts "passed".green + ": #{path} " + "1/1".green
68
+ end
35
69
  end
36
70
  end
37
71
 
72
+
38
73
  `rm -rf _site/; bundle exec jekyll build --trace`
39
74
 
40
75
  # Test include
@@ -45,5 +80,8 @@ test 'wrap'
45
80
  test 'assign'
46
81
  test 'capture'
47
82
  test 'return'
83
+ test_layout 'include_layout'
84
+ test_layout 'render_layout'
85
+
48
86
 
49
87
  abort if has_failed
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-liquid-plus
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Mathis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-18 00:00:00.000000000 Z
11
+ date: 2013-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: 1.1.2
19
+ version: 1.3.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ~>
25
25
  - !ruby/object:Gem::Version
26
- version: 1.1.2
26
+ version: 1.3.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: liquid
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -90,16 +90,18 @@ files:
90
90
  - lib/jekyll-liquid-plus/tags/assign.rb
91
91
  - lib/jekyll-liquid-plus/tags/capture.rb
92
92
  - lib/jekyll-liquid-plus/tags/include.rb
93
- - lib/jekyll-liquid-plus/tags/render.rb
94
93
  - lib/jekyll-liquid-plus/tags/return.rb
95
94
  - lib/jekyll-liquid-plus/tags/wrap.rb
96
95
  - lib/jekyll-liquid-plus/version.rb
97
96
  - test/_config.yml
98
97
  - test/source/.gitignore
98
+ - test/source/_includes/custom/include_layout.html
99
99
  - test/source/_includes/file.html
100
100
  - test/source/_includes/file2.html
101
101
  - test/source/_includes/file3.html
102
- - test/source/_layouts/default.html
102
+ - test/source/_layouts/custom/render_layout.html
103
+ - test/source/_layouts/include.html
104
+ - test/source/_layouts/render.html
103
105
  - test/source/_plugins/liquid-plus.rb
104
106
  - test/source/assign.html
105
107
  - test/source/capture.html
@@ -109,7 +111,9 @@ files:
109
111
  - test/source/f/file4.html
110
112
  - test/source/f/file5.html
111
113
  - test/source/include.html
114
+ - test/source/include_layout.html
112
115
  - test/source/render.html
116
+ - test/source/render_layout.html
113
117
  - test/source/return.html
114
118
  - test/source/wrap.html
115
119
  - test/test.rb
@@ -1,132 +0,0 @@
1
- # Title: Render Partial Tag for Jekyll
2
- # Author: Brandon Mathis
3
- # Description: Import files on your filesystem into any blog post and render them inline.
4
- # Note: Paths are relative to the source directory, if you import a file with yaml front matter, the yaml will be stripped out.
5
- #
6
- # Syntax {% render_partial path/to/file %}
7
- #
8
- # Example 1:
9
- # {% render_partial about/_bio.markdown %}
10
- #
11
- # This will import source/about/_bio.markdown and render it inline.
12
- # In this example I used an underscore at the beginning of the filename to prevent Jekyll
13
- # from generating an about/bio.html (Jekyll doesn't convert files beginning with underscores)
14
- #
15
- # Example 2:
16
- # {% render_partial ../README.markdown %}
17
- #
18
- # You can use relative pathnames, to include files outside of the source directory.
19
- # This might be useful if you want to have a page for a project's README without having
20
- # to duplicated the contents
21
- #
22
- #
23
-
24
- require File.join File.expand_path('../../', __FILE__), 'helpers/path'
25
- require File.join File.expand_path('../../', __FILE__), 'helpers/include'
26
- require 'jekyll'
27
- require 'yaml'
28
- require 'pathname'
29
-
30
- module Jekyll
31
-
32
- # Create a new page class to allow partials to trigger Jekyll Page Hooks.
33
- class ConvertiblePage
34
- include Convertible
35
-
36
- attr_accessor :name, :content, :site, :ext, :output, :data
37
-
38
- def initialize(site, name, content)
39
- @site = site
40
- @name = name
41
- @ext = File.extname(name)
42
- @content = content
43
- @data = { layout: "no_layout" } # hack
44
-
45
- end
46
-
47
- def render(payload, info)
48
- do_layout(payload, { no_layout: nil })
49
- end
50
- end
51
- end
52
-
53
- module LiquidPlus
54
- class RenderTag < Liquid::Tag
55
- def initialize(tag_name, markup, tokens)
56
- @markup = markup.strip
57
- super
58
- end
59
-
60
- def parse_markup
61
- # If raw, strip from the markup as not to confuse the Path syntax parsing
62
- if @markup =~ /^(\s*raw\s)?(.+?)(\sraw\s*)?$/
63
- @markup = $2.strip
64
- @raw = true unless $1.nil? and $3.nil?
65
- end
66
-
67
- # Separate params from markup
68
- @markup, @params = Include.split_params(@markup)
69
- end
70
-
71
- def get_path(context)
72
- if file = Path.parse(@markup, context)
73
- path = Pathname.new Path.expand(file, context)
74
- @markup = file
75
- path
76
- end
77
- end
78
-
79
- def render(context)
80
- parse_markup
81
- path = get_path(context)
82
- if path and Cache.exists(path)
83
-
84
- Dir.chdir(File.dirname(path)) do
85
- content = path.read
86
-
87
- #Strip out yaml header from partials
88
- if content =~ /\A-{3}(.+[^\A])-{3}\n(.+)/m
89
- @local_vars = YAML.safe_load($1.strip)
90
- content = $2.strip
91
- end
92
-
93
- if @raw
94
- content
95
- else
96
- content = parse_params(content, context) if @params or @local_vars
97
-
98
- page = Jekyll::ConvertiblePage.new(context.registers[:site], path, content)
99
- payload = { 'page' => context.registers[:page] }.merge(context.registers[:site].site_payload)
100
- page.render(payload, { registers: context.registers })
101
- page.output.strip
102
- end
103
- end
104
- elsif path
105
- name = File.basename(path)
106
- dir = path.to_s.sub(context.registers[:site].source + '/', '')
107
-
108
- msg = "From #{context.registers[:page]['path']}: "
109
- msg += "File '#{name}' not found"
110
- msg += " in '#{dir}' directory" unless name == dir
111
-
112
- puts msg.red
113
- return msg
114
- end
115
- end
116
-
117
- def parse_params(content, context)
118
- if @params
119
- markup = @markup + @params
120
- end
121
- partial = Liquid::Template.parse(content)
122
-
123
- context.stack do
124
- context['render'] = Jekyll::Tags::IncludeTag.new('', markup, []).parse_params(context) if @params
125
- context['page'] = context['page'].deep_merge(@local_vars) if @local_vars and @local_vars.keys.size > 0
126
- content = partial.render(context)
127
- end
128
- content
129
- end
130
- end
131
- end
132
-
@@ -1,11 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8">
5
- <title>{{ page.title }}</title>
6
- <meta name="viewport" content="width=device-width">
7
- </head>
8
- <body>
9
- {{ content }}
10
- </body>
11
- </html>