]> git.openstreetmap.org Git - rails.git/commitdiff
Merge branch 'master' into feature/add-communities-page
authorAdam Hoyle <atomoil@users.noreply.github.com>
Tue, 14 Dec 2021 10:42:42 +0000 (10:42 +0000)
committerGitHub <noreply@github.com>
Tue, 14 Dec 2021 10:42:42 +0000 (10:42 +0000)
app/abilities/ability.rb
app/controllers/site_controller.rb
app/views/layouts/_header.html.erb
app/views/site/communities.html.erb [new file with mode: 0644]
config/locales/en.yml
config/routes.rb
lib/osm_community_index/local_chapter.rb [new file with mode: 0644]
lib/osm_community_index/osm_community_index.rb [new file with mode: 0644]
package.json
yarn.lock

index 769fbca475e401ba9538ae6164cd60f84e6bf6fe..f33ce182dd6a7c7d5f9075c61d85524ee3c9fbdb 100644 (file)
@@ -7,7 +7,7 @@ class Ability
     can [:relation, :relation_history, :way, :way_history, :node, :node_history,
          :changeset, :note, :new_note, :query], :browse
     can :search, :direction
-    can [:index, :permalink, :edit, :help, :fixthemap, :offline, :export, :about, :preview, :copyright, :key, :id], :site
+    can [:index, :permalink, :edit, :help, :fixthemap, :offline, :export, :about, :communities, :preview, :copyright, :key, :id], :site
     can [:finish, :embed], :export
     can [:search, :search_latlon, :search_ca_postcode, :search_osm_nominatim,
          :search_geonames, :search_osm_nominatim_reverse, :search_geonames_reverse], :geocoder
index 00b3e78da4c858b7c36e0211106ba1190e69436c..a73d1e2e50e74f9595605917440a60a5cf7ba4f5 100644 (file)
@@ -106,6 +106,11 @@ class SiteController < ApplicationController
     @locale = params[:about_locale] || I18n.locale
   end
 
+  def communities
+    OsmCommunityIndex::LocalChapter.add_to_i18n # this should be called on app init
+    @local_chapters = OsmCommunityIndex::LocalChapter.local_chapters
+  end
+
   def export; end
 
   def offline; end
index 0171752ff4a4e23966852ff99484028a21bde906..904665ca78451a533901b4cb77aca1e9bd87a793 100644 (file)
@@ -50,6 +50,9 @@
       <li class="compact-hide nav-item <%= current_page_class(diary_entries_path) %>">
         <%= link_to t("layouts.user_diaries"), diary_entries_path, :class => "nav-link" %>
       </li>
+      <li class="compact-hide nav-item <%= current_page_class(communities_path) %>">
+        <%= link_to t("layouts.communities"), communities_path, :class => "nav-link" %>
+      </li>
       <li class="compact-hide nav-item <%= current_page_class(copyright_path) %>">
         <%= link_to t("layouts.copyright"), copyright_path, :class => "nav-link" %>
       </li>
@@ -72,6 +75,7 @@
           <% end %>
           <li class="<%= current_page_class(traces_path) %>"><%= link_to t("layouts.gps_traces"), traces_path, :class => "dropdown-item" %></li>
           <li class="<%= current_page_class(diary_entries_path) %>"><%= link_to t("layouts.user_diaries"), diary_entries_path, :class => "dropdown-item" %></li>
+          <li class="<%= current_page_class(communities_path) %>"><%= link_to t("layouts.communities"), communities_path, :class => "dropdown-item" %></li>
           <li class="<%= current_page_class(copyright_path) %>"><%= link_to t("layouts.copyright"), copyright_path, :class => "dropdown-item" %></li>
           <li class="<%= current_page_class(help_path) %>"><%= link_to t("layouts.help"), help_path, :class => "dropdown-item" %></li>
           <li class="<%= current_page_class(about_path) %>"><%= link_to t("layouts.about"), about_path, :class => "dropdown-item" %></li>
