jekyll_search 0.0.4 → 0.0.5
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 +4 -0
 - data/lib/jekyll_search/html_processor.rb +17 -1
 - data/lib/jekyll_search/version.rb +1 -1
 - data/spec/lib/jekyll_search/html_processor_spec.rb +17 -3
 - metadata +3 -3
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: b9f5a6e19df158ca78f8a482e24ed2c8e119863e
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 72cb71a8338ef6ca12dd5a0f646b9b19dabdba69
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 6993e0271bcb0b4eb10cd73ca0b7c7fb49fffda454c747bca26fa62bde403b17acaa41644c7ce2991eca7b393ad9c039f3c74b1fbe72086e259e2553ecca7f94
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 752b3aeedfb31a8881f694ec899bc6746bf60102b04b43f7903a748e8b181be0fc2dfd0415df932506eff57afb84759aa7f47073be4e9fd29169ce52dc1eb1a9
         
     | 
    
        data/README.md
    CHANGED
    
    | 
         @@ -4,6 +4,10 @@ 
     | 
|
| 
       4 
4 
     | 
    
         
             
            [](https://rubygems.org/gems/jekyll_search)
         
     | 
| 
       5 
5 
     | 
    
         
             
            [](http://opensource.org/licenses/MIT)
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
      
 7 
     | 
    
         
            +
            ## Live demo
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
            See it in action on my [blog](http://choffmeister.de/search.html).
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
       7 
11 
     | 
    
         
             
            ## Installation
         
     | 
| 
       8 
12 
     | 
    
         | 
| 
       9 
13 
     | 
    
         
             
            Add this line to your application's Gemfile:
         
     | 
| 
         @@ -26,7 +26,7 @@ module JekyllSearch 
     | 
|
| 
       26 
26 
     | 
    
         
             
                    if node.name =~ /^h\d$/
         
     | 
| 
       27 
27 
     | 
    
         
             
                      result << current
         
     | 
| 
       28 
28 
     | 
    
         
             
                      current = { :id => nil, :title => nil, :content => '' }
         
     | 
| 
       29 
     | 
    
         
            -
                      current[:id] =  
     | 
| 
      
 29 
     | 
    
         
            +
                      current[:id] = extract_headline_id(node)
         
     | 
| 
       30 
30 
     | 
    
         
             
                      current[:title] = node.text
         
     | 
| 
       31 
31 
     | 
    
         
             
                    else
         
     | 
| 
       32 
32 
     | 
    
         
             
                      current[:content] += node.to_html
         
     | 
| 
         @@ -38,5 +38,21 @@ module JekyllSearch 
     | 
|
| 
       38 
38 
     | 
    
         | 
| 
       39 
39 
     | 
    
         
             
                  result
         
     | 
| 
       40 
40 
     | 
    
         
             
                end
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
      
 42 
     | 
    
         
            +
                def self.extract_headline_id(node)
         
     | 
| 
      
 43 
     | 
    
         
            +
                  if node.has_attribute?('id')
         
     | 
| 
      
 44 
     | 
    
         
            +
                    node.attribute('id').value
         
     | 
| 
      
 45 
     | 
    
         
            +
                  else
         
     | 
| 
      
 46 
     | 
    
         
            +
                    children = []
         
     | 
| 
      
 47 
     | 
    
         
            +
                    node.traverse { |n| children << n }
         
     | 
| 
      
 48 
     | 
    
         
            +
                    children_with_id = children.select { |n| n['id'] }
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
                    if children_with_id.count == 1
         
     | 
| 
      
 51 
     | 
    
         
            +
                      children_with_id.first['id']
         
     | 
| 
      
 52 
     | 
    
         
            +
                    else
         
     | 
| 
      
 53 
     | 
    
         
            +
                      nil
         
     | 
| 
      
 54 
     | 
    
         
            +
                    end
         
     | 
| 
      
 55 
     | 
    
         
            +
                  end
         
     | 
| 
      
 56 
     | 
    
         
            +
                end
         
     | 
| 
       41 
57 
     | 
    
         
             
              end
         
     | 
| 
       42 
58 
     | 
    
         
             
            end
         
     | 
| 
         @@ -8,16 +8,30 @@ RSpec.describe JekyllSearch::HtmlProcessor do 
     | 
|
| 
       8 
8 
     | 
    
         | 
| 
       9 
9 
     | 
    
         
             
              it 'detects sections' do
         
     | 
| 
       10 
10 
     | 
    
         
             
                expect(JekyllSearch::HtmlProcessor.detect_sections('test')).to eq [
         
     | 
| 
       11 
     | 
    
         
            -
                    { :id => nil, :title => nil, :content => 'test'}
         
     | 
| 
      
 11 
     | 
    
         
            +
                    { :id => nil, :title => nil, :content => 'test' }
         
     | 
| 
      
 12 
     | 
    
         
            +
                ]
         
     | 
| 
      
 13 
     | 
    
         
            +
              end
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
              it 'detects sections' do
         
     | 
| 
      
 16 
     | 
    
         
            +
                expect(JekyllSearch::HtmlProcessor.detect_sections('<h1>foo</h1>test')).to eq [
         
     | 
| 
      
 17 
     | 
    
         
            +
                    { :id => nil, :title => nil, :content => '' },
         
     | 
| 
      
 18 
     | 
    
         
            +
                    { :id => nil, :title => 'foo', :content => 'test' }
         
     | 
| 
       12 
19 
     | 
    
         
             
                ]
         
     | 
| 
       13 
20 
     | 
    
         
             
              end
         
     | 
| 
       14 
21 
     | 
    
         | 
| 
       15 
22 
     | 
    
         
             
              it 'detects sections' do
         
     | 
| 
       16 
23 
     | 
    
         
             
                expect(JekyllSearch::HtmlProcessor.detect_sections("foo<h1>first</h1>bar <p>\npara\n</p>\n\n<H4 ID=\"sec\">sec<span>ond</span></H4>apple<h2>third</h2>")).to eq [
         
     | 
| 
       17 
     | 
    
         
            -
                    { :id => nil, :title => nil, :content => "foo"},
         
     | 
| 
       18 
     | 
    
         
            -
                    { :id => nil, :title => 'first', :content => "bar <p>\npara\n</p>\n\n"},
         
     | 
| 
      
 24 
     | 
    
         
            +
                    { :id => nil, :title => nil, :content => "foo" },
         
     | 
| 
      
 25 
     | 
    
         
            +
                    { :id => nil, :title => 'first', :content => "bar <p>\npara\n</p>\n\n" },
         
     | 
| 
       19 
26 
     | 
    
         
             
                    { :id => 'sec', :title => 'second', :content => "apple" },
         
     | 
| 
       20 
27 
     | 
    
         
             
                    { :id => nil, :title => 'third', :content => '' }
         
     | 
| 
       21 
28 
     | 
    
         
             
                ]
         
     | 
| 
       22 
29 
     | 
    
         
             
              end
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
              it 'detects sections' do
         
     | 
| 
      
 32 
     | 
    
         
            +
                expect(JekyllSearch::HtmlProcessor.detect_sections("<h1>foo<div id=\"inner-id\"></div></h1>bar")).to eq [
         
     | 
| 
      
 33 
     | 
    
         
            +
                    { :id => nil, :title => nil, :content => '' },
         
     | 
| 
      
 34 
     | 
    
         
            +
                    { :id => 'inner-id', :title => 'foo', :content => 'bar' }
         
     | 
| 
      
 35 
     | 
    
         
            +
                ]
         
     | 
| 
      
 36 
     | 
    
         
            +
              end
         
     | 
| 
       23 
37 
     | 
    
         
             
            end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: jekyll_search
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.0.5
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Christian Hoffmeister
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2015- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2015-03-10 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: bundler
         
     | 
| 
         @@ -134,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       134 
134 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       135 
135 
     | 
    
         
             
            requirements: []
         
     | 
| 
       136 
136 
     | 
    
         
             
            rubyforge_project: 
         
     | 
| 
       137 
     | 
    
         
            -
            rubygems_version: 2. 
     | 
| 
      
 137 
     | 
    
         
            +
            rubygems_version: 2.4.6
         
     | 
| 
       138 
138 
     | 
    
         
             
            signing_key: 
         
     | 
| 
       139 
139 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       140 
140 
     | 
    
         
             
            summary: An Elasticsearch full text search index generator for Jekyll.
         
     |