Attempt to better manage markdown, for the linuxfr digest!
This commit is contained in:
parent
45b18e0c34
commit
83bcde3101
@ -45,18 +45,23 @@ module EventsHelper
|
||||
end: l(event.end_time, format: :at)
|
||||
end
|
||||
|
||||
def wrap(s, width = 78)
|
||||
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 }
|
||||
.sort_by(&:city)
|
||||
end
|
||||
|
||||
def display_attr(item, label, value = item[label])
|
||||
# return unless value
|
||||
item.class.human_attribute_name(label).rjust(12) + " #{value}"
|
||||
end
|
||||
|
||||
def to_markdown(description, line_width = -1)
|
||||
desc = sanitize description,
|
||||
tags: %w[p br h1 h2 h3 h4 table tr th td ul ol li a strong
|
||||
b em i sub sup],
|
||||
attributes: %w[href]
|
||||
Kramdown::Document.new(desc, input: :html, line_width: line_width)
|
||||
.to_kramdown
|
||||
end
|
||||
end
|
||||
|
@ -8,10 +8,7 @@
|
||||
- @events.sort_by(&:start_time).each do |event|
|
||||
[#{event.region.region.try(:code) || event.region.try(:code)} #{event.city}] [#{event.title}](#{event_url event}) - #{display_date event}
|
||||
\-----
|
||||
|
||||
- Kramdown::Document.new(event.description, input: 'html').to_kramdown.split(/\n/)[0..2].each do |p|
|
||||
= p
|
||||
\
|
||||
= to_markdown event.description, -1
|
||||
\
|
||||
* #{[event.place_name, event.full_address].compact.join ', '}
|
||||
- if event.url.present?
|
||||
|
@ -12,7 +12,7 @@ def event_to_rss(xml, event)
|
||||
|
||||
xml.title "#{event.city}: #{event.title}, #{display_date event}"
|
||||
xml.link event_url event
|
||||
xml.description strip_tags event.description
|
||||
xml.description event.description
|
||||
xml.content(:encoded) { xml.cdata! event.description }
|
||||
end
|
||||
|
||||
|
@ -1,19 +1,19 @@
|
||||
================================================================================
|
||||
= 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
|
||||
==============================================================================
|
||||
= display_attr @event, :title
|
||||
= display_attr @event, :start_time, l(@event.start_time, format: :at)
|
||||
= display_attr @event, :end_time, l(@event.end_time, format: :at)
|
||||
= display_attr @event, :place_name
|
||||
= display_attr @event, :address
|
||||
= display_attr @event, :city
|
||||
= display_attr @event, :region, @event.region
|
||||
= display_attr @event, :locality, t("attributes.locality_#{@event.locality}")
|
||||
= display_attr @event, :url
|
||||
= display_attr @event, :contact
|
||||
= display_attr @event, :submitter
|
||||
= display_attr @event, :tag_list, @event.tag_list
|
||||
- if @event.repeat > 0
|
||||
= display_attr :repeat
|
||||
= display_attr :rule, t(@event.rule, scope: 'activerecord.attributes.event.rule_values')
|
||||
= display_attr @event, :repeat
|
||||
= display_attr @event, :rule, t(@event.rule, scope: 'activerecord.attributes.event.rule_values')
|
||||
\
|
||||
= Kramdown::Document.new(@event.description, input: 'html').to_kramdown
|
||||
================================================================================
|
||||
= to_markdown @event.description, 78
|
||||
==============================================================================
|
||||
|
@ -1,20 +1,18 @@
|
||||
=====================================================
|
||||
#{Orga.human_attribute_name(:kind).concat(':').ljust 12 } #{@orga.kind.name}
|
||||
#{Orga.human_attribute_name(:name).concat(':').ljust 12 } #{@orga.name}
|
||||
#{Orga.human_attribute_name(:place_name).concat(':').ljust 12 } #{@orga.place_name}
|
||||
#{Orga.human_attribute_name(:address).concat(':').ljust 12 } #{@orga.address}
|
||||
#{Orga.human_attribute_name(:city).concat(':').ljust 12 } #{@orga.city}
|
||||
#{Orga.human_attribute_name(:department).concat(':').ljust 12 } #{@orga.department}
|
||||
#{Orga.human_attribute_name(:region).concat(':').ljust 12 } #{@orga.region}
|
||||
#{Orga.human_attribute_name(:url).concat(':').ljust 12 } #{@orga.url}
|
||||
#{Orga.human_attribute_name(:diaspora).concat(':').ljust 12 } #{@orga.diaspora}
|
||||
#{Orga.human_attribute_name(:feed).concat(':').ljust 12 } #{@orga.feed}
|
||||
#{Orga.human_attribute_name(:contact).concat(':').ljust 12 } #{@orga.contact}
|
||||
#{Orga.human_attribute_name(:submitter).concat(':').ljust 12 } #{@orga.submitter}
|
||||
#{Orga.human_attribute_name(:tags).concat(':').ljust 12 } #{@orga.tag_list}
|
||||
- if @orga.active.present?
|
||||
#{Orga.human_attribute_name(:active).concat(':').ljust 12 } #{t @orga.active.to_s}
|
||||
- unless @orga.description.blank?
|
||||
#{Orga.human_attribute_name(:description).concat(':').ljust 12}
|
||||
= wrap(strip_tags(@orga.description).gsub(/ /, '')).gsub /^/, ' '
|
||||
=====================================================
|
||||
==============================================================================
|
||||
= display_attr @orga, :kind, t("activerecord.attributes.kind.name_#{@orga.kind.name}")
|
||||
= display_attr @orga, :name
|
||||
= display_attr @orga, :place_name
|
||||
= display_attr @orga, :address
|
||||
= display_attr @orga, :city
|
||||
= display_attr @orga, :department
|
||||
= display_attr @orga, :region, @orga.region
|
||||
= display_attr @orga, :url
|
||||
= display_attr @orga, :diaspora
|
||||
= display_attr @orga, :feed
|
||||
= display_attr @orga, :contact
|
||||
= display_attr @orga, :submitter
|
||||
= display_attr @orga, :tag_list, @orga.tag_list
|
||||
= display_attr @orga, :active, t(@orga.active.to_s)
|
||||
\
|
||||
= to_markdown @orga.description, 78
|
||||
==============================================================================
|
||||
|
@ -77,7 +77,7 @@ fr:
|
||||
city: Ville
|
||||
region: Région
|
||||
locality: Portée
|
||||
url: URL
|
||||
url: Adresse web
|
||||
contact: Contact
|
||||
submitter: Soumetteur
|
||||
submission_time: En attente depuis
|
||||
|
Loading…
Reference in New Issue
Block a user