From 4b83bf5c08d58618dfa63b786016759eb5e4d6b6 Mon Sep 17 00:00:00 2001 From: Fire Demon Date: Mon, 17 Aug 2020 20:18:52 -0500 Subject: [Feature] Post signatures --- app/lib/command_tag/command/footer_tools.rb | 33 +++++++++++++++++++++++++++++ app/lib/command_tag/processor.rb | 2 +- app/lib/formatter.rb | 17 ++++++++++++--- app/lib/sanitize_config.rb | 2 +- 4 files changed, 49 insertions(+), 5 deletions(-) create mode 100644 app/lib/command_tag/command/footer_tools.rb (limited to 'app/lib') diff --git a/app/lib/command_tag/command/footer_tools.rb b/app/lib/command_tag/command/footer_tools.rb new file mode 100644 index 000000000..c0f347303 --- /dev/null +++ b/app/lib/command_tag/command/footer_tools.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true +module CommandTag::Command::FooterTools + def handle_footertools_startup + @status.footer = var('persist:footer:default')[0] + end + + def handle_footer_before_save(args) + return if args.blank? + + name = normalize(args.shift) + return (@status.footer = nil) if read_falsy_from(name) + + var_name = "persist:footer:#{name}" + return @status.footer = var(var_name)[0] if args.blank? + return @vars.delete(var_name) if read_falsy_from(normalize(args[0])) + + if name == 'default' + @vars['persist:footer:default'] = @vars[var_name].presence || [args.join(' ')] + elsif %w(default DEFAULT).include?(args[0]) + @vars['persist:footer:default'] = var(var_name) + else + @vars[var_name] = [args.join(' ')] + end + + @status.footer = var(var_name)[0] + end + + alias handle_signature_before_save handle_footer_before_save + alias handle_sign_before_save handle_footer_before_save + alias handle_sig_before_save handle_footer_before_save + alias handle_am_before_save handle_footer_before_save + alias handle_are_before_save handle_footer_before_save +end \ No newline at end of file diff --git a/app/lib/command_tag/processor.rb b/app/lib/command_tag/processor.rb index f96bddca0..01c06faf3 100644 --- a/app/lib/command_tag/processor.rb +++ b/app/lib/command_tag/processor.rb @@ -84,7 +84,7 @@ class CommandTag::Processor execute_statements(:at_end) all_handlers!(:shutdown) - rescue Failure => e + rescue StandardError => e @status.update(published: false) @status.destroy raise diff --git a/app/lib/formatter.rb b/app/lib/formatter.rb index 5cc4761e5..5559ddb73 100644 --- a/app/lib/formatter.rb +++ b/app/lib/formatter.rb @@ -61,7 +61,7 @@ class Formatter html = "📄 #{html}" if summary_mode return html if options[:plaintext] - linkable_accounts = status.active_mentions.map(&:account) + linkable_accounts = status.mentions.map(&:account) linkable_accounts << status.account keep_html = !summary_mode && %w(text/markdown text/html).include?(status.content_type) @@ -73,20 +73,31 @@ class Formatter unless keep_html html = simple_format(html, {}, sanitize: false) - html = html.delete("\n") + html.delete!("\n") end html = summary_mode ? format_article_summary(html, status) : format_article_content(summary, html) if summary.present? + html = format_footer(html, status.footer, linkable_accounts, status.emojis, **options) if status.footer.present? html.html_safe # rubocop:disable Rails/OutputSafety end def format_remote_content(html, emojis, **options) - html = reformat(html) + html = reformat(html, options[:outgoing]) html = encode_custom_emojis(html, emojis, options[:autoplay]) if options[:custom_emojify] html = format_article_content(options[:summary], html) if options[:article_content] && options[:summary].present? html.html_safe # rubocop:disable Rails/OutputSafety end + def format_footer(html, footer, linkable_accounts, emojis, **options) + footer = encode_and_link_urls(footer, linkable_accounts) + footer = encode_custom_emojis(footer, emojis, options[:autoplay]) if options[:custom_emojify] + footer = "– #{footer}" + footer = simple_format(footer, { 'data-name': 'footer' }, sanitize: false) + footer.delete!("\n") + + "#{html}#{footer}" + end + def format_markdown(html) html = markdown_formatter.render(html) html.delete("\r").delete("\n") diff --git a/app/lib/sanitize_config.rb b/app/lib/sanitize_config.rb index 93260c7dc..adbbd2168 100644 --- a/app/lib/sanitize_config.rb +++ b/app/lib/sanitize_config.rb @@ -43,7 +43,7 @@ class Sanitize return unless name_list name_list.keep_if do |name| - next true if %w(summary abstract permalink).include?(name) + next true if %w(summary abstract permalink footer).include?(name) end node['data-name'] = name_list.join(' ') -- cgit