Skip to content

Commit 8cd74be

Browse files
committed
Supporting zeitwerk
1 parent 4040ea3 commit 8cd74be

File tree

5 files changed

+102
-93
lines changed

5 files changed

+102
-93
lines changed

app/overrides/issues.rb

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,33 @@
1-
Deface::Override.new(
2-
:virtual_path => "issues/index",
3-
:name => "deface_view_issues_index_map",
4-
:insert_after => "h2",
5-
:original => 'b807967c7184cb012c4bd5ccce90893349bc66e3',
6-
:partial => "issues/index/map"
7-
)
1+
module Issues
2+
Deface::Override.new(
3+
:virtual_path => "issues/index",
4+
:name => "deface_view_issues_index_map",
5+
:insert_after => "h2",
6+
:original => 'b807967c7184cb012c4bd5ccce90893349bc66e3',
7+
:partial => "issues/index/map"
8+
)
89

9-
Deface::Override.new(
10-
:virtual_path => "issues/index",
11-
:name => "deface_view_issues_index_format_geojson",
12-
:insert_after => "erb[loud]:contains('PDF')",
13-
:original => '2b4102bf118f0a9866cf50477dce9cc7a78da6d5',
14-
:partial => "issues/index/geojson"
15-
)
10+
Deface::Override.new(
11+
:virtual_path => "issues/index",
12+
:name => "deface_view_issues_index_format_geojson",
13+
:insert_after => "erb[loud]:contains('PDF')",
14+
:original => '2b4102bf118f0a9866cf50477dce9cc7a78da6d5',
15+
:partial => "issues/index/geojson"
16+
)
1617

17-
Deface::Override.new(
18-
:virtual_path => "issues/show",
19-
:name => "deface_view_issues_show_map",
20-
:insert_before => "div.attributes",
21-
:original => '2042e7171bb2eaa98259e9ccbff8209910565e7a',
22-
:partial => "issues/show/map"
23-
)
18+
Deface::Override.new(
19+
:virtual_path => "issues/show",
20+
:name => "deface_view_issues_show_map",
21+
:insert_before => "div.attributes",
22+
:original => '2042e7171bb2eaa98259e9ccbff8209910565e7a',
23+
:partial => "issues/show/map"
24+
)
2425

25-
Deface::Override.new(
26-
:virtual_path => "issues/show",
27-
:name => "deface_view_issues_show_format_geojson",
28-
:insert_after => "erb[loud]:contains('PDF')",
29-
:original => '1419e0dcba37f62ff95372d41d9b73845889d826',
30-
:partial => "issues/show/geojson"
31-
)
26+
Deface::Override.new(
27+
:virtual_path => "issues/show",
28+
:name => "deface_view_issues_show_format_geojson",
29+
:insert_after => "erb[loud]:contains('PDF')",
30+
:original => '1419e0dcba37f62ff95372d41d9b73845889d826',
31+
:partial => "issues/show/geojson"
32+
)
33+
end

app/overrides/projects.rb

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
Deface::Override.new(
2-
:virtual_path => "projects/show",
3-
:name => "deface_view_projects_show_map",
4-
:insert_bottom => "div.splitcontentright",
5-
:original => 'b939fb5ea208476399dbfb4b253dcff0ab1ace91',
6-
:partial => "projects/show/map"
7-
)
1+
module Projects
2+
Deface::Override.new(
3+
:virtual_path => "projects/show",
4+
:name => "deface_view_projects_show_map",
5+
:insert_bottom => "div.splitcontentright",
6+
:original => 'b939fb5ea208476399dbfb4b253dcff0ab1ace91',
7+
:partial => "projects/show/map"
8+
)
89

9-
Deface::Override.new(
10-
:virtual_path => "projects/show",
11-
:name => "deface_view_projects_show_other_formats",
12-
:insert_bottom => "div.splitcontentright",
13-
:original => '868cdb34ed1c52af47076776295dcba1311914f9',
14-
:partial => "projects/show/other_formats"
15-
)
10+
Deface::Override.new(
11+
:virtual_path => "projects/show",
12+
:name => "deface_view_projects_show_other_formats",
13+
:insert_bottom => "div.splitcontentright",
14+
:original => '868cdb34ed1c52af47076776295dcba1311914f9',
15+
:partial => "projects/show/other_formats"
16+
)
17+
end

app/overrides/users.rb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
Deface::Override.new(
2-
:virtual_path => "users/show",
3-
:name => "deface_view_users_show_other_formats",
4-
:insert_bottom => "div.splitcontentleft",
5-
:partial => "users/show/other_formats"
6-
)
1+
module Users
2+
Deface::Override.new(
3+
:virtual_path => "users/show",
4+
:name => "deface_view_users_show_other_formats",
5+
:insert_bottom => "div.splitcontentleft",
6+
:partial => "users/show/other_formats"
7+
)
8+
end

init.rb

Lines changed: 48 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
require 'redmine'
1+
# Global Hooks
2+
require File.expand_path('../lib/redmine_gtt/hooks/view_layouts_base_html_head_hook', __FILE__)
3+
require File.expand_path('../lib/redmine_gtt/view_hooks', __FILE__)
24

