Skip to content

Commit

Permalink
Markdown description rendering to HTML
Browse files Browse the repository at this point in the history
  • Loading branch information
ivankocienski committed Oct 2, 2024
1 parent 4ac6a0e commit 06bb356
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 5 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ gem "haml-rails" # view template language
gem "sassc-rails" # scss
gem "ancestry" # for geo-location nesting
gem "rubyzip" # for de/compressing geo-enclosure postcode data
gem "kramdown"

group :development, :test do
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ GEM
actionview (>= 5.0.0)
activesupport (>= 5.0.0)
json (2.7.2)
kramdown (2.4.0)
rexml
language_server-protocol (3.17.0.3)
logger (1.6.0)
loofah (2.22.0)
Expand Down Expand Up @@ -327,6 +329,7 @@ DEPENDENCIES
haml-rails
importmap-rails
jbuilder
kramdown
puma (>= 5.0)
rails (~> 7.2.0)
rails-controller-testing
Expand Down
2 changes: 1 addition & 1 deletion app/views/events/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
- if @event.address.present?
— #{address_map_link_to @event.address, :events_path}

= format_for_content(@event.description)
#description.indent= @event.description_html.to_s.html_safe

- if @event.publisher_url.present?
%p= external_link_to @event.publisher_url, text: 'More info'
Expand Down
2 changes: 1 addition & 1 deletion app/views/partners/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

- if @partner.description.present?
%h2 Description
= format_for_content(@partner.description)
#description.indent= @partner.description_html.to_s.html_safe

- if @upcoming_events.blank? && @previous_events.blank?
%br
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddMarkdownHtmlFieldsToPartnersAndEvents < ActiveRecord::Migration[7.2]
def change
add_column :partners, :description_html, :text
add_column :events, :description_html, :text
end
end
4 changes: 3 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions lib/tasks/db/import/placecal_snapshot.rake
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ module PlacecalSnapshotImporter
Event.destroy_all
end

def make_html_from_text(text)
Kramdown::Document.new(text).to_html
end

def import_partners
path = Rails.root.join('db/fixtures/partners.json')
puts "Importing partners from #{path}"
Expand Down Expand Up @@ -39,7 +43,8 @@ module PlacecalSnapshotImporter
url: partner_url,
address_street: partner_address_street,
address_postcode: partner_address_postcode,
logo_url: partner_logo_url
logo_url: partner_logo_url,
description_html: make_html_from_text(partner_description)
)
end
end
Expand Down Expand Up @@ -80,7 +85,8 @@ module PlacecalSnapshotImporter
organizer_placecal_id: organizer_id,
address_street: event_data['address']['streetAddress'],
address_postcode: event_data['address']['postalCode'],
partner_id: partner.id
partner_id: partner.id,
description_html: make_html_from_text(event_data['description'])
},
instances: [ event_instance ]
}
Expand Down

0 comments on commit 06bb356

Please sign in to comment.