Rails 3 - Precompilation of all css, sass and scss files in a folder

So I have a project with page and css styles. I put these files in my own directory assets/#{type}/page-specific/, and I'm trying to write a regex rule to tell the precompiler to do this with them.

This works fine on the JS side of the house, but css is more complex.

# page specific style files:
app/assets/stylesheets/page-specific/something.css.sass
app/assets/stylesheets/page-specific/default.css
app/assets/stylesheets/page-specific/home.css.scss

I worked with this regular expression in a file config/initializers/assets.rb:

Rails.application.config.assets.precompile << /(page-specific\/[^(css)]+.css)/

The problem is that the section [^(css)]does not do what I want, as it will filter out everything that has c or s in it. What I'm really looking for is a way to match the entire string "css" and stop there.

Also, I know that the usual wisdom would be to simply write styles so that you don't need tabular stylesheets in favor of application.css containing all the stylesheets. I agree. However, this is a very large code base, and there is a lot of time to bring this Rails update to home, and there is no time to analyze and refactor such things.

[^\.] , , , jquery.treeview.css.sass. , , - , , , , , , .

+3
2

. " css" [^(css)].


:

/(page-specific\/(?:(?!\.css).)++\.css)/

:

  • page-specific\/ / ".
  • (?: , .
    • (?!\.css) , .css ".

, , ( /.css ), , .css \.css)/ .

    • . -, .
  • )++ ( ). : Ruby , Ruby 1.9.
  • \.css .css ".

visualization

:


, , nongreedy:

/(page-specific\/.+?\.css)/

.+? , .css.

visualization

:


PS: , .css/.


:
http://www.tutorialspoint.com/ruby/ruby_regular_expressions.htm

+3

, , . , :

app/assets/stylesheets/page-specific/default.css
app/assets/stylesheets/page-specific/more-specific/home.css.scss

, config/initializers/assets.rb

Rails.application.config.assets.paths << Rails.root.join('app', 'assets', 'stylesheets', 'page-specific')
Rails.application.config.assets.precompile << /.+\.css$/

, / (, , config.assets.paths).

ERB :

  <%= stylesheet_link_tag 'default', media: 'all' %>
  <%= stylesheet_link_tag 'more-specific/home', media: 'all' %>

, .

0

Source: https://habr.com/ru/post/1684002/


All Articles