Skip to content
This repository has been archived by the owner on Mar 21, 2018. It is now read-only.

Commit

Permalink
Merge b083da0 into e079b44
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelastic committed Jan 7, 2016
2 parents e079b44 + b083da0 commit be547e6
Show file tree
Hide file tree
Showing 58 changed files with 518 additions and 220 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Gemfile.lock
pkg/
coverage/
gemfiles/*.lock
spec/fixtures/*/_site


.DS_Store
Expand Down
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
language: ruby
cache: bundler
gemfile:
- gemfiles/jekyll_v2.gemfile
- gemfiles/jekyll_v3.gemfile
before_script: bundle update
script: ./scripts/test_ci
rvm:
- 2.2
- 2.1
Expand Down
8 changes: 8 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
appraise 'jekyll-v2' do
gem 'jekyll', '~> 2.5'
end

appraise 'jekyll-v3' do
gem 'jekyll', '~> 3.0'
gem 'jekyll-paginate', '~> 1.1.0'
end
13 changes: 11 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,17 @@ for collaboration. The workflow is as follow:

# Development workflow

After the necessary `bundle install`, you can simply launch `guard` to start the
test suite in watch mode (perfect for TDD).
After the necessary `bundle install`, you'll also need to run `appraisal
install`. This will configure the repository so that tests can be run both from
Jekyll 2.5 and Jekyll 3.

You can then launch:
- `./scripts/test_v2` to launch tests on Jekyll v2
- `./scripts/test_v3` to launch tests on Jekyll v3
- `./scripts/test` to launch tests on both
- `./scripts/watch` to start a test watcher (for TDD) for Jekyll v2
- `./scripts/watch_v3` to start a test watcher (for TDD) for Jekyll v3 (you
cannot run both at the same time)

If you want to test the plugin on an existing Jekyll website while developping,
I suggest updating the website `Gemfile` to point to the correct local directory
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
source 'http://rubygems.org'

gem 'algoliasearch', '~> 1.4'
gem 'appraisal', '~> 2.1.0'
gem 'awesome_print', '~> 1.6'
gem 'json', '~> 1.8'
gem 'nokogiri', '~> 1.6'
Expand All @@ -10,7 +11,6 @@ group :development do
gem 'flay', '~> 2.6'
gem 'flog', '~> 4.3'
gem 'guard-rspec', '~> 4.6'
gem 'jekyll', '~> 2.5' # Jekyll custom commands only available from 2.5
gem 'jeweler', '~> 2.0'
gem 'rspec', '~> 3.0'
gem 'rubocop', '~> 0.31'
Expand Down
18 changes: 14 additions & 4 deletions Guardfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
guard :rspec, cmd: 'bundle exec rspec --color --format documentation' do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { 'spec' }
group :jekyll_v3 do
guard :rspec, cmd: 'appraisal jekyll-v3 bundle exec rspec --color --format documentation' do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { 'spec' }
end
end

group :jekyll_v2 do
guard :rspec, cmd: 'appraisal jekyll-v2 bundle exec rspec --color --format documentation' do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { 'spec' }
end
end

notification :off
21 changes: 21 additions & 0 deletions gemfiles/jekyll_v2.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# This file was generated by Appraisal

source "http://rubygems.org"

gem "algoliasearch", "~> 1.4"
gem "appraisal", "~> 2.1.0"
gem "awesome_print", "~> 1.6"
gem "json", "~> 1.8"
gem "nokogiri", "~> 1.6"
gem "jekyll", "~> 2.5"

group :development do
gem "coveralls", "~> 0.8"
gem "flay", "~> 2.6"
gem "flog", "~> 4.3"
gem "guard-rspec", "~> 4.6"
gem "jeweler", "~> 2.0"
gem "rspec", "~> 3.0"
gem "rubocop", "~> 0.31"
gem "simplecov", "~> 0.10"
end
22 changes: 22 additions & 0 deletions gemfiles/jekyll_v3.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# This file was generated by Appraisal

source "http://rubygems.org"

gem "algoliasearch", "~> 1.4"
gem "appraisal", "~> 2.1.0"
gem "awesome_print", "~> 1.6"
gem "json", "~> 1.8"
gem "nokogiri", "~> 1.6"
gem "jekyll", "~> 3.0"
gem "jekyll-paginate", "~> 1.1.0"

group :development do
gem "coveralls", "~> 0.8"
gem "flay", "~> 2.6"
gem "flog", "~> 4.3"
gem "guard-rspec", "~> 4.6"
gem "jeweler", "~> 2.0"
gem "rspec", "~> 3.0"
gem "rubocop", "~> 0.31"
gem "simplecov", "~> 0.10"
end
42 changes: 30 additions & 12 deletions lib/record_extractor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

# Given an HTML file as input, will return an array of records to index
class AlgoliaSearchRecordExtractor
attr_reader :file

def initialize(file)
@file = file
@config = file.site.config
Expand Down Expand Up @@ -31,26 +33,42 @@ def metadata
metadata[:type] = @file.class.name.split('::')[1].downcase
metadata[:url] = @file.url

if @file.respond_to? :slug
metadata[:slug] = @file.slug
else
basename = File.basename(@file.path)
extname = File.extname(basename)
metadata[:slug] = File.basename(basename, extname)
end
metadata[:slug] = slug

metadata[:posted_at] = @file.date.to_time.to_i if @file.respond_to? :date
metadata[:tags] = tags if @file.respond_to? :tags
metadata[:tags] = tags

metadata
end

# Returns the slug of the document
def slug
# Jekyll v3 has it in data
return @file.data['slug'] if @file.data.key?('slug')
# Old Jekyll v2 has it at the root
return @file.slug if @file.respond_to? :slug
# Otherwise, we guess it from the filename
basename = File.basename(@file.path)
extname = File.extname(basename)
File.basename(basename, extname)
end

# Extract a list of tags
def tags
return nil unless @file.respond_to? :tags
# Some plugins will extend the tags from simple strings to full featured
# objects. We'll simply call .to_s to always have a string
@file.tags.map(&:to_s)
tags = nil

# Jekyll v3 has it in data, while v2 have it at the root
if @file.data.key?('tags')
tags = @file.data['tags']
elsif @file.respond_to? :tags
tags = @file.tags
end

return tags if tags.nil?

# Anyway, we force cast it to string as some plugins will extend the tags to
# full featured objects
tags.map(&:to_s)
end

# Get the list of all HTML nodes to index
Expand Down
2 changes: 1 addition & 1 deletion scripts/git_hooks/pre-push
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

rake spec || exit 1
./scripts/test || exit 1

# No over-complex methods
./scripts/check_flog || exit 1
Expand Down
4 changes: 4 additions & 0 deletions scripts/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
cd "$(dirname "$BASH_SOURCE")"

./test_v2 && ./test_v3
7 changes: 7 additions & 0 deletions scripts/test_ci
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
# This script will be started by Travis, in the correct context (matrix of Ruby
# version + Gemfile version), so it only needs to load the tests, without
# worrying about appraisal
cd "$(dirname "$BASH_SOURCE")"/..

bundle exec rspec
5 changes: 5 additions & 0 deletions scripts/test_v2
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
cd "$(dirname "$BASH_SOURCE")"/..

echo "Testing under Jekyll 2.5"
appraisal jekyll-v2 bundle exec rspec
6 changes: 6 additions & 0 deletions scripts/test_v3
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash
cd "$(dirname "$BASH_SOURCE")"/..

echo "Testing under Jekyll 3.0"
appraisal jekyll-v3 bundle exec rspec

1 change: 1 addition & 0 deletions scripts/watch
4 changes: 4 additions & 0 deletions scripts/watch_v2
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
cd "$(dirname "$BASH_SOURCE")"/..

guard -g jekyll_v2
4 changes: 4 additions & 0 deletions scripts/watch_v3
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
cd "$(dirname "$BASH_SOURCE")"/..

guard -g jekyll_v3
2 changes: 1 addition & 1 deletion spec/credential_checker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe(AlgoliaSearchCredentialChecker) do
let(:config) do
{
'source' => File.expand_path('./spec/fixtures'),
'source' => fixture_path,
'markdown_ext' => 'md,mkd',
'algolia' => {
'application_id' => 'APPID',
Expand Down
26 changes: 0 additions & 26 deletions spec/fixtures/_site/2015/07/02/test-post.html

This file was deleted.

3 changes: 0 additions & 3 deletions spec/fixtures/_site/2015/07/03/test-post-again.html

This file was deleted.

31 changes: 0 additions & 31 deletions spec/fixtures/_site/about.html

This file was deleted.

31 changes: 0 additions & 31 deletions spec/fixtures/_site/hierarchy.html

This file was deleted.

17 changes: 0 additions & 17 deletions spec/fixtures/_site/index.html

This file was deleted.

Loading

0 comments on commit be547e6

Please sign in to comment.