administrate-field-globalize 0.0.1.alpha1

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
+ SHA256:
3
+ metadata.gz: 6ad4d058ac5a70fe6fbcfd41e8b06a0f890d53b271a0d00702914ab16fae182c
4
+ data.tar.gz: 9ac37c011e55011a0f148e15307fffadcc025bd4c55882405d2decf7a4561a09
5
+ SHA512:
6
+ metadata.gz: 187be46ee25dad9192c62a35f7fc7cb41b2bf92d39fd747f51c0326ce1d8f40270f2f06e0471cde255fd486290c3d6bbceade7ba3eed7cc6cd4ab84798398ae9
7
+ data.tar.gz: 940bafefddb03610b881ffb53a303b15e1d9f379606e15c95c517553b1cfef0089fb8a5897d2443ae4e98bc94de989ccc57442522b21c79ec8880946a08a25e7
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ .rubocop-https---raw-githubusercontent-com-thoughtbot-guides-master-style-ruby--rubocop-yml
2
+ /administrate-field-globalize-string/.bundle/
3
+ /administrate-field-globalize-string/.yardoc
4
+ /administrate-field-globalize-string/Gemfile.lock
5
+ /administrate-field-globalize-string/_yardoc/
6
+ /administrate-field-globalize-string/coverage/
7
+ /administrate-field-globalize-string/doc/
8
+ /administrate-field-globalize-string/pkg/
9
+ /administrate-field-globalize-string/spec/reports/
10
+ /administrate-field-globalize-string/tmp/
data/.rubocop.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+
3
+ inherit_from:
4
+ - https://raw.githubusercontent.com/thoughtbot/guides/master/style/ruby/.rubocop.yml
5
+ Metrics/LineLength:
6
+ Exclude:
7
+ - config/routes.rb
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # Administrate::Field::Globalize
2
+
3
+ ## Warning
4
+ This gem is under early development and overrides Administrate search functions.
5
+
6
+ This Administrate plugin adds support for string fields that use the Globalize gem to hold
7
+ translated values.
8
+
9
+ Requirements in Globalize
10
+ ----------------------
11
+
12
+ You need to install the accessors for easy access to the translations.
13
+
14
+ ```ruby
15
+ gem "globalize-accessors"
16
+ ```
17
+
18
+ Add the helper to your translated models.
19
+
20
+ ```ruby
21
+ globalize_accessors locales: I18n.available_locales
22
+ ```
23
+
24
+ Getting Started
25
+ ----------------------
26
+
27
+ Add Administrate::Field::Globalize gems to your Gemfile:
28
+
29
+ ```ruby
30
+ gem "administrate-field-globalize", "0.0.1.alpha1"
31
+ ```
32
+
33
+ Add the Administrate Globalize Field to your dashboard.
34
+
35
+ ```ruby
36
+ ATTRIBUTE_TYPES = {
37
+ created_at: Field::DateTime,
38
+ update_at: Field::DateTime,
39
+ name: Field::Globalize::String,
40
+ }.freeze
41
+ ```
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
@@ -0,0 +1,19 @@
1
+ The MIT License
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env rake
2
+
3
+ begin
4
+ require "bundler/setup"
5
+ rescue LoadError
6
+ puts "You must `gem install bundler` and `bundle install` to run rake tasks"
7
+ end
8
+
9
+ require "bundler/gem_tasks"
10
+
11
+ ##
12
+ # Configure the test suite.
13
+ ##
14
+ require "rspec/core"
15
+ require "rspec/core/rake_task"
16
+
17
+ RSpec::Core::RakeTask.new
18
+
19
+ ##
20
+ # By default, just run the tests.
21
+ ##
22
+ task default: :spec
@@ -0,0 +1,22 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+
3
+ require_relative "../lib/administrate/field/globalize/version.rb"
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = "administrate-field-globalize-string"
7
+ gem.version = Administrate::Field::Globalize.version
8
+ gem.authors = ["Armin Kirchner"]
9
+ gem.email = ["armin.kirchner@gmail.com"]
10
+ gem.homepage = "https://github.com/arkirchner/administrate-field-globalize"
11
+ gem.summary = "Globalized string and text field plugin for Administrate"
12
+ gem.description = gem.summary
13
+ gem.license = "MIT"
14
+
15
+ gem.require_paths = ["lib"]
16
+ gem.files = `git ls-files`.split("\n")
17
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+
19
+ gem.add_dependency "administrate", "~> 0.10", ">= 0.10.0"
20
+
21
+ gem.add_development_dependency "rspec", "~> 3.4"
22
+ end
@@ -0,0 +1,9 @@
1
+ <div class="field-unit__label">
2
+ <%= f.label field.attribute %>
3
+ </div>
4
+ <div class="field-unit__field">
5
+ <% I18n.available_locales.each do |locale| %>
6
+ <%= f.text_field "#{field.attribute}_#{locale.downcase}".to_s %>
7
+ (<%= locale %>)
8
+ <% end %>
9
+ </div>
@@ -0,0 +1,6 @@
1
+ <% I18n.available_locales.each do |locale| %>
2
+ <% I18n.with_locale(locale) do %>
3
+ <%= "#{field.resource[field.attribute]} (#{locale})" %>
4
+ <% end %>
5
+ </br>
6
+ <% end %>
@@ -0,0 +1,35 @@
1
+ require "administrate/field/base"
2
+ require "rails"
3
+
4
+ module Administrate
5
+ module Field
6
+ module Globalize
7
+ class String < Administrate::Field::Base
8
+ class Engine < ::Rails::Engine
9
+ end
10
+
11
+ def self.permitted_attribute(attr, _options = nil)
12
+ I18n.available_locales.map { |locale| "#{attr}_#{locale.downcase}" }
13
+ end
14
+
15
+ def truncate
16
+ data.to_s[0...truncation_length]
17
+ end
18
+
19
+ def self.searchable?
20
+ true
21
+ end
22
+
23
+ def self.translation?
24
+ true
25
+ end
26
+
27
+ private
28
+
29
+ def truncation_length
30
+ options.fetch(:truncate, 50)
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,14 @@
1
+ require "administrate/field/globalize/string"
2
+
3
+ describe Administrate::Field::Globalize::String do
4
+ describe "#to_partial_path" do
5
+ it "returns a partial based on the page being rendered" do
6
+ page = :show
7
+ field = Administrate::Field::Globalize::String.new(:string, "/a.jpg", page)
8
+
9
+ path = field.to_partial_path
10
+
11
+ expect(path).to eq("/fields/string/#{page}")
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,21 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+ require_relative "lib/administrate/field/globalize/version.rb"
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = "administrate-field-globalize"
6
+ gem.version = Administrate::Field::Globalize.version
7
+ gem.authors = ["Armin Kirchner"]
8
+ gem.email = ["armin.kirchner@gmail.com"]
9
+ gem.homepage = "https://github.com/arkirchner/administrate-field-globalize"
10
+ gem.summary = "Globalized string and text field plugin for Administrate"
11
+ gem.description = gem.summary
12
+ gem.license = "MIT"
13
+
14
+ gem.require_paths = ["lib"]
15
+ gem.files = `git ls-files`.split("\n")
16
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+
18
+ gem.add_dependency "administrate", "~> 0.10", ">= 0.10.0"
19
+
20
+ gem.add_dependency "administrate-field-globalize-string", gem.version
21
+ end
@@ -0,0 +1,9 @@
1
+ module Administrate
2
+ module Field
3
+ module Globalize
4
+ def self.version
5
+ "0.0.1.alpha1"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,41 @@
1
+ require "rails"
2
+ require "administrate/field/globalize/string"
3
+
4
+ module Administrate
5
+ module Field
6
+ module Globalize
7
+ class Engine < ::Rails::Engine
8
+ initializer "administrate-field-globalize.patch", before: :load_config_initializers do |app|
9
+ Administrate::Search.class_eval do
10
+ def tables_to_join
11
+ attribute_types.keys.select do |attribute|
12
+ attribute_types[attribute].searchable? && association_search?(attribute)
13
+ end + translation_join
14
+ end
15
+
16
+ def translation_join
17
+ return [] unless attribute_types.values.any? do |field|
18
+ field.respond_to?(:translation?) && field.translation?
19
+ end
20
+ [:translations]
21
+ end
22
+
23
+ def query_table_name(attr)
24
+ if attribute_types[attr].respond_to?(:translation?)
25
+ ActiveRecord::Base.connection.
26
+ quote_table_name(
27
+ "#{@scoped_resource.table_name.singularize}_translations",
28
+ )
29
+ elsif association_search?(attr)
30
+ ActiveRecord::Base.connection.quote_table_name(attr.to_s.pluralize)
31
+ else
32
+ ActiveRecord::Base.connection.
33
+ quote_table_name(@scoped_resource.table_name)
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: administrate-field-globalize
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.alpha1
5
+ platform: ruby
6
+ authors:
7
+ - Armin Kirchner
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-08-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: administrate
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.10'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.10.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '0.10'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 0.10.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: administrate-field-globalize-string
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - '='
38
+ - !ruby/object:Gem::Version
39
+ version: 0.0.1.alpha1
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - '='
45
+ - !ruby/object:Gem::Version
46
+ version: 0.0.1.alpha1
47
+ description: Globalized string and text field plugin for Administrate
48
+ email:
49
+ - armin.kirchner@gmail.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - ".gitignore"
55
+ - ".rubocop.yml"
56
+ - README.md
57
+ - administrate-field-globalize-string/Gemfile
58
+ - administrate-field-globalize-string/LICENSE
59
+ - administrate-field-globalize-string/Rakefile
60
+ - administrate-field-globalize-string/administrate-field-globalize-string.gemspec
61
+ - administrate-field-globalize-string/app/views/fields/globalize/string/_form.html.erb
62
+ - administrate-field-globalize-string/app/views/fields/globalize/string/_index.html.erb
63
+ - administrate-field-globalize-string/app/views/fields/globalize/string/_show.html.erb
64
+ - administrate-field-globalize-string/lib/administrate/field/globalize/string.rb
65
+ - administrate-field-globalize-string/spec/lib/administrate/field/globalize/string_spec.rb
66
+ - administrate-field-globalize.gemspec
67
+ - lib/administrate/field/globalize.rb
68
+ - lib/administrate/field/globalize/version.rb
69
+ homepage: https://github.com/arkirchner/administrate-field-globalize
70
+ licenses:
71
+ - MIT
72
+ metadata: {}
73
+ post_install_message:
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">"
85
+ - !ruby/object:Gem::Version
86
+ version: 1.3.1
87
+ requirements: []
88
+ rubyforge_project:
89
+ rubygems_version: 2.7.6
90
+ signing_key:
91
+ specification_version: 4
92
+ summary: Globalized string and text field plugin for Administrate
93
+ test_files: []