<commit_before>require "inline_styles"
require "inline_styles_mailer/version"
require "sass"

module InlineStylesMailer

  def self.included(base)
    base.extend(ClassMethods)
  end

  module ClassMethods

    def use_stylesheet(*stylesheets)
      @stylesheets = Array(stylesheets)
    end

    def stylesheet_path(path)
      @stylesheet_path = path
    end

    def locate_template(name)
      "#{self.name.underscore}/#{name}.html"
    end

    def css_content
      @stylesheets ||= ["_#{self.name.underscore}*"]
      @stylesheet_path ||= File.join("app", "assets", "stylesheets")
      @css_content ||= @stylesheets.map {|stylesheet|
        Dir[Rails.root.join(@stylesheet_path, "#{stylesheet}")].map {|file|
          case file
          when /\.scss$/
            Sass::Engine.new(File.read(file), syntax: :scss).render
          when /\.sass$/
            Sass::Engine.new(File.read(file), syntax: :sass).render
          else
            # Plain old CSS? Let's assume it is.
            File.read(file)
          end
        }.join("\n")
      }.compact.join("\n")
      @css_content
    end

    def locate_layout
      "mailer"
    end

    def page
      @page ||= InlineStyles::Page.new.with_css(css_content)
    end

    # For testing
    def reset
      @css_content = nil
      @page = nil
    end

  end

  def mail(options, &block)
    if block
      super(mail, &block) # We'll just let this pass through
    else
      super(options) do |format|
        lookup_context.find_all(action_name, self.class.name.underscore).each do |template|
          template.formats.each do |f|
            format.send(f) do
              case f.to_s
              when "html"
                html = render_to_string :file => template.inspect, :layout => self.class.locate_layout
                render :text => self.class.page.with_html(html).apply, :formats => [:html]
              else
                render :formats => [f]
              end
            end
          end
        end
      end
    end
  end

end<commit_msg>Pass an array as the second argument to lookup_context.find_all.<commit_after>require "inline_styles"
require "inline_styles_mailer/version"
require "sass"

module InlineStylesMailer

  def self.included(base)
    base.extend(ClassMethods)
  end

  module ClassMethods

    def use_stylesheet(*stylesheets)
      @stylesheets = Array(stylesheets)
    end

    def stylesheet_path(path)
      @stylesheet_path = path
    end

    def locate_template(name)
      "#{self.name.underscore}/#{name}.html"
    end

    def css_content
      @stylesheets ||= ["_#{self.name.underscore}*"]
      @stylesheet_path ||= File.join("app", "assets", "stylesheets")
      @css_content ||= @stylesheets.map {|stylesheet|
        Dir[Rails.root.join(@stylesheet_path, "#{stylesheet}")].map {|file|
          case file
          when /\.scss$/
            Sass::Engine.new(File.read(file), syntax: :scss).render
          when /\.sass$/
            Sass::Engine.new(File.read(file), syntax: :sass).render
          else
            # Plain old CSS? Let's assume it is.
            File.read(file)
          end
        }.join("\n")
      }.compact.join("\n")
      @css_content
    end

    def locate_layout
      "mailer"
    end

    def page
      @page ||= InlineStyles::Page.new.with_css(css_content)
    end

    # For testing
    def reset
      @css_content = nil
      @page = nil
    end

  end

  def mail(options, &block)
    if block
      super(mail, &block) # We'll just let this pass through
    else
      super(options) do |format|
        # Rails 3.1 takes an array, while Rails 3.0 takes a string.
        # See https://github.com/billhorsman/inline_styles_mailer/issues/1
        prefixes = self.class.name.underscore
        prefixes = [prefixes] unless Rails.version =~ /^3\.0/
        lookup_context.find_all(action_name, prefixes).each do |template|
          template.formats.each do |f|
            format.send(f) do
              case f.to_s
              when "html"
                html = render_to_string :file => template.inspect, :layout => self.class.locate_layout
                render :text => self.class.page.with_html(html).apply, :formats => [:html]
              else
                render :formats => [f]
              end
            end
          end
        end
      end
    end
  end

end
{'fraction_non_alphanumeric': 0.1148369315571888, 'fraction_numerical': 0.001607717041800643, 'mean_word_length': 2.0264072272411395, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 1, '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': '635824', 'n_tokens_mistral': 1395, 'n_tokens_neox': 1330, 'n_words': 307}