From 525f46aba60d26a907a8e1cd7f1a798b8d34c822 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Wed, 1 Jun 2016 13:08:09 +0200 Subject: [PATCH 1/2] [feature] ability to use HTML in machine specs and description --- app/assets/javascripts/filters/filters.coffee | 15 ++++++++++++++- app/assets/templates/machines/_form.html.erb | 6 ++++-- app/assets/templates/machines/index.html.erb | 2 +- app/assets/templates/machines/show.html.erb | 2 +- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/filters/filters.coffee b/app/assets/javascripts/filters/filters.coffee index 9b6334d91..2bd145688 100644 --- a/app/assets/javascripts/filters/filters.coffee +++ b/app/assets/javascripts/filters/filters.coffee @@ -98,10 +98,23 @@ Application.Filters.filter "humanize", [ -> Humanize.truncate(element, param, null) ] +## +# This filter will convert ASCII carriage-return character to the HTML break-line tag +## Application.Filters.filter "breakFilter", [ -> (text) -> if text != undefined - text.replace(/\n/g, '
') + text.replace(/\n+/g, '
') +] + +## +# This filter will take a HTML text as input and will return it without the html tags +## +Application.Filters.filter "simpleText", [ -> + (text) -> + if text != undefined + text = text.replace(//g, '\n') + text.replace(/<\/?\w+>/g, '') ] Application.Filters.filter "toTrusted", [ "$sce", ($sce) -> diff --git a/app/assets/templates/machines/_form.html.erb b/app/assets/templates/machines/_form.html.erb index 0aa424824..3f60f290f 100644 --- a/app/assets/templates/machines/_form.html.erb +++ b/app/assets/templates/machines/_form.html.erb @@ -46,7 +46,8 @@
- + + {{ 'description_is_required' }}
@@ -54,7 +55,8 @@
- + + {{ 'technical_specifications_are_required' }}
diff --git a/app/assets/templates/machines/index.html.erb b/app/assets/templates/machines/index.html.erb index f6804be64..2f08ecd20 100644 --- a/app/assets/templates/machines/index.html.erb +++ b/app/assets/templates/machines/index.html.erb @@ -35,7 +35,7 @@

{{machine.name}}

-

{{machine.description | humanize : 140 }}

+

-

{{machine.spec}}

+

From 0e6698a9ed37c0976ad5cf2796b8d8da274fda31 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Wed, 1 Jun 2016 13:53:55 +0200 Subject: [PATCH 2/2] fix short descriptions in machines index --- app/assets/javascripts/filters/filters.coffee | 2 +- app/assets/templates/machines/index.html.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/filters/filters.coffee b/app/assets/javascripts/filters/filters.coffee index 2bd145688..babeea9df 100644 --- a/app/assets/javascripts/filters/filters.coffee +++ b/app/assets/javascripts/filters/filters.coffee @@ -114,7 +114,7 @@ Application.Filters.filter "simpleText", [ -> (text) -> if text != undefined text = text.replace(//g, '\n') - text.replace(/<\/?\w+>/g, '') + text.replace(/<\/?\w+[^>]*>/g, '') ] Application.Filters.filter "toTrusted", [ "$sce", ($sce) -> diff --git a/app/assets/templates/machines/index.html.erb b/app/assets/templates/machines/index.html.erb index 2f08ecd20..e31795edb 100644 --- a/app/assets/templates/machines/index.html.erb +++ b/app/assets/templates/machines/index.html.erb @@ -35,7 +35,7 @@

{{machine.name}}

-

+