Parsing LESS options in a Sinatra app

混江龙づ霸主 提交于 2019-12-01 00:26:23

I hit this today, and was able to solve it like so:

require 'less'
require 'sinatra/base'

class App < Sinatra::Base
  # Make LESS @import statements work
  Less.paths << settings.views

  # Use LESS for CSS
  get '/stylesheets/:style.css' do
    less(params[:style].to_sym)
  end
end

You can use something like this here which I use to pick up all .css files whether scss or plain css (i.e. it looks in public first by default and then moves on to check in views):

get '/css/:file.css' do                                                                                                                                               
  halt 404 unless File.exist?("views/#{params[:file]}.scss")                                                                                                          
  time = File.stat("views/#{params[:file]}.scss").ctime                                                                                                               
  last_modified(time)                                                                                                                                                 
  scss params[:file].intern                                                                                                                                           
end

You'd have to replace scss with less to make it work.

Passing options to Less should be fixed in tilt by this commit 70465f9.

If you are using bundler, adding the following line to your Gemfile should fix the problem:

gem 'tilt', :git => 'git://github.com/rtomayko/tilt.git'
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!