Class: Tailwindcss::Compiler::FileCompiler

Inherits:
Object
  • Object
show all
Defined in:
lib/tailwindcss/compiler/file_parser.rb

Instance Method Summary collapse

Instance Method Details

#call(file_path:) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/tailwindcss/compiler/file_parser.rb', line 7

def call(file_path:)
  file_content = File.read(file_path)
  code = if file_is_ruby?(file_path:)
    extract_ruby_from_rb(file_content:)
  elsif file_is_erb?(file_path:)
    extract_ruby_from_erb(erb: file_content)
  else
    return
  end

  buffer = Parser::Source::Buffer.new(file_path)
  buffer.source = code

  parser = Parser::CurrentRuby.new
  parser.parse(buffer)
rescue Parser::SyntaxError
  Rails.logger.error("Tailwindcss: Failed to parse #{file_path}. Skipping...")
end