Class: Inkcite::Cli::Validate

Inherits:
Object
  • Object
show all
Defined in:
lib/inkcite/cli/validate.rb

Class Method Summary collapse

Class Method Details

.invoke(email, opts) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/inkcite/cli/validate.rb', line 7

def self.invoke email, opts

  # True if all versions of the email are valid.
  valid = true

  # Grab the environment (e.g. production) that will be validated.
  environment = opts[:environment]

  # Check to see if a specific version is requested or if unspecified
  # all versions of the email should be validated.
  versions = Array(opts[:version] || email.versions)
  versions.each do |version|

    # The version of the email we will be sending.
    view = email.view(environment, :email, version)

    subject = view.subject

    print "Validating '#{subject}' ... "

    validator = Nokogiri::HTML(view.render!) do |config|
      config.strict
    end

    if validator.errors.any?
      puts 'Invalid!'
      validator.errors.each do |err|
        puts err.inspect
        puts err.line
      end

    else
      puts 'Valid!'

    end

    if versions.length > 1
      puts ''
    end

  end

  valid
end