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: ac54fc8ad22d4a400991d3fbd96a47d057a2c3be
4
- data.tar.gz: ed1179657f6660f4751ad554385b8142f452e3b9
3
+ metadata.gz: 250e3e9ad4a5034f674789ca9d64462cabeaa117
4
+ data.tar.gz: 3863551105993718c2c9a81fef0a5308013426a8
5
5
  SHA512:
6
- metadata.gz: 910a0893d65c34bb12a10c4bf944d6dca8123a7ef6ecee275e5e7a6f00eb808bc8c5e2967ef75eb469fc78ab17585dd90118e2af53289704c77b3132126a881b
7
- data.tar.gz: b225dfaf0c9c1a9bf888e7c6bad514b529aede002d87fb0957ea2b316f8ee5eabbd057a2cbe54934bfdfc4c41f17bf3ce919b641162beccb543eb9a794f97e48
6
+ metadata.gz: aa1b3727e239364339f32ff438b26b25a01552ccbf7c44771de68c3cb22ac2ebc3dd3a622e44a5b150de45eec75c307cb82df8053c270b9c090699bb3a40a067
7
+ data.tar.gz: 9fed3896cd1c2dd10655f10d11bc85cc49dc44afe6d1de05ed6c2afbe0e767b0b49422e47afc0a92d5520ffe24df5ca5de88059b4243a077f270a3313162eec1
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.0.6 - 2015-05-12
4
+ - Minor: Improvements to regex clarity.
5
+ - Minor: Using `parse` method instead of `new` for Liquid 3 compatibility.
6
+
3
7
  ## 1.0.5 - 2015-05-11
4
8
  - Minor: Jekyll 3 is fine.
5
9
 
@@ -1,17 +1,18 @@
1
1
  module Octopress
2
2
  module TagHelpers
3
3
  module Conditional
4
- SYNTAX = /(.*)\s(if|unless)\s(.+)/
4
+ SYNTAX = /(?<tag>.*)\s(?<condition>if|unless)\s(?<expression>.+)/
5
5
 
6
6
  def self.parse(markup, context)
7
- if markup =~ SYNTAX
8
- case $2
7
+ matched = markup.strip.match(SYNTAX)
8
+ if matched
9
+ case matched['condition'].strip
9
10
  when 'if'
10
- tag = Liquid::If.new('if', $3, ["true","{% endif %}"])
11
+ tag = Liquid::Template.parse("{% if #{matched['expression']} %}true{% endif %}")
11
12
  when 'unless'
12
- tag = Liquid::Unless.new('unless', $3, ["true","{% endunless %}"])
13
+ tag = Liquid::Template.parse("{% unless #{matched['expression']} %}true{% endunless %}")
13
14
  end
14
- tag.render(context) != '' ? $1 : false
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 = /(\S+)(\s?)(.*)/
4
+ FILE = /(?<path>\S+)(\s?)(?<other>.*)/
5
5
  def self.parse(markup, context)
6
- if markup =~ FILE
7
- (context[$1].nil? ? $1 : context[$1]) + ' ' + ($3 || '')
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 = /(.*?)\(\s*(.+?)\s+\?\s+(.+?)\s+:\s+(.+?)\s*\)(.+)?/
5
- HAS_FILTERS = /(.*?)(\s+\|\s+.+)/
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
- if vars =~ HAS_FILTERS
28
- vars = $1
29
- filters = $2
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 markup =~ TERNARY
49
- $1 + (Conditional.parse(" if #{$2}", context) ? $3 : $4) + $5
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
@@ -1,5 +1,5 @@
1
1
  module Octopress
2
2
  module TagHelpers
3
- VERSION = "1.0.5"
3
+ VERSION = "1.0.6"
4
4
  end
5
5
  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.5
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
- description: Making it easier to build smart Jekyll/Octopress Liquid tags.
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: []