aboutsummaryrefslogtreecommitdiff
path: root/app/helpers
diff options
context:
space:
mode:
authorhellekin <hellekin@cepheide.org>2020-11-12 01:10:28 +0100
committerhellekin <hellekin@cepheide.org>2020-11-12 01:10:28 +0100
commit8d9387cf64929b6467b6ba52f22ca0aa5ed35782 (patch)
tree37533e75476680ebad4cd1d47e3e578b879726ba /app/helpers
parentb6aeac4d9274f17e748efb3715aa08f4b7c361f2 (diff)
parent757decefafb5d82557a8b7fa9691f94f19c3207e (diff)
downloadincommon-map-8d9387cf64929b6467b6ba52f22ca0aa5ed35782.tar.gz
Merged master
Diffstat (limited to 'app/helpers')
-rw-r--r--app/helpers/agents_helper.rb4
-rw-r--r--app/helpers/application_helper.rb47
-rw-r--r--app/helpers/categories_helper.rb6
-rw-r--r--app/helpers/resources_helper.rb4
-rw-r--r--app/helpers/taxonomies_helper.rb23
-rw-r--r--app/helpers/users_helper.rb4
-rw-r--r--app/helpers/welcome_helper.rb4
7 files changed, 92 insertions, 0 deletions
diff --git a/app/helpers/agents_helper.rb b/app/helpers/agents_helper.rb
index 7e54438..bbaeeca 100644
--- a/app/helpers/agents_helper.rb
+++ b/app/helpers/agents_helper.rb
@@ -1,2 +1,6 @@
+# SPDX-FileCopyrightText: 2020 IN COMMON Collective <collective@incommon.cc>
+#
+# SPDX-License-Identifier: AGPL-3.0-or-later
+
module AgentsHelper
end
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index aa3a8d7..15d5082 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -1,3 +1,7 @@
+# SPDX-FileCopyrightText: 2020 IN COMMON Collective <collective@incommon.cc>
+#
+# SPDX-License-Identifier: AGPL-3.0-or-later
+
module ApplicationHelper
def current_agency
current_user.agencies.where(agent: current_agent).first
@@ -21,4 +25,47 @@ module ApplicationHelper
'map-zoom': map.zoom
})
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/helpers/categories_helper.rb b/app/helpers/categories_helper.rb
new file mode 100644
index 0000000..f6d7a86
--- /dev/null
+++ b/app/helpers/categories_helper.rb
@@ -0,0 +1,6 @@
+# SPDX-FileCopyrightText: 2020 IN COMMON Collective <collective@incommon.cc>
+#
+# SPDX-License-Identifier: AGPL-3.0-or-later
+
+module CategoriesHelper
+end
diff --git a/app/helpers/resources_helper.rb b/app/helpers/resources_helper.rb
index 157a8f5..a949311 100644
--- a/app/helpers/resources_helper.rb
+++ b/app/helpers/resources_helper.rb
@@ -1,3 +1,7 @@
+# SPDX-FileCopyrightText: 2020 IN COMMON Collective <collective@incommon.cc>
+#
+# SPDX-License-Identifier: AGPL-3.0-or-later
+
module ResourcesHelper
# Return a SELECT tag to choose a section in a given taxonomy
def section_select(taxonomy, selected = nil)
diff --git a/app/helpers/taxonomies_helper.rb b/app/helpers/taxonomies_helper.rb
new file mode 100644
index 0000000..a584177
--- /dev/null
+++ b/app/helpers/taxonomies_helper.rb
@@ -0,0 +1,23 @@
+# SPDX-FileCopyrightText: 2020 IN COMMON Collective <collective@incommon.cc>
+#
+# SPDX-License-Identifier: AGPL-3.0-or-later
+
+# coding: utf-8
+# frozen_string_literal: true
+
+module TaxonomiesHelper
+ def taxonomy_filter
+ @taxonomy ||= Taxonomy.first
+ html = []
+ @taxonomy.categories.each do |cat|
+ list = []
+ cat.sections.each do |sec|
+ list << tag.li(h("#{sec.rank}. #{sec.name}"), id: "section-#{sec.id}", data: { action: "taxonomy#section" })
+ end
+ html << tag.li(h("#{cat.rank}. #{cat.name}") << tag.ol(list.join.html_safe),
+ id: "category-#{cat.id}",
+ data: { action: "taxonomy#category" })
+ end
+ raw(tag.nav(tag.ol(html.join.html_safe), id: "taxonomy-#{@taxonomy.uuid}"))
+ end
+end
diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb
index 2310a24..0adb3be 100644
--- a/app/helpers/users_helper.rb
+++ b/app/helpers/users_helper.rb
@@ -1,2 +1,6 @@
+# SPDX-FileCopyrightText: 2020 IN COMMON Collective <collective@incommon.cc>
+#
+# SPDX-License-Identifier: AGPL-3.0-or-later
+
module UsersHelper
end
diff --git a/app/helpers/welcome_helper.rb b/app/helpers/welcome_helper.rb
index eeead45..8e575f1 100644
--- a/app/helpers/welcome_helper.rb
+++ b/app/helpers/welcome_helper.rb
@@ -1,2 +1,6 @@
+# SPDX-FileCopyrightText: 2020 IN COMMON Collective <collective@incommon.cc>
+#
+# SPDX-License-Identifier: AGPL-3.0-or-later
+
module WelcomeHelper
end