Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ exclude_patterns:
- ".*"
- Gemfile
- example/
- features/
- spec/
- lib/jekyll/locale/version.rb
2 changes: 1 addition & 1 deletion .simplecov
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
SimpleCov.start do
track_files "lib/**/*.rb"
add_filter %r!spec|version!
add_filter %r!features/|spec/|version!
end

SimpleCov.at_exit do
Expand Down
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ rvm:
- 2.4
- 2.3

env:
- TEST_SUITE=rspec
- TEST_SUITE=cucumber

branches:
only:
- master
Expand All @@ -15,7 +19,7 @@ before_script:
- chmod +x ./cc-test-reporter
- ./cc-test-reporter before-build

script: bundle exec rspec
script: bash ./script/cibuild

after_script:
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
source "https://rubygems.org"
gemspec

gem "cucumber", "~> 3.1"
gem "rspec"
gem "rubocop-jekyll"
gem "simplecov", :require => false
Expand Down
16 changes: 15 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,22 @@ branches:
environment:
matrix:
- RUBY_FOLDER_VER: "25"
TEST_SUITE : "rspec"

- RUBY_FOLDER_VER: "25"
TEST_SUITE : "cucumber"

- RUBY_FOLDER_VER: "24"
TEST_SUITE : "rspec"

- RUBY_FOLDER_VER: "24"
TEST_SUITE : "cucumber"

- RUBY_FOLDER_VER: "23"
TEST_SUITE : "rspec"

- RUBY_FOLDER_VER: "23"
TEST_SUITE : "cucumber"

install:
- SET PATH=C:\Ruby%RUBY_FOLDER_VER%\bin;%PATH%
Expand All @@ -22,7 +36,7 @@ before_test:
- bundle --version

test_script:
- bundle exec rspec
- bash ./script/cibuild

cache:
- 'vendor\bundle -> appveyor.yml,Gemfile,jekyll-locale.gemspec'
Expand Down
99 changes: 99 additions & 0 deletions features/advanced_usage.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
Feature: Advanced Usage
Heavily customized usage of `jekyll-locale`

Scenario: Advanced usage with 'manual' mode
Given I have a fixture site
And I have the following "localization" configuration:
| key | value |
| mode | manual |
| locale | en |
| locales_set | ["en", "fr"] |
| data_dir | localization |
| content_dir | _locale_contents |
And I have a "_data/localization" directory
And I have a "_data/localization/en" directory
And I have a "_data/localization/en/strings.yml" file with content:
"""
Welcome: Hello
welcome: Namasté
"""
And I have a "_data/localization/fr" directory
And I have a "_data/localization/fr/strings.yml" file with content:
"""
Welcome: Bonjour
welcome: Namasté
"""
And I have an "index.md" page with content:
"""
{{ locale.strings.Welcome }} User.
"""
And I have an "download.md" page with content:
"""
Download our {{ locale.strings.welcome }} Collections here!!
"""
And I have a "_locale_contents/fr" directory
And I have a "_locale_contents/fr/index.md" page with content:
"""
{{ locale.strings.Welcome }} User.
"""
And I have a "_locale_contents/fr/download.md" file with content:
"""
---
layout: none
permalink: /télécharger/
---

Téléchargez nos {{ locale.strings.welcome }} Collections ici !!
"""
When I run jekyll build
Then I should get a zero exit status
And the "_site" directory should exist
And I should see "Hello User" in "_site/index.html"
And I should see "Download our Namasté Collections here!!" in "_site/download.html"
And I should see "Bonjour User" in "_site/fr/index.html"
And I should see "Téléchargez nos Namasté Collections ici !!" in "_site/fr/télécharger/index.html"

Scenario: Advanced usage with 'auto' mode
Given I have a fixture site
And I have the following "localization" configuration:
| key | value |
| mode | auto |
| locale | en |
| locales_set | ["en", "fr"] |
| data_dir | localization |
| exclude_set | ["download.md"] |
And I have a "_data/localization" directory
And I have a "_data/localization/en" directory
And I have a "_data/localization/en/strings.yml" file with content:
"""
welcome: Hello
Welcome: Namasté
"""
And I have a "_data/localization/fr" directory
And I have a "_data/localization/fr/strings.yml" file with content:
"""
welcome: Bonjour
Welcome: Namasté
"""
And I have a "index.md" page with content:
"""
{{ locale.strings.welcome }} User.
"""
And I have a "download.md" page with content:
"""
Download our {{ locale.strings.Welcome }} Collections here!!
"""
And I have a "_locales/fr" directory
And I have a "_locales/fr/download.md" page with content:
"""
Download our {{ locale.strings.Welcome }} Collections here!!
"""
When I run jekyll build
Then I should get a zero exit status
And the "_site" directory should exist
And I should see "Hello User" in "_site/index.html"
And I should see "Bonjour User" in "_site/fr/index.html"
And I should see "Canonical Content" in "_site/about.html"
And I should see "Canonical Content" in "_site/fr/about.html"
And I should see "Download our Namasté Collections here!!" in "_site/download.html"
But the "_site/fr/download.html" file should not exist
30 changes: 30 additions & 0 deletions features/basic_usage.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Feature: Basic Usage
Basic usage of `jekyll-locale`

