middleman-transpath 0.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 62d93b69d638c1d6e6e80c37efe5950bcb99edc0
4
+ data.tar.gz: 5e97daa8405d3a3a4a5d392b77d13258fee1094c
5
+ SHA512:
6
+ metadata.gz: 32c9f0fbc58124886d886e819cbf505efb9b41e947a801791cab08cdbc23c017cc6403a9a56db47b486ee592c376fa21dd5b8746e1692780b57bbea7cfcee489
7
+ data.tar.gz: fee39ee94882d6777344355f11d31aaaf9e1716aa1fd21c6669578ca8ce8e3a4b5e2c9ce2b1f1356e3628af0d5d8a6c31da95a5c112fb15c98704b3e70e4c640
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ # Ignore bundler lock file
2
+ /Gemfile.lock
3
+
4
+ # Ignore pkg folder
5
+ /pkg
data/Gemfile ADDED
@@ -0,0 +1,18 @@
1
+ # If you do not have OpenSSL installed, update
2
+ # the following line to use "http://" instead
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in middleman-transpath.gemspec
6
+ gemspec
7
+
8
+ group :development do
9
+ gem 'rake'
10
+ gem 'rdoc'
11
+ gem 'yard'
12
+ end
13
+
14
+ group :test do
15
+ gem 'cucumber'
16
+ gem 'aruba'
17
+ gem 'rspec'
18
+ end
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Bastien ROBERT
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # Middleman-transpath
2
+ You're using i18n for your middleman website ? This extension is for you !
3
+
4
+ ## Why ?
5
+ Translating path with middleman, or access to the same page but different locale and slug is not integrate by default in middleman-i18n.
6
+
7
+ For example, you cannot access from :
8
+
9
+ `projets/premier-projet` to `projects/first-project`
10
+
11
+ ## Solution ?
12
+ Yep, easily. Follow the steps :
13
+ - Install and configure i18n with your favorite locales ! Presize your default locale too.
14
+ - Then, generate a file named `languages.yml`, and configure how you want your languages links to be displayed. Here an example:
15
+
16
+ ```yaml
17
+ fr: "πŸ‡«πŸ‡· - FR"
18
+ en: "πŸ‡ΊπŸ‡Έ - EN"
19
+ ```
20
+
21
+ - Wow, such great, your links are displayed ! Now, let's configure paths in the next step.
22
+
23
+ ## Path configuration
24
+ Here is the most difficult part. You'll need your locales files (locales dir in the root folder). For each locale, you have to precise :
25
+ - The title title of the page (identifier)
26
+ - The title translation : in locale.titles
27
+ - Subdirectories dir in a list (URL direction)
28
+ - Subdirectories translation : in locale.paths (one by one, not a list)
29
+
30
+ ## Helper to translate the current page
31
+ Simply use the following helper to translate your current page in another language. Replace the **:fr** by the locale symbol of your choise.
32
+ ```RUBY
33
+ <%= link_translate(:fr) %>
34
+ ```
35
+
36
+ ## Contributing
37
+
38
+ 1. Fork it ( https://github.com/bastienrobert/middleman-transpath/fork )
39
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
40
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
41
+ 4. Push to the branch (`git push origin my-new-feature`)
42
+ 5. Create a new Pull Request
43
+
44
+
45
+ ## License
46
+
47
+ See LICENSE, which applies to everything in this repository.
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'cucumber/rake/task'
5
+
6
+ Cucumber::Rake::Task.new(:cucumber, 'Run features that should pass') do |t|
7
+ t.cucumber_opts = '--color --tags ~@wip --strict'
8
+ end
9
+
10
+ require 'rake/clean'
11
+
12
+ task test: ['cucumber']
13
+
14
+ task default: :test
@@ -0,0 +1,4 @@
1
+ PROJECT_ROOT_PATH = File.dirname(File.dirname(File.dirname(__FILE__)))
2
+ require 'middleman-core'
3
+ require 'middleman-core/step_definitions'
4
+ require File.join(PROJECT_ROOT_PATH, 'lib', 'middleman-transpath')
@@ -0,0 +1,38 @@
1
+ # Require core library
2
+ require 'middleman-core'
3
+
4
+ # Extension namespace
5
+ class Transpath < ::Middleman::Extension
6
+
7
+ def initialize(app, options_hash={}, &block)
8
+ super
9
+ end
10
+
11
+ helpers do
12
+ def path_translate(lang)
13
+ begin
14
+ current_page.data.dir.map { |dir| t("paths.#{dir}", locale: lang, :default => dir) + '/'}.join('')
15
+ rescue
16
+ return ''
17
+ end
18
+ end
19
+
20
+ def title_translate(lang)
21
+ t("paths.#{current_page.data.title}", locale: lang, :default => current_page.data.title)
22
+ end
23
+
24
+ def link_translate(lang)
25
+ return link_to data.languages.send(lang.to_s),
26
+ if lang === I18n.default_locale
27
+ config[:host] + '/' +
28
+ path_translate(lang) +
29
+ title_translate(lang)
30
+ else
31
+ config[:host] + '/' +
32
+ lang.to_s + '/' +
33
+ path_translate(lang) +
34
+ title_translate(lang)
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,6 @@
1
+ require "middleman-core"
2
+
3
+ Middleman::Extensions.register :transpath do
4
+ require "middleman-transpath/extension"
5
+ Transpath
6
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "middleman-transpath"
6
+ s.version = "0.0.1"
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = ["Bastien Robert"]
9
+ # s.email = ["email@example.com"]
10
+ # s.homepage = "http://example.com"
11
+ s.summary = "i18n helper for slug and current page translating"
12
+ s.description = "This helper allows you to translate your current path to the same path in another locale, with a different slug. It can be include in a partial, in the header for example ; and need a simple 2 minutes configuration."
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.require_paths = ["lib"]
18
+
19
+ # The version of middleman-core your extension depends on
20
+ s.add_runtime_dependency("middleman-core", [">= 4.2.1"])
21
+
22
+ # Additional dependencies
23
+ # s.add_runtime_dependency("gem-name", "gem-version")
24
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: middleman-transpath
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Bastien Robert
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-12-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: middleman-core
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 4.2.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 4.2.1
27
+ description: This helper allows you to translate your current path to the same path
28
+ in another locale, with a different slug. It can be include in a partial, in the
29
+ header for example ; and need a simple 2 minutes configuration.
30
+ email:
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - ".gitignore"
36
+ - Gemfile
37
+ - LICENSE
38
+ - README.md
39
+ - Rakefile
40
+ - features/support/env.rb
41
+ - lib/middleman-transpath.rb
42
+ - lib/middleman-transpath/extension.rb
43
+ - middleman-transpath.gemspec
44
+ homepage:
45
+ licenses: []
46
+ metadata: {}
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubyforge_project:
63
+ rubygems_version: 2.6.13
64
+ signing_key:
65
+ specification_version: 4
66
+ summary: i18n helper for slug and current page translating
67
+ test_files:
68
+ - features/support/env.rb