diff --git a/app/views/site/communities.html.erb b/app/views/site/communities.html.erb
new file mode 100644 (file)
index 0000000..adbd7ab
--- /dev/null
@@ -0,0 +1,19 @@
+<% content_for :heading do %>
+  <%= tag.h1 do %>
+    <%= t ".title" %>
+  <% end %>
+<% end %>
+
+<%= tag.div do %>
+  <p><%= t ".lede_text" %></p>
+  <h2><%= t ".local_chapters.title" %></h2>
+  <p><%= t ".local_chapters.about_text" %></p>
+  <p><%= t ".local_chapters.list_text" %></p>
+  <ul>
+    <% @local_chapters.each do |chapter| %>
+      <li><a href="<%= chapter.url %>"><%= t "osm_community_index.local_chapter." + chapter.id + ".name" %></a></li>
+    <% end %>
+  </ul>
+  <h2><%= t ".other_groups.title" %></h2>
+  <p><%= t ".other_groups.about_html" %></p>
+<% end %>
index df3ae37f560513ddef3b1af79b0c5babb9ef64fc..f3bde72d7e970000b569cec144c4336f77525125 100644 (file)
@@ -1459,6 +1459,7 @@ en:
     help: Help
     about: About
     copyright: Copyright
+    communities: Communities
     community: Community
     community_blogs: "Community Blogs"
     community_blogs_title: "Blogs from members of the OpenStreetMap community"
@@ -2224,6 +2225,30 @@ en:
           Just go to <a href='%{map_url}'>the map</a> and click the note icon:
           <span class='icon note'></span>. This will add a marker to the map, which you can move
           by dragging. Add your message, then click save, and other mappers will investigate.
+    communities:
+      title: Communities
+      lede_text: |
+        People from all over the world contribute to or use OpenStreetMap.
+        Whilst some are content to participate as individuals, others have formed communities.
+        These groups come in a range of sizes and represent geographies from small towns to large multi-country regions.
+        They can also be formal or informal.
+      local_chapters:
+        title: Local Chapters
+        about_text: |
+          Local Chapters are country-level or region-level groups that have taken the formal step of
+          establishing not-for-profit legal entities. They represent the area's map and mappers when
+          dealing with local government, business, and media. They have also formed an affiliation
+          with the OpenStreetMap Foundation (OSMF), giving them a link to the legal and copyright
+          governing body.
+        list_text: |
+          So far we have the following formally established foundation Local Chapters:
+      other_groups:
+        title: Other Groups
+        about_html: |
+          There is no need to formally establish a group to the same extent as the Local Chapters.
+          Indeed many groups exist very sucessfully as an informal gathering of people or as a
+          community group. Anyone can set up or join these. Read more on the
+          <a href="https://wiki.openstreetmap.org/wiki/User_group">Communities wiki page</a>.
   traces:
     visibility:
       private: "Private (only shared as anonymous, unordered points)"
index f4c19f88cb9278ad050e9c972ad0a2939efefc8f..f52ee739dc0950c6cdce2466574a66415019f424 100644 (file)
@@ -147,6 +147,7 @@ OpenStreetMap::Application.routes.draw do
   get "/help" => "site#help"
   get "/about/:about_locale" => "site#about"
   get "/about" => "site#about"
+  get "/communities" => "site#communities"
   get "/history" => "changesets#index"
   get "/history/feed" => "changesets#feed", :defaults => { :format => :atom }
   get "/history/comments/feed" => "changeset_comments#index", :as => :changesets_comments_feed, :defaults => { :format => "rss" }
