octopress-tag-helpers 1.0.5 → 1.0.6
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 250e3e9ad4a5034f674789ca9d64462cabeaa117
|
4
|
+
data.tar.gz: 3863551105993718c2c9a81fef0a5308013426a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa1b3727e239364339f32ff438b26b25a01552ccbf7c44771de68c3cb22ac2ebc3dd3a622e44a5b150de45eec75c307cb82df8053c270b9c090699bb3a40a067
|
7
|
+
data.tar.gz: 9fed3896cd1c2dd10655f10d11bc85cc49dc44afe6d1de05ed6c2afbe0e767b0b49422e47afc0a92d5520ffe24df5ca5de88059b4243a077f270a3313162eec1
|
data/CHANGELOG.md
CHANGED
@@ -1,17 +1,18 @@
|
|
1
1
|
module Octopress
|
2
2
|
module TagHelpers
|
3
3
|
module Conditional
|
4
|
-
SYNTAX = /(
|
4
|
+
SYNTAX = /(?<tag>.*)\s(?<condition>if|unless)\s(?<expression>.+)/
|
5
5
|
|
6
6
|
def self.parse(markup, context)
|
7
|
-
|
8
|
-
|
7
|
+
matched = markup.strip.match(SYNTAX)
|
8
|
+
if matched
|
9
|
+
case matched['condition'].strip
|
9
10
|
when 'if'
|
10
|
-
tag = Liquid::
|
11
|
+
tag = Liquid::Template.parse("{% if #{matched['expression']} %}true{% endif %}")
|
11
12
|
when 'unless'
|
12
|
-
tag = Liquid::
|
13
|
+
tag = Liquid::Template.parse("{% unless #{matched['expression']} %}true{% endunless %}")
|
13
14
|
end
|
14
|
-
tag.render(context) != '' ?
|
15
|
+
tag.render!(context) != '' ? matched['tag'] : false
|
15
16
|
else
|
16
17
|
markup
|
17
18
|
end
|
@@ -1,10 +1,11 @@
|
|
1
1
|
module Octopress
|
2
2
|
module TagHelpers
|
3
3
|
module Path
|
4
|
-
FILE = /(
|
4
|
+
FILE = /(?<path>\S+)(\s?)(?<other>.*)/
|
5
5
|
def self.parse(markup, context)
|
6
|
-
|
7
|
-
|
6
|
+
matched = markup.strip.match(FILE)
|
7
|
+
if matched
|
8
|
+
(context[matched['path']].nil? ? matched['path'] : context[matched['path']]) + ' ' + (matched['other'] || '')
|
8
9
|
else
|
9
10
|
markup
|
10
11
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module Octopress
|
2
2
|
module TagHelpers
|
3
3
|
module Var
|
4
|
-
TERNARY = /(
|
5
|
-
HAS_FILTERS = /(
|
4
|
+
TERNARY = /(?<markup>.*?)\(\s*(?<condition>.+?)\s+\?\s+(?<trueresult>.+?)\s+:\s+(?<falseresult>.+?)\s*\)(?<other>.+)?/
|
5
|
+
HAS_FILTERS = /(?<markup>.*?)(?<filters>\s+\|\s+.+)/
|
6
6
|
|
7
7
|
def self.set_var(var, operator, value, context)
|
8
8
|
case operator
|
@@ -23,10 +23,13 @@ module Octopress
|
|
23
23
|
def self.get_value(vars, context)
|
24
24
|
vars = evaluate_ternary(vars, context)
|
25
25
|
vars = vars.strip.gsub(/ or /, ' || ')
|
26
|
+
|
26
27
|
filters = false
|
27
|
-
|
28
|
-
|
29
|
-
|
28
|
+
|
29
|
+
matched = vars.strip.match(HAS_FILTERS)
|
30
|
+
if matched
|
31
|
+
vars = matched['markup']
|
32
|
+
filters = matched['filters']
|
30
33
|
end
|
31
34
|
|
32
35
|
vars = vars.split(/ \|\| /).map { |v|
|
@@ -45,8 +48,9 @@ module Octopress
|
|
45
48
|
end
|
46
49
|
|
47
50
|
def self.evaluate_ternary(markup, context)
|
48
|
-
if
|
49
|
-
|
51
|
+
if matched = markup.strip.match(TERNARY)
|
52
|
+
condition = Liquid::Template.parse("{% if #{matched['condition']} %}true{% endif %}")
|
53
|
+
"#{matched['markup']} #{(condition.render!(context) != '' ? matched['trueresult'] : matched['falseresult'])} #{matched['other']}"
|
50
54
|
else
|
51
55
|
markup
|
52
56
|
end
|
@@ -9,7 +9,6 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["Brandon Mathis"]
|
10
10
|
spec.email = ["brandon@imathis.com"]
|
11
11
|
spec.summary = %q{Making it easier to build smart Jekyll/Octopress Liquid tags.}
|
12
|
-
spec.description = %q{Making it easier to build smart Jekyll/Octopress Liquid tags.}
|
13
12
|
spec.homepage = "https://github.com/octopress/tag-helpers"
|
14
13
|
spec.license = "MIT"
|
15
14
|
|
@@ -22,4 +21,8 @@ Gem::Specification.new do |spec|
|
|
22
21
|
|
23
22
|
spec.add_development_dependency "bundler", "~> 1.6"
|
24
23
|
spec.add_development_dependency "rake"
|
24
|
+
|
25
|
+
if RUBY_VERSION >= "2"
|
26
|
+
spec.add_development_dependency "pry-byebug"
|
27
|
+
end
|
25
28
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: octopress-tag-helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandon Mathis
|
@@ -52,7 +52,21 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
-
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry-byebug
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description:
|
56
70
|
email:
|
57
71
|
- brandon@imathis.com
|
58
72
|
executables: []
|