From eca6705b299c5afe2e8ed995529f7afc5559ae0b Mon Sep 17 00:00:00 2001 From: Nemael <100dragons@gmail.com> Date: Sat, 24 Oct 2020 11:14:07 +0200 Subject: Added sanitization of data, puts instead of null or / data. Also strips trailing whitespaces. It only sanitizes phone_number, website and email because they these data are following a format. Name, address, etc... are not sanitized --- doc/import/LocationsParser.rb | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/doc/import/LocationsParser.rb b/doc/import/LocationsParser.rb index 3ce79c0..ccb165a 100644 --- a/doc/import/LocationsParser.rb +++ b/doc/import/LocationsParser.rb @@ -10,6 +10,18 @@ class Parser @list_of_locations["type"] = "FeatureCollection" @list_of_locations["features"] = [] end + def sanitize(data) + #Sanitize data. Puts "" instead of null in empty data, and puts "" instead of "/" + if (data == nil) + data = "" + end + data = data.strip + res = data + if (data == "/") + res = "" + end + return res + end def parseDeweyFiles(data_file) #Parses the .json files contained in the Dewey folder data = JSON.parse(File.read(data_file)) @@ -27,9 +39,9 @@ class Parser new_item["properties"]["name"] = data[i]["fields"]["name"] new_item["properties"]["description"] = data[i]["fields"]["comment"] new_item["properties"]["entry_number"] = data[i]["pk"] - new_item["properties"]["phone_number"] = data[i]["fields"]["phone"] - new_item["properties"]["website"] = data[i]["fields"]["web"] - new_item["properties"]["email"] = data[i]["fields"]["email"] + new_item["properties"]["phone_number"] = sanitize(data[i]["fields"]["phone"]) + new_item["properties"]["website"] = sanitize(data[i]["fields"]["web"]) + new_item["properties"]["email"] = sanitize(data[i]["fields"]["email"]) new_item["properties"]["address"] = data[i]["fields"]["address"] new_item["properties"]["city"] = "" #No equivalent in Dewey data new_item["properties"]["postal_code"] = "" #No equivalent in Dewey data @@ -55,9 +67,9 @@ class Parser new_item["properties"]["name"] = data[i]["Denomination_FULL"] new_item["properties"]["description"] = data[i]["description"] new_item["properties"]["entry_number"] = data[i]["NumEntr"] - new_item["properties"]["phone_number"] = coord[i]["Tel"] - new_item["properties"]["website"] = coord[i]["Web"] - new_item["properties"]["email"] = coord[i]["Email"] + new_item["properties"]["phone_number"] = sanitize(coord[i]["Tel"]) + new_item["properties"]["website"] = sanitize(coord[i]["Web"]) + new_item["properties"]["email"] = sanitize(coord[i]["Email"]) new_item["properties"]["address"] = coord[i]["Adresse"] new_item["properties"]["city"] = data[i]["INS_COMMUNE"] new_item["properties"]["postal_code"] = coord[i]["Code postal"] -- cgit v1.2.3 From 8110b287a1b406ecffa6e8321b9048542f4d5ff1 Mon Sep 17 00:00:00 2001 From: hellekin Date: Tue, 27 Oct 2020 11:48:44 +0100 Subject: User commonmarker gem This adds support for Markdown for Resource descriptions. CommonMark: https://commonmark.org/ Gem documentation: https://gjtorikian.github.io/commonmarker/ --- Gemfile | 2 ++ Gemfile.lock | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/Gemfile b/Gemfile index 1897dd4..f094cc3 100644 --- a/Gemfile +++ b/Gemfile @@ -28,6 +28,8 @@ gem 'jbuilder', '~> 2.7' gem 'acts_as_list' # Use bitfields in models gem 'bitfields' +# Use Markdown for descriptions +gem 'commonmarker' # Use Discourse API gem 'discourse_api' # User pagination diff --git a/Gemfile.lock b/Gemfile.lock index aa16165..9d940e0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -66,6 +66,8 @@ GEM builder (3.2.4) byebug (11.1.3) coderay (1.1.3) + commonmarker (0.21.0) + ruby-enum (~> 0.5) concurrent-ruby (1.1.7) crass (1.0.6) discourse_api (0.42.0) @@ -170,6 +172,8 @@ GEM rb-fsevent (0.10.4) rb-inotify (0.10.1) ffi (~> 1.0) + ruby-enum (0.8.0) + i18n sass-rails (6.0.0) sassc-rails (~> 2.1, >= 2.1.1) sassc (2.4.0) @@ -226,6 +230,7 @@ DEPENDENCIES bitfields bootsnap (>= 1.4.2) byebug + commonmarker discourse_api jbuilder (~> 2.7) kaminari -- cgit v1.2.3 From c3f4936dbb524237d1e3d465d2301627758c2180 Mon Sep 17 00:00:00 2001 From: hellekin Date: Tue, 27 Oct 2020 16:51:07 +0100 Subject: Add Markdown to format Resource.description --- app/helpers/application_helper.rb | 43 ++++++++++++++++++++++++++++++++++ app/views/resources/_resource.html.erb | 2 +- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 0b22f4b..2b6e109 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -7,4 +7,47 @@ module ApplicationHelper current_agency.send(:"#{role}?") end end + + # Markdown helper + # Always use all extensions. Additional parser and render options may be + # passed as a second argument. + # + # @param markdown (String) a string to parse as Markdown source + # @param options (String or Array) an optional parser/renderer option + # @return String HTML-formatted from Mardkown source + def m(markdown, options = nil) + tag.div( + CommonMarker.render_doc( + markdown.to_s, + options.to_a + default_commonmarker_options, + default_commonmarker_extensions + ).to_html.html_safe, class: 'markdown') + end + + private + + # CommonMarker extensions + # See https://github.com/gjtorikian/commonmarker#extensions + def default_commonmarker_extensions + [ + :table, + :tasklist, + :strikethrough, + :autolink, + :tagfilter + ] + end + + # CommonMarker options + # See https://github.com/gjtorikian/commonmarker#options + def default_commonmarker_options + [ + #:HARDBREAKS, # only seems to work with render_html, but then all others + # only work with render_doc + :FOOTNOTES, + :SMART, + :STRIKETHROUGH_DOUBLE_TILDE, + :VALIDATE_UTF8 + ] + end end diff --git a/app/views/resources/_resource.html.erb b/app/views/resources/_resource.html.erb index 585bed8..2debec2 100644 --- a/app/views/resources/_resource.html.erb +++ b/app/views/resources/_resource.html.erb @@ -5,7 +5,7 @@