diff --git a/lib/osm_community_index/local_chapter.rb b/lib/osm_community_index/local_chapter.rb
new file mode 100644 (file)
index 0000000..10029a7
--- /dev/null
@@ -0,0 +1,61 @@
+module OsmCommunityIndex
+  class LocalChapter
+    attr_reader :id, :url
+
+    def initialize(id, url)
+      @id = id
+      @url = url
+    end
+
+    def self.local_chapters
+      @chapters = init_local_chapters
+    end
+
+    def self.init_local_chapters
+      raw_local_chapters = load_raw_local_chapters
+      local_chapters = []
+      raw_local_chapters.each do |chapter|
+        id = chapter[:id]
+        url = chapter[:resource]["strings"]["url"]
+        local_chapters.push(LocalChapter.new(id, url))
+      end
+      local_chapters
+    end
+
+    def self.load_raw_local_chapters
+      community_index = OsmCommunityIndex.community_index
+      raw_local_chapters = []
+      community_index["resources"].each do |id, resource|
+        resource.each do |key, value|
+          next unless key == "type" && value == "osm-lc" && id != "OSMF"
+          raw_local_chapters.push({ :id => id, :resource => resource })
+        end
+      end
+      raw_local_chapters
+    end
+
+    def self.add_to_i18n
+      raw_local_chapters = load_raw_local_chapters
+      files = Dir.glob(Rails.root.join("node_modules/osm-community-index/i18n/*"))
+      files.each do |file|
+        locale = File.basename(file,".yaml")
+        community_index_yaml = YAML.safe_load(File.read(file))[locale]
+        # rails wants en-GB but osm-community-index has en_GB
+        locale_rails = locale.split("_").join("-")
+        data = {}
+
+        raw_local_chapters.each do |chapter|
+          id = chapter[:id]
+          resource = chapter[:resource]
+
+          strings = community_index_yaml[id] || {}
+          # if the name isn't defined then fall back on community,
+          # as per discussion here: https://github.com/osmlab/osm-community-index/issues/483
+          strings['name'] = strings['name'] || resource["strings"]["name"] || resource["strings"]["community"]
+
+          data.deep_merge!({"osm_community_index" => {"local_chapter" => {id => strings}}})
+        end
+      end
+    end
+  end
+end
diff --git a/lib/osm_community_index/osm_community_index.rb b/lib/osm_community_index/osm_community_index.rb
new file mode 100644 (file)
index 0000000..cceb1e0
--- /dev/null
@@ -0,0 +1,15 @@
+module OsmCommunityIndex
+  class OsmCommunityIndex
+    require "yaml"
+
+    def self.community_index
+      @community_index ||= community_index_from_json
+    end
+
+    def self.community_index_from_json
+      json_file = Rails.root.join("node_modules/osm-community-index/dist/resources.json")
+      JSON.parse(File.read(json_file))
+    end
+
+  end
+end
index 5a50c3c21ddae14a1185d4f402fe2c8ec5ccbf86..944ac1ba9d2bc014fe6ba6b83b7c19cd80feee24 100644 (file)
@@ -7,6 +7,7 @@
     "js-cookie": "^3.0.0",
     "leaflet": "^1.6.0",
     "leaflet.locatecontrol": "^0.75.0",
+    "osm-community-index": "^5.1.3",
     "qs": "^6.9.4"
   },
   "devDependencies": {
index c13ba694214e3c02467376e9c79fa08c1148f400..385a1b33a6844d3477fc732e432a3f6f0eecff42 100644 (file)
--- a/yarn.lock
+++ b/yarn.lock
@@ -156,6 +156,11 @@ deep-is@^0.1.3:
   resolved "https://registry.yarnpkg.com/deep-is/-/deep-is-0.1.3.tgz#b369d6fb5dbc13eecf524f91b070feedc357cf34"
   integrity sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ=
 
+diacritics@^1.3.0:
+  version "1.3.0"
+  resolved "https://registry.yarnpkg.com/diacritics/-/diacritics-1.3.0.tgz#3efa87323ebb863e6696cebb0082d48ff3d6f7a1"
+  integrity sha1-PvqHMj67hj5mls67AILUj/PW96E=
+
 doctrine@^3.0.0:
   version "3.0.0"
   resolved "https://registry.yarnpkg.com/doctrine/-/doctrine-3.0.0.tgz#addebead72a6574db783639dc87a121773973961"
@@ -523,6 +528,13 @@ optionator@^0.9.1:
     type-check "^0.4.0"
     word-wrap "^1.2.3"
 
+osm-community-index@^5.1.3:
+  version "5.1.3"
+  resolved "https://registry.yarnpkg.com/osm-community-index/-/osm-community-index-5.1.3.tgz#df2bd0db2b3e43b95fa026138905dc2f3f473062"
+  integrity sha512-kERHt/O+QFp7DB5jH/Pkh3P1GwT3vH+lYskN7EVEBcnnsW8AIcdGpmQDlLO9IZNCbzmP7YY81wlUv8AuWKUTIg==
+  dependencies:
+    diacritics "^1.3.0"
+
 parent-module@^1.0.0:
   version "1.0.1"
   resolved "https://registry.yarnpkg.com/parent-module/-/parent-module-1.0.1.tgz#691d2709e78c79fae3a156622452d00762caaaa2"