jekyll-geo-pattern 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/jekyll-geo-pattern.rb +18 -12
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e68b92ed0b6887ef0b9bc4cdacc655b825bdd2f4
4
- data.tar.gz: b3277d94027a8ad38eab563b1c9e99d23de16a7a
3
+ metadata.gz: a70b8b1fdf70a51eb239da2a4ccd6e4c9f8e9824
4
+ data.tar.gz: 6e851c7a53a09abe62ed81a2e2cdf4b67e9e8b29
5
5
  SHA512:
6
- metadata.gz: ec263b210938b4421705a9cf921d203d1d090dd14e17819ebf61eb3efc1933bdd52c32e8a234502c0a326b5f92d68f496d6d8be7cc5ad07ca6d1e0be4f7428eb
7
- data.tar.gz: 439704259b90175b231e5158d378cdc1d1a647295de28dc8c1e29b9839a3f4a6066b1f2290a95605d7be9c038f7431c7a590d9ae4225a8dbc018ca76e3907b2c
6
+ metadata.gz: 5866a38c05a4d5c9981079a7a208eb44260046c9b4f17a204cd4a6d18bad873a131750c7d925d7a324784f3b59505d418ac0490c3d9d5c17d2c76455d2ae9d39
7
+ data.tar.gz: 66c7c92bd0639fca3d17fd627d882a5278e482554b7182b50928eea848b938ca9ebed3f13668595bc1863509d648123a5d5718dadb4c1edee78215548937c9fd
@@ -2,18 +2,26 @@ require 'geo_pattern'
2
2
 
3
3
  module Jekyll
4
4
  module GeoPatterns
5
- HASH_REGEXP = /\{(.+?)\}/
6
5
  VALID_KEYS = %w(:base_color :generator :text)
6
+ VALID_SYNTAX = /([\w-]+)\s*=\s*(?:"([^"\\]*(?:\\.[^"\\]*)*)"|'([^'\\]*(?:\\.[^'\\]*)*)'|([\w\.-]+))/
7
7
 
8
8
  # from a string of options, construct a hash, without using `eval`
9
9
  def self.extract_options( input )
10
- opts = Hash.new
11
- input.split(/, /).each do |entry|
12
- entryMap = entry.split(/\=>/)
13
- key = entryMap[0].strip
14
- next unless VALID_KEYS.include? key
15
- value = entryMap[1]
16
- opts[key.strip[1..-1].to_sym] = value.nil? ? nil : value.strip
10
+ opts = {}
11
+ markup = input
12
+
13
+ while match = VALID_SYNTAX.match(markup) do
14
+ markup = markup[match.end(0)..-1]
15
+
16
+ value = if match[2]
17
+ match[2].gsub(/\\"/, '"')
18
+ elsif match[3]
19
+ match[3].gsub(/\\'/, "'")
20
+ elsif match[4]
21
+ context[match[4]]
22
+ end
23
+
24
+ opts[match[1].to_sym] = value
17
25
  end
18
26
  opts
19
27
  end
@@ -48,8 +56,7 @@ module Jekyll
48
56
  end
49
57
 
50
58
  def render(context)
51
- m = HASH_REGEXP.match(@text)
52
- opts = GeoPatterns.extract_options(m[1])
59
+ opts = GeoPatterns.extract_options(@text)
53
60
 
54
61
  raise ArgumentError, "You must have the :text property passed in" if opts[:text].nil?
55
62
 
@@ -65,8 +72,7 @@ module Jekyll
65
72
  end
66
73
 
67
74
  def render(context)
68
- m = HASH_REGEXP.match(@text)
69
- opts = GeoPatterns.extract_options(m[1])
75
+ opts = GeoPatterns.extract_options(@text)
70
76
 
71
77
  raise ArgumentError, "You must have the :text property passed in" if opts[:text].nil?
72
78
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-geo-pattern
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Garen J. Torikian
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-18 00:00:00.000000000 Z
11
+ date: 2014-02-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll