venomi 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ab55ad61fa60519fcc71df09779dec55261f432b
4
+ data.tar.gz: 0a009dfba2c1202572d3f56c52c3c6bc7e192b3c
5
+ SHA512:
6
+ metadata.gz: 62ca4a26053259c2193c2a08c524d944c6e43a858b22fd0cb72ceb3b14f06a1475ac247a863adcb7b1ba805f54566d0375a08b2d8f1a20bae3d5ddfc3e7796f7
7
+ data.tar.gz: 5b971504da103e810dfb87902adbbdf4110541c12664728e078a0deaa8a3e607b1933b1fc987ab09401e5e51a5a049b5ce8824e3711411936c887264852eff80
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.13.1
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at lexfox777@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1 @@
1
+ source 'https://rubygems.org'
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Alexandr Turchyn
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # Venomi
2
+
3
+ United I18n backend simple with mongoid provider and adds translation functionality to Rails Admin.
4
+
5
+ ## Dependency
6
+
7
+ ```ruby
8
+ gem 'mongoid'
9
+ gem 'rails_admin'
10
+ ```
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ ```ruby
17
+ gem 'venomi'
18
+ ```
19
+
20
+ And then execute:
21
+
22
+ $ bundle
23
+
24
+ Or install it yourself as:
25
+
26
+ $ gem install venomi
27
+
28
+ ## Usage
29
+
30
+ rails g venomi:install
31
+
32
+ ## Uninstall
33
+
34
+ rails d venomi:install
35
+
36
+ ## Contributing
37
+
38
+ 1. Fork it ( https://github.com/AlexandrToorchyn/venomi/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
+ ## License
45
+
46
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ Dir['lib/tasks/*.rake'].each { |rake| load rake }
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "venomi"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,38 @@
1
+ RailsAdmin.config do |config|
2
+
3
+ ### Popular gems integration
4
+
5
+ # == Devise ==
6
+ config.authenticate_with do
7
+ warden.authenticate! scope: :user
8
+ end
9
+ config.current_user_method(&:current_user)
10
+
11
+ ## == Cancan ==
12
+ # config.authorize_with :cancan
13
+
14
+ ## == Pundit ==
15
+ # config.authorize_with :pundit
16
+
17
+ ## == PaperTrail ==
18
+ # config.audit_with :paper_trail, 'User', 'PaperTrail::Version' # PaperTrail >= 3.0.0
19
+
20
+ ### More at https://github.com/sferik/rails_admin/wiki/Base-configuration
21
+
22
+ config.actions do
23
+ dashboard # mandatory
24
+ index # mandatory
25
+ new
26
+ export
27
+ bulk_delete
28
+ show
29
+ edit
30
+ delete
31
+ show_in_app
32
+
33
+ ## With an audit adapter, you can add:
34
+ # history_index
35
+ # history_show
36
+ end
37
+
38
+ end
@@ -0,0 +1,3 @@
1
+ require_relative("../../lib/i18n/backend/mongoid")
2
+
3
+ I18n.backend = I18n::Backend::Chain.new( I18n::Backend::Simple.new, I18n::Backend::Mongoid.new(Translation) )
@@ -0,0 +1,72 @@
1
+ require 'i18n/backend/base'
2
+
3
+ module I18n
4
+ module Backend
5
+ class Mongoid
6
+ module Implementation
7
+ attr_accessor :model
8
+ include Base, Flatten
9
+
10
+ def initialize(model)
11
+ @model = model
12
+ init_translations
13
+ end
14
+
15
+ def initialized?
16
+ @initialized ||= false
17
+ end
18
+
19
+ # Stores translations for the given locale in memory.
20
+ # This uses a deep merge for the translations hash, so existing
21
+ # translations will be overwritten by new ones only at the deepest
22
+ # level of the hash.
23
+ def store_translations(locale, data, options = {})
24
+ locale = locale.to_sym
25
+ translations[locale] ||= {}
26
+ data = data.deep_symbolize_keys
27
+ translations[locale].deep_merge!(data)
28
+ end
29
+
30
+ # Get available locales from the translations hash
31
+ def available_locales
32
+ init_translations unless initialized?
33
+ translations.inject([]) do |locales, (locale, data)|
34
+ locales << locale unless (data.keys - [:i18n]).empty?
35
+ locales
36
+ end
37
+ end
38
+
39
+ # Clean up translations hash and set initialized to false on reload!
40
+ def reload!
41
+ @initialized = false
42
+ @translations = nil
43
+ init_translations
44
+ end
45
+
46
+ protected
47
+
48
+ def init_translations
49
+ load_translations
50
+ @initialized = true
51
+ end
52
+
53
+ def load_translations
54
+ @translations = {}
55
+ @model.all.each{ |t| @lookuptranslations[t.key] = t.value_translations }
56
+ end
57
+
58
+ def translations
59
+ @translations ||= {}
60
+ end
61
+
62
+ def lookup(locale, key, scope = [], options = {})
63
+ init_translations unless initialized?
64
+ #translations.dig(key,value)
65
+ translations[key].blank? ? nil : translations[key][locale]
66
+ end
67
+ end
68
+
69
+ include Implementation
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,15 @@
1
+ class Translation
2
+ include Mongoid::Document
3
+
4
+ after_save do
5
+ I18n.backend.reload!
6
+ end
7
+
8
+ store_in collection: "i18n"
9
+ # scope :default, ->{ order_by(locale: :asc, key: :asc) }
10
+
11
+ field :key, type: String
12
+ field :value, type: String, localize: true
13
+
14
+ validates :key, presence: true, uniqueness: true
15
+ end
@@ -0,0 +1,28 @@
1
+ require 'rails/generators/base'
2
+ require 'venomi/rails_admin'
3
+
4
+ module Venomi
5
+ module Generators
6
+ class InstallGenerator < Rails::Generators::Base
7
+ source_root File.expand_path("../../templates", __FILE__)
8
+
9
+ desc 'Venomi installation generator'
10
+
11
+ def copy_initializer
12
+ template "translation.rb", "app/models/translation.rb"
13
+ template "locale.rb", "config/initializers/locale.rb"
14
+ template "mongoid.rb", "lib/i18n/backend/mongoid.rb"
15
+ end
16
+
17
+ def install
18
+ case self.behavior
19
+ when :invoke
20
+ Venomi::RailsAdmin.configure
21
+ when :revoke
22
+ Venomi::RailsAdmin.rollback
23
+ end
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,11 @@
1
+ namespace :venomi do
2
+ desc 'Install venomi'
3
+ task :install do
4
+ system 'rails g venomi:install'
5
+ end
6
+
7
+ desc 'Uninstall venomi'
8
+ task :uninstall do
9
+ system 'rails d venomi:install'
10
+ end
11
+ end
data/lib/venomi.rb ADDED
@@ -0,0 +1,10 @@
1
+ module Venomi
2
+ end
3
+
4
+ begin
5
+ require 'rails'
6
+ rescue LoadError
7
+ #do nothing
8
+ end
9
+
10
+ require "venomi/version"
@@ -0,0 +1,87 @@
1
+ require 'pathname'
2
+ require 'fileutils'
3
+ require 'tempfile'
4
+ include FileUtils
5
+
6
+ module Venomi
7
+ module RailsAdmin
8
+
9
+ if defined? ::Rails
10
+ @rails_root = Rails.root.to_s
11
+ @rails_admin_root = @rails_root + "/config/initializers/rails_admin.rb"
12
+ else
13
+ @gem_root = Pathname.new File.expand_path('../../', __FILE__)
14
+ @rails_admin_root = @gem_root.to_s + "/debug/initializers/rails_admin.rb"
15
+ end
16
+
17
+ def self.configure
18
+ unless file_include?(@rails_admin_root, "config.model Translation do")
19
+ replace(@rails_admin_root, "RailsAdmin.config do |config|", ("RailsAdmin.config do |config|\n" + @translation))
20
+ end
21
+
22
+ unless file_include?(@rails_admin_root, " new do")
23
+ replace(@rails_admin_root, " new", @new)
24
+ end
25
+
26
+ unless file_include?(@rails_admin_root, " delete do")
27
+ replace(@rails_admin_root, " delete", @delete)
28
+ end
29
+ end
30
+
31
+ def self.rollback
32
+ text = File.read(@rails_admin_root)
33
+ text.gsub!(@delete, " delete\n")
34
+ text.gsub!(@new, " new\n")
35
+ text.gsub!(@translation, "")
36
+ File.open(@rails_admin_root, "w") {|file| file.puts text }
37
+ end
38
+
39
+ def self.replace(path, pattern, new_line)
40
+ t_file = Tempfile.new('temp.rb')
41
+ File.open(path, 'r') do |f|
42
+ f.each_line do |line|
43
+ t_file.puts (line.include? pattern)? new_line : line
44
+ end
45
+ end
46
+ t_file.close
47
+ FileUtils.mv(t_file.path, path)
48
+ end
49
+
50
+ def self.file_include?(path, include)
51
+ File.open(path, 'r') do |f|
52
+ f.each_line do |line|
53
+ return true if line.include? include
54
+ end
55
+ end
56
+ false
57
+ end
58
+
59
+ @new = <<-MSG
60
+ new do
61
+ except [:Translation]
62
+ end
63
+ MSG
64
+
65
+ @delete = <<-MSG
66
+ delete do
67
+ except [:Translation]
68
+ end
69
+ MSG
70
+
71
+ @translation = <<-MSG
72
+ config.model Translation do
73
+ list do
74
+ field :key
75
+ field :value
76
+ end
77
+ edit do
78
+ field :key do
79
+ read_only true
80
+ end
81
+ field :value
82
+ end
83
+ end
84
+ MSG
85
+
86
+ end
87
+ end
@@ -0,0 +1,3 @@
1
+ module Venomi
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
2
+ require "venomi"
@@ -0,0 +1,11 @@
1
+ require "spec_helper"
2
+
3
+ describe Venomi do
4
+ it "has a version number" do
5
+ expect(Venomi::VERSION).not_to be nil
6
+ end
7
+
8
+ it "does something useful" do
9
+ expect(false).to eq(true)
10
+ end
11
+ end
data/venomi.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'venomi/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "venomi"
8
+ spec.version = Venomi::VERSION
9
+ spec.authors = ["Alexandr Turchyn"]
10
+ spec.email = ["lexfox777@gmail.com"]
11
+
12
+ spec.summary = 'United I18n backend simple with mongoid provider.'
13
+ spec.description = 'United I18n backend simple with mongoid provider and adds translation functionality to Rails Admin.'
14
+ spec.homepage = "https://github.com/AlexandrToorchyn/venomi"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.require_paths = %w(lib)
20
+
21
+ spec.add_development_dependency 'rspec', '~> 3.4.0'
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+
24
+ spec.add_dependency 'bundler', '~> 1.7'
25
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: venomi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Alexandr Turchyn
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-09-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 3.4.0
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 3.4.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.7'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.7'
55
+ description: United I18n backend simple with mongoid provider and adds translation
56
+ functionality to Rails Admin.
57
+ email:
58
+ - lexfox777@gmail.com
59
+ executables:
60
+ - console
61
+ - setup
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - ".gitignore"
66
+ - ".rspec"
67
+ - ".travis.yml"
68
+ - CODE_OF_CONDUCT.md
69
+ - Gemfile
70
+ - LICENSE.txt
71
+ - README.md
72
+ - Rakefile
73
+ - bin/console
74
+ - bin/setup
75
+ - lib/debug/initializers/rails_admin.rb
76
+ - lib/generators/templates/locale.rb
77
+ - lib/generators/templates/mongoid.rb
78
+ - lib/generators/templates/translation.rb
79
+ - lib/generators/venomi/install_generator.rb
80
+ - lib/tasks/venomi.rake
81
+ - lib/venomi.rb
82
+ - lib/venomi/rails_admin.rb
83
+ - lib/venomi/version.rb
84
+ - spec/spec_helper.rb
85
+ - spec/venomi_spec.rb
86
+ - venomi.gemspec
87
+ homepage: https://github.com/AlexandrToorchyn/venomi
88
+ licenses:
89
+ - MIT
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.5.1
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: United I18n backend simple with mongoid provider.
111
+ test_files: []