localizable_value 0.1.20
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 +9 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +21 -0
- data/README.md +93 -0
- data/Rakefile +2 -0
- data/app/controllers/localizable_value/localized_values_controller.rb +31 -0
- data/app/helpers/localizable_value_helper.rb +27 -0
- data/app/views/localizable_value/_element.html.slim +5 -0
- data/app/views/localizable_value/_link.html.slim +8 -0
- data/app/views/localizable_value/_link_attr.html.slim +11 -0
- data/app/views/localizable_value/_string.html.slim +4 -0
- data/app/views/localizable_value/_string_read.html.slim +4 -0
- data/app/views/localizable_value/_text.html.slim +4 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/config/routes.rb +5 -0
- data/lib/localizable_value/app/models/localized_group.rb +17 -0
- data/lib/localizable_value/app/models/localized_image.rb +21 -0
- data/lib/localizable_value/app/models/localized_page.rb +57 -0
- data/lib/localizable_value/app/models/localized_value.rb +29 -0
- data/lib/localizable_value/app/uploaders/localizable_image_uploader.rb +52 -0
- data/lib/localizable_value/engine.rb +4 -0
- data/lib/localizable_value/railtie.rb +7 -0
- data/lib/localizable_value/tasks/localizable.rake +25 -0
- data/lib/localizable_value/version.rb +3 -0
- data/lib/localizable_value.rb +15 -0
- data/localizable_value.gemspec +39 -0
- metadata +102 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a1d0ae477b1c7020129d94b1995c0e8947f5926e
|
4
|
+
data.tar.gz: 320de2cfaf95e11015930cf2ed051707437b202a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 18015e4ab18de3d91786ed9f06d64ca22da3a57520d3a5c499a0b12ef5ad8cefa1c72a345daf6d9eb0e2fccc568e13687af64c9a719d46f0da7e06f148dec9e6
|
7
|
+
data.tar.gz: c1dd99ebbf6c15abf312c2a6eafb7b5ffc71310caed22847db868f686b367c56cb8f965e175ccc9b66bb78cb8e3acd05bac7da64efb5e0fba140b5d602e78867
|
data/.gitignore
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -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 hrangel@nucleo235.com.br. 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
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Henrique Rangel
|
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,93 @@
|
|
1
|
+
# LocalizableValue
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/localizable_value`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'localizable_value'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install localizable_value
|
22
|
+
|
23
|
+
Then, create tables:
|
24
|
+
|
25
|
+
$ rake localizable:setup
|
26
|
+
|
27
|
+
Add to the controllers you want (e.g. ApplicationController)
|
28
|
+
```ruby
|
29
|
+
before_action :set_editor_config
|
30
|
+
before_action :set_localizable_pages
|
31
|
+
|
32
|
+
# Inplace Editor config
|
33
|
+
def set_editor_config
|
34
|
+
@can_edit = false # or true
|
35
|
+
@inplace_editing_mode = (@can_edit ? 'edit' : 'read')
|
36
|
+
end
|
37
|
+
|
38
|
+
# set pages
|
39
|
+
|
40
|
+
def set_localizable_pages
|
41
|
+
@global_page = LocalizableValue::LocalizedPage.global_page
|
42
|
+
@current_page = LocalizableValue::LocalizedPage.current_page(controller_name, action_name)
|
43
|
+
end
|
44
|
+
```
|
45
|
+
|
46
|
+
Don't forget to add scripts
|
47
|
+
|
48
|
+
//= require jquery
|
49
|
+
//= require best_in_place
|
50
|
+
//= require inplace_editing
|
51
|
+
|
52
|
+
$(document).ready(function() {
|
53
|
+
/* Activating Best In Place */
|
54
|
+
jQuery(".best_in_place").best_in_place();
|
55
|
+
});
|
56
|
+
|
57
|
+
|
58
|
+
## Usage
|
59
|
+
|
60
|
+
The exambple belows considers you are using @global_page and @current_page
|
61
|
+
|
62
|
+
```slim
|
63
|
+
- # editable h1
|
64
|
+
h1 = localized_value_string(@current_page, 'main-title', 'My Main Title')
|
65
|
+
|
66
|
+
- # read only h1
|
67
|
+
h1 = localized_value_string_read(@current_page, 'main-title', 'My Main Title')
|
68
|
+
|
69
|
+
- # editable text section
|
70
|
+
div.text = localized_value_text(@current_page, 'main-text', 'My Main Text with markdown')
|
71
|
+
|
72
|
+
- # others
|
73
|
+
= localized_value_element(page, key, default_value, label)
|
74
|
+
= localized_value_link(page, key, default_value, link)
|
75
|
+
= localized_value_link_attr(page, key, default_value, link_attrs)
|
76
|
+
|
77
|
+
```
|
78
|
+
|
79
|
+
## Development
|
80
|
+
|
81
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
82
|
+
|
83
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
84
|
+
|
85
|
+
## Contributing
|
86
|
+
|
87
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/localizable_value. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
88
|
+
|
89
|
+
|
90
|
+
## License
|
91
|
+
|
92
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
93
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
module LocalizableValue
|
2
|
+
class LocalizedValuesController < ApplicationController
|
3
|
+
respond_to :html, :json
|
4
|
+
|
5
|
+
skip_before_action :verify_authenticity_token
|
6
|
+
before_action :check_can_edit
|
7
|
+
before_action :require_value
|
8
|
+
|
9
|
+
def update
|
10
|
+
@localized_value.update(localized_value_params)
|
11
|
+
respond_with(@localized_value)
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
def check_can_edit
|
16
|
+
return head(:unauthorized) if !@can_edit
|
17
|
+
end
|
18
|
+
|
19
|
+
def require_value
|
20
|
+
@localized_value = LocalizedValue.find(params[:id])
|
21
|
+
end
|
22
|
+
|
23
|
+
def localized_value_params
|
24
|
+
if params.key? :localized_image
|
25
|
+
params.require(:localizable_value_localized_value).permit(:value)
|
26
|
+
else
|
27
|
+
params.require(:localizable_value_localized_value).permit(:value)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module LocalizableValueHelper
|
2
|
+
def localized_value_string(page, key, default_value)
|
3
|
+
render partial: 'localizable_value/string', :locals => { localized_page: page, key: key, default_value: default_value }
|
4
|
+
end
|
5
|
+
|
6
|
+
def localized_value_text(page, key, default_value)
|
7
|
+
render partial: 'localizable_value/text', :locals => { localized_page: page, key: key, default_value: default_value }
|
8
|
+
end
|
9
|
+
|
10
|
+
def localized_value_string_read(page, key, default_value)
|
11
|
+
render partial: 'localizable_value/string_read', :locals => { localized_page: page, key: key, default_value: default_value }
|
12
|
+
end
|
13
|
+
|
14
|
+
def localized_value_element(page, key, default_value, label)
|
15
|
+
render layout: 'localizable_value/element', :locals => { localized_page: page, key: key, default_value: default_value, label: label } do |locals|
|
16
|
+
yield locals
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def localized_value_link(page, key, default_value, link)
|
21
|
+
render partial: 'localizable_value/link', :locals => { localized_page: page, key: key, default_value: default_value, link: link }
|
22
|
+
end
|
23
|
+
|
24
|
+
def localized_value_link_attr(page, key, default_value, attrs)
|
25
|
+
render partial: 'localizable_value/link_attr', :locals => { localized_page: page, key: key, default_value: default_value, attrs: attrs }
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,5 @@
|
|
1
|
+
- local_assigns[:localized_object] = localized_page.get_value(key, default_value) if !local_assigns[:localized_object]
|
2
|
+
- local_assigns[:property] = :value if !local_assigns[:property]
|
3
|
+
|
4
|
+
= element_editor(localized_object, property, local_assigns[:place_holder], local_assigns[:label]) do |args|
|
5
|
+
= yield args
|
@@ -0,0 +1,8 @@
|
|
1
|
+
- localized_value = localized_page.get_value(key, default_value)
|
2
|
+
- if @can_edit
|
3
|
+
.best_link
|
4
|
+
= string_editor(localized_value, :value, "[troque o texto aqui]")
|
5
|
+
a href="#{link}"
|
6
|
+
i.fa.fa-sign-in
|
7
|
+
- else
|
8
|
+
a href="#{link}" = render partial: 'localizable_value/string_read', :locals => { localized_page: localized_page, :key => key, default_value: default_value }
|
@@ -0,0 +1,11 @@
|
|
1
|
+
- localized_value = localized_page.get_value(key, default_value)
|
2
|
+
- if @can_edit
|
3
|
+
.best_link
|
4
|
+
= string_editor(localized_value, :value, "[troque o texto aqui]")
|
5
|
+
= content_tag :a do |el|
|
6
|
+
- attrs.each do |attr_item| el[attr_item[:name]] = attr_item[:value] end
|
7
|
+
i.fa.fa-sign-in
|
8
|
+
- else
|
9
|
+
= content_tag :a do |el|
|
10
|
+
- attrs.each do |attr_item| el[attr_item[:name]] = attr_item[:value] end
|
11
|
+
= render partial: 'localizable_value/string_read', :locals => { localized_page: localized_page, :key => key, default_value: default_value }
|
@@ -0,0 +1,4 @@
|
|
1
|
+
- local_assigns[:localized_object] = localized_page.get_value(key, default_value) if !local_assigns[:localized_object]
|
2
|
+
- local_assigns[:property] = :value if !local_assigns[:property]
|
3
|
+
|
4
|
+
= string_editor(local_assigns[:localized_object], local_assigns[:property], local_assigns[:place_holder])
|
@@ -0,0 +1,4 @@
|
|
1
|
+
- local_assigns[:localized_object] = localized_page.get_value(key, default_value) if !local_assigns[:localized_object]
|
2
|
+
- local_assigns[:property] = :value if !local_assigns[:property]
|
3
|
+
|
4
|
+
= text_editor(local_assigns[:localized_object], local_assigns[:property], local_assigns[:place_holder])
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "localizable_value"
|
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
data/config/routes.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
module LocalizableValue
|
2
|
+
class LocalizedGroup
|
3
|
+
attr_accessor :prefix_key
|
4
|
+
attr_accessor :page
|
5
|
+
|
6
|
+
def values
|
7
|
+
if !@values
|
8
|
+
@values = page.localized_values.where('key like ?', self.prefix_key + '_%')
|
9
|
+
end
|
10
|
+
@values
|
11
|
+
end
|
12
|
+
|
13
|
+
def get_value(property)
|
14
|
+
self.values.find_by(key: self.prefix_key + '_' + property)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# == Schema Information
|
2
|
+
#
|
3
|
+
# Table name: localized_values
|
4
|
+
#
|
5
|
+
# id :integer not null, primary key
|
6
|
+
# localized_page_id :integer
|
7
|
+
# key :string
|
8
|
+
# value :string
|
9
|
+
# created_at :datetime not null
|
10
|
+
# updated_at :datetime not null
|
11
|
+
# type :string
|
12
|
+
#
|
13
|
+
|
14
|
+
require 'carrierwave'
|
15
|
+
require 'carrierwave/orm/activerecord'
|
16
|
+
|
17
|
+
module LocalizableValue
|
18
|
+
class LocalizedImage < LocalizableValue::LocalizedValue
|
19
|
+
mount_uploader :value, LocalizableImageUploader
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# == Schema Information
|
2
|
+
#
|
3
|
+
# Table name: localized_pages
|
4
|
+
#
|
5
|
+
# id :integer not null, primary key
|
6
|
+
# locale :string
|
7
|
+
# page_uid :string
|
8
|
+
# created_at :datetime not null
|
9
|
+
# updated_at :datetime not null
|
10
|
+
#
|
11
|
+
|
12
|
+
module LocalizableValue
|
13
|
+
class LocalizedPage < ActiveRecord::Base
|
14
|
+
has_many :localized_values, dependent: :destroy
|
15
|
+
|
16
|
+
def self.global_page
|
17
|
+
@@global_page ||= LocalizedPage.by_locale(I18n.locale.to_s.downcase, 'GLOBAL')
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.current_page(controller_name, action_name)
|
21
|
+
LocalizedPage.by_locale(I18n.locale.to_s.downcase, controller_name + '#' + action_name)
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.by_locale(locale, page_uid)
|
25
|
+
LocalizedPage.find_or_create_by(locale: locale.to_s.downcase, page_uid: page_uid)
|
26
|
+
end
|
27
|
+
|
28
|
+
def get_value(key, default_value, type = nil)
|
29
|
+
value = localized_values.select { |v| v.key == key && v.type == type }.first
|
30
|
+
value = localized_values.create(localized_page: self, key: key, type: type, value: default_value) if !value
|
31
|
+
value
|
32
|
+
end
|
33
|
+
|
34
|
+
def insert_grouped_values(prefix_key, values)
|
35
|
+
new_order = get_last_grouped_value_order(prefix_key) + 1
|
36
|
+
values.each do |property, text|
|
37
|
+
key = "%s_%04d_%s" % [prefix_key, new_order, property.to_s]
|
38
|
+
get_value(key, text)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def get_last_grouped_value_order(prefix_key)
|
43
|
+
values = localized_values.where(localized_page: self).where('key like ?', prefix_key + '_%' ).order('key DESC')
|
44
|
+
return values.first ? values.first.get_grouped_value_order(prefix_key) : 0
|
45
|
+
end
|
46
|
+
|
47
|
+
def get_grouped_value_list(prefix_key, main_property = 'title')
|
48
|
+
values = localized_values.where(localized_page: self).where('key like ? and key like ?', prefix_key + '_%', '%_' + main_property.to_s).order('key ASC')
|
49
|
+
group = values.map { |item|
|
50
|
+
group = LocalizedGroup.new
|
51
|
+
group.page = self
|
52
|
+
group.prefix_key = prefix_key + '_' + item.get_grouped_value_order_key(prefix_key)
|
53
|
+
group
|
54
|
+
}
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# == Schema Information
|
2
|
+
#
|
3
|
+
# Table name: localized_values
|
4
|
+
#
|
5
|
+
# id :integer not null, primary key
|
6
|
+
# localized_page_id :integer
|
7
|
+
# key :string
|
8
|
+
# value :string
|
9
|
+
# created_at :datetime not null
|
10
|
+
# updated_at :datetime not null
|
11
|
+
# type :string
|
12
|
+
#
|
13
|
+
|
14
|
+
module LocalizableValue
|
15
|
+
class LocalizedValue < ActiveRecord::Base
|
16
|
+
belongs_to :localized_page
|
17
|
+
|
18
|
+
def get_grouped_value_order_key(prefix)
|
19
|
+
prefix_length = prefix.length + 1
|
20
|
+
without_prefix = key[prefix_length, key.length - prefix_length]
|
21
|
+
order_index = without_prefix.index('_')
|
22
|
+
without_prefix[0, order_index]
|
23
|
+
end
|
24
|
+
|
25
|
+
def get_grouped_value_order(prefix)
|
26
|
+
get_grouped_value_order_key(prefix).to_i
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module LocalizableValue
|
3
|
+
class LocalizableImageUploader < CarrierWave::Uploader::Base
|
4
|
+
|
5
|
+
# Include RMagick or MiniMagick support:
|
6
|
+
# include CarrierWave::RMagick
|
7
|
+
# include CarrierWave::MiniMagick
|
8
|
+
|
9
|
+
# Choose what kind of storage to use for this uploader:
|
10
|
+
# storage :file
|
11
|
+
# storage :fog
|
12
|
+
|
13
|
+
# Override the directory where uploaded files will be stored.
|
14
|
+
# This is a sensible default for uploaders that are meant to be mounted:
|
15
|
+
def store_dir
|
16
|
+
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
|
17
|
+
end
|
18
|
+
|
19
|
+
# Provide a default URL as a default if there hasn't been a file uploaded:
|
20
|
+
# def default_url
|
21
|
+
# # For Rails 3.1+ asset pipeline compatibility:
|
22
|
+
# # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
|
23
|
+
#
|
24
|
+
# "/images/fallback/" + [version_name, "default.png"].compact.join('_')
|
25
|
+
# end
|
26
|
+
|
27
|
+
# Process files as they are uploaded:
|
28
|
+
# process :scale => [200, 300]
|
29
|
+
#
|
30
|
+
# def scale(width, height)
|
31
|
+
# # do something
|
32
|
+
# end
|
33
|
+
|
34
|
+
# Create different versions of your uploaded files:
|
35
|
+
# version :thumb do
|
36
|
+
# process :resize_to_fit => [50, 50]
|
37
|
+
# end
|
38
|
+
|
39
|
+
# Add a white list of extensions which are allowed to be uploaded.
|
40
|
+
# For images you might use something like this:
|
41
|
+
# def extension_white_list
|
42
|
+
# %w(jpg jpeg gif png)
|
43
|
+
# end
|
44
|
+
|
45
|
+
# Override the filename of the uploaded files:
|
46
|
+
# Avoid using model.id or version_name here, see uploader/store.rb for details.
|
47
|
+
# def filename
|
48
|
+
# "something.jpg" if original_filename
|
49
|
+
# end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
namespace :localizable do
|
2
|
+
task setup: :environment do
|
3
|
+
ActiveRecord::Schema.define do
|
4
|
+
unless ActiveRecord::Base.connection.tables.include? 'localized_pages'
|
5
|
+
create_table :localized_pages do |t|
|
6
|
+
t.string :locale, null: false
|
7
|
+
t.string :page_uid, null: false
|
8
|
+
|
9
|
+
t.timestamps null: false
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
unless ActiveRecord::Base.connection.tables.include? 'localized_values'
|
14
|
+
create_table :localized_values do |t|
|
15
|
+
t.references :localized_page, index: true, foreign_key: true
|
16
|
+
t.string :key, null: false
|
17
|
+
t.string :type
|
18
|
+
t.string :value
|
19
|
+
|
20
|
+
t.timestamps null: false
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "localizable_value/version"
|
2
|
+
|
3
|
+
module LocalizableValue
|
4
|
+
# Your code goes here...
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'localizable_value/engine'
|
8
|
+
require "localizable_value/railtie"
|
9
|
+
require "localizable_value/app/uploaders/localizable_image_uploader"
|
10
|
+
require "localizable_value/app/models/localized_page"
|
11
|
+
require "localizable_value/app/models/localized_value"
|
12
|
+
require "localizable_value/app/models/localized_image"
|
13
|
+
require "localizable_value/app/models/localized_group"
|
14
|
+
# require "localizable_value/app/controllers/localized_values_controller"
|
15
|
+
# require "localizable_value/config/routes"
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'localizable_value/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "localizable_value"
|
8
|
+
spec.version = LocalizableValue::VERSION
|
9
|
+
spec.authors = ["Henrique Rangel"]
|
10
|
+
spec.email = ["dev@hrangel.com.br"]
|
11
|
+
|
12
|
+
spec.summary = <<SUM
|
13
|
+
Gem to allow easy editable localized text and other elements
|
14
|
+
SUM
|
15
|
+
spec.description = <<DESC
|
16
|
+
Gem to allow easy editable localized text and other elements
|
17
|
+
DESC
|
18
|
+
spec.homepage = "https://github.com/hrangel/localizable_value"
|
19
|
+
spec.license = "MIT"
|
20
|
+
|
21
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
22
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
23
|
+
if spec.respond_to?(:metadata)
|
24
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
25
|
+
else
|
26
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
27
|
+
"public gem pushes."
|
28
|
+
end
|
29
|
+
|
30
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
31
|
+
f.match(%r{^(test|spec|features)/})
|
32
|
+
end
|
33
|
+
spec.bindir = "exe"
|
34
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
35
|
+
spec.require_paths = ["lib"]
|
36
|
+
|
37
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
38
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
39
|
+
end
|
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: localizable_value
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.20
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Henrique Rangel
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-02-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.13'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.13'
|
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
|
+
description: |2
|
42
|
+
Gem to allow easy editable localized text and other elements
|
43
|
+
email:
|
44
|
+
- dev@hrangel.com.br
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- CODE_OF_CONDUCT.md
|
51
|
+
- Gemfile
|
52
|
+
- LICENSE.txt
|
53
|
+
- README.md
|
54
|
+
- Rakefile
|
55
|
+
- app/controllers/localizable_value/localized_values_controller.rb
|
56
|
+
- app/helpers/localizable_value_helper.rb
|
57
|
+
- app/views/localizable_value/_element.html.slim
|
58
|
+
- app/views/localizable_value/_link.html.slim
|
59
|
+
- app/views/localizable_value/_link_attr.html.slim
|
60
|
+
- app/views/localizable_value/_string.html.slim
|
61
|
+
- app/views/localizable_value/_string_read.html.slim
|
62
|
+
- app/views/localizable_value/_text.html.slim
|
63
|
+
- bin/console
|
64
|
+
- bin/setup
|
65
|
+
- config/routes.rb
|
66
|
+
- lib/localizable_value.rb
|
67
|
+
- lib/localizable_value/app/models/localized_group.rb
|
68
|
+
- lib/localizable_value/app/models/localized_image.rb
|
69
|
+
- lib/localizable_value/app/models/localized_page.rb
|
70
|
+
- lib/localizable_value/app/models/localized_value.rb
|
71
|
+
- lib/localizable_value/app/uploaders/localizable_image_uploader.rb
|
72
|
+
- lib/localizable_value/engine.rb
|
73
|
+
- lib/localizable_value/railtie.rb
|
74
|
+
- lib/localizable_value/tasks/localizable.rake
|
75
|
+
- lib/localizable_value/version.rb
|
76
|
+
- localizable_value.gemspec
|
77
|
+
homepage: https://github.com/hrangel/localizable_value
|
78
|
+
licenses:
|
79
|
+
- MIT
|
80
|
+
metadata:
|
81
|
+
allowed_push_host: https://rubygems.org
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
requirements: []
|
97
|
+
rubyforge_project:
|
98
|
+
rubygems_version: 2.4.8
|
99
|
+
signing_key:
|
100
|
+
specification_version: 4
|
101
|
+
summary: Gem to allow easy editable localized text and other elements
|
102
|
+
test_files: []
|