releaf-core 3.0.3 → 4.0.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 +4 -4
- data/app/assets/javascripts/releaf/include/field.type_richtext.js +2 -18
- data/app/assets/javascripts/releaf/include/remote_validator.js +2 -12
- data/app/assets/stylesheets/releaf/environment/mixins/blocks.scss +1 -1
- data/app/assets/stylesheets/releaf/layout/fields.scss +1 -2
- data/app/assets/stylesheets/releaf/layout.scss +0 -1
- data/app/builders/releaf/builders/form_builder/fields.rb +0 -1
- data/app/builders/releaf/builders/form_builder/richtext_fields.rb +1 -3
- data/app/builders/releaf/builders/utilities/resolve_attribute_field_method_name.rb +2 -7
- data/app/controllers/releaf/action_controller.rb +0 -1
- data/app/helpers/releaf/button_helper.rb +1 -1
- data/app/lib/releaf/default_searchable_fields.rb +1 -12
- data/app/lib/releaf/resource_base.rb +1 -9
- data/app/lib/releaf/resource_params.rb +0 -12
- data/app/lib/releaf/resource_table_fields.rb +1 -1
- data/app/lib/releaf/search.rb +1 -8
- data/lib/generators/dummy/templates/config/routes.rb +0 -37
- data/lib/generators/dummy/templates/initializers/releaf.rb +1 -26
- data/lib/generators/dummy/templates/migrations/create_books.rb +1 -2
- data/lib/generators/dummy/templates/models/book.rb +0 -3
- data/lib/generators/releaf/templates/initializers/releaf.rb +1 -3
- data/lib/generators/releaf/templates/seeds/seeds.rb +0 -10
- data/lib/releaf/humanize_missing_translations.rb +13 -0
- data/lib/releaf/route_mapper.rb +0 -3
- data/lib/releaf-core.rb +2 -3
- metadata +16 -75
- data/app/assets/javascripts/ckeditor/plugins/mediaembed/icons/hidpi/mediaembed.png +0 -0
- data/app/assets/javascripts/ckeditor/plugins/mediaembed/icons/mediaembed.png +0 -0
- data/app/assets/javascripts/ckeditor/plugins/mediaembed/lang/en.js +0 -12
- data/app/assets/javascripts/ckeditor/plugins/mediaembed/lang/es.js +0 -12
- data/app/assets/javascripts/ckeditor/plugins/mediaembed/plugin.js +0 -63
- data/app/assets/javascripts/releaf/include/localization.js +0 -208
- data/app/assets/stylesheets/releaf/layout/localization.scss +0 -79
- data/app/builders/releaf/builders/form_builder/i18n_fields.rb +0 -75
- data/app/lib/releaf/action_controller/richtext_attachments.rb +0 -20
- data/app/models/releaf/richtext_attachment.rb +0 -6
- data/lib/generators/dummy/templates/assets/javascripts/controllers/admin/nodes.js +0 -1
- data/lib/generators/dummy/templates/assets/javascripts/controllers/admin/other_site/other_nodes.js +0 -1
- data/lib/generators/dummy/templates/assets/stylesheets/controllers/admin/nodes.scss +0 -1
- data/lib/generators/dummy/templates/assets/stylesheets/controllers/admin/other_site/other_nodes.scss +0 -1
- data/lib/generators/dummy/templates/builders/admin/nodes/form_builder.rb +0 -7
- data/lib/generators/dummy/templates/controllers/admin/nodes_controller.rb +0 -3
- data/lib/generators/dummy/templates/controllers/admin/other_site/other_nodes_controller.rb +0 -3
- data/lib/generators/dummy/templates/controllers/application_controller.rb +0 -61
- data/lib/generators/dummy/templates/controllers/concerns/node_controller.rb +0 -47
- data/lib/generators/dummy/templates/controllers/contacts_controller.rb +0 -5
- data/lib/generators/dummy/templates/controllers/home_pages_controller.rb +0 -3
- data/lib/generators/dummy/templates/controllers/text_pages_controller.rb +0 -3
- data/lib/generators/dummy/templates/migrations/create_banner_pages.rb +0 -11
- data/lib/generators/dummy/templates/migrations/create_bundles.rb +0 -7
- data/lib/generators/dummy/templates/migrations/create_home_pages.rb +0 -9
- data/lib/generators/dummy/templates/migrations/create_node_extra_fields.rb +0 -5
- data/lib/generators/dummy/templates/migrations/create_other_nodes.rb +0 -29
- data/lib/generators/dummy/templates/migrations/create_text_pages.rb +0 -9
- data/lib/generators/dummy/templates/models/banner_page.rb +0 -7
- data/lib/generators/dummy/templates/models/bundle.rb +0 -17
- data/lib/generators/dummy/templates/models/home_page.rb +0 -3
- data/lib/generators/dummy/templates/models/node.rb +0 -10
- data/lib/generators/dummy/templates/models/other_site/other_node.rb +0 -7
- data/lib/generators/dummy/templates/models/text_page.rb +0 -4
- data/lib/generators/dummy/templates/views/contacts/show.html.haml +0 -1
- data/lib/generators/dummy/templates/views/home_pages/show.haml +0 -1
- data/lib/generators/dummy/templates/views/layouts/application.html.haml +0 -30
- data/lib/generators/dummy/templates/views/text_pages/show.haml +0 -1
- data/lib/generators/releaf/templates/migrations/create_releaf_nodes.rb +0 -28
- data/lib/generators/releaf/templates/migrations/create_releaf_richtext_attachments.rb +0 -12
- data/lib/generators/releaf/templates/migrations/create_releaf_translations.rb +0 -20
- data/lib/generators/releaf/templates/models/node.rb +0 -3
- data/lib/releaf/rails_ext/globalize-accessors.rb +0 -64
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
module Releaf::Builders::FormBuilder::I18nFields
|
|
2
|
-
def releaf_text_i18n_field(name, input: {}, label: {}, field: {}, options: {})
|
|
3
|
-
options = {field: {type: "text"}}.deep_merge(options)
|
|
4
|
-
input = {class: "text"}.deep_merge(input)
|
|
5
|
-
localized_field(name, :text_field, input: input, label: label, field: field, options: options)
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
def releaf_link_i18n_field(name, input: {}, label: {}, field: {}, options: {})
|
|
9
|
-
options = {field: {type: "link"}}.deep_merge(options)
|
|
10
|
-
releaf_text_i18n_field(name, input: input, label: label, field: field, options: options)
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def releaf_textarea_i18n_field(name, input: {}, label: {}, field: {}, options: {})
|
|
14
|
-
input = {
|
|
15
|
-
rows: 5,
|
|
16
|
-
cols: 75,
|
|
17
|
-
}.merge(input)
|
|
18
|
-
options = {field: {type: "textarea"}}.deep_merge(options)
|
|
19
|
-
localized_field(name, :text_area, input: input, label: label, field: field, options: options)
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def releaf_richtext_i18n_field(name, input: {}, label: {}, field: {}, options: {})
|
|
23
|
-
input = richtext_input_attributes(name).merge(input)
|
|
24
|
-
options = richtext_options(name, options)
|
|
25
|
-
releaf_textarea_i18n_field(name, input: input, label: label, field: field, options: options)
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def localized_field(name, field_type, input: {}, label: {}, field: {}, options: {})
|
|
29
|
-
options = {i18n: true, label: {translation_key: name}}.deep_merge(options)
|
|
30
|
-
|
|
31
|
-
wrapper(field_attributes(name, field, options)) do
|
|
32
|
-
content = object.class.globalize_locales.collect do |locale|
|
|
33
|
-
localized_name = "#{name}_#{locale}"
|
|
34
|
-
html_class = ["localization"]
|
|
35
|
-
html_class << "active" if locale == default_locale
|
|
36
|
-
|
|
37
|
-
tag(:div, class: html_class, data: {locale: locale}) do
|
|
38
|
-
releaf_label(localized_name, label, options) <<
|
|
39
|
-
tag(:div, class: "value") do
|
|
40
|
-
attributes = input_attributes(name, {value: object.send(localized_name)}.merge(input), options)
|
|
41
|
-
send(field_type, localized_name, attributes)
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
content << localization_switch
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
def localization_switch
|
|
51
|
-
tag(:div, class: "localization-switch") do
|
|
52
|
-
button_tag(type: 'button', title: t('Switch locale'), class: "trigger") do
|
|
53
|
-
tag(:span, default_locale, class: "label") + tag(:i, nil, class: ["fa", "fa-chevron-down"])
|
|
54
|
-
end <<
|
|
55
|
-
tag(:menu, class: ["localization-menu-items"], type: 'toolbar') do
|
|
56
|
-
tag(:ul) do
|
|
57
|
-
object.class.globalize_locales.collect do |locale|
|
|
58
|
-
tag(:li) do
|
|
59
|
-
tag(:button, translate_locale(locale), type: "button", data: {locale: locale})
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
def locales
|
|
68
|
-
object.class.globalize_locales
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
def default_locale
|
|
72
|
-
selected_locale = (layout_settings("releaf.i18n.locale") || I18n.locale).to_sym
|
|
73
|
-
locales.include?(selected_locale) ? selected_locale : locales.first
|
|
74
|
-
end
|
|
75
|
-
end
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
module Releaf::ActionController::RichtextAttachments
|
|
2
|
-
extend ActiveSupport::Concern
|
|
3
|
-
|
|
4
|
-
included do
|
|
5
|
-
skip_before_action :verify_authenticity_token, only: [:create_releaf_richtext_attachment]
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
def releaf_richtext_attachment_upload_url
|
|
9
|
-
begin
|
|
10
|
-
url_for(action: :create_releaf_richtext_attachment)
|
|
11
|
-
rescue ::ActionController::UrlGenerationError
|
|
12
|
-
nil
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def create_releaf_richtext_attachment
|
|
17
|
-
return unless params[:upload]
|
|
18
|
-
@resource = Releaf::RichtextAttachment.create!(file_type: params[:upload].content_type, file: params[:upload])
|
|
19
|
-
end
|
|
20
|
-
end
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//= require controllers/releaf/content/nodes
|
data/lib/generators/dummy/templates/assets/javascripts/controllers/admin/other_site/other_nodes.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//= require controllers/releaf/content/nodes
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
@import 'controllers/releaf/content/nodes';
|
data/lib/generators/dummy/templates/assets/stylesheets/controllers/admin/other_site/other_nodes.scss
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
@import 'controllers/releaf/content/nodes';
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
class ApplicationController < ActionController::Base
|
|
2
|
-
class PageNotFound < StandardError; end
|
|
3
|
-
rescue_from ActionController::RoutingError, with: :render_404
|
|
4
|
-
rescue_from ActiveRecord::RecordNotFound, with: :render_404
|
|
5
|
-
|
|
6
|
-
protect_from_forgery with: :exception
|
|
7
|
-
before_action :set_locale
|
|
8
|
-
layout "application"
|
|
9
|
-
helper_method :translation_scope, :node_class, :site
|
|
10
|
-
|
|
11
|
-
def render_404
|
|
12
|
-
render file: Rails.root.join('public', '404.html'), status: 404, layout: nil
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def set_locale
|
|
16
|
-
I18n.locale = params[:locale]
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def redirect_to_locale_root
|
|
20
|
-
# if no matching root found for any of client locales
|
|
21
|
-
# use first root
|
|
22
|
-
target_root = available_roots.first
|
|
23
|
-
if target_root
|
|
24
|
-
redirect_to target_root.path
|
|
25
|
-
else
|
|
26
|
-
render plain: "Welcome to Releaf", layout: true
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def translation_scope
|
|
31
|
-
"public." + self.class.name.gsub("Controller", "").underscore
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def node_class
|
|
35
|
-
if @node_class.blank?
|
|
36
|
-
# this method detects whether the dummy application is running in a single or multiple node context
|
|
37
|
-
routing = Releaf::Content.routing
|
|
38
|
-
|
|
39
|
-
if routing.length == 1
|
|
40
|
-
# for single node class site
|
|
41
|
-
# the node class is the first and only defined class
|
|
42
|
-
node_class = routing.keys.first.constantize
|
|
43
|
-
else
|
|
44
|
-
# for multinode sites
|
|
45
|
-
# for non-node routes the node class can be detected from hostname via routing config
|
|
46
|
-
node_class = Releaf::Content.routing.find { |node_class_name, options| request.host =~ options[:constraints][:host] }.first.constantize
|
|
47
|
-
end
|
|
48
|
-
@node_class = node_class
|
|
49
|
-
end
|
|
50
|
-
@node_class
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def site
|
|
54
|
-
# for non-node routes site is detectable from node class via routing config
|
|
55
|
-
@site = Releaf::Content.routing[node_class.name][:site]
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
def available_roots
|
|
59
|
-
@roots ||= node_class.roots.where(locale: I18n.available_locales, active: true)
|
|
60
|
-
end
|
|
61
|
-
end
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
module NodeController
|
|
2
|
-
extend ActiveSupport::Concern
|
|
3
|
-
|
|
4
|
-
included do
|
|
5
|
-
before_action :load_node
|
|
6
|
-
# node finding helpers
|
|
7
|
-
helper_method :root_node, :menu, :node_active?
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def show
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def root_node
|
|
14
|
-
@root ||= available_roots.find_by(locale: I18n.locale)
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def menu
|
|
18
|
-
@menu ||= root_node.children.where(active: true)
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def node_class
|
|
22
|
-
# for node routes the node class can be detected from params
|
|
23
|
-
@node_class ||= params[:node_class].constantize
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def site
|
|
27
|
-
# for node routes site can be detected from params
|
|
28
|
-
@site ||= params[:site]
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def node_active? node
|
|
32
|
-
@active_nodes.include? node
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
private
|
|
36
|
-
|
|
37
|
-
def load_node
|
|
38
|
-
@node = node_class.find(params[:node_id])
|
|
39
|
-
@content = @node.content unless @node.nil?
|
|
40
|
-
|
|
41
|
-
@active_nodes = []
|
|
42
|
-
if @node.present?
|
|
43
|
-
@active_nodes += @node.ancestors.reorder(node_class.arel_table[:depth])
|
|
44
|
-
@active_nodes << @node
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
end
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
class CreateOtherNodes < ActiveRecord::Migration[5.0]
|
|
2
|
-
def change
|
|
3
|
-
create_table "other_nodes", :force => true do |t|
|
|
4
|
-
t.string "name"
|
|
5
|
-
t.string "slug"
|
|
6
|
-
t.integer "parent_id"
|
|
7
|
-
t.integer "lft"
|
|
8
|
-
t.integer "rgt"
|
|
9
|
-
t.integer "depth"
|
|
10
|
-
t.string "locale", :limit => 6
|
|
11
|
-
t.string "content_type"
|
|
12
|
-
t.integer "content_id"
|
|
13
|
-
t.datetime "created_at", :null => false
|
|
14
|
-
t.datetime "updated_at", :null => false
|
|
15
|
-
t.integer "item_position"
|
|
16
|
-
t.boolean 'active', :null => false, :default => true
|
|
17
|
-
t.text 'description'
|
|
18
|
-
end
|
|
19
|
-
add_index :other_nodes, :parent_id
|
|
20
|
-
add_index :other_nodes, [:content_type, :content_id]
|
|
21
|
-
add_index :other_nodes, :lft
|
|
22
|
-
add_index :other_nodes, :rgt
|
|
23
|
-
add_index :other_nodes, :depth
|
|
24
|
-
add_index :other_nodes, :slug
|
|
25
|
-
add_index :other_nodes, :name
|
|
26
|
-
add_index :other_nodes, :active
|
|
27
|
-
add_index :other_nodes, :locale
|
|
28
|
-
end
|
|
29
|
-
end
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
class BannerPage < ActiveRecord::Base
|
|
2
|
-
acts_as_node
|
|
3
|
-
has_many :banner_groups, -> { order(:item_position) }, dependent: :destroy
|
|
4
|
-
accepts_nested_attributes_for :banner_groups, allow_destroy: true
|
|
5
|
-
dragonfly_accessor :top_banner
|
|
6
|
-
dragonfly_accessor :bottom_banner
|
|
7
|
-
end
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
class Bundle < ActiveRecord::Base
|
|
2
|
-
acts_as_node
|
|
3
|
-
|
|
4
|
-
# This model was created especially to test a specific bug, that was
|
|
5
|
-
# discovered with such classes as this.
|
|
6
|
-
# It turns out that Node didn't create content object because no field of
|
|
7
|
-
# placeholder model was rendered in form, thus no attribute of content object
|
|
8
|
-
# was submitted.
|
|
9
|
-
#
|
|
10
|
-
# This class was added to test this bug, and to prevent regressions.
|
|
11
|
-
#
|
|
12
|
-
# Real life scenario:
|
|
13
|
-
# At the moment of impllementing system, programmer knew he will need to
|
|
14
|
-
# create bundles, however details about this funcionality wasn't fully clear.
|
|
15
|
-
# Thus he created placeholder model.
|
|
16
|
-
#
|
|
17
|
-
end
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
class Node < ActiveRecord::Base
|
|
2
|
-
include Releaf::Content::Node
|
|
3
|
-
validates_with Releaf::Content::Node::RootValidator, allow: [HomePage]
|
|
4
|
-
validates_with Releaf::Content::Node::ParentValidator, for: [ContactsController], under: HomePage
|
|
5
|
-
validates_with Releaf::Content::Node::SinglenessValidator, for: [ContactsController], under: HomePage
|
|
6
|
-
|
|
7
|
-
def locale_selection_enabled?
|
|
8
|
-
root?
|
|
9
|
-
end
|
|
10
|
-
end
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
= link_to "Releaf github repository", 'https://github.com/cubesystems/releaf'
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
= @content.intro_text_html.html_safe
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
!!!
|
|
2
|
-
%html
|
|
3
|
-
%head
|
|
4
|
-
%meta{:'http-equiv' => 'Content-Type', :content => 'text/html; charset=utf-8'}
|
|
5
|
-
%title AppName
|
|
6
|
-
- %w[.scss .css.scss .css].each do |ext|
|
|
7
|
-
- if File.exists?(Rails.root.to_s + "/app/assets/stylesheets/controllers/#{ params[:controller] + ext }")
|
|
8
|
-
= stylesheet_link_tag "controllers/#{params[:controller]}"
|
|
9
|
-
- break
|
|
10
|
-
|
|
11
|
-
= csrf_meta_tags
|
|
12
|
-
%body(class = "#{params[:controller].tr('/', '-')}-controller #{params[:action]}-view #{I18n.locale}-locale")
|
|
13
|
-
#body_wrap
|
|
14
|
-
#content_wrap
|
|
15
|
-
#header
|
|
16
|
-
%p
|
|
17
|
-
Site:
|
|
18
|
-
= site
|
|
19
|
-
%p
|
|
20
|
-
Node class:
|
|
21
|
-
= node_class
|
|
22
|
-
%p
|
|
23
|
-
Node name:
|
|
24
|
-
= @node.name if @node.present?
|
|
25
|
-
#content= yield
|
|
26
|
-
#footer
|
|
27
|
-
Footer
|
|
28
|
-
|
|
29
|
-
- if File.exists? Rails.root.to_s + "/app/assets/javascripts/controllers/#{params[:controller]}.js"
|
|
30
|
-
= javascript_include_tag "controllers/#{params[:controller]}"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
=@content.text_html.html_safe
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
class CreateReleafNodes < ActiveRecord::Migration[5.0]
|
|
2
|
-
def change
|
|
3
|
-
create_table "nodes", :force => true do |t|
|
|
4
|
-
t.string "name"
|
|
5
|
-
t.string "slug"
|
|
6
|
-
t.integer "parent_id"
|
|
7
|
-
t.integer "lft"
|
|
8
|
-
t.integer "rgt"
|
|
9
|
-
t.integer "depth"
|
|
10
|
-
t.string "locale", :limit => 6
|
|
11
|
-
t.string "content_type"
|
|
12
|
-
t.integer "content_id"
|
|
13
|
-
t.datetime "created_at", :null => false
|
|
14
|
-
t.datetime "updated_at", :null => false
|
|
15
|
-
t.integer "item_position"
|
|
16
|
-
t.boolean 'active', :null => false, :default => true
|
|
17
|
-
end
|
|
18
|
-
add_index :nodes, :parent_id
|
|
19
|
-
add_index :nodes, [:content_type, :content_id]
|
|
20
|
-
add_index :nodes, :lft
|
|
21
|
-
add_index :nodes, :rgt
|
|
22
|
-
add_index :nodes, :depth
|
|
23
|
-
add_index :nodes, :slug
|
|
24
|
-
add_index :nodes, :name
|
|
25
|
-
add_index :nodes, :active
|
|
26
|
-
add_index :nodes, :locale
|
|
27
|
-
end
|
|
28
|
-
end
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
class CreateReleafRichtextAttachments < ActiveRecord::Migration[5.0]
|
|
2
|
-
def change
|
|
3
|
-
create_table :releaf_richtext_attachments do |t|
|
|
4
|
-
t.string :file_uid
|
|
5
|
-
t.string :file_name
|
|
6
|
-
t.string :file_type
|
|
7
|
-
t.string :title
|
|
8
|
-
|
|
9
|
-
t.timestamps(null: false)
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
end
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
class CreateReleafTranslations < ActiveRecord::Migration[5.0]
|
|
2
|
-
def change
|
|
3
|
-
create_table :releaf_i18n_entries do |t|
|
|
4
|
-
t.string :key, null: false
|
|
5
|
-
t.timestamps null: false
|
|
6
|
-
end
|
|
7
|
-
add_index :releaf_i18n_entries, :key
|
|
8
|
-
|
|
9
|
-
create_table :releaf_i18n_entry_translations do |t|
|
|
10
|
-
t.integer :i18n_entry_id, null: false
|
|
11
|
-
t.string :locale, null: false, limit: 5
|
|
12
|
-
t.text :text
|
|
13
|
-
t.timestamps null: false
|
|
14
|
-
end
|
|
15
|
-
add_index :releaf_i18n_entry_translations, :locale
|
|
16
|
-
add_index :releaf_i18n_entry_translations, :i18n_entry_id
|
|
17
|
-
add_index :releaf_i18n_entry_translations, [:locale, :i18n_entry_id], unique: true,
|
|
18
|
-
name: :index_releaf_i18n_entry_translations_on_locale_i18n_entry_id
|
|
19
|
-
end
|
|
20
|
-
end
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
require 'globalize'
|
|
2
|
-
|
|
3
|
-
module Globalize::Accessors
|
|
4
|
-
def globalize_accessors(options = {})
|
|
5
|
-
options.reverse_merge!(:locales => I18n.available_locales, :attributes => translated_attribute_names)
|
|
6
|
-
class_attribute :globalize_locales, :globalize_attribute_names, :instance_writer => false
|
|
7
|
-
|
|
8
|
-
self.globalize_locales = options[:locales]
|
|
9
|
-
self.globalize_attribute_names = []
|
|
10
|
-
|
|
11
|
-
each_attribute_and_locale(options) do |attr_name, locale|
|
|
12
|
-
define_accessors(attr_name, locale)
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
include InstanceMethods
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def localized_attr_name_for(attr_name, locale)
|
|
19
|
-
"#{attr_name}_#{locale.to_s.underscore}"
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
private
|
|
23
|
-
|
|
24
|
-
def define_accessors(attr_name, locale)
|
|
25
|
-
define_getter(attr_name, locale)
|
|
26
|
-
define_setter(attr_name, locale)
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def define_getter(attr_name, locale)
|
|
30
|
-
define_method localized_attr_name_for(attr_name, locale) do
|
|
31
|
-
globalize.stash.contains?(locale, attr_name) ? globalize.send(:fetch_stash, locale, attr_name) : globalize.send(:fetch_attribute, locale, attr_name)
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def define_setter(attr_name, locale)
|
|
36
|
-
localized_attr_name = localized_attr_name_for(attr_name, locale)
|
|
37
|
-
|
|
38
|
-
define_method :"#{localized_attr_name}=" do |value|
|
|
39
|
-
attribute_will_change!(localized_attr_name) if value != send(localized_attr_name)
|
|
40
|
-
write_attribute(attr_name, value, :locale => locale)
|
|
41
|
-
translation_for(locale)[attr_name] = value
|
|
42
|
-
end
|
|
43
|
-
if respond_to?(:accessible_attributes) && accessible_attributes.include?(attr_name)
|
|
44
|
-
attr_accessible :"#{localized_attr_name}"
|
|
45
|
-
end
|
|
46
|
-
self.globalize_attribute_names << localized_attr_name.to_sym
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def each_attribute_and_locale(options)
|
|
50
|
-
options[:attributes].each do |attr_name|
|
|
51
|
-
options[:locales].each do |locale|
|
|
52
|
-
yield attr_name, locale
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
module InstanceMethods
|
|
58
|
-
def localized_attr_name_for(attr_name, locale)
|
|
59
|
-
self.class.localized_attr_name_for(attr_name, locale)
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
ActiveRecord::Base.extend Globalize::Accessors
|