jekyll-geo-pattern 0.0.1 → 0.1.0
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 +4 -4
- data/lib/jekyll-geo-pattern.rb +44 -15
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: e68b92ed0b6887ef0b9bc4cdacc655b825bdd2f4
         | 
| 4 | 
            +
              data.tar.gz: b3277d94027a8ad38eab563b1c9e99d23de16a7a
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: ec263b210938b4421705a9cf921d203d1d090dd14e17819ebf61eb3efc1933bdd52c32e8a234502c0a326b5f92d68f496d6d8be7cc5ad07ca6d1e0be4f7428eb
         | 
| 7 | 
            +
              data.tar.gz: 439704259b90175b231e5158d378cdc1d1a647295de28dc8c1e29b9839a3f4a6066b1f2290a95605d7be9c038f7431c7a590d9ae4225a8dbc018ca76e3907b2c
         | 
    
        data/lib/jekyll-geo-pattern.rb
    CHANGED
    
    | @@ -2,18 +2,41 @@ require 'geo_pattern' | |
| 2 2 |  | 
| 3 3 | 
             
            module Jekyll
         | 
| 4 4 | 
             
              module GeoPatterns
         | 
| 5 | 
            -
                HASH_REGEXP = /\{ | 
| 6 | 
            -
                VALID_KEYS = %w(base_color generator text)
         | 
| 5 | 
            +
                HASH_REGEXP = /\{(.+?)\}/
         | 
| 6 | 
            +
                VALID_KEYS = %w(:base_color :generator :text)
         | 
| 7 7 |  | 
| 8 8 | 
             
                # from a string of options, construct a hash, without using `eval`
         | 
| 9 9 | 
             
                def self.extract_options( input )
         | 
| 10 10 | 
             
                  opts = Hash.new
         | 
| 11 | 
            -
                  input | 
| 11 | 
            +
                  input.split(/, /).each do |entry|
         | 
| 12 12 | 
             
                    entryMap = entry.split(/\=>/)
         | 
| 13 | 
            -
                    key = entryMap[0].strip | 
| 13 | 
            +
                    key = entryMap[0].strip
         | 
| 14 14 | 
             
                    next unless VALID_KEYS.include? key
         | 
| 15 15 | 
             
                    value = entryMap[1]
         | 
| 16 | 
            -
                    opts[key.to_sym] = value.nil? ? nil : value.strip | 
| 16 | 
            +
                    opts[key.strip[1..-1].to_sym] = value.nil? ? nil : value.strip
         | 
| 17 | 
            +
                  end
         | 
| 18 | 
            +
                  opts
         | 
| 19 | 
            +
                end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                # set it up such that variables, like `post.title`, are still processed
         | 
| 22 | 
            +
                def self.look_up(context, name)
         | 
| 23 | 
            +
                  lookup = context
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                  name.split(".").each do |value|
         | 
| 26 | 
            +
                    lookup = lookup[value]
         | 
| 27 | 
            +
                  end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                  lookup
         | 
| 30 | 
            +
                end
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                def self.scrub_options(opts, context)
         | 
| 33 | 
            +
                  opts.each do |opt, value|
         | 
| 34 | 
            +
                    value.gsub! /"|'/, ""
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                    if value =~ /([\w]+(\.[\w]+)*)/i
         | 
| 37 | 
            +
                      context_val = GeoPatterns.look_up(context, $1)
         | 
| 38 | 
            +
                      opts[opt] = context_val unless context_val.nil?
         | 
| 39 | 
            +
                    end
         | 
| 17 40 | 
             
                  end
         | 
| 18 41 | 
             
                  opts
         | 
| 19 42 | 
             
                end
         | 
| @@ -21,28 +44,34 @@ module Jekyll | |
| 21 44 | 
             
                class Base64GeoPattern < Liquid::Tag
         | 
| 22 45 | 
             
                  def initialize(tag_name, text, tokens)
         | 
| 23 46 | 
             
                    super
         | 
| 24 | 
            -
                     | 
| 25 | 
            -
                      @opts = GeoPatterns.extract_options(m[0])
         | 
| 26 | 
            -
                    end
         | 
| 47 | 
            +
                    @text = text
         | 
| 27 48 | 
             
                  end
         | 
| 28 49 |  | 
| 29 50 | 
             
                  def render(context)
         | 
| 30 | 
            -
                     | 
| 31 | 
            -
                     | 
| 51 | 
            +
                    m = HASH_REGEXP.match(@text)
         | 
| 52 | 
            +
                    opts = GeoPatterns.extract_options(m[1])
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                    raise ArgumentError, "You must have the :text property passed in" if opts[:text].nil?
         | 
| 55 | 
            +
             | 
| 56 | 
            +
                    opts = GeoPatterns.scrub_options(opts, context)
         | 
| 57 | 
            +
                    GeoPattern.generate(opts[:text], opts).base64_string
         | 
| 32 58 | 
             
                  end
         | 
| 33 59 | 
             
                end
         | 
| 34 60 |  | 
| 35 61 | 
             
                class SVGGeoPattern < Liquid::Tag
         | 
| 36 62 | 
             
                  def initialize(tag_name, text, tokens)
         | 
| 37 63 | 
             
                    super
         | 
| 38 | 
            -
                     | 
| 39 | 
            -
                      @opts = GeoPatterns.extract_options(m[0])
         | 
| 40 | 
            -
                    end
         | 
| 64 | 
            +
                    @text = text
         | 
| 41 65 | 
             
                  end
         | 
| 42 66 |  | 
| 43 67 | 
             
                  def render(context)
         | 
| 44 | 
            -
                     | 
| 45 | 
            -
                     | 
| 68 | 
            +
                    m = HASH_REGEXP.match(@text)
         | 
| 69 | 
            +
                    opts = GeoPatterns.extract_options(m[1])
         | 
| 70 | 
            +
             | 
| 71 | 
            +
                    raise ArgumentError, "You must have the :text property passed in" if opts[:text].nil?
         | 
| 72 | 
            +
             | 
| 73 | 
            +
                    opts = GeoPatterns.scrub_options(opts, context)
         | 
| 74 | 
            +
                    GeoPattern.generate(opts[:text], opts).svg_string
         | 
| 46 75 | 
             
                  end
         | 
| 47 76 | 
             
                end
         | 
| 48 77 | 
             
              end
         | 
    
        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.0 | 
| 4 | 
            +
              version: 0.1.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- | 
| 11 | 
            +
            date: 2014-02-18 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: jekyll
         |