octopress-ink 1.0.0.alpha.22 → 1.0.0.alpha.23

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: ddc8138d15559a1928f3bc9d7f4a4d8a6ab95fcd
4
- data.tar.gz: 6dc4f36adadf0d70480f395e2d98077c2d025e94
3
+ metadata.gz: 37ae1d79d24dfabbbe224a384bc2867a41911996
4
+ data.tar.gz: 1b2b6d06f7877c7387482c6516ed2947f67144e9
5
5
  SHA512:
6
- metadata.gz: fdbb1c6acc6f9188b803e22503f4d37c1e4982f1a0bc7965f9bc317586ed16fe848161532bf830a0fcdab177323efdbcbe8eeddac9a016927fb8118e2c42c774
7
- data.tar.gz: 063ac8ad2903c3d679b9710c463fa148cc870825e32abefb4b3ab4fb1e0ebc5ca8bc3f3debc6cf032566bf042aab2e19dc8a86c6d98f0592248a717ba952b4c5
6
+ metadata.gz: b5c703a3ce89c9e3f2551b09d3baec20c96945200ae6a9b94e330183cfaac09f33b520a41b34a69097ed3d5621e98a62c8c63f79ace419896125a5450ebad63f
7
+ data.tar.gz: fe8902c99f7f4bba176594b9aa6da57cd1d1969b70706033f9e94e4f3e03643b6d4c1d1f407a36d98741e23d86dd2bda596974bbcfeb0addb3265d58667c1143
data/lib/octopress-ink.rb CHANGED
@@ -28,6 +28,7 @@ Liquid::Template.register_tag('include', Octopress::Tags::IncludeTag)
28
28
  Liquid::Template.register_tag('assign', Octopress::Tags::AssignTag)
29
29
  Liquid::Template.register_tag('capture', Octopress::Tags::CaptureTag)
30
30
  Liquid::Template.register_tag('return', Octopress::Tags::ReturnTag)
31
+ Liquid::Template.register_tag('render', Octopress::Tags::RenderTag)
31
32
  Liquid::Template.register_tag('octopress_js', Octopress::Tags::JavascriptTag)
32
33
  Liquid::Template.register_tag('octopress_css', Octopress::Tags::StylesheetTag)
33
34
  Liquid::Template.register_tag('content_for', Octopress::Tags::ContentForBlock)
@@ -24,12 +24,12 @@ module Octopress
24
24
  if @plugin.type != 'local_plugin'
25
25
  default = plugin_path
26
26
  if exists? default
27
- config = YAML::load(File.open(default))
27
+ config = YAML.safe_load(File.open(default))
28
28
  end
29
29
  end
30
30
  override = user_path(site)
31
31
  if exists? override
32
- config = config.deep_merge YAML::load(File.open(override))
32
+ config = config.deep_merge YAML.safe_load(File.open(override))
33
33
  end
34
34
  config
35
35
  end
@@ -1,7 +1,7 @@
1
1
  module Octopress
2
2
  module Helpers
3
3
  module Path
4
- FILE = /(\S+)(\s.+)/
4
+ FILE = /(\S+)(\s.*)/
5
5
  def self.parse(markup, context)
6
6
  if markup =~ FILE
7
7
  (context[$1].nil? ? $1 : context[$1]) + $2
@@ -9,6 +9,34 @@ module Octopress
9
9
  markup
10
10
  end
11
11
  end
12
+
13
+ # Allow paths to begin from the directory of the context page or
14
+ # have absolute paths
15
+ #
16
+ # Input:
17
+ # - file: "file.html"
18
+ # - context: A Jekyll context object
19
+ #
20
+ # Returns the full path to a file
21
+ #
22
+ def self.expand(file, context)
23
+ root = context.registers[:site].source
24
+
25
+ # If local file, e.g. ./somefile
26
+ if file =~ /^\.\/(.+)/
27
+ local_dir = File.dirname context.registers[:page]['path']
28
+ File.join root, local_dir, $1
29
+
30
+ # If absolute or relative to a user directory, e.g. /Users/Bob/somefile or ~/somefile
31
+ elsif file =~ /^[\/~]/
32
+ Pathname.new(file).expand_path
33
+
34
+ # Otherwise, assume relative to site root
35
+ else
36
+ File.join root, file
37
+ end
38
+ end
39
+
12
40
  end
13
41
  end
14
42
  end
@@ -20,9 +20,7 @@ module Octopress
20
20
  end
21
21
 
22
22
  def self.get_value(vars, context)
23
- if vars =~ TERNARY
24
- vars = $1 + evaluate_ternary($2, $3, $4, context) + $5
25
- end
23
+ vars = evaluate_ternary(vars, context)
26
24
  vars = vars.strip.gsub(/ or /, ' || ')
27
25
  vars = vars.split(/ \|\| /).map { |v|
28
26
  Liquid::Variable.new(v.strip).render(context)
@@ -31,8 +29,12 @@ module Octopress
31
29
  vars.empty? ? nil : vars.first
32
30
  end
33
31
 
34
- def self.evaluate_ternary(expression, if_true, if_false, context)
35
- Conditional.parse("if #{expression}", context) ? if_true : if_false
32
+ def self.evaluate_ternary(markup, context)
33
+ if markup =~ TERNARY
34
+ $1 + (Conditional.parse("if #{$2}", context) ? $3 : $4) + $5
35
+ else
36
+ markup
37
+ end
36
38
  end
37
39
 
38
40
  end
@@ -11,4 +11,24 @@ module Jekyll
11
11
  do_layout_orig(payload, layouts)
12
12
  end
13
13
  end
14
+
15
+ # Create a new page class to allow partials to trigger Jekyll Page Hooks.
16
+ class ConvertiblePage
17
+ include Convertible
18
+
19
+ attr_accessor :name, :content, :site, :ext, :output, :data
20
+
21
+ def initialize(site, name, content)
22
+ @site = site
23
+ @name = name
24
+ @ext = File.extname(name)
25
+ @content = content
26
+ @data = { layout: "no_layout" } # hack
27
+
28
+ end
29
+
30
+ def render(payload)
31
+ do_layout(payload, { no_layout: nil })
32
+ end
33
+ end
14
34
  end
@@ -3,6 +3,7 @@ module Octopress
3
3
  autoload :IncludeTag, 'octopress-ink/tags/include'
4
4
  autoload :AssignTag, 'octopress-ink/tags/assign'
5
5
  autoload :ReturnTag, 'octopress-ink/tags/return'
6
+ autoload :RenderTag, 'octopress-ink/tags/render'
6
7
  autoload :CaptureTag, 'octopress-ink/tags/capture'
7
8
  autoload :JavascriptTag, 'octopress-ink/tags/javascript'
8
9
  autoload :StylesheetTag, 'octopress-ink/tags/stylesheet'
@@ -11,6 +11,7 @@ module Octopress
11
11
  def render(context)
12
12
  markup = Helpers::Conditional.parse(@markup, context)
13
13
  return unless markup
14
+ markup = Helpers::Var.evaluate_ternary(markup, context)
14
15
  markup = Helpers::Path.parse(markup, context)
15
16
 
16
17
  include_tag = Jekyll::Tags::IncludeTag.new('include', markup, [])
@@ -29,6 +30,7 @@ module Octopress
29
30
  context['include'] = include_tag.parse_params(context)
30
31
  partial.render!(context)
31
32
  }.strip
33
+
32
34
  # Otherwise, use Jekyll's default include tag
33
35
  else
34
36
  include_tag.render(context).strip
@@ -0,0 +1,62 @@
1
+ module Octopress
2
+ module Tags
3
+ class RenderTag < Liquid::Tag
4
+ SYNTAX = /(\S+)(.+)/
5
+
6
+ def initialize(tag_name, markup, tokens)
7
+ super
8
+ @og_markup = @markup = markup
9
+ if markup =~ /^(\s*raw\s)?(.+?)(\sraw\s*)?$/
10
+ @markup = $2
11
+ @raw = true unless $1.nil? and $3.nil?
12
+ end
13
+ end
14
+
15
+ def render(context)
16
+ markup = Helpers::Conditional.parse(@markup, context)
17
+ return unless markup
18
+ markup = Helpers::Var.evaluate_ternary(markup, context)
19
+ markup = Helpers::Path.parse(markup, context)
20
+
21
+ content = read(markup, context)
22
+
23
+ if content =~ /\A-{3}(.+[^\A])-{3}\n(.+)/m
24
+ local_vars = YAML.safe_load($1.strip)
25
+ content = $2.strip
26
+ end
27
+
28
+ return content if @raw
29
+
30
+ include_tag = Jekyll::Tags::IncludeTag.new('include', markup, [])
31
+
32
+ partial = Liquid::Template.parse(content)
33
+ content = context.stack {
34
+ context['include'] = include_tag.parse_params(context)
35
+ context['page'] = context['page'].deep_merge(local_vars) if local_vars
36
+ partial.render!(context)
37
+ }.strip
38
+
39
+ parse_convertible(content, context)
40
+
41
+ end
42
+
43
+ def read(markup, context)
44
+ path = markup.match(SYNTAX)[1]
45
+ @path = Helpers::Path.expand(path, context)
46
+ begin
47
+ Pathname.new(@path).read
48
+ rescue
49
+ raise IOError.new "Render failed: {% #{@tag_name} #{@og_markup}%}. The file '#{path}' could not be found at #{@path}."
50
+ end
51
+ end
52
+
53
+ def parse_convertible(content, context)
54
+ page = Jekyll::ConvertiblePage.new(context.registers[:site], @path, content)
55
+ page.render({})
56
+ page.output.strip
57
+ end
58
+
59
+ end
60
+ end
61
+ end
62
+
@@ -1,5 +1,5 @@
1
1
  module Octopress
