]> git.openstreetmap.org Git - rails.git/commitdiff
Tidy
authorAdam Hoyle <atomoil@gmail.com>
Tue, 24 Aug 2021 20:12:48 +0000 (21:12 +0100)
committerAdam Hoyle <atomoil@gmail.com>
Tue, 24 Aug 2021 20:38:05 +0000 (21:38 +0100)
app/models/communities.rb
app/views/site/communities.html.erb

index cd8d6c0fe1e4209bd0914f4b95bff6e536778980..05e330b265383c6cc0d90f56c0042a2f0f7fbf31 100644 (file)
@@ -1,70 +1,55 @@
-
 class Communities
-
-  require 'yaml'
+  require "yaml"
 
   @local_chapters = {}
 
   def self.local_chapters(locale)
-    puts "locale is "+ locale.to_s
-    @local_chapters[locale] = self.local_chapter_for(locale)
+    @local_chapters[locale] = local_chapter_for(locale)
   end
 
-  protected
-
   def self.local_chapter_for(locale)
-
-    @local_chapters_index = self.load_local_chapters
-
-    locale_dict = self.locale_dict_for(locale)
-
+    @local_chapters_index = load_local_chapters
+    locale_dict = locale_dict_for(locale)
     localised_chapters = []
     @local_chapters_index.each do |chapter|
       id = chapter[:id]
-      name = locale_dict.dig(id,"name") || chapter[:name]
+      name = locale_dict.dig(id, "name") || chapter[:name]
       url = chapter[:url]
-      localised_chapters.push({ id: id, name: name, url: url })
+      localised_chapters.push({ :id => id, :name => name, :url => url })
     end
-    puts localised_chapters
     localised_chapters
   end
 
   def self.load_local_chapters
-
-    json_file = File.expand_path("node_modules/osm-community-index/dist/resources.json", Dir.pwd);
+    json_file = File.expand_path("node_modules/osm-community-index/dist/resources.json", Dir.pwd)
     community_index = JSON.parse(File.read(json_file))
-
     local_chapters = []
-    community_index['resources'].each do |id, resource|
+    community_index["resources"].each do |id, resource|
       resource.each do |key, value|
-        if key == "type" and value == "osm-lc" and id != "OSMF"
-          strings = resource['strings']
-          chapter_name = strings['community'] ||strings['name']
-          url = strings['url']
-          local_chapters.push({ id: id, name: chapter_name, url: url})
-        end
+        next unless key == "type" && value == "osm-lc" && id != "OSMF"
+
+        strings = resource["strings"]
+        chapter_name = strings["community"] || strings["name"]
+        url = strings["url"]
+        local_chapters.push({ :id => id, :name => chapter_name, :url => url })
       end
     end
-    return local_chapters
+    local_chapters
   end
 
-
-  def self.locale_dict_for(localeIn)
-    locale = localeIn.to_s.gsub("-","_")
-    full_local_path = File.expand_path("node_modules/osm-community-index/i18n/"+locale+".yaml", Dir.pwd)
+  def self.locale_dict_for(locale_in)
+    locale = locale_in.to_s.tr("-", "_")
+    full_local_path = File.expand_path("node_modules/osm-community-index/i18n/#{locale}.yaml", Dir.pwd)
     locale_dict = {}
-    if File.exists?(full_local_path)
-      locale_dict = YAML.load(File.read(full_local_path))[locale]
+    if File.exist?(full_local_path)
+      locale_dict = YAML.safe_load(File.read(full_local_path))[locale]
     else
       shortened_locale = locale.split("_").first
       if shortened_locale != locale
-        shortened_local_path = File.expand_path("node_modules/osm-community-index/i18n/"+shortened_locale+".yaml", Dir.pwd)
-        if File.exists?(shortened_local_path)
-          locale_dict = YAML.load(File.read(shortened_local_path))[shortened_locale]
-        end
+        shortened_local_path = File.expand_path("node_modules/osm-community-index/i18n/#{shortened_locale}.yaml", Dir.pwd)
+        locale_dict = YAML.safe_load(File.read(shortened_local_path))[shortened_locale] if File.exist?(shortened_local_path)
       end
     end
-    return locale_dict
+    locale_dict
   end
-
 end
index b92b3140c031b7859c96d4bfb6bbed9a9bc4ea04..d09c36caa052f5460823a3494982701fe185c150 100644 (file)
@@ -16,4 +16,4 @@
   </ul>
   <h2><%= t ".other_groups.title", :locale => @locale %></h2>
   <p><%= t ".other_groups.about_html", :locale => @locale %></p>
-<% end %>
\ No newline at end of file
+<% end %>