jekyll-conrefifier 0.4.3 → 0.5.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/.gitignore +1 -0
- data/lib/jekyll-conrefifier.rb +16 -12
- data/lib/version.rb +1 -1
- data/spec/conrefifier_spec.rb +8 -0
- data/spec/fixtures/_config.yml +5 -0
- data/spec/fixtures/_data/warnings.yml +6 -0
- data/spec/fixtures/warnings.html +5 -0
- metadata +4 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: efdff59b0efc358924f29d372fdde512b16c1280
         | 
| 4 | 
            +
              data.tar.gz: 32e3178eb7720e9e7f8371251fc057495584f386
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: ebf92a86304459d5004088293efdd19e1586a30ccc3c61680eaee9fdfc875895c84cb4d221eeba215391fa51f2b7b4c3ff14ba0235327d66d3df2308148a00e8
         | 
| 7 | 
            +
              data.tar.gz: 459315d522117b7db0d552cd053727c01f3959da75e7cfc67d792918c682096ff9c36336505c1890ee8e7cedafffd9a3abcecb5442ecdd83acc5df96b2492dc0
         | 
    
        data/.gitignore
    CHANGED
    
    
    
        data/lib/jekyll-conrefifier.rb
    CHANGED
    
    | @@ -116,11 +116,9 @@ module Jekyll | |
| 116 116 | 
             
                        ConrefifierUtils.og_paths << path.slice(dir.index(src) + src.length + 1..-1).sub(/\.[^.]+\z/, '')
         | 
| 117 117 | 
             
                        # if we hit upon if/unless conditionals, we'll need to pause and render them
         | 
| 118 118 | 
             
                        contents = File.read(path)
         | 
| 119 | 
            -
                        if (matches = contents.scan /(\{% (?:if|unless).+? %\}.*?\{% end(?:if|unless) %\})/m)
         | 
| 119 | 
            +
                        if (matches = contents.scan /(\s*\{% (?:if|unless).+? %\}.*?\{% end(?:if|unless) %\})/m)
         | 
| 120 120 | 
             
                          unless ConrefifierUtils.data_file_variables(config, path).nil?
         | 
| 121 | 
            -
                            contents = contents | 
| 122 | 
            -
                            contents = apply_vars_to_datafile(contents, matches, path)
         | 
