The markdown digest seemed broken, no line breaks, we now use kramdown which is able to generate markdown from html

This commit is contained in:
echarp 2017-06-04 12:59:14 +02:00
parent 4ce608dd5c
commit 45b18e0c34
13 changed files with 114461 additions and 45 deletions

View File

@ -50,7 +50,7 @@ gem 'differ'
gem 'activeadmin', github: 'activeadmin'
# Markdown display
gem 'redcarpet'
gem 'kramdown'
gem 'flag-icons-rails'
gem 'geocoder'

View File

@ -1,6 +1,6 @@
GIT
remote: git://github.com/activeadmin/activeadmin.git
revision: 54dcfeaf76b92e42b46cb573cdfa2093e6356a31
revision: e558e8c08e8c5d625a2d01369bfe2704cecdc296
specs:
activeadmin (1.0.0)
arbre (>= 1.1.1)
@ -179,11 +179,11 @@ GEM
haml (>= 4.0.6, < 6.0)
html2haml (>= 1.0.1)
railties (>= 4.0.1)
haml_lint (0.25.1)
haml_lint (0.26.0)
haml (>= 4.0, < 5.1)
rainbow
rake (>= 10, < 13)
rubocop (>= 0.47.0)
rubocop (>= 0.49.0)
sysexits (~> 1.1)
has_scope (0.6.0)
actionpack (>= 3.2, < 5)
@ -233,6 +233,7 @@ GEM
activerecord
kaminari-core (= 1.0.1)
kaminari-core (1.0.1)
kramdown (1.13.2)
leaflet-rails (1.0.3)
rails (>= 4.2.0)
libv8 (3.16.14.19)
@ -335,7 +336,6 @@ GEM
rb-inotify (0.9.8)
ffi (>= 0.5.0)
rdoc (4.3.0)
redcarpet (3.4.0)
ref (2.0.0)
request_store (1.3.2)
responders (2.4.0)
@ -461,6 +461,7 @@ DEPENDENCIES
jbuilder
jquery-rails
jquery-sparkline-rails!
kramdown
leaflet-rails
meta-tags
modernizr-rails
@ -472,7 +473,6 @@ DEPENDENCIES
rails
rails-assets-leaflet.markercluster!
rails-i18n
redcarpet
sass-rails
sdoc
simple_calendar

View File

@ -1,16 +1,16 @@
$(document).on 'turbolinks:load', ->
# Setup the graphical editor for event's description
tinyMCE.init
schema: 'html5',
height: '40em',
menubar: '',
branding: false,
language: 'fr_FR',
selector: 'input.description',
content_css: '<%= asset_path 'application.css' %>',
entity_encoding : 'raw',
add_unload_trigger: true,
browser_spellcheck: true,
schema: 'html5'
height: '40em'
menubar: false
branding: false
language: 'fr_FR'
selector: 'input.description'
content_css: '<%= asset_path 'application.css' %>'
entity_encoding: 'raw'
add_unload_trigger: true
browser_spellcheck: true
toolbar: [
' cut copy paste
| undo redo
@ -23,7 +23,7 @@ $(document).on 'turbolinks:load', ->
| bullist numlist
| alignleft aligncenter alignright alignjustify alignnone
| outdent indent'
],
]
plugins: 'lists, advlist, autolink, link, image, charmap, paste, print,
preview, table, fullscreen, searchreplace, media, insertdatetime,
visualblocks, wordcount, contextmenu, code'

View File

