localized_render 0.1.0
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/MIT-LICENSE +20 -0
- data/README.md +74 -0
- data/Rakefile +32 -0
- data/app/helpers/localized_render/application_helper.rb +54 -0
- data/lib/localized_render.rb +5 -0
- data/lib/localized_render/engine.rb +5 -0
- data/lib/localized_render/version.rb +3 -0
- data/lib/tasks/localized_render_tasks.rake +4 -0
- metadata +94 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b8220db8d2e44859190d519a1556076f2b084e09b09d4aaf6bd0cf8db0e2cc7c
|
4
|
+
data.tar.gz: f5e52234976446f2e152a1835957570fc3d21d96192ebe32bc0dc313c5366d87
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cb393355bc0daf41c6ef6c8ee03a70d33dcf925642560cbdc06ec86e5c4b0d1b6ee112878bee896965c60ff34dbb3c23eb532b86ce07d3cf8a447d27e1e90417
|
7
|
+
data.tar.gz: 6064f6209937106f68cac146aac8214d8967663aa2f74e7199764f95a2cae2231100a91917b8e2b967e0c9a85bd9d4155241297adb5f9f2df4406e080bb33a8f
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2018 Danil Pismenny
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# LocalizedRender
|
2
|
+
|
3
|
+
[](https://travis-ci.org/BrandyMint/localized_render)
|
4
|
+
|
5
|
+
|
6
|
+
Позволяет удобно редаткировать globalized-атрибуты моделей во вьюхах с
|
7
|
+
поддержкой CSS от bootstrap 3
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
Имеем модель с атрибутом title подключенным через globalize
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
class Content < ApplicationRecord
|
15
|
+
translates :title
|
16
|
+
end
|
17
|
+
```
|
18
|
+
|
19
|
+
Добавляем в контроллер:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
class ApplicationController < ActionController::Base
|
23
|
+
helper LocalizedRender.helpers
|
24
|
+
end
|
25
|
+
|
26
|
+
```
|
27
|
+
|
28
|
+
В представлении формы добавляем переключатель между доступными локалями:
|
29
|
+
|
30
|
+
|
31
|
+
```slim
|
32
|
+
= simple_form_for content do |f|
|
33
|
+
= localized_render do |locale|
|
34
|
+
= f.input localized_attribute(:title, locale)
|
35
|
+
```
|
36
|
+
|
37
|
+
Получаем:
|
38
|
+
|
39
|
+

|
40
|
+
|
41
|
+
|
42
|
+
## Доступные методы
|
43
|
+
|
44
|
+
Модуль представляет всего два публичных метода:
|
45
|
+
|
46
|
+
* localized_render - рендерит несколько input-ов для разных локалей в виде
|
47
|
+
bootstrap css nav-tabs
|
48
|
+
* localied_attribute_title - отдает название атрибута с постфиксом в виде локали
|
49
|
+
(_ru, /_en). Используйте для этого gem globalize-accessors
|
50
|
+
|
51
|
+
## Installation
|
52
|
+
Add this line to your application's Gemfile:
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
gem 'localized_render'
|
56
|
+
```
|
57
|
+
|
58
|
+
And then execute:
|
59
|
+
```bash
|
60
|
+
$ bundle
|
61
|
+
```
|
62
|
+
|
63
|
+
Or install it yourself as:
|
64
|
+
```bash
|
65
|
+
$ gem install localized_render
|
66
|
+
```
|
67
|
+
|
68
|
+
Рекомендую использовать gem globalize-accessors
|
69
|
+
|
70
|
+
## Contributing
|
71
|
+
Contribution directions go here.
|
72
|
+
|
73
|
+
## License
|
74
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'LocalizedRender'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
|
18
|
+
load 'rails/tasks/engine.rake'
|
19
|
+
|
20
|
+
load 'rails/tasks/statistics.rake'
|
21
|
+
|
22
|
+
require 'bundler/gem_tasks'
|
23
|
+
|
24
|
+
require 'rake/testtask'
|
25
|
+
|
26
|
+
Rake::TestTask.new(:test) do |t|
|
27
|
+
t.libs << 'test'
|
28
|
+
t.pattern = 'test/**/*_test.rb'
|
29
|
+
t.verbose = false
|
30
|
+
end
|
31
|
+
|
32
|
+
task default: :test
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module LocalizedRender
|
2
|
+
module ApplicationHelper
|
3
|
+
def localized_attribute(attr, locale)
|
4
|
+
"#{attr}_#{locale.to_s.underscore}"
|
5
|
+
end
|
6
|
+
|
7
|
+
def localized_render(tab_name: nil, &block)
|
8
|
+
tab_name = next_localized_tab_name
|
9
|
+
# если доступен только 1 язык то не выводим табы
|
10
|
+
if I18n.available_locales.count == 1
|
11
|
+
yield(I18n.available_locales.first)
|
12
|
+
return ''
|
13
|
+
end
|
14
|
+
|
15
|
+
buffer = ''
|
16
|
+
|
17
|
+
buffer << localized_render_tabs(tab_name)
|
18
|
+
buffer << localized_render_content(tab_name, block)
|
19
|
+
buffer.html_safe
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def next_localized_tab_name
|
25
|
+
@current_localized_tab_name ||= 0
|
26
|
+
@current_localized_tab_name +=1
|
27
|
+
'localized-tab-' + @current_localized_tab_name.to_s
|
28
|
+
end
|
29
|
+
|
30
|
+
def localized_render_tabs(tab_name)
|
31
|
+
content_tag(:ul, class: 'nav nav-tabs') do
|
32
|
+
I18n.available_locales.each_with_index do |locale, i|
|
33
|
+
concat(content_tag(:li, class: ('active' if i.zero?)) do
|
34
|
+
content_tag(:a, 'data-toggle': 'tab', href: "##{tab_name}-#{i}", 'aria-expanded': false) do
|
35
|
+
t("locales.#{locale}")
|
36
|
+
end
|
37
|
+
end)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def localized_render_content(tab_name, block)
|
43
|
+
content_tag(:div, class: 'tab-content') do
|
44
|
+
I18n.available_locales.each_with_index do |locale, i|
|
45
|
+
concat(content_tag(:div, class: "tab-pane #{('active' if i.zero?)}", id: "#{tab_name}-#{i}") do
|
46
|
+
content_tag(:div, class: 'panel-body') do
|
47
|
+
block.call(locale)
|
48
|
+
end
|
49
|
+
end)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: localized_render
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Danil Pismenny
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-10-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 5.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: 5.2.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: globalize
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: sqlite3
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Добавляет метод localized_render для поддержки globalize-полей
|
56
|
+
email:
|
57
|
+
- danil@brandymint.ru
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- MIT-LICENSE
|
63
|
+
- README.md
|
64
|
+
- Rakefile
|
65
|
+
- app/helpers/localized_render/application_helper.rb
|
66
|
+
- lib/localized_render.rb
|
67
|
+
- lib/localized_render/engine.rb
|
68
|
+
- lib/localized_render/version.rb
|
69
|
+
- lib/tasks/localized_render_tasks.rake
|
70
|
+
homepage: https://github.com/BrandyMint/localized_render
|
71
|
+
licenses:
|
72
|
+
- MIT
|
73
|
+
metadata: {}
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
requirements: []
|
89
|
+
rubyforge_project:
|
90
|
+
rubygems_version: 2.7.7
|
91
|
+
signing_key:
|
92
|
+
specification_version: 4
|
93
|
+
summary: Отображаем мультиязычные поля в табах
|
94
|
+
test_files: []
|