| 123 | 
            -
                            contents = contents.gsub(/\[\[/, '{{')
         | 
| 121 | 
            +
                            contents = apply_vars_to_datafile(contents, matches, path, { preserve_all: true } )
         | 
| 124 122 | 
             
                          end
         | 
| 125 123 | 
             
                        end
         | 
| 126 124 |  | 
| @@ -139,13 +137,14 @@ module Jekyll | |
| 139 137 | 
             
                    keys = path.split('/')
         | 
| 140 138 | 
             
                    value = keys.inject(data, :fetch)
         | 
| 141 139 | 
             
                    yaml_dump = YAML::dump value
         | 
| 140 | 
            +
             | 
| 142 141 | 
             
                    keys[0...-1].inject(data, :fetch)[keys.last] = SafeYAML.load transform_liquid_variables(yaml_dump, path)
         | 
| 143 142 | 
             
                  end
         | 
| 144 143 | 
             
                  old_read_collections
         | 
| 145 144 | 
             
                end
         | 
| 146 145 |  | 
| 147 146 | 
             
                # apply the custom scope plus the rest of the `site.data` information
         | 
| 148 | 
            -
                def apply_vars_to_datafile(contents, matches, path)
         | 
| 147 | 
            +
                def apply_vars_to_datafile(contents, matches, path, preserve_all: true, preserve_non_vars: false)
         | 
| 149 148 | 
             
                  return contents if matches.empty?
         | 
| 150 149 |  | 
| 151 150 | 
             
                  data_vars = path.nil? ? {} : ConrefifierUtils.data_file_variables(config, path)
         | 
| @@ -155,16 +154,21 @@ module Jekyll | |
| 155 154 |  | 
| 156 155 | 
             
                  matches.each do |match|
         | 
| 157 156 | 
             
                    match = match.is_a?(Array) ? match.first : match
         | 
| 157 | 
            +
                    safe_match = if preserve_all
         | 
| 158 | 
            +
                                   match.gsub(/\{\{/, '[[\1')
         | 
| 159 | 
            +
                                  elsif preserve_non_vars
         | 
| 160 | 
            +
                                    match.gsub(/\{\{(\s*)(?!\s*(site|page))/, '[[\1')
         | 
| 161 | 
            +
                                  end
         | 
| 158 162 |  | 
| 159 163 | 
             
                    parsed_content = begin
         | 
| 160 | 
            -
                                      Liquid::Template.parse( | 
| 161 | 
            -
             | 
| 164 | 
            +
                                      parsed = Liquid::Template.parse(safe_match).render(config)
         | 
| 165 | 
            +
                                      parsed.gsub(/\[\[/, '{{\1') if preserve_all || preserve_non_vars
         | 
| 166 | 
            +
                                     rescue Exception => e
         | 
| 167 | 
            +
                                      puts "Parse error in #{matches}: #{e}"
         | 
| 162 168 | 
             
                                      match
         | 
| 163 169 | 
             
                                     end
         | 
| 164 | 
            -
             | 
| 165 | 
            -
                     | 
| 166 | 
            -
                      contents = contents.sub(match, parsed_content)
         | 
| 167 | 
            -
                    end
         | 
| 170 | 
            +
                    next if parsed_content.nil?
         | 
| 171 | 
            +
                    contents = contents.sub(match, parsed_content)
         | 
| 168 172 | 
             
                  end
         | 
| 169 173 | 
             
                  contents
         | 
| 170 174 | 
             
                end
         | 
| @@ -174,7 +178,7 @@ module Jekyll | |
| 174 178 | 
             
                # renders as "GitHub Glossary" for dotcom, but "GitHub Enterprise Glossary" for Enterprise
         | 
| 175 179 | 
             
                def transform_liquid_variables(contents, path = nil)
         | 
| 176 180 | 
             
                  if (matches = contents.scan /(\{\{.+?\}\})/)
         | 
| 177 | 
            -
                    contents = apply_vars_to_datafile(contents, matches, path)
         | 
| 181 | 
            +
                    contents = apply_vars_to_datafile(contents, matches, path, preserve_all: false, preserve_non_vars: true)
         | 
| 178 182 | 
             
                  end
         | 
| 179 183 |  | 
| 180 184 | 
             
                  contents
         | 
    
        data/lib/version.rb
    CHANGED
    
    
    
        data/spec/conrefifier_spec.rb
    CHANGED
    
    | @@ -64,4 +64,12 @@ describe("Conrefifier") do | |
| 64 64 | 
             
                expect(filtering_layout_contents.scan(/Article v2.0/).count).to eq(1)
         | 
| 65 65 | 
             
                expect(filtering_layout_contents.scan(/Ignored/).count).to eq(1)
         | 
| 66 66 | 
             
              end
         | 
| 67 | 
            +
             | 
| 68 | 
            +
              it 'filters items even if they have other curlies' do
         | 
| 69 | 
            +
                warnings = @dest.join("warnings.html")
         | 
| 70 | 
            +
                expect(warnings).to exist
         | 
| 71 | 
            +
                warnings_contents = File.read(warnings)
         | 
| 72 | 
            +
                expect(warnings_contents.scan(/- A dotcom Article/).count).to eq(1)
         | 
| 73 | 
            +
                expect(warnings_contents.scan(/Article v2.0/).count).to eq(0)
         | 
| 74 | 
            +
              end
         | 
| 67 75 | 
             
            end
         | 
    
        data/spec/fixtures/_config.yml
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: jekyll-conrefifier
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.5.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: 2015- | 
| 11 | 
            +
            date: 2015-09-29 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: jekyll
         | 
| @@ -79,12 +79,14 @@ files: | |
| 79 79 | 
             
            - spec/fixtures/_data/conrefs.yml
         | 
| 80 80 | 
             
            - spec/fixtures/_data/enterprise_filtered_categories.yml
         | 
| 81 81 | 
             
            - spec/fixtures/_data/filtered_categories.yml
         | 
| 82 | 
            +
            - spec/fixtures/_data/warnings.yml
         | 
| 82 83 | 
             
            - spec/fixtures/_layouts/article.html
         | 
| 83 84 | 
             
            - spec/fixtures/_layouts/filtering_layout.html
         | 
| 84 85 | 
             
            - spec/fixtures/enterprise_filtered_index.html
         | 
| 85 86 | 
             
            - spec/fixtures/filtered_index.html
         | 
| 86 87 | 
             
            - spec/fixtures/filtering_layout.html
         | 
| 87 88 | 
             
            - spec/fixtures/index.html
         | 
| 89 | 
            +
            - spec/fixtures/warnings.html
         | 
| 88 90 | 
             
            - spec/spec_helper.rb
         | 
| 89 91 | 
             
            homepage: ''
         | 
| 90 92 | 
             
            licenses:
         |