jekyll-data 0.2.0 → 0.2.1
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/README.md +1 -1
- data/lib/jekyll-data.rb +16 -16
- data/lib/jekyll-data/version.rb +3 -3
- data/lib/jekyll/theme.rb +66 -66
- data/lib/jekyll/theme_reader.rb +35 -14
- 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: 7c383a01aa3bb9fe5690b81d7cd54125be7ac8b3
         | 
| 4 | 
            +
              data.tar.gz: 0f98f59af2bee263e7af7e10304e23318b632cd0
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 3bc5a33b09beb3c7cb19c474c723928eb0e8f79f93beac5568f0714440a196ae5e8bfbba58bd54e550082688576c3d696b6cbdd8b3112078006aff8081a8cbc4
         | 
| 7 | 
            +
              data.tar.gz: 72e1317d7b637897ac35a0ccecc711772145bc45baf1b6a016b5e4a879d32136816e5f6bac9f0d9e6395e24f0950d8d72b1aa8fb677da4adc1f454c26183a51e
         | 
    
        data/README.md
    CHANGED
    
    | @@ -2,7 +2,7 @@ | |
| 2 2 |  | 
| 3 3 | 
             
            [](https://rubygems.org/gems/jekyll-data)
         | 
| 4 4 |  | 
| 5 | 
            -
            Introducing a plugin that reads data files within **jekyll theme gems** and adds  | 
| 5 | 
            +
            Introducing a plugin that reads data files within **jekyll theme gems** and adds the resulting hash to the site's internal data hash.
         | 
| 6 6 |  | 
| 7 7 | 
             
            ## Installation
         | 
| 8 8 |  | 
    
        data/lib/jekyll-data.rb
    CHANGED
    
    | @@ -1,16 +1,16 @@ | |
| 1 | 
            -
            require "jekyll"
         | 
| 2 | 
            -
            require "jekyll-data/version"
         | 
| 3 | 
            -
             | 
| 4 | 
            -
            # Plugin inclusions
         | 
| 5 | 
            -
            require_relative "jekyll/theme_reader"
         | 
| 6 | 
            -
            require_relative "jekyll/readers/theme_data_reader"
         | 
| 7 | 
            -
            require_relative "jekyll/drops/themed_site_drop"
         | 
| 8 | 
            -
             | 
| 9 | 
            -
            # Monkey-patches
         | 
| 10 | 
            -
            require_relative "jekyll/theme"
         | 
| 11 | 
            -
            require_relative "jekyll/drops/unified_payload_drop"
         | 
| 12 | 
            -
             | 
| 13 | 
            -
            # replace Jekyll::Reader with a subclass Jekyll::ThemeReader
         | 
| 14 | 
            -
            Jekyll::Hooks.register :site, :after_init do |site|
         | 
| 15 | 
            -
              site.reader = Jekyll::ThemeReader.new(site)
         | 
| 16 | 
            -
            end
         | 
| 1 | 
            +
            require "jekyll"
         | 
| 2 | 
            +
            require "jekyll-data/version"
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            # Plugin inclusions
         | 
| 5 | 
            +
            require_relative "jekyll/theme_reader"
         | 
| 6 | 
            +
            require_relative "jekyll/readers/theme_data_reader"
         | 
| 7 | 
            +
            require_relative "jekyll/drops/themed_site_drop"
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            # Monkey-patches
         | 
| 10 | 
            +
            require_relative "jekyll/theme"
         | 
| 11 | 
            +
            require_relative "jekyll/drops/unified_payload_drop"
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            # replace Jekyll::Reader with a subclass Jekyll::ThemeReader
         | 
| 14 | 
            +
            Jekyll::Hooks.register :site, :after_init do |site|
         | 
| 15 | 
            +
              site.reader = Jekyll::ThemeReader.new(site)
         | 
| 16 | 
            +
            end
         | 
    
        data/lib/jekyll-data/version.rb
    CHANGED
    
    | @@ -1,3 +1,3 @@ | |
| 1 | 
            -
            module JekyllData
         | 
| 2 | 
            -
              VERSION = "0.2. | 
| 3 | 
            -
            end
         | 
| 1 | 
            +
            module JekyllData
         | 
| 2 | 
            +
              VERSION = "0.2.1".freeze
         | 
| 3 | 
            +
            end
         | 
    
        data/lib/jekyll/theme.rb
    CHANGED
    
    | @@ -1,66 +1,66 @@ | |
| 1 | 
            -
            module Jekyll
         | 
| 2 | 
            -
              class Theme
         | 
| 3 | 
            -
                extend Forwardable
         | 
| 4 | 
            -
                attr_reader :name
         | 
| 5 | 
            -
                def_delegator :gemspec, :version, :version
         | 
| 6 | 
            -
             | 
| 7 | 
            -
                def initialize(name)
         | 
| 8 | 
            -
                  @name = name.downcase.strip
         | 
| 9 | 
            -
                  configure_sass
         | 
| 10 | 
            -
                end
         | 
| 11 | 
            -
             | 
| 12 | 
            -
                def root
         | 
| 13 | 
            -
                  # Must use File.realpath to resolve symlinks created by rbenv
         | 
| 14 | 
            -
                  # Otherwise, Jekyll.sanitized path with prepend the unresolved root
         | 
| 15 | 
            -
                  @root ||= File.realpath(gemspec.full_gem_path)
         | 
| 16 | 
            -
                rescue Errno::ENOENT, Errno::EACCES, Errno::ELOOP
         | 
| 17 | 
            -
                  nil
         | 
| 18 | 
            -
                end
         | 
| 19 | 
            -
             | 
| 20 | 
            -
                def includes_path
         | 
| 21 | 
            -
                  path_for "_includes".freeze
         | 
| 22 | 
            -
                end
         | 
| 23 | 
            -
             | 
| 24 | 
            -
                def layouts_path
         | 
| 25 | 
            -
                  path_for "_layouts".freeze
         | 
| 26 | 
            -
                end
         | 
| 27 | 
            -
             | 
| 28 | 
            -
                def sass_path
         | 
| 29 | 
            -
                  path_for "_sass".freeze
         | 
| 30 | 
            -
                end
         | 
| 31 | 
            -
             | 
| 32 | 
            -
                def data_path
         | 
| 33 | 
            -
                  path_for "_data".freeze
         | 
| 34 | 
            -
                end
         | 
| 35 | 
            -
             | 
| 36 | 
            -
                def assets_path
         | 
| 37 | 
            -
                  path_for "assets".freeze
         | 
| 38 | 
            -
                end
         | 
| 39 | 
            -
             | 
| 40 | 
            -
                def configure_sass
         | 
| 41 | 
            -
                  return unless sass_path
         | 
| 42 | 
            -
                  require "sass"
         | 
| 43 | 
            -
                  Sass.load_paths << sass_path
         | 
| 44 | 
            -
                end
         | 
| 45 | 
            -
             | 
| 46 | 
            -
                private
         | 
| 47 | 
            -
             | 
| 48 | 
            -
                def path_for(folder)
         | 
| 49 | 
            -
                  path = realpath_for(folder)
         | 
| 50 | 
            -
                  path if path && File.directory?(path)
         | 
| 51 | 
            -
                end
         | 
| 52 | 
            -
             | 
| 53 | 
            -
                def realpath_for(folder)
         | 
| 54 | 
            -
                  File.realpath(Jekyll.sanitized_path(root, folder.to_s))
         | 
| 55 | 
            -
                rescue Errno::ENOENT, Errno::EACCES, Errno::ELOOP
         | 
| 56 | 
            -
                  nil
         | 
| 57 | 
            -
                end
         | 
| 58 | 
            -
             | 
| 59 | 
            -
                def gemspec
         | 
| 60 | 
            -
                  @gemspec ||= Gem::Specification.find_by_name(name)
         | 
| 61 | 
            -
                rescue Gem::LoadError
         | 
| 62 | 
            -
                  raise Jekyll::Errors::MissingDependencyException,
         | 
| 63 | 
            -
                    "The #{name} theme could not be found."
         | 
| 64 | 
            -
                end
         | 
| 65 | 
            -
              end
         | 
| 66 | 
            -
            end
         | 
| 1 | 
            +
            module Jekyll
         | 
| 2 | 
            +
              class Theme
         | 
| 3 | 
            +
                extend Forwardable
         | 
| 4 | 
            +
                attr_reader :name
         | 
| 5 | 
            +
                def_delegator :gemspec, :version, :version
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                def initialize(name)
         | 
| 8 | 
            +
                  @name = name.downcase.strip
         | 
| 9 | 
            +
                  configure_sass
         | 
| 10 | 
            +
                end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                def root
         | 
| 13 | 
            +
                  # Must use File.realpath to resolve symlinks created by rbenv
         | 
| 14 | 
            +
                  # Otherwise, Jekyll.sanitized path with prepend the unresolved root
         | 
| 15 | 
            +
                  @root ||= File.realpath(gemspec.full_gem_path)
         | 
| 16 | 
            +
                rescue Errno::ENOENT, Errno::EACCES, Errno::ELOOP
         | 
| 17 | 
            +
                  nil
         | 
| 18 | 
            +
                end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                def includes_path
         | 
| 21 | 
            +
                  path_for "_includes".freeze
         | 
| 22 | 
            +
                end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                def layouts_path
         | 
| 25 | 
            +
                  path_for "_layouts".freeze
         | 
| 26 | 
            +
                end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                def sass_path
         | 
| 29 | 
            +
                  path_for "_sass".freeze
         | 
| 30 | 
            +
                end
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                def data_path
         | 
| 33 | 
            +
                  path_for "_data".freeze
         | 
| 34 | 
            +
                end
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                def assets_path
         | 
| 37 | 
            +
                  path_for "assets".freeze
         | 
| 38 | 
            +
                end
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                def configure_sass
         | 
| 41 | 
            +
                  return unless sass_path
         | 
| 42 | 
            +
                  require "sass"
         | 
| 43 | 
            +
                  Sass.load_paths << sass_path
         | 
| 44 | 
            +
                end
         | 
| 45 | 
            +
             | 
| 46 | 
            +
                private
         | 
| 47 | 
            +
             | 
| 48 | 
            +
                def path_for(folder)
         | 
| 49 | 
            +
                  path = realpath_for(folder)
         | 
| 50 | 
            +
                  path if path && File.directory?(path)
         | 
| 51 | 
            +
                end
         | 
| 52 | 
            +
             | 
| 53 | 
            +
                def realpath_for(folder)
         | 
| 54 | 
            +
                  File.realpath(Jekyll.sanitized_path(root, folder.to_s))
         | 
| 55 | 
            +
                rescue Errno::ENOENT, Errno::EACCES, Errno::ELOOP
         | 
| 56 | 
            +
                  nil
         | 
| 57 | 
            +
                end
         | 
| 58 | 
            +
             | 
| 59 | 
            +
                def gemspec
         | 
| 60 | 
            +
                  @gemspec ||= Gem::Specification.find_by_name(name)
         | 
| 61 | 
            +
                rescue Gem::LoadError
         | 
| 62 | 
            +
                  raise Jekyll::Errors::MissingDependencyException,
         | 
| 63 | 
            +
                    "The #{name} theme could not be found."
         | 
| 64 | 
            +
                end
         | 
| 65 | 
            +
              end
         | 
| 66 | 
            +
            end
         | 
    
        data/lib/jekyll/theme_reader.rb
    CHANGED
    
    | @@ -38,7 +38,6 @@ module Jekyll | |
| 38 38 | 
             
                  end
         | 
| 39 39 | 
             
                end
         | 
| 40 40 |  | 
| 41 | 
            -
             | 
| 42 41 | 
             
                private
         | 
| 43 42 |  | 
| 44 43 | 
             
                def debug_theme_reader
         | 
| @@ -52,29 +51,45 @@ module Jekyll | |
| 52 51 | 
             
                end
         | 
| 53 52 |  | 
| 54 53 | 
             
                def debug_theme_data_reader
         | 
| 55 | 
            -
                   | 
| 56 | 
            -
                   | 
| 57 | 
            -
                  process_hash @site.data
         | 
| 54 | 
            +
                  print "Inspecting:", "Site Data >>"
         | 
| 55 | 
            +
                  inspect_hash @site.data
         | 
| 58 56 | 
             
                  print_clear_line
         | 
| 59 57 | 
             
                end
         | 
| 60 58 |  | 
| 61 | 
            -
                def  | 
| 59 | 
            +
                def inspect_hash(hash)
         | 
| 62 60 | 
             
                  hash.each do |key, value|
         | 
| 63 61 | 
             
                    print_key key
         | 
| 62 | 
            +
                    if key == @site.theme.name
         | 
| 63 | 
            +
                      inspect_theme_override value
         | 
| 64 | 
            +
                    end
         | 
| 64 65 | 
             
                    if value.class == Hash
         | 
| 65 | 
            -
                       | 
| 66 | 
            +
                      inspect_inner_hash value
         | 
| 67 | 
            +
                    elsif value.class == Array
         | 
| 68 | 
            +
                      print_label key
         | 
| 69 | 
            +
                      extract_hashes_and_print value
         | 
| 66 70 | 
             
                    else
         | 
| 67 71 | 
             
                      print_value "'#{value}'"
         | 
| 68 72 | 
             
                    end
         | 
| 69 73 | 
             
                  end
         | 
| 70 74 | 
             
                end
         | 
| 71 75 |  | 
| 72 | 
            -
                def  | 
| 76 | 
            +
                def inspect_theme_override(value)
         | 
| 77 | 
            +
                  if value == false
         | 
| 78 | 
            +
                    abort_with_msg "Cannot define or override Theme Configuration " \
         | 
| 79 | 
            +
                                   "with an empty file!"
         | 
| 80 | 
            +
                  end
         | 
| 81 | 
            +
                  unless value.class == Hash
         | 
| 82 | 
            +
                    abort_with_msg "Theme Config or its override should be a Hash of " \
         | 
| 83 | 
            +
                        "key:value pairs or mappings. But got #{value.class} instead."
         | 
| 84 | 
            +
                  end
         | 
| 85 | 
            +
                end
         | 
| 86 | 
            +
             | 
| 87 | 
            +
                def inspect_inner_hash(hash)
         | 
| 73 88 | 
             
                  hash.each do |key, value|
         | 
| 74 89 | 
             
                    if value.class == Array
         | 
| 75 90 | 
             
                      print_label key
         | 
| 76 91 | 
             
                      extract_hashes_and_print value
         | 
| 77 | 
            -
                       | 
| 92 | 
            +
                      print_clear_line
         | 
| 78 93 | 
             
                    elsif value.class == Hash
         | 
| 79 94 | 
             
                      print_subkey_and_value key, value
         | 
| 80 95 | 
             
                    else
         | 
| @@ -84,14 +99,17 @@ module Jekyll | |
| 84 99 | 
             
                end
         | 
| 85 100 |  | 
| 86 101 | 
             
                def extract_hashes_and_print(array)
         | 
| 87 | 
            -
                  array.each do | | 
| 88 | 
            -
                     | 
| 102 | 
            +
                  array.each do |entry|
         | 
| 103 | 
            +
                    if entry.class == String
         | 
| 104 | 
            +
                      print "-", entry
         | 
| 105 | 
            +
                    else
         | 
| 106 | 
            +
                      inspect_inner_hash entry
         | 
| 107 | 
            +
                    end
         | 
| 89 108 | 
             
                  end
         | 
| 90 109 | 
             
                end
         | 
| 91 110 |  | 
| 92 111 | 
             
                def print_hash(key, value)
         | 
| 93 | 
            -
                   | 
| 94 | 
            -
                  print key, value
         | 
| 112 | 
            +
                  print "#{key}:", value
         | 
| 95 113 | 
             
                end
         | 
| 96 114 |  | 
| 97 115 | 
             
                def print_key(key)
         | 
| @@ -103,7 +121,6 @@ module Jekyll | |
| 103 121 |  | 
| 104 122 | 
             
                def print_subkey_and_value(key, value)
         | 
| 105 123 | 
             
                  print_label key
         | 
| 106 | 
            -
                  print_dashes
         | 
| 107 124 | 
             
                  value.each do |subkey, val|
         | 
| 108 125 | 
             
                    print_hash subkey, val
         | 
| 109 126 | 
             
                  end
         | 
| @@ -119,7 +136,7 @@ module Jekyll | |
| 119 136 | 
             
                end
         | 
| 120 137 |  | 
| 121 138 | 
             
                def print_label(key)
         | 
| 122 | 
            -
                  print "#{key | 
| 139 | 
            +
                  print "#{key}:"
         | 
| 123 140 | 
             
                end
         | 
| 124 141 |  | 
| 125 142 | 
             
                def print_dashes
         | 
| @@ -133,5 +150,9 @@ module Jekyll | |
| 133 150 | 
             
                def print(arg1, arg2 = "")
         | 
| 134 151 | 
             
                  Jekyll.logger.debug arg1, arg2
         | 
| 135 152 | 
             
                end
         | 
| 153 | 
            +
             | 
| 154 | 
            +
                def abort_with_msg(msg)
         | 
| 155 | 
            +
                  Jekyll.logger.abort_with "JekyllData:", msg
         | 
| 156 | 
            +
                end
         | 
| 136 157 | 
             
              end
         | 
| 137 158 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: jekyll-data
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.2. | 
| 4 | 
            +
              version: 0.2.1
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Ashwin Maroli
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: exe
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2016-10- | 
| 11 | 
            +
            date: 2016-10-21 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: jekyll
         |