Scenario: Basic Site under 'manual' mode
Given I have a fixture site
And I have the following "localization" configuration:
| key | value |
| mode | manual |
| locale | en |
| locales_set | ["en", "fr"] |
And I have a "_locales/fr" locale content directory
And I have a "_locales/fr/index.md" locale fixture
When I run jekyll build
Then I should get a zero exit status
And the "_site" directory should exist
And I should see "Hello!" in "_site/index.html"
And I should see "Bonjour!" in "_site/fr/index.html"

Scenario: Basic Site under 'auto' mode
Given I have a fixture site
And I have the following "localization" configuration:
| key | value |
| mode | auto |
| locale | en |
| locales_set | ["en", "fr"] |
When I run jekyll build
Then I should get a zero exit status
And the "_site" directory should exist
And I should see "Hello!" in "_site/index.html"
And I should see "Bonjour!" in "_site/fr/index.html"
56 changes: 56 additions & 0 deletions features/step_definitions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# frozen_string_literal: true

Given "I have a fixture site" do
Paths.setup_sandbox
end

Given "I have a {string} directory" do |dirname|
Paths.mk_dir(dirname)
end

Given %r!I have an? "(.*?)" file with content:! do |file, text|
Paths.create_file(file, text)
end

Given %r!I have an? "(.*?)" page with content:! do |file, text|
content = <<~TEXT
---
layout: none
---

#{text}
TEXT
Paths.create_file(file, content.lstrip)
end

Given "I have a {string} locale content directory" do |dirname|
Paths.mk_locale_dir(dirname)
end

Given "I have a {string} locale fixture" do |path|
Paths.locale_fixture(path)
end

Given "I have the following {string} configuration:" do |key, table|
Paths.configure(key, table.hashes)
end

When %r!I run jekyll (.*)! do |args|
Runner.run(args)
end

Then "I should get a zero exit status" do
expect(Runner.exit_status).to eql(0)
end

Then %r!the "(.*?)" (?:file|directory) should (not )?exist! do |name, negative|
if negative.nil?
expect(Paths.path(name)).to exist
else
expect(Paths.path(name)).to_not exist
end
end

Then "I should see {string} in {string}" do |text, path|
expect(Paths.content(path)).to include(text)
end
93 changes: 93 additions & 0 deletions features/support/helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# frozen_string_literal: true

require "fileutils"
require "jekyll"

require_relative "../../lib/jekyll-locale"

module Paths
extend self

SANDBOX = File.expand_path("../../tmp/sandbox", __dir__).freeze
FIXTURE = File.expand_path("../../spec/fixtures", __dir__).freeze

def setup_sandbox
FileUtils.rm_rf(SANDBOX) if File.directory?(SANDBOX)
FileUtils.mkdir_p(SANDBOX)
FileUtils.cp_r File.join(FIXTURE, "."), SANDBOX
end

def sandbox_item(path)
@sandbox ||= {}
@sandbox[path] ||= File.join(SANDBOX, path)
end

def path(name)
name.strip.split("/")
Pathname.new(sandbox_item(name))
end

def content(path)
path = sandbox_item(path)
File.read path
end

def mk_locale_dir(dirname)
@locale_dirname = dirname
path = sandbox_item(dirname)
FileUtils.mkdir_p(path) unless File.directory?(path)
end

def mk_dir(dirname)
path = sandbox_item(dirname)
FileUtils.rm_rf(path)
FileUtils.mkdir_p(path)
end

def create_file(file, content)
File.open(sandbox_item(file), "wb") do |f|
f.puts content
end
end

def locale_fixture(path)
fixture_path = path.sub("#{@locale_dirname}/", "")
src = sandbox_item(fixture_path)
dest = sandbox_item(path)
FileUtils.cp src, dest
end

def configure(key, data)
config_file = sandbox_item("_config.yml")
config = SafeYAML.load_file(config_file)
config[key] = {}
data.each do |entry|
value = entry["value"]
value = JSON.parse(value) if value.include?("[\"")
config[key][entry["key"]] = value
end
File.open(config_file, "wb+") { |f| f.puts YAML.dump(config) }
end
end

module Runner
class << self
attr_reader :exit_status

def run(args)
Dir.chdir(Paths::SANDBOX) do
args = args.strip.split(" ")
process, output = Jekyll::Utils::Exec.run("jekyll", *args)

@exit_status = process.exitstatus
File.open(Paths.sandbox_item("output.txt"), "wb") do |f|
f.print "$ jekyll "
f.puts args.join(" ")
f.puts output
end

process
end
end
end
end
4 changes: 4 additions & 0 deletions script/cibuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

set -e
bundle exec $TEST_SUITE