<commit_before>require_dependency 'email_styles'

class EmailRenderer

  def initialize(message, opts=nil)
    @message = message
    @opts = opts || {}
  end

  def text
    @text ||= @message.body.to_s.force_encoding('UTF-8')
  end

  def logo_url
    logo_url = SiteSetting.logo_url
    if logo_url !~ /http(s)?\:\/\//
      logo_url = "#{Discourse.base_url}#{logo_url}"
    end
    logo_url
  end

  def html
    formatted_body = EmailStyles.new(PrettyText.cook(text, environment: 'email')).format

    if @opts[:html_template]
      ActionView::Base.new(Rails.configuration.paths["app/views"]).render(
        template: 'email/template',
        format: :html,
        locals: { html_body: formatted_body, logo_url: logo_url }
      )
    else
      formatted_body
    end
  end

end<commit_msg>Don't apply styling unless the HTML template is active<commit_after>require_dependency 'email_styles'

class EmailRenderer

  def initialize(message, opts=nil)
    @message = message
    @opts = opts || {}
  end

  def text
    @text ||= @message.body.to_s.force_encoding('UTF-8')
  end

  def logo_url
    logo_url = SiteSetting.logo_url
    if logo_url !~ /http(s)?\:\/\//
      logo_url = "#{Discourse.base_url}#{logo_url}"
    end
    logo_url
  end

  def html
    cooked = PrettyText.cook(text, environment: 'email')

    if @opts[:html_template]
      ActionView::Base.new(Rails.configuration.paths["app/views"]).render(
        template: 'email/template',
        format: :html,
        locals: { html_body: EmailStyles.new(cooked).format, logo_url: logo_url }
      )
    else
      cooked
    end
  end

end
{'fraction_non_alphanumeric': 0.12430426716141002, 'fraction_numerical': 0.0012368583797155227, 'mean_word_length': 2.9559902200489, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5177898', 'n_tokens_mistral': 550, 'n_tokens_neox': 542, 'n_words': 111}