Skip to content

Commit 830ba2f

Browse files
committed
Merge branch 'feature/rails-5-2' of github.com:refinery/refinerycms into feature/rails-5-2
2 parents 046265e + 164c441 commit 830ba2f

56 files changed

Lines changed: 559 additions & 410 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ end
2828
if !ENV['TRAVIS'] || ENV['DB'] == 'mysql'
2929
group :mysql do
3030
gem 'activerecord-jdbcmysql-adapter', '>= 1.3.0.rc1', platform: :jruby
31-
gem 'mysql2', '~> 0.3.18', :platform => :ruby
31+
gem 'mysql2', '~> 0.4.10', :platform => :ruby
3232
end
3333
end
3434

changelog.md

Lines changed: 58 additions & 26 deletions
Large diffs are not rendered by default.

core/lib/generators/refinery/engine/engine_generator.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,6 @@ def reject_file?(file)
4343
def in_frontend_directory?(file)
4444
file.to_s.include?('app') && file.to_s.scan(/admin|models|mailers/).empty?
4545
end
46+
4647
end
4748
end

core/lib/generators/refinery/engine/templates/Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ end
2020

2121
platforms :ruby do
2222
gem 'sqlite3'
23-
gem 'mysql2'
23+
gem 'mysql2', '~> 0.4.10'
2424
gem 'pg'
2525
end
2626

core/lib/generators/refinery/engine/templates/app/controllers/refinery/namespace/plural_name_controller.rb.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ module Refinery
2626
end
2727

2828
def find_page
29-
@page = ::Refinery::Page.where(:link_url => "/<%= plural_name %>").first
29+
@page = ::Refinery::Page.where(link_url: "<%= index_route %>").first
3030
end
3131

3232
end

core/lib/generators/refinery/engine/templates/app/models/refinery/namespace/singular_name.rb.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module Refinery
66
<% end %>
77
<% if localized? -%>
88

9+
extend Mobility
910
translates <%= localized_attributes.map { |a| ":#{a.name}" }.join(', ') %>
1011
<% end -%>
1112
<% if string_attributes.any? -%>

core/lib/generators/refinery/engine/templates/app/views/refinery/namespace/admin/plural_name/_form.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
<% if localized? -%>
1111
<%%= render '/refinery/admin/locale_picker',
12-
:current_locale => Globalize.locale %>
12+
:current_locale => Mobility.locale %>
1313
<% end -%>
1414
<% attributes.each_with_index do |attribute, index| -%>
1515
<% if attribute.refinery_type == :image -%>
@@ -52,7 +52,7 @@
5252
continue_editing: false,
5353
delete_title: t('delete', scope: 'refinery.<%= plural_name %>.admin.<%= plural_name %>.<%= singular_name %>'),
5454
delete_confirmation: t('message', scope: 'refinery.admin.delete'<% if (title = attributes.detect { |a| a.type.to_s == "string" }).present? %>, title: @<%= singular_name %>.<%= title.name %><% end %>),
55-
cancel_url: refinery.<%= plural_name %>_admin_<%= plural_name %>_path -%>
55+
cancel_url: refinery.<%= namespacing.underscore %>_admin_<%= plural_name %>_path -%>
5656
<%% end -%>
5757
<% if text_areas.any? -%>
5858

core/lib/generators/refinery/engine/templates/db/migrate/1_create_namespace_plural_name.rb.erb

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,30 @@ class Create<%= namespacing %><%= class_name.pluralize %> < ActiveRecord::Migrat
22

33
def up
44
create_table :refinery_<%= "#{namespacing.underscore}_" if table_name != namespacing.underscore.pluralize -%><%= table_name %> do |t|
5-
<% attributes.each do |attribute| -%>
5+
<% (attributes - localized_attributes).each do |attribute| -%>
66
t.<%= attribute.type %> :<%= attribute.column_name %>
77
<% end -%>
88
t.integer :position
99