35
Redmine::Plugin.register :redmine_gtt do
46
name 'Redmine GTT plugin'
57
author 'Georepublic'
68
author_url 'https://github.com/georepublic'
79
url 'https://github.com/gtt-project/redmine_gtt'
810
description 'Adds location-based task management and maps'
9-
version '3.0.0'
11+
version '3.0.0' # TODO: 4.0.0?
1012

1113
requires_redmine :version_or_higher => '4.0.0'
1214

@@ -38,30 +40,57 @@
3840
caption: :label_gtt_tile_source_plural, :html => {:class => 'icon'}
3941
end
4042

41-
ActiveSupport::Reloader.to_prepare do
43+
# Register MIME Types
44+
Mime::Type.register_alias "application/json", :geojson
4245

43-
# Automatically encode points to geojson with as_json in rails3
44-
RGeo::ActiveRecord::GeometryMixin.set_json_generator(:geojson)
46+
# Automatically encode points to geojson with as_json in rails3
47+
RGeo::ActiveRecord::GeometryMixin.set_json_generator(:geojson)
4548

46-
RedmineGtt.setup_normal_patches
49+
RGeo::ActiveRecord::SpatialFactoryStore.instance.tap do |config|
50+
# By default, use the GEOS implementation for spatial columns.
51+
# config.default = RGeo::Geos.factory_generator
52+
53+
config.register RGeo::Cartesian.preferred_factory(srid: 4326), geo_type: 'geometry', sql_type: "geometry", srid: 4326
4754

48-
# ActiveRecord::Base.include_root_in_json = true
49-
# module RGeo
50-
# module Feature
51-
# module Point
52-
# def as_json(params)
53-
# ::RGeo::GeoJSON.encode(self)
54-
# end
55-
# end
56-
# end
57-
# end
55+
# But use a geographic implementation for point columns.
56+
# config.register(RGeo::Geographic.spherical_factory(srid: 4326), geo_type: "point")
5857
end
5958

60-
Rails.configuration.to_prepare do
61-
RedmineGtt.setup_controller_patches
59+
if Rails.version > '6.0' && Rails.autoloaders.zeitwerk_enabled?
60+
require File.expand_path('../app/overrides/issues', __FILE__)
61+
require File.expand_path('../app/overrides/projects', __FILE__)
62+
require File.expand_path('../app/overrides/users', __FILE__)
63+
RedmineGtt.setup_normal_patches
64+
Rails.application.config.after_initialize do
65+
RedmineGtt.setup_controller_patches
66+
end
67+
else
68+
# Configure View Overrides
69+
Rails.application.paths["app/overrides"] ||= []
70+
Rails.application.paths["app/overrides"] << File.expand_path("../app/overrides", __FILE__)
71+
72+
ActiveSupport::Reloader.to_prepare do
73+
RedmineGtt.setup_normal_patches
74+
75+
# ActiveRecord::Base.include_root_in_json = true
76+
# module RGeo
77+
# module Feature
78+
# module Point
79+
# def as_json(params)
80+
# ::RGeo::GeoJSON.encode(self)
81+
# end
82+
# end
83+
# end
84+
# end
85+
end
86+
87+
Rails.configuration.to_prepare do
88+
RedmineGtt.setup_controller_patches
89+
end
6290
end
6391

64-
class GttListener < Redmine::Hook::ViewListener
92+
#class GttListener < Redmine::Hook::ViewListener
93+
Class.new(Redmine::Hook::ViewListener) do |c|
6594
render_on :view_layouts_base_html_head, inline: <<-END
6695
<%= stylesheet_link_tag 'gtt', :plugin => 'redmine_gtt' %>
6796
END

lib/redmine_gtt.rb

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,5 @@
11
# frozen_string_literal: true
22

3-
# Global Hooks
4-
require 'redmine_gtt/hooks/view_layouts_base_html_head_hook'
5-
require 'redmine_gtt/view_hooks'
6-
7-
8-
# API Template Hooks
9-
# Seems like this is not necessary
10-
# require 'redmine_gtt/patches/api_template_handler_patch.rb'
11-
12-
# Configure View Overrides
13-
Rails.application.paths["app/overrides"] ||= []
14-
Rails.application.paths["app/overrides"] << File.expand_path("../../app/overrides", __FILE__)
15-
16-
# Register MIME Types
17-
Mime::Type.register_alias "application/json", :geojson
18-
19-
RGeo::ActiveRecord::SpatialFactoryStore.instance.tap do |config|
20-
# By default, use the GEOS implementation for spatial columns.
21-
# config.default = RGeo::Geos.factory_generator
22-
23-
config.register RGeo::Cartesian.preferred_factory(srid: 4326), geo_type: 'geometry', sql_type: "geometry", srid: 4326
24-
25-
# But use a geographic implementation for point columns.
26-
# config.register(RGeo::Geographic.spherical_factory(srid: 4326), geo_type: "point")
27-
end
28-
293
module RedmineGtt
304

315
def self.setup_normal_patches

0 commit comments

Comments
 (0)