2
2
  module Ink
3
- VERSION = "1.0.0.alpha.22"
3
+ VERSION = "1.0.0.alpha.23"
4
4
  end
5
5
  end
data/test/_config.yml CHANGED
@@ -4,4 +4,5 @@ pygments: true
4
4
  source: source
5
5
  destination: site
6
6
  include_test: foo.html
7
+ render_test: kittens
7
8
  timezone: America/Chicago
@@ -1,4 +1,4 @@
1
- <meta name='generator' content='Octopress 1.0.0.alpha.22'>
1
+ <meta name='generator' content='Octopress 1.0.0.alpha.23'>
2
2
  Testing head tag
3
3
  Testing that content_for is additive
4
4
 
@@ -20,6 +20,10 @@ Yo Dawg, I heard you like includes. → Yo Dawg, I heard you like includes.
20
20
  '' → ''
21
21
  Yo Dawg, I heard you like includes. → Yo Dawg, I heard you like includes.
22
22
 
23
+ ## Ternary include
24
+ , I heard you like includes. → , I heard you like includes.
25
+ Testing Include → Testing Include
26
+
23
27
  ## Theme Include override
24
28
  include from theme override → include from theme override
25
29
 
@@ -0,0 +1,30 @@
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
+ ## Ternary include
22
+ kittens → kittens
23
+ Testing Render → Testing Render
24
+
25
+ ## Render markdown with local vars
26
+ <p><strong>page vars</strong></p> → <p><strong>page vars</strong></p>
27
+
28
+ ## Render raw
29
+ Testing Render {{ include.var }} → Testing Render {{ include.var }}
30
+
@@ -20,6 +20,10 @@ Yo Dawg, I heard you like includes. → Yo Dawg, I heard you like includes.
20
20
  '' → ''
21
21
  Yo Dawg, I heard you like includes. → Yo Dawg, I heard you like includes.
22
22
 
23
+ ## Ternary include
24
+ , I heard you like includes. → , I heard you like includes.
25
+ Testing Include → Testing Include
26
+
23
27
  ## Theme Include override
24
28
  include from theme override → include from theme override
25
29
 
