Browse Source

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

rails5
echarp 5 years ago
parent
commit
45b18e0c34
  1. 2
      Gemfile
  2. 10
      Gemfile.lock
  3. 22
      app/assets/javascripts/tinymce.coffee.erb
  4. 5
      app/helpers/events_helper.rb
  5. 13
      app/views/digests/markdown.html.haml
  6. 39
      app/views/events/show.text.haml
  7. 2
      public/assets/.sprockets-manifest-2856a8fbeb29238a5e8833501260de39.json
  8. 23377
      public/assets/active_admin-fd7fb0c97af897e3d2bd899ce6eb90c3cd652ea5814e2b014b6a313088942deb.js
  9. BIN
      public/assets/active_admin-fd7fb0c97af897e3d2bd899ce6eb90c3cd652ea5814e2b014b6a313088942deb.js.gz
  10. 91013
      public/assets/application-26b8730696412047e403b4d08bfed7ba730f7090594b39d0805e906c221b3713.js
  11. BIN
      public/assets/application-26b8730696412047e403b4d08bfed7ba730f7090594b39d0805e906c221b3713.js.gz
  12. 23
      public/assets/tinymce-1480d9c46189dee73267704292bd452c571360372ed0723cdeaf8487c02c6a81.js
  13. BIN
      public/assets/tinymce-1480d9c46189dee73267704292bd452c571360372ed0723cdeaf8487c02c6a81.js.gz

2
Gemfile

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

10
Gemfile.lock

@ -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

22
app/assets/javascripts/tinymce.coffee.erb

@ -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'

5
app/helpers/events_helper.rb

@ -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 }

13
app/views/digests/markdown.html.haml

@ -9,9 +9,9 @@
[#{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?
@ -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

39
app/views/events/show.text.haml

@ -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}
-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 :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
= display_attr :repeat
= display_attr :rule, t(@event.rule, scope: 'activerecord.attributes.event.rule_values')
\
= Kramdown::Document.new(@event.description, input: 'html').to_kramdown
================================================================================

2
public/assets/.sprockets-manifest-2856a8fbeb29238a5e8833501260de39.json

File diff suppressed because one or more lines are too long

23377
public/assets/active_admin-fd7fb0c97af897e3d2bd899ce6eb90c3cd652ea5814e2b014b6a313088942deb.js

File diff suppressed because one or more lines are too long

BIN
public/assets/active_admin-fd7fb0c97af897e3d2bd899ce6eb90c3cd652ea5814e2b014b6a313088942deb.js.gz

Binary file not shown.

91013
public/assets/application-26b8730696412047e403b4d08bfed7ba730f7090594b39d0805e906c221b3713.js

File diff suppressed because one or more lines are too long

BIN
public/assets/application-26b8730696412047e403b4d08bfed7ba730f7090594b39d0805e906c221b3713.js.gz

Binary file not shown.

23
public/assets/tinymce-1480d9c46189dee73267704292bd452c571360372ed0723cdeaf8487c02c6a81.js

@ -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);

BIN
public/assets/tinymce-1480d9c46189dee73267704292bd452c571360372ed0723cdeaf8487c02c6a81.js.gz

Binary file not shown.
Loading…
Cancel
Save