From eee4e4f22c6b3551820814a6d3e29e2b12541250 Mon Sep 17 00:00:00 2001 From: Ana Date: Tue, 9 Aug 2016 00:20:18 +0200 Subject: [PATCH] Add markdown to users biography Closes https://github.com/openSUSE/osem/issues/1090 Closes https://github.com/openSUSE/osem/issues/701 --- app/serializers/speaker_serializer.rb | 8 -------- app/views/admin/events/_proposal.html.haml | 2 +- app/views/admin/users/_form.html.haml | 3 ++- app/views/admin/users/show.html.haml | 3 +++ app/views/proposal/show.html.haml | 2 +- app/views/users/edit.html.haml | 3 ++- app/views/users/show.html.haml | 2 +- spec/serializers/speaker_serializer_spec.rb | 2 +- 8 files changed, 11 insertions(+), 14 deletions(-) diff --git a/app/serializers/speaker_serializer.rb b/app/serializers/speaker_serializer.rb index 64fb8936..c017fb31 100644 --- a/app/serializers/speaker_serializer.rb +++ b/app/serializers/speaker_serializer.rb @@ -6,12 +6,4 @@ class SpeakerSerializer < ActiveModel::Serializer def name object.name end - - def biography - if object.biography.blank? - nil - else - simple_format(object.biography).gsub('\n', '') - end - end end diff --git a/app/views/admin/events/_proposal.html.haml b/app/views/admin/events/_proposal.html.haml index 98d70e34..118f6034 100644 --- a/app/views/admin/events/_proposal.html.haml +++ b/app/views/admin/events/_proposal.html.haml @@ -133,7 +133,7 @@ %td %b Biography %td - = simple_format(@event.submitter.biography) + = markdown(@event.submitter.biography) %tr %td %b Submitted on diff --git a/app/views/admin/users/_form.html.haml b/app/views/admin/users/_form.html.haml index e945bad7..a2d8cf97 100644 --- a/app/views/admin/users/_form.html.haml +++ b/app/views/admin/users/_form.html.haml @@ -4,6 +4,7 @@ = f.input :name, :as => :string = f.input :email = f.input :affiliation, :as => :string - = f.input :biography, :input_html => {:rows => 10} + = f.input :biography, input_html: { rows: 10, data: { provide: 'markdown-editable' } }, + hint: markdown_hint = f.actions do = f.action :submit, :button_html => {:class => "btn btn-primary"} diff --git a/app/views/admin/users/show.html.haml b/app/views/admin/users/show.html.haml index 0670665f..48f2908b 100644 --- a/app/views/admin/users/show.html.haml +++ b/app/views/admin/users/show.html.haml @@ -29,6 +29,9 @@ - if attr == 'roles' %td = show_roles(@user.get_roles) + - elsif attr == 'biography' + %td + = markdown(@user.biography) - else %td= @user.send(attr) #submissions-content.tab-pane{class: "#{'active' if params[:tab] == 'submissions-content'}"} diff --git a/app/views/proposal/show.html.haml b/app/views/proposal/show.html.haml index b80d3ece..bc08c14c 100644 --- a/app/views/proposal/show.html.haml +++ b/app/views/proposal/show.html.haml @@ -36,7 +36,7 @@ from = @speaker.affiliation -if @speaker.biography? - = simple_format(@speaker.biography) + = markdown(@speaker.biography) .col-md-9 .row .col-md-12 diff --git a/app/views/users/edit.html.haml b/app/views/users/edit.html.haml index 4fa47b82..825cd9f1 100644 --- a/app/views/users/edit.html.haml +++ b/app/views/users/edit.html.haml @@ -14,7 +14,8 @@ = link_to 'Change your avatar here', 'https://gravatar.com' = f.input :affiliation, as: :string, hint: 'This could be a company, a user group, or nothing at all.' - = f.input :biography, input_html: { rows: 5, 'onkeyup' => "word_count(this, 'biography-count', 150)" } + = f.input :biography, input_html: { rows: 5, data: { provide: 'markdown-editable' }, 'onkeyup' => "word_count(this, 'biography-count', 150)" }, + hint: markdown_hint You have used %span#bio_length = @user.biography ? @user.biography.split.length : 0 diff --git a/app/views/users/show.html.haml b/app/views/users/show.html.haml index 0b172898..355cda88 100644 --- a/app/views/users/show.html.haml +++ b/app/views/users/show.html.haml @@ -8,7 +8,7 @@ %small = @user.nickname %p - = @user.biography + = markdown(@user.biography) .row .col-md-12 - if @user.events.confirmed.any? diff --git a/spec/serializers/speaker_serializer_spec.rb b/spec/serializers/speaker_serializer_spec.rb index a62c882c..74545709 100644 --- a/spec/serializers/speaker_serializer_spec.rb +++ b/spec/serializers/speaker_serializer_spec.rb @@ -25,7 +25,7 @@ describe SpeakerSerializer, type: :serializer do speaker: { name: 'John Doe', affiliation: 'JohnDoesInc', - biography: '

Doest of all Jon Does

' + biography: 'Doest of all Jon Does' } }.to_json