@@ -0,0 +1,30 @@
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
+ ## Ternary include
22
+ kittens → kittens
23
+ Testing Render → Testing Render
24
+
25
+ ## Render markdown with local vars
26
+ <p><strong>page vars</strong></p> → <p><strong>page vars</strong></p>
27
+
28
+ ## Render raw
29
+ Testing Render {{ include.var }} → Testing Render {{ include.var }}
30
+
@@ -0,0 +1 @@
1
+ Testing Render {{ include.var }}
@@ -0,0 +1 @@
1
+ {% assign bar = site.render_test %}{{ bar }}
@@ -0,0 +1,4 @@
1
+ ---
2
+ foo: page vars
3
+ ---
4
+ **{{page.foo}}**
@@ -23,6 +23,10 @@ Yo Dawg, I heard you like includes. → {% include theme:greet.html greeting="Yo
23
23
  '' → '{% include theme:greet.html greeting="Yo Dawg" unless some_bool %}'
24
24
  Yo Dawg, I heard you like includes. → {% include theme:greet.html greeting="Yo Dawg" if some_bool %}
25
25
 
26
+ ## Ternary include
27
+ , I heard you like includes. → {% include (false ? foo.html : theme:greet.html) %}
28
+ Testing Include → {% include (some_bool ? foo.html : theme:greet.html) %}
29
+
26
30
  ## Theme Include override
27
31
  include from theme override → {% include theme:bar.html %}
28
32
 
@@ -0,0 +1,32 @@
1
+ ---
2
+ layout: nil
3
+ ---
4
+ {% assign file = 'test_render/_f.html' %}
5
+ {% assign file2 = 'test_render/_var.html' %}
6
+ {% assign relative = './_test_render.md' %}
7
+ {% assign some_bool = true %}
8
+ {% assign test_var = 'variable' %}
9
+
10
+ ## Simple render
11
+ Testing Render → {% render test_render/_f.html %}
12
+ Testing Render whatever → {% render test_render/_f.html var="whatever" %}
13
+
14
+ ## File name stored in variable
15
+ Testing Render → {% render file %}
16
+
17
+ ## Post conditional render
18
+ '' → '{% render file unless true %}'
19
+ Testing Render → {% render file if some_bool %}
20
+
21
+ ## Test Variables
22
+ kittens → {% render test_render/_var.html %}
23
+
24
+ ## Ternary include
25
+ kittens → {% render (false ? file : file2) %}
26
+ Testing Render → {% render (some_bool ? file : file2) %}
27
+
28
+ ## Render markdown with local vars
29
+ <p><strong>page vars</strong></p> → {% render relative %}
30
+
31
+ ## Render raw
32
+ {% raw %}Testing Render {{ include.var }}{% endraw %} → {% render raw file %}
data/test/test.rb CHANGED
@@ -39,7 +39,7 @@ end
39
39
  build
40
40
 
41
41
  def test_tags(dir)
42
- tags = %w{content_for footer head include scripts assign capture wrap}
42
+ tags = %w{content_for footer head include scripts assign capture wrap render}
43
43
  tags.each { |file| test("test_tags/#{file}.html", dir) }
44
44
  end
45
45
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: octopress-ink
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.alpha.22
4
+ version: 1.0.0.alpha.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Mathis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-21 00:00:00.000000000 Z
11
+ date: 2014-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -124,6 +124,7 @@ files:
124
124
  - lib/octopress-ink/tags/head.rb
125
125
  - lib/octopress-ink/tags/include.rb
126
126
  - lib/octopress-ink/tags/javascript.rb
127
+ - lib/octopress-ink/tags/render.rb
127
128
  - lib/octopress-ink/tags/return.rb
128
129
  - lib/octopress-ink/tags/scripts.rb
129
130
  - lib/octopress-ink/tags/stylesheet.rb
@@ -161,6 +162,7 @@ files:
161
162
  - test/expected/test_tags/footer.html
162
163
  - test/expected/test_tags/head.html
163
164
  - test/expected/test_tags/include.html
165
+ - test/expected/test_tags/render.html
164
166
  - test/expected/test_tags/scripts.html
165
167
  - test/expected/test_tags/wrap.html
166
168
  - test/sass_compact/stylesheets/all-e10f647557c9d610df6df40a458bc823.css
@@ -185,6 +187,7 @@ files:
185
187
  - test/site/test_tags/footer.html
186
188
  - test/site/test_tags/head.html
187
189
  - test/site/test_tags/include.html
190
+ - test/site/test_tags/render.html
188
191
  - test/site/test_tags/return.html
189
192
  - test/site/test_tags/scripts.html
190
193
  - test/site/test_tags/wrap.html
@@ -232,12 +235,16 @@ files:
232
235
  - test/source/test_layouts/plugin_layout.html
233
236
  - test/source/test_layouts/theme.html
234
237
  - test/source/test_layouts/theme_override.html
238
+ - test/source/test_render/_f.html
239
+ - test/source/test_render/_var.html
240
+ - test/source/test_tags/_test_render.md
235
241
  - test/source/test_tags/assign.html
236
242
  - test/source/test_tags/capture.html
237
243
  - test/source/test_tags/content_for.html
238
244
  - test/source/test_tags/footer.html
239
245
  - test/source/test_tags/head.html
240
246
  - test/source/test_tags/include.html
247
+ - test/source/test_tags/render.html
241
248
  - test/source/test_tags/return.html
242
249
  - test/source/test_tags/scripts.html
243
250
  - test/source/test_tags/wrap.html
@@ -297,6 +304,7 @@ test_files:
297
304
  - test/expected/test_tags/footer.html
298
305
  - test/expected/test_tags/head.html
299
306
  - test/expected/test_tags/include.html
307
+ - test/expected/test_tags/render.html
300
308
  - test/expected/test_tags/scripts.html
301
309
  - test/expected/test_tags/wrap.html
302
310
  - test/sass_compact/stylesheets/all-e10f647557c9d610df6df40a458bc823.css
@@ -321,6 +329,7 @@ test_files:
321
329
  - test/site/test_tags/footer.html
322
330
  - test/site/test_tags/head.html
323
331
  - test/site/test_tags/include.html
332
+ - test/site/test_tags/render.html
324
333
  - test/site/test_tags/return.html
325
334
  - test/site/test_tags/scripts.html
326
335
  - test/site/test_tags/wrap.html
@@ -368,12 +377,16 @@ test_files:
368
377
  - test/source/test_layouts/plugin_layout.html
369
378
  - test/source/test_layouts/theme.html
370
379
  - test/source/test_layouts/theme_override.html
380
+ - test/source/test_render/_f.html
381
+ - test/source/test_render/_var.html
382
+ - test/source/test_tags/_test_render.md
371
383
  - test/source/test_tags/assign.html
372
384
  - test/source/test_tags/capture.html
373
385
  - test/source/test_tags/content_for.html
374
386
  - test/source/test_tags/footer.html
375
387
  - test/source/test_tags/head.html
376
388
  - test/source/test_tags/include.html
389
+ - test/source/test_tags/render.html
377
390
  - test/source/test_tags/return.html
378
391
  - test/source/test_tags/scripts.html
379
392
  - test/source/test_tags/wrap.html