Module: RailsMaint::MaintenancePageHelper

Included in:
CLI, Middleware
Defined in:
lib/rails_maint/helpers/maintenance_page_helper.rb

Instance Method Summary collapse

Instance Method Details

#available_localesObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/rails_maint/helpers/maintenance_page_helper.rb', line 36

def available_locales
  base_path = File.expand_path('../../', __FILE__)
  locale_dir = File.join(base_path, 'assets/locales')
  app_locale_dir = 'config/locales'

  gem_locales = Dir.glob("#{locale_dir}/*.yml").map { |f| File.basename(f, '.yml') }
  app_locales = if Dir.exist?(app_locale_dir)
                  Dir.glob("#{app_locale_dir}/rails_maint.*.yml").map { |f| File.basename(f, '.yml').split('.').last }
                else
                  []
                end

  (gem_locales + app_locales).uniq
end

#default_maintenance_page_content(locale = 'en') ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rails_maint/helpers/maintenance_page_helper.rb', line 6

def default_maintenance_page_content(locale = 'en')
  base_path = File.expand_path('../../', __FILE__)
  css_file = File.join(base_path, 'assets/default.css')
  html_file = File.join(base_path, 'assets/maintenance.html')
  locale_file = File.join(base_path, "assets/locales/#{locale}.yml")

  # CSS ve HTML içeriğini oku
  css_content = File.read(css_file)
  html_template = File.read(html_file)

  app_locale_file = "config/locales/rails_maint.#{locale}.yml"

  puts "APP LOCALE FILE: #{app_locale_file}"
  translations = if File.exist?(app_locale_file)
                   YAML.load_file(app_locale_file)[locale]['rails_maint']
                 else
                   YAML.load_file(locale_file)[locale]['rails_maint']
                 end

  # Placeholder'ları değiştir
  html_content = html_template
                   .gsub('<%= css_content %>', css_content)
                   .gsub('<%= lang %>', locale)
                   .gsub('<%= title %>', translations['title'])
                   .gsub('<%= description %>', translations['description'])
                   .gsub('<%= estimated_time %>', translations['estimated_time'])

  html_content
end