Class: ActiveCanvas::TailwindCompiler

Inherits:
Object
  • Object
show all
Defined in:
app/services/active_canvas/tailwind_compiler.rb

Defined Under Namespace

Classes: CompilationError

Constant Summary collapse

LOG_PREFIX =
"[ActiveCanvas::TailwindCompiler]".freeze

Class Method Summary collapse

Class Method Details

.available?Boolean

Returns:

  • (Boolean)


49
50
51
52
# File 'app/services/active_canvas/tailwind_compiler.rb', line 49

def available?
  # Always check fresh - no caching
  defined?(Tailwindcss::Ruby) && Tailwindcss::Ruby.respond_to?(:executable)
end

.clear_availability_cache!Object



54
55
56
# File 'app/services/active_canvas/tailwind_compiler.rb', line 54

def clear_availability_cache!
  # No longer caches, but keep method for compatibility
end

.compile(html_content, identifier: "content") ⇒ Object

Compile Tailwind CSS for raw HTML content



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
# File 'app/services/active_canvas/tailwind_compiler.rb', line 11

def compile(html_content, identifier: "content")
  log_info "Starting compilation for #{identifier}"
  start_time = Time.current

  unless available?
    log_error "tailwindcss-ruby gem is not installed"
    raise CompilationError, "tailwindcss-ruby gem is not installed"
  end

  if html_content.blank?
    log_info "#{identifier} has no content, skipping compilation"
    return ""
  end

  log_debug "Content size: #{html_content.bytesize} bytes"

  Dir.mktmpdir("active_canvas_tailwind") do |dir|
    log_debug "Created temp directory: #{dir}"

    html_file = File.join(dir, "input.html")
    css_file = File.join(dir, "output.css")

    File.write(html_file, html_content)
    log_debug "Wrote HTML content to #{html_file}"

    compiled_css = compile_css(html_file, css_file, identifier)

    elapsed = ((Time.current - start_time) * 1000).round(2)
    log_info "Compilation completed for #{identifier} in #{elapsed}ms (output: #{compiled_css.bytesize} bytes)"

    compiled_css
  end
end

.compile_for_page(page) ⇒ Object



45
46
47
# File 'app/services/active_canvas/tailwind_compiler.rb', line 45

def compile_for_page(page)
  compile(page.content.to_s, identifier: "page ##{page.id} (#{page.title})")
end