diff --git a/Gemfile.lock b/Gemfile.lock index 45a5648..535db65 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -5,6 +5,7 @@ PATH git haml-rails rails (>= 7.0.4) + redcarpet GEM remote: https://rubygems.org/ @@ -194,6 +195,7 @@ GEM rb-inotify (0.10.1) ffi (~> 1.0) rchardet (1.8.0) + redcarpet (3.5.1) regexp_parser (2.6.1) rspec (3.12.0) rspec-core (~> 3.12.0) diff --git a/app/controllers/merged/sections_controller.rb b/app/controllers/merged/sections_controller.rb index cd8c8ae..2ce3978 100644 --- a/app/controllers/merged/sections_controller.rb +++ b/app/controllers/merged/sections_controller.rb @@ -11,7 +11,7 @@ module Merged @images = Image.all end def select_template - @sections = Style.sections + @sections = SectionStyle.sections end def select_card_template @cards = Style.cards diff --git a/app/helpers/merged/merged_helper.rb b/app/helpers/merged/merged_helper.rb index 69f91dd..e9e6697 100644 --- a/app/helpers/merged/merged_helper.rb +++ b/app/helpers/merged/merged_helper.rb @@ -1,5 +1,23 @@ +require "redcarpet" + module Merged module MergedHelper + @@renderer = nil + + def renderer + return @@renderer unless @@renderer.nil? + options = {hard_wrap: true , autolink: true, no_intra_emphasis: true , + safe_links_only: true, no_styles: true , + link_attributes: { target: '_blank' }} + html = Redcarpet::Render::HTML.new(options) + @@renderer = Redcarpet::Markdown.new(html, options) + end + + def markdown(text) + text = text.text unless text.is_a?(String) + return "" if text.blank? + renderer.render(text).html_safe + end def blue_button( text, url) button( text , url , "bg-blue-500" ) end diff --git a/app/models/merged/section.rb b/app/models/merged/section.rb index f09e129..8d4744e 100644 --- a/app/models/merged/section.rb +++ b/app/models/merged/section.rb @@ -147,7 +147,7 @@ module Merged def self.build_data(template) data = { "template" => template , "id" => SecureRandom.hex(10) } - style = Style.sections[ template ] + style = SectionStyle.sections[ template ] style.fields.each do |key| data[key] = key.upcase end unless style.fields.blank? diff --git a/app/views/merged/view/_section_cards.haml b/app/views/merged/view/_section_cards.haml index 8fb24fc..12275b1 100644 --- a/app/views/merged/view/_section_cards.haml +++ b/app/views/merged/view/_section_cards.haml @@ -4,7 +4,7 @@ %h1.text-2xl.font-bold.tracking-tight.sm:text-4xl = section.header %p.mt-4.text-lg.pt-10 - = section.text + = markdown(section) - template = "merged/view/cards/" + section.card_template .grid{ column_option(section)} - section.cards.each do |card| diff --git a/app/views/merged/view/_section_full_image.haml b/app/views/merged/view/_section_full_image.haml index e9ff6df..e576070 100644 --- a/app/views/merged/view/_section_full_image.haml +++ b/app/views/merged/view/_section_full_image.haml @@ -11,7 +11,7 @@ %h2.text-2xl.font-bold.md:text-5xl = section.header %p.hidden.sm:mt-4.sm:block.text-2xl - = section.text + = markdown(section) .mt-4.md:mt-8 -if section.has_option?("button_text") = render 'merged/view/elements/button' , section: section diff --git a/app/views/merged/view/_section_full_up.haml b/app/views/merged/view/_section_full_up.haml index edcdbf8..7b6a763 100644 --- a/app/views/merged/view/_section_full_up.haml +++ b/app/views/merged/view/_section_full_up.haml @@ -7,4 +7,4 @@ %h4.text-xl.mt-10.md:text-2xl = section.option("subheader") %p.mt-4.text-lg.pt-10 - = section.text.html_safe + = markdown(section) diff --git a/app/views/merged/view/_section_half_header.haml b/app/views/merged/view/_section_half_header.haml index 64a6394..eabc097 100644 --- a/app/views/merged/view/_section_half_header.haml +++ b/app/views/merged/view/_section_half_header.haml @@ -9,6 +9,4 @@ .lg:py-16 %article.space-y-4.text-gray-600 %p - = section.text - %p - = section.text + = markdown(section) diff --git a/app/views/merged/view/_section_half_image.haml b/app/views/merged/view/_section_half_image.haml index 02bb2e1..382d68c 100644 --- a/app/views/merged/view/_section_half_image.haml +++ b/app/views/merged/view/_section_half_image.haml @@ -9,7 +9,7 @@ %h4.text-xl.mt-10.md:text-2xl = section.option("subheader") %p.mt-8.md:block - = section.text + = markdown(section) -if section.has_option?("text") %p.mt-8.md:block = section.option("text") diff --git a/app/views/merged/view/_section_large_image.haml b/app/views/merged/view/_section_large_image.haml index 07abbba..5a4458f 100644 --- a/app/views/merged/view/_section_large_image.haml +++ b/app/views/merged/view/_section_large_image.haml @@ -8,4 +8,4 @@ -if section.has_option?("subheader") %h4.text-xl.mt-10.md:text-2xl = section.option("subheader") - %p.mt-3= section.text + %p.mt-3= markdown(section) diff --git a/app/views/merged/view/cards/_card_full_image.haml b/app/views/merged/view/cards/_card_full_image.haml index 747aa9f..393d20e 100644 --- a/app/views/merged/view/cards/_card_full_image.haml +++ b/app/views/merged/view/cards/_card_full_image.haml @@ -6,4 +6,4 @@ %h3.text-lg = card.header %p.mt-1.text-xs.font-medium - = card.text + = markdown(card) diff --git a/app/views/merged/view/cards/_card_gap_square.haml b/app/views/merged/view/cards/_card_gap_square.haml index 7bc9ee1..45acd11 100644 --- a/app/views/merged/view/cards/_card_gap_square.haml +++ b/app/views/merged/view/cards/_card_gap_square.haml @@ -5,4 +5,4 @@ %h3.p-4.mt-10.text-3xl.font-bold= card.header -if card.has_option?("subheader") %h4.p-4.text-xl= card.option("subheader") - %p.m-10= card.text + %p.m-10= markdown(card) diff --git a/app/views/merged/view/cards/_card_normal_square.haml b/app/views/merged/view/cards/_card_normal_square.haml index d2bff2c..4745a2a 100644 --- a/app/views/merged/view/cards/_card_normal_square.haml +++ b/app/views/merged/view/cards/_card_normal_square.haml @@ -4,4 +4,4 @@ %h3.p-4.text-2xl.font-bold= card.header -if card.has_option?("subheader") %h4.p-4.text-xl= card.option("subheader") - %p.mt-2.p-4= card.text + %p.mt-2.p-4= markdown(card) diff --git a/merged.gemspec b/merged.gemspec index cc97aec..1d2b861 100644 --- a/merged.gemspec +++ b/merged.gemspec @@ -21,4 +21,5 @@ Gem::Specification.new do |spec| spec.add_dependency "rails", ">= 7.0.4" spec.add_dependency "haml-rails" spec.add_dependency "git" + spec.add_dependency "redcarpet" end