]> git.openstreetmap.org Git - rails.git/blob - app/models/communities.rb
render local chapters in html
[rails.git] / app / models / communities.rb
1
2 # require 'sprockets/railtie'
3
4 class Communities
5
6   # include Sprockets::Helpers::RailsHelper
7
8   def self.local_chapters
9     self.load_local_chapters
10   end
11
12   protected
13
14   def self.load_local_chapters
15     puts Dir.pwd
16     json_file = File.expand_path("node_modules/osm-community-index/dist/completeFeatureCollection.json", Dir.pwd);
17     # json_file = File.expand_path("./node_modules/osm-community-index", Dir.pwd);
18
19     path = File.exist?(json_file) # Dir.pwd # File.open(json_file, "r")
20     community_index = JSON.parse(File.read(json_file))
21
22     array_of_entries = []
23     community_index['features'].each do |feature|
24       feature['properties']['resources'].each do |id, data|
25         data.each do |key, value|
26           if key == "type" and value == "osm-lc" and data['strings']['community']
27             array_of_entries.push({ id: id, name: data['strings']['community'], url: data['strings']['url'] });
28           end
29         end
30       end
31     end
32
33     return array_of_entries
34   end
35
36 end