1010
t.timestamps
1111
end
12+
1213
<% if localized? %>
13-
Refinery::<%= namespacing %>::<%= class_name %>.create_translation_table! <%= attributes_for_translation_table %>
14+
create_table :<%= localized_table_name %> do |t|
15+
<% localized_attributes.each do |attribute| -%>
16+
t.<%= attribute.type %> :<%= attribute.column_name %>
17+
<% end -%>
18+
t.string :locale, null: false
19+
t.integer :refinery_<%= singular_table_name %>_id, null: false
20+
t.timestamps
21+
end
22+
23+
add_index :<%= localized_table_name %>, :locale, name: :index_<%= localized_table_name %>_on_locale
24+
add_index :<%= localized_table_name %>, [:refinery_<%= singular_table_name %>_id, :locale], name: :index_<%= Digest::SHA1.hexdigest(localized_table_name) %>, unique: true
1425
<% end %>
1526
end
1627

28+
1729
def down
1830
if defined?(::Refinery::UserPlugin)
1931
::Refinery::UserPlugin.destroy_all({:name => "refinerycms-<%= namespacing.underscore %>"})
@@ -25,8 +37,7 @@ class Create<%= namespacing %><%= class_name.pluralize %> < ActiveRecord::Migrat
2537
<% end %>
2638
drop_table :refinery_<%= "#{namespacing.underscore}_" if table_name != namespacing.underscore.pluralize -%><%= table_name %>
2739
<% if localized? %>
28-
Refinery::<%= namespacing %>::<%= class_name %>.drop_translation_table!
40+
drop_table :<%= localized_table_name %>
2941
<% end %>
3042
end
31-
3243
end

core/lib/refinery/core/engine.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ def refinery_inclusion!
4444
WillPaginate.per_page = 20
4545
end
4646

47+
initializer "refinery.mobility" do
48+
Mobility.configure do |config|
49+
config.default_backend = :table
50+
config.accessor_method = :translates
51+
config.query_method = :i18n
52+
config.default_options[:dirty] = true
53+
end
54+
end
55+
4756
before_inclusion do
4857
Refinery::Plugin.register do |plugin|
4958
plugin.pathname = root

core/lib/refinery/extension_generation.rb

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ def localized_attributes
6868
@localized_attributes ||= attributes.select{ |a| options[:i18n].include?(a.name)}
6969
end
7070

71+
def localized_table_name
72+
localized_table_name = [ 'refinery']
73+
localized_table_name << namespacing.underscore if table_name != namespacing.underscore.pluralize
74+
localized_table_name << [ singular_table_name, 'translations']
75+
localized_table_name.join('_')
76+
end
77+
7178
def attributes_for_translation_table
7279
localized_attributes.inject([]) { |memo, attr| memo << ":#{attr.name} => :#{attr.type}"}.join(', ')
7380
end
@@ -333,6 +340,14 @@ def substitute_path_placeholders(path)
333340
gsub('namespace', namespacing.underscore)
334341
end
335342

343+
def index_route
344+
if namespacing.underscore == plural_name
345+
'/' + plural_name
346+
else
347+
'/' + namespacing.underscore + '/' + plural_name
348+
end
349+
end
350+
336351
def viable_templates
337352
@viable_templates ||= begin
338353
all_templates.reject(&method(:reject_template?)).inject({}) do |hash, path|
@@ -393,8 +408,10 @@ def templated_merge!
393408
end
394409
end
395410

411+
# merge_rb is only used for merging routes.rb
412+
# Put destination lines first, so that extension namespaced routes precede the default extension route
396413
def merge_rb
397-
(source_lines[0..-2] + destination_lines[1..-2] + [source_lines.last]).join "\n"
414+
(destination_lines[0..-2] + source_lines[1..-2] + [destination_lines.last]).join "\n"
398415
end
399416

400417
def merge_yaml

0 commit comments

Comments
 (0)