@ -49,6 +49,11 @@ module EventsHelper
s.gsub(/(.{1,#{width}})(\s+|\Z)/, "\\1\n")
end
def display_attr(label, value = @event[label])
return unless value
Event.human_attribute_name(label).rjust(12) + " #{value}"
end
# Select the events to display in a month, sorted
def month_events(events, date)
events.select { |e| (e.start_time.to_date..e.end_time.to_date).cover? date }

View File

@ -9,10 +9,10 @@
[#{event.region.region.try(:code) || event.region.try(:code)} #{event.city}] [#{event.title}](#{event_url event}) - #{display_date event}
\-----
- lines = strip_tags(event.description).split(/\r\n/).reject(&:blank?)
- lines[0..2].each do |p|
- Kramdown::Document.new(event.description, input: 'html').to_kramdown.split(/\n/)[0..2].each do |p|
= p
\
\
* #{[event.place_name, event.full_address].compact.join ', '}
- if event.url.present?
* #{Event.human_attribute_name :url}: #{event.url}
@ -31,13 +31,12 @@
:markdown
* [April](http://april.org)
* [Agenda du Libre](http://www.agendadulibre.org)
* [Carte des événements]
(#{maps_url future: false, period: { year: @week.year, week: @week.cweek }})
* [Carte des événements](#{maps_url future: false, period:
{ year: @week.year, week: @week.cweek }})
* [Proposer un événement](http://www.agendadulibre.org/events/new)
* [Annuaire des organisations](http://www.agendadulibre.org/orgas)
* [Agenda pour la semaine précédante]
(#{digest_url :markdown, future: false, period: {
year: @week.year, week: (@week - 1.week).cweek }})
* [Agenda pour la semaine précédante](#{digest_url :markdown,
future: false, period: { year: @week.year, week: (@week - 1.week).cweek }})
%hr

View File

@ -1,20 +1,19 @@
=====================================================
#{Event.human_attribute_name(:title).concat(':').ljust 12 } #{@event.title}
#{Event.human_attribute_name(:start_time).concat(':').ljust 12 } #{l @event.start_time, format: :at}
#{Event.human_attribute_name(:end_time).concat(':').ljust 12 } #{l @event.end_time, format: :at}
================================================================================
= display_attr :title
= display_attr :start_time, l(@event.start_time, format: :at)
= display_attr :end_time, l(@event.end_time, format: :at)
= display_attr :place_name
= display_attr :address
= display_attr :city
= display_attr :region, @event.region
= display_attr :locality, t("attributes.locality_#{@event.locality}")
= display_attr :url
= display_attr :contact
= display_attr :submitter
= display_attr :tags, @event.tag_list
- if @event.repeat > 0
#{Event.human_attribute_name(:repeat).concat(':').ljust 12 } #{@event.repeat}
#{Event.human_attribute_name(:rule).concat(':').ljust 12 } #{t @event.rule, scope: 'activerecord.attributes.event.rule_values'}
#{Event.human_attribute_name(:place_name).concat(':').ljust 12 } #{@event.place_name}
#{Event.human_attribute_name(:address).concat(':').ljust 12 } #{@event.address}
#{Event.human_attribute_name(:city).concat(':').ljust 12 } #{@event.city}
#{Event.human_attribute_name(:region).concat(':').ljust 12 } #{@event.region}
#{Event.human_attribute_name(:locality).concat(':').ljust 12 } #{t "attributes.locality_#{@event.locality}"}
- if @event.url.present?
#{Event.human_attribute_name(:url).concat(':').ljust 12 } #{@event.url}
#{Event.human_attribute_name(:contact).concat(':').ljust 12 } #{@event.contact}
#{Event.human_attribute_name(:submitter).concat(':').ljust 12 } #{@event.submitter}
#{Event.human_attribute_name(:tags).concat(':').ljust 12 } #{@event.tag_list}
#{Event.human_attribute_name(:description).concat(':').ljust 12}
= wrap(strip_tags(@event.description).gsub(/&#13;/, '')).gsub /^/, ' '
=====================================================
= display_attr :repeat
= display_attr :rule, t(@event.rule, scope: 'activerecord.attributes.event.rule_values')
\
= Kramdown::Document.new(@event.description, input: 'html').to_kramdown
================================================================================

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,23 @@
(function() {
$(document).on('turbolinks:load', function() {
return tinyMCE.init({
schema: 'html5',
height: '40em',
menubar: false,
branding: false,
language: 'fr_FR',
selector: 'input.description',
content_css: '/assets/application-453868b5e8524811b06953b99485725a8bb6787b4936274042f7695531abcda3.css',
entity_encoding: 'raw',
add_unload_trigger: true,
browser_spellcheck: true,
toolbar: [' cut copy paste | undo redo | searchreplace | link image media charmap table | code visualblocks preview fullscreen', ' removeformat | bold italic strikethrough | superscript subscript | bullist numlist | alignleft aligncenter alignright alignjustify alignnone | outdent indent'],
plugins: 'lists, advlist, autolink, link, image, charmap, paste, print, preview, table, fullscreen, searchreplace, media, insertdatetime, visualblocks, wordcount, contextmenu, code'
});
});
$(document).on('turbolinks:before-cache', function() {
return tinymce.remove();
});
}).call(this);