dragoman 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 +7 -0
- data/.gitignore +17 -0
- data/.rspec +1 -0
- data/Appraisals +17 -0
- data/Gemfile +5 -0
- data/Guardfile +79 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/dragoman.gemspec +22 -0
- data/gemfiles/rails_3.2.gemfile +8 -0
- data/gemfiles/rails_4.2.gemfile +8 -0
- data/lib/dragoman/mapper.rb +56 -0
- data/lib/dragoman/mapper_rails3.rb +39 -0
- data/lib/dragoman/mapper_rails4.rb +21 -0
- data/lib/dragoman/railtie.rb +13 -0
- data/lib/dragoman/translation_visitor.rb +14 -0
- data/lib/dragoman/translator.rb +12 -0
- data/lib/dragoman/url_helpers.rb +19 -0
- data/lib/dragoman/version.rb +3 -0
- data/lib/dragoman.rb +21 -0
- data/spec/dragoman_spec.rb +12 -0
- data/spec/fake_app.rb +26 -0
- data/spec/fixtures/config/routes.rb +17 -0
- data/spec/fixtures/locales/routes.yml +13 -0
- data/spec/minimal_spec_helper.rb +5 -0
- data/spec/routing/routes_spec.rb +76 -0
- data/spec/spec_helper.rb +26 -0
- metadata +107 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 127dbccea787a7238a460c76d61ee6b0fcc90c9f
|
4
|
+
data.tar.gz: 0e75c1d8df90190e98f30f88364ea39d42e47803
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4f23021dd1c0377525fb59ef808df8ba0ad8e958eab803231c7c0fc8b14f082dcfdca8ed21d92783557d1d4aae4d53f6d5ca9c9b6b9858362038de2484bb774e
|
7
|
+
data.tar.gz: 6a6507b47d6dfde740485eebdf91085c36209c8c237d2abe67ae3283d6801dac83ac9f8fd6e532eff5a7ad3f74ee6a996f68d83befdcf689b20c3098b69440c3
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Appraisals
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
appraise "rails-3.2" do
|
2
|
+
gem "rails", "~> 3.2.0"
|
3
|
+
end
|
4
|
+
|
5
|
+
|
6
|
+
appraise "rails-4.2" do
|
7
|
+
gem "rails", "~> 4.2.0"
|
8
|
+
end
|
9
|
+
|
10
|
+
# DOES NOT WORK FOR 4.0 en 4.1
|
11
|
+
# appraise "rails-4.0" do
|
12
|
+
# gem "rails", "~> 4.0.0"
|
13
|
+
# end
|
14
|
+
|
15
|
+
# appraise "rails-4.1" do
|
16
|
+
# gem "rails", "~> 4.1.0"
|
17
|
+
# end
|
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
## Uncomment and set this to only include directories you want to watch
|
5
|
+
# directories %w(app lib config test spec features)
|
6
|
+
|
7
|
+
## Uncomment to clear the screen before every task
|
8
|
+
clearing :on
|
9
|
+
|
10
|
+
## Guard internally checks for changes in the Guardfile and exits.
|
11
|
+
## If you want Guard to automatically start up again, run guard in a
|
12
|
+
## shell loop, e.g.:
|
13
|
+
##
|
14
|
+
## $ while bundle exec guard; do echo "Restarting Guard..."; done
|
15
|
+
##
|
16
|
+
## Note: if you are using the `directories` clause above and you are not
|
17
|
+
## watching the project directory ('.'), then you will want to move
|
18
|
+
## the Guardfile to a watched dir and symlink it back, e.g.
|
19
|
+
#
|
20
|
+
# $ mkdir config
|
21
|
+
# $ mv Guardfile config/
|
22
|
+
# $ ln -s config/Guardfile .
|
23
|
+
#
|
24
|
+
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"
|
25
|
+
|
26
|
+
# Note: The cmd option is now required due to the increasing number of ways
|
27
|
+
# rspec may be run, below are examples of the most common uses.
|
28
|
+
# * bundler: 'bundle exec rspec'
|
29
|
+
# * bundler binstubs: 'bin/rspec'
|
30
|
+
# * spring: 'bin/rspec' (This will use spring if running and you have
|
31
|
+
# installed the spring binstubs per the docs)
|
32
|
+
# * zeus: 'zeus rspec' (requires the server to be started separately)
|
33
|
+
# * 'just' rspec: 'rspec'
|
34
|
+
|
35
|
+
guard :rspec, cmd: "bundle exec rspec" do
|
36
|
+
require "guard/rspec/dsl"
|
37
|
+
dsl = Guard::RSpec::Dsl.new(self)
|
38
|
+
|
39
|
+
# Feel free to open issues for suggestions and improvements
|
40
|
+
|
41
|
+
# RSpec files
|
42
|
+
rspec = dsl.rspec
|
43
|
+
watch(%r(^spec/.*spec_helper\.rb$)) { rspec.spec_dir }
|
44
|
+
watch(rspec.spec_support) { rspec.spec_dir }
|
45
|
+
watch(rspec.spec_files)
|
46
|
+
watch(%r(^spec/fixtures/)) { rspec.spec_dir}
|
47
|
+
|
48
|
+
# Ruby files
|
49
|
+
ruby = dsl.ruby
|
50
|
+
dsl.watch_spec_files_for(ruby.lib_files)
|
51
|
+
watch(%r(^lib/.*\.rb$)) { rspec.spec_dir}
|
52
|
+
|
53
|
+
# Rails files
|
54
|
+
# rails = dsl.rails(view_extensions: %w(erb haml slim))
|
55
|
+
# dsl.watch_spec_files_for(rails.app_files)
|
56
|
+
# dsl.watch_spec_files_for(rails.views)
|
57
|
+
|
58
|
+
# watch(rails.controllers) do |m|
|
59
|
+
# [
|
60
|
+
# rspec.spec.("routing/#{m[1]}_routing"),
|
61
|
+
# rspec.spec.("controllers/#{m[1]}_controller"),
|
62
|
+
# rspec.spec.("acceptance/#{m[1]}")
|
63
|
+
# ]
|
64
|
+
# end
|
65
|
+
|
66
|
+
# Rails config changes
|
67
|
+
# watch(rails.spec_helper) { rspec.spec_dir }
|
68
|
+
# watch(rails.routes) { "#{rspec.spec_dir}/routing" }
|
69
|
+
# watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
|
70
|
+
|
71
|
+
# # Capybara features specs
|
72
|
+
# watch(rails.view_dirs) { |m| rspec.spec.("features/#{m[1]}") }
|
73
|
+
|
74
|
+
# # Turnip features and steps
|
75
|
+
# watch(%r{^spec/acceptance/(.+)\.feature$})
|
76
|
+
# watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
|
77
|
+
# Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
|
78
|
+
# end
|
79
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Pieter Visser
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Dragoman
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'dragoman'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install dragoman
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( http://github.com/<my-github-username>/dragoman/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/dragoman.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'dragoman/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "dragoman"
|
8
|
+
spec.version = Dragoman::VERSION
|
9
|
+
spec.authors = ["Pieter Visser", "Robert Jan de Gelder"]
|
10
|
+
spec.email = ["info@greenonline.nl"]
|
11
|
+
spec.summary = %q{Simple Rails Routes Translator}
|
12
|
+
spec.homepage = "http://github.com/pietervisser/dragoman"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency("rspec-rails")
|
21
|
+
spec.add_development_dependency("guard-rspec")
|
22
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Dragoman
|
2
|
+
module Mapper
|
3
|
+
|
4
|
+
module Mapping
|
5
|
+
def build_with_localization scope, set, path, as, options
|
6
|
+
if options[:locale]
|
7
|
+
Dragoman::UrlHelpers.add_untranslated_helpers as, set.named_routes.path_helpers_module, set.named_routes.url_helpers_module if as
|
8
|
+
as = "#{as}_#{options[:locale]}" if as.present?
|
9
|
+
as = nil if as && set.named_routes.routes[as.to_sym] # TODO: why do we need to set as to nil?
|
10
|
+
end
|
11
|
+
build_without_localization scope, set, path, as, options
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def localize
|
18
|
+
@current_locale = nil
|
19
|
+
locales = I18n.available_locales
|
20
|
+
locales.each do |locale|
|
21
|
+
@current_locale = locale
|
22
|
+
yield
|
23
|
+
end
|
24
|
+
@current_locale = nil
|
25
|
+
end
|
26
|
+
|
27
|
+
def add_route_with_localization(action, options)
|
28
|
+
if @current_locale
|
29
|
+
options[:path] = Dragoman::Translator.translate_path(action, @current_locale) unless canonical_action?(action)
|
30
|
+
options[:locale] = @current_locale
|
31
|
+
end
|
32
|
+
add_route_without_localization action, options
|
33
|
+
end
|
34
|
+
|
35
|
+
def scope_with_localization(*args, &block)
|
36
|
+
if @current_locale
|
37
|
+
options = args.extract_options!.dup
|
38
|
+
if options[:path] || args.any?
|
39
|
+
options[:path] = Dragoman::Translator.translate_path(options[:path] || args.flatten.join('/'), @current_locale)
|
40
|
+
end
|
41
|
+
scope_without_localization options, &block
|
42
|
+
else
|
43
|
+
scope_without_localization *args, &block
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def resources_with_localization(*resources, &block)
|
48
|
+
options = resources.extract_options!.dup
|
49
|
+
if @current_locale
|
50
|
+
options[:path] = Dragoman::Translator.translate_path(resources.last, @current_locale)
|
51
|
+
end
|
52
|
+
resources_without_localization(*resources, options, &block)
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Dragoman
|
2
|
+
|
3
|
+
module MapperRails3
|
4
|
+
include Mapper
|
5
|
+
|
6
|
+
def self.included(base)
|
7
|
+
base.send :alias_method_chain, :add_route, :localization
|
8
|
+
base.send :alias_method_chain, :scope, :localization
|
9
|
+
|
10
|
+
base.send :alias_method_chain, :resources, :localization
|
11
|
+
|
12
|
+
base::Mapping.send :include, MappingRails3
|
13
|
+
end
|
14
|
+
|
15
|
+
module MappingRails3
|
16
|
+
def self.included(base)
|
17
|
+
base.send :alias_method_chain, :to_route, :localization
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_route_with_localization
|
21
|
+
if @options[:locale]
|
22
|
+
Dragoman::UrlHelpers.add_untranslated_helpers @options[:as], @set.named_routes.module, @set.named_routes.module if @options[:as]
|
23
|
+
@options[:as] = "#{@options[:as]}_#{@options[:locale]}" if @options[:as].present?
|
24
|
+
@options[:as] = nil if @options[:as] && @set.named_routes.routes[@options[:as].to_sym] # TODO: why do we need to set as to nil?
|
25
|
+
end
|
26
|
+
to_route_without_localization
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def add_route_with_localization(action, options)
|
31
|
+
if @current_locale
|
32
|
+
options[:path] = Dragoman::Translator.translate_path(action, @current_locale) unless canonical_action?(action, true)
|
33
|
+
options[:locale] = @current_locale
|
34
|
+
end
|
35
|
+
add_route_without_localization action, options
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Dragoman
|
2
|
+
module MapperRails4
|
3
|
+
|
4
|
+
include Mapper
|
5
|
+
|
6
|
+
def self.included(base)
|
7
|
+
base.send :alias_method_chain, :add_route, :localization
|
8
|
+
base.send :alias_method_chain, :scope, :localization
|
9
|
+
|
10
|
+
base.send :alias_method_chain, :resources, :localization
|
11
|
+
|
12
|
+
base::Mapping.extend Mapping
|
13
|
+
base::Mapping.class_eval do
|
14
|
+
class << self
|
15
|
+
alias_method_chain :build, :localization
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Dragoman
|
2
|
+
|
3
|
+
class Railtie < Rails::Railtie
|
4
|
+
initializer 'dragoman.insert_into_routing_mapper' do |app|
|
5
|
+
if Rails::VERSION::MAJOR >= 4
|
6
|
+
ActionDispatch::Routing::Mapper.send :include, Dragoman::MapperRails4
|
7
|
+
else
|
8
|
+
ActionDispatch::Routing::Mapper.send :include, Dragoman::MapperRails3
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Dragoman
|
2
|
+
class TranslationVisitor < Dragoman::Journey::Visitors::String
|
3
|
+
|
4
|
+
def initialize locale
|
5
|
+
@locale = locale
|
6
|
+
super()
|
7
|
+
end
|
8
|
+
|
9
|
+
def visit_LITERAL node
|
10
|
+
I18n.t node, scope: :routes, default: node.to_s, locale: @locale
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Dragoman
|
2
|
+
class UrlHelpers
|
3
|
+
|
4
|
+
def self.add_untranslated_helpers name, path_module, url_module
|
5
|
+
path_module.send :define_method, "#{name}_path" do |*args|
|
6
|
+
__send__(Dragoman::UrlHelpers.localized_helper_name(name, :path), *args)
|
7
|
+
end
|
8
|
+
url_module.send :define_method, "#{name}_url" do |*args|
|
9
|
+
__send__(Dragoman::UrlHelpers.localized_helper_name(name, :url), *args)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.localized_helper_name name, url_helper_type
|
14
|
+
locale = I18n.locale
|
15
|
+
"#{name}_#{locale}_#{url_helper_type}"
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
data/lib/dragoman.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
module Dragoman
|
2
|
+
Journey = if Rails::VERSION::MAJOR >= 4
|
3
|
+
ActionDispatch::Journey
|
4
|
+
else
|
5
|
+
require 'journey'
|
6
|
+
Journey
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
require "dragoman/translator"
|
11
|
+
require "dragoman/translation_visitor"
|
12
|
+
require "dragoman/url_helpers"
|
13
|
+
require "dragoman/mapper"
|
14
|
+
require "dragoman/railtie" if defined?(Rails)
|
15
|
+
require "dragoman/version"
|
16
|
+
|
17
|
+
if Rails::VERSION::MAJOR >= 4
|
18
|
+
require "dragoman/mapper_rails4"
|
19
|
+
else
|
20
|
+
require "dragoman/mapper_rails3"
|
21
|
+
end
|
data/spec/fake_app.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
class ApplicationController < ActionController::Base
|
2
|
+
protect_from_forgery
|
3
|
+
end
|
4
|
+
|
5
|
+
module Dummy
|
6
|
+
|
7
|
+
def self.rails4?
|
8
|
+
Rails::VERSION::MAJOR >= 4
|
9
|
+
end
|
10
|
+
|
11
|
+
class Application < Rails::Application
|
12
|
+
config.secret_key_base = "test"
|
13
|
+
config.paths["public"] = ["spec/fixtures/public"]
|
14
|
+
config.paths["config/locales"] = ["spec/fixtures/locales/routes.yml"]
|
15
|
+
config.eager_load = false
|
16
|
+
|
17
|
+
if Dummy.rails4?
|
18
|
+
config.paths["config/routes.rb"] = ["spec/fixtures/config/routes.rb"]
|
19
|
+
else
|
20
|
+
config.paths["config/routes"] = ["spec/fixtures/config/routes.rb"]
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
Dummy::Application.initialize!
|
@@ -0,0 +1,17 @@
|
|
1
|
+
Dummy::Application.routes.draw do
|
2
|
+
get 'comments' => 'application#index'
|
3
|
+
|
4
|
+
localize do
|
5
|
+
namespace 'admin' do
|
6
|
+
get 'customers' => 'application#index'
|
7
|
+
end
|
8
|
+
|
9
|
+
scope 'secret' do
|
10
|
+
get 'payments' => 'application#index'
|
11
|
+
end
|
12
|
+
|
13
|
+
resources :products
|
14
|
+
resource :account
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class ProductsController < ApplicationController
|
4
|
+
end
|
5
|
+
|
6
|
+
describe 'routes' do
|
7
|
+
|
8
|
+
context "unlocalized routes" do
|
9
|
+
it 'does not change routes' do
|
10
|
+
expect(comments_path).to eq '/comments'
|
11
|
+
expect(Rails.application.routes.url_helpers.respond_to? :comments_nl_path).to eq false
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'translates resources' do
|
16
|
+
expect(products_en_path).to eq '/products'
|
17
|
+
expect(new_product_en_path).to eq '/products/new'
|
18
|
+
expect(edit_product_en_path(1)).to eq '/products/1/edit'
|
19
|
+
expect(products_nl_path).to eq '/producten'
|
20
|
+
expect(new_product_nl_path).to eq '/producten/nieuw'
|
21
|
+
expect(edit_product_nl_path(1)).to eq '/producten/1/wijzigen'
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'translates resource' do
|
25
|
+
expect(account_en_path).to eq '/account'
|
26
|
+
expect(edit_account_en_path).to eq '/account/edit'
|
27
|
+
expect(new_account_en_path).to eq '/account/new'
|
28
|
+
expect(account_nl_path).to eq '/profiel'
|
29
|
+
expect(edit_account_nl_path).to eq '/profiel/wijzigen'
|
30
|
+
expect(new_account_nl_path).to eq '/profiel/nieuw'
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'translates namespaced routes' do
|
34
|
+
expect(admin_customers_nl_path).to eq '/beheer/klanten'
|
35
|
+
expect(admin_customers_en_path).to eq '/admin/customers'
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'translates scoped routes' do
|
39
|
+
expect(payments_nl_path).to eq '/geheim/betalingen'
|
40
|
+
expect(payments_en_path).to eq '/secret/payments'
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'sets the correct locale' do
|
44
|
+
assert_routing '/producten', :controller => 'products', :action => 'index', :locale => :nl
|
45
|
+
assert_routing '/products', :controller => 'products', :action => 'index', :locale => :en
|
46
|
+
end
|
47
|
+
|
48
|
+
describe 'adds untranslated path helpers' do
|
49
|
+
it 'uses the I18n locale' do
|
50
|
+
I18n.locale = :nl
|
51
|
+
expect(payments_path).to eq '/geheim/betalingen'
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe 'adds untranslated url helpers' do
|
56
|
+
it 'uses the I18n locale' do
|
57
|
+
print_routes
|
58
|
+
I18n.locale = :nl
|
59
|
+
expect(payments_url).to eq 'http://example.com/geheim/betalingen'
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
def print_routes
|
66
|
+
all_routes = Rails.application.routes.routes
|
67
|
+
if Rails::VERSION::MAJOR >= 4
|
68
|
+
require 'action_dispatch/routing/inspector'
|
69
|
+
inspector = ActionDispatch::Routing::RoutesInspector.new(all_routes)
|
70
|
+
puts '', inspector.format(ActionDispatch::Routing::ConsoleFormatter.new, ENV['CONTROLLER'])
|
71
|
+
else
|
72
|
+
require 'rails/application/route_inspector'
|
73
|
+
inspector = Rails::Application::RouteInspector.new
|
74
|
+
puts inspector.format(all_routes, ENV['CONTROLLER']).join "\n"
|
75
|
+
end
|
76
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
ENV["RAILS_ENV"] = "test"
|
2
|
+
|
3
|
+
# require 'rails/all'
|
4
|
+
|
5
|
+
require "action_controller/railtie"
|
6
|
+
require 'action_view/railtie'
|
7
|
+
require 'action_dispatch/railtie'
|
8
|
+
require 'rspec/rails'
|
9
|
+
|
10
|
+
require "dragoman"
|
11
|
+
require 'fake_app'
|
12
|
+
|
13
|
+
Rails.application.routes.default_url_options[:host] = 'example.com'
|
14
|
+
|
15
|
+
Rails.backtrace_cleaner.remove_silencers!
|
16
|
+
|
17
|
+
RSpec.configure do |config|
|
18
|
+
|
19
|
+
config.infer_spec_type_from_file_location!
|
20
|
+
|
21
|
+
config.after(:each) do
|
22
|
+
I18n.locale = I18n.default_locale = :en
|
23
|
+
# Rails.application.reload_routes!
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dragoman
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Pieter Visser
|
8
|
+
- Robert Jan de Gelder
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-05-04 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec-rails
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - '>='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - '>='
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: guard-rspec
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
description:
|
43
|
+
email:
|
44
|
+
- info@greenonline.nl
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- .gitignore
|
50
|
+
- .rspec
|
51
|
+
- Appraisals
|
52
|
+
- Gemfile
|
53
|
+
- Guardfile
|
54
|
+
- LICENSE.txt
|
55
|
+
- README.md
|
56
|
+
- Rakefile
|
57
|
+
- dragoman.gemspec
|
58
|
+
- gemfiles/rails_3.2.gemfile
|
59
|
+
- gemfiles/rails_4.2.gemfile
|
60
|
+
- lib/dragoman.rb
|
61
|
+
- lib/dragoman/mapper.rb
|
62
|
+
- lib/dragoman/mapper_rails3.rb
|
63
|
+
- lib/dragoman/mapper_rails4.rb
|
64
|
+
- lib/dragoman/railtie.rb
|
65
|
+
- lib/dragoman/translation_visitor.rb
|
66
|
+
- lib/dragoman/translator.rb
|
67
|
+
- lib/dragoman/url_helpers.rb
|
68
|
+
- lib/dragoman/version.rb
|
69
|
+
- spec/dragoman_spec.rb
|
70
|
+
- spec/fake_app.rb
|
71
|
+
- spec/fixtures/config/routes.rb
|
72
|
+
- spec/fixtures/locales/routes.yml
|
73
|
+
- spec/minimal_spec_helper.rb
|
74
|
+
- spec/routing/routes_spec.rb
|
75
|
+
- spec/spec_helper.rb
|
76
|
+
homepage: http://github.com/pietervisser/dragoman
|
77
|
+
licenses:
|
78
|
+
- MIT
|
79
|
+
metadata: {}
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
requirements: []
|
95
|
+
rubyforge_project:
|
96
|
+
rubygems_version: 2.0.14
|
97
|
+
signing_key:
|
98
|
+
specification_version: 4
|
99
|
+
summary: Simple Rails Routes Translator
|
100
|
+
test_files:
|
101
|
+
- spec/dragoman_spec.rb
|
102
|
+
- spec/fake_app.rb
|
103
|
+
- spec/fixtures/config/routes.rb
|
104
|
+
- spec/fixtures/locales/routes.yml
|
105
|
+
- spec/minimal_spec_helper.rb
|
106
|
+
- spec/routing/routes_spec.rb
|
107
|
+
- spec/spec_helper.rb
|