Class: Solidcrud::AssetsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/solidcrud/assets_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#flash

Instance Method Details

#javascriptObject



18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/solidcrud/assets_controller.rb', line 18

def javascript
  filename = params[:filename]
  # Ensure we have the .js extension
  filename = "#{filename}.js" unless filename.end_with?('.js')
  asset_path = Solidcrud::Engine.root.join('app', 'assets', 'javascripts', 'solidcrud', filename)

  if File.exist?(asset_path)
    render plain: File.read(asset_path), content_type: 'application/javascript'
  else
    head :not_found
  end
end

#stylesheetObject



5
6
7
8
9
10
11
12
13
14
15
16
# File 'app/controllers/solidcrud/assets_controller.rb', line 5

def stylesheet
  filename = params[:filename]
  # Ensure we have the .css extension
  filename = "#{filename}.css" unless filename.end_with?('.css')
  asset_path = Solidcrud::Engine.root.join('app', 'assets', 'stylesheets', 'solidcrud', filename)

  if File.exist?(asset_path)
    render plain: File.read(asset_path), content_type: 'text/css'
  else
    head :not_found
  end
end

#webfontObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/controllers/solidcrud/assets_controller.rb', line 31

def webfont
  filename = params[:filename]
  # Add format extension if present
  filename = "#{filename}.#{params[:format]}" if params[:format].present?
  
  asset_path = Solidcrud::Engine.root.join('app', 'assets', 'stylesheets', 'solidcrud', 'webfonts', filename)

  if File.exist?(asset_path)
    # Determine content type based on file extension
    content_type = case File.extname(filename).downcase
                   when '.woff2'
                     'font/woff2'
                   when '.woff'
                     'font/woff'
                   when '.ttf'
                     'font/ttf'
                   when '.otf'
                     'font/otf'
                   else
                     'application/octet-stream'
                   end

    send_file asset_path, type: content_type, disposition: 'inline'
  else
    head :not_found
  end
end