Sha256: b0d844365e885654a35f1c99debd9e2c7f6a48eb58f328271cf9d5e0bbd4180a

Contents?: true

Size: 1.35 KB

Versions: 24

Compression:

Stored size: 1.35 KB

Contents

# frozen_string_literal: true

class ThemeController < ContentController
  # Allow javascripts via Get request
  skip_before_action :verify_authenticity_token, only: :javascripts

  def stylesheets
    render_theme_item(:stylesheets, params[:filename], "text/css; charset=utf-8")
  end

  def javascripts
    render_theme_item(:javascripts, params[:filename], "text/javascript; charset=utf-8")
  end

  def images
    render_theme_item(:images, params[:filename])
  end

  def fonts
    render_theme_item(:fonts, params[:filename])
  end

  def error
    head :not_found
  end

  def static_view_test; end

  private

  def render_theme_item(type, file, mime = nil)
    return render_not_found if file.split(%r{[\\/]}).include?("..")

    src = this_blog.current_theme.path + "/#{type}/#{file}"
    return render_not_found unless File.exist? src

    mime ||= mime_for(file)
    send_file(src, type: mime, disposition: "inline", stream: true)
  end

  def render_not_found
    render plain: "Not Found", status: :not_found
  end

  def mime_for(filename)
    case filename.downcase
    when /\.js$/
      "text/javascript"
    when /\.css$/
      "text/css"
    when /\.gif$/
      "image/gif"
    when /(\.jpg|\.jpeg)$/
      "image/jpeg"
    when /\.png$/
      "image/png"
    when /\.swf$/
      "application/x-shockwave-flash"
    else
      "application/binary"
    end
  end
end

Version data entries

24 entries across 24 versions & 2 rubygems

Version Path
publify_core-10.0.2 app/controllers/theme_controller.rb
HornsAndHooves-publify_core-10.5.0 app/controllers/theme_controller.rb
HornsAndHooves-publify_core-10.4.0 app/controllers/theme_controller.rb
HornsAndHooves-publify_core-10.3.0 app/controllers/theme_controller.rb
HornsAndHooves-publify_core-10.2.0 app/controllers/theme_controller.rb
publify_core-10.0.1 app/controllers/theme_controller.rb
publify_core-10.0.0 app/controllers/theme_controller.rb
publify_core-9.2.10 app/controllers/theme_controller.rb
HornsAndHooves-publify_core-10.1.1 app/controllers/theme_controller.rb
HornsAndHooves-publify_core-10.1.0 app/controllers/theme_controller.rb
HornsAndHooves-publify_core-10.0.3 app/controllers/theme_controller.rb
HornsAndHooves-publify_core-10.0.2 app/controllers/theme_controller.rb
HornsAndHooves-publify_core-10.0.1 app/controllers/theme_controller.rb
HornsAndHooves-publify_core-10.0.0 app/controllers/theme_controller.rb
publify_core-9.2.9 app/controllers/theme_controller.rb
publify_core-9.2.8 app/controllers/theme_controller.rb
publify_core-9.2.7 app/controllers/theme_controller.rb
publify_core-9.2.6 app/controllers/theme_controller.rb
publify_core-9.2.5 app/controllers/theme_controller.rb
publify_core-9.2.4 app/controllers/theme_controller.rb