{"id":13482961,"url":"https://github.com/metaskills/less-rails","last_synced_at":"2025-05-15T11:03:51.450Z","repository":{"id":1723932,"uuid":"2454588","full_name":"metaskills/less-rails","owner":"metaskills","description":":-1: :train: Less.js For Rails","archived":false,"fork":false,"pushed_at":"2022-02-10T11:29:39.000Z","size":182,"stargazers_count":340,"open_issues_count":11,"forks_count":133,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-04-07T08:12:46.205Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://github.com/metaskills/less-rails","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/metaskills.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2011-09-25T12:50:28.000Z","updated_at":"2024-05-29T09:16:45.000Z","dependencies_parsed_at":"2022-08-06T11:00:43.411Z","dependency_job_id":null,"html_url":"https://github.com/metaskills/less-rails","commit_stats":null,"previous_names":[],"tags_count":34,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metaskills%2Fless-rails","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metaskills%2Fless-rails/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metaskills%2Fless-rails/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metaskills%2Fless-rails/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/metaskills","download_url":"https://codeload.github.com/metaskills/less-rails/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248912225,"owners_count":21182238,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T17:01:07.077Z","updated_at":"2025-04-14T15:54:58.108Z","avatar_url":"https://github.com/metaskills.png","language":"Ruby","funding_links":[],"categories":["Assets","CSS and Styling","UI/Theme Frameworks and Components"],"sub_categories":[],"readme":"# The dynamic stylesheet language for the Rails 5+ asset pipeline.\n\nThis gem provides integration for Rails projects using the Less stylesheet language in the asset pipeline.\n\n[![Build Status](https://secure.travis-ci.org/metaskills/minitest-spec-rails.svg)](http://travis-ci.org/metaskills/less-rails)\n\n\n## Installing\n\nJust bundle up less-rails in your Gemfile. This will pull in less as a runtime dependency too.\n\n```ruby\ngem 'less-rails', '~\u003e 4.0.0'\n```\n\nBut be warned, less.rb relies on a JavaScript runtime gem too. Just like ExecJS, it will look for a gem that is appropriate to your system. Typically, this means you will need one of the following.\n\n```ruby\ngem 'therubyracer' # Ruby\ngem 'therubyrhino' # JRuby\n```\n\n\n## Configuration\n\nThis gem was made for other gems to properly hook into one place to provide paths to the Less::Parser. For example, the less-rails-bootstrap project at http://github.com/metaskills/less-rails-bootstrap and each project should do the path configuration for you. If you need to, you can configure less-rails with additional paths. These paths have higher priority than those from your applications assets load paths.\n\n```ruby\nMyProject::Application.configure do\n  config.less.paths \u003c\u003c \"#{Rails.root}/lib/less/protractor/stylesheets\"\n  config.less.compress = true\nend\n```\n\n#### About Compression\n\nIf `config.assets.compress` is set to true, we will set the `config.less.compress` to true as well. Less has real basic compression and it is recommended that you set the rails `config.assets.css_compressor` to something more stronger like `:yui` in your `config/environments/production.rb` file. Note, this requires the [yui-compressor](https://rubygems.org/gems/yui-compressor) gem but does an excellent job of compressing assets.\n\n\n\n## Import Hooks\n\nAny `@import` to a `.less` file will automatically declare that file as a sprockets dependency to the file importing it. This means that you can edit imported framework files and see changes reflected in the parent during development. So this:\n\n```css\n@import \"frameworks/bootstrap/mixins\";\n\n#leftnav { .border-radius(5px); }\n```\n\nWill end up acting as if you had done this below:\n\n```css\n/*\n *= depend_on \"frameworks/bootstrap/mixins.less\"\n*/\n\n@import \"frameworks/bootstrap/mixins\";\n\n#leftnav { .border-radius(5px); }\n```\n\n## Passing parameters to less.rb\n\nYou can pass any parameters that the [`less.rb`](https://github.com/cowboyd/less.rb) gem (which `less-rails` is based upon) supports by modifying `Rails.application.config.less.raw`.\nFor example, `less.rb` uses [lessc --relative-urls](http://lesscss.org/usage/#command-line-usage-relative-urls) by default. This means that `url('../ralative/paths.png')` for `@import`ed files will be modified according to `.less` file location. To return back to default `lessc` behavior, add these lines to `config/initializers/assets.rb`:\n\n```ruby\nRails.application.config.less.raw.relativeUrls = false\n```\n\nFor more parameters supported by `less.rb`, please consult [less.rb gem](https://github.com/cowboyd/less.rb/blob/master/lib/less/defaults.rb).\n\n\n## Helpers\n\nWhen referencing assets use the following helpers in LESS.\n\n```css\nasset-path(@relative-asset-path)  /* Returns a string to the asset. */\nasset-path(\"rails.png\")           /* Becomes: \"/assets/rails.png\" */\n\nasset-url(@relative-asset-path)   /* Returns url reference to the asset. */\nasset-url(\"rails.png\")            /* Becomes: url(/assets/rails.png) */\n```\n\nAs a convenience, for each of the following asset classes there are corresponding `-path` and `-url` helpers image, font, video, audio, javascript and stylesheet. The following examples only show the `-url` variants since you get the idea of the `-path` ones above.\n\n```css\nimage-url(\"rails.png\")            /* Becomes: url(/assets/rails.png) */\nfont-url(\"rails.ttf\")             /* Becomes: url(/assets/rails.ttf) */\nvideo-url(\"rails.mp4\")            /* Becomes: url(/videos/rails.mp4) */\naudio-url(\"rails.mp3\")            /* Becomes: url(/audios/rails.mp3) */\njavascript-url(\"rails.js\")        /* Becomes: url(/assets/rails.js) */\nstylesheet-url(\"rails.css\")       /* Becomes: url(/assets/rails.css) */\n```\n\nLastly, we provide a data url method for base64 encoding assets.\n\n```css\nasset-data-url(\"rails.png\")       /* Becomes: url(data:image/png;base64,iVBORw0K...) */\n```\n\nPlease note that these helpers are only available server-side, and something like ERB templates should be used if client-side rendering is desired.\n\n\n\n## Generators\n\nInstallation of the gem will set your applications stylesheet engine to use Less. It is possible to have many gems that set the stylesheet engine, for instance the sass-rails and/or stylus gems. In this case, you can resolve the ambiguity by setting the stylesheet engine in your `config/application.rb` file like so. Doing so would mean all generated assets will be in the a fresh `css.less` template.\n\n```ruby\nconfig.app_generators.stylesheet_engine :less\n```\n\nWe have generators for both assets and scaffold in the `less` namespace. For instance the following would generate a blank `app/assets/stylesheets/posts.css.less` template.\n\n```\n$ rails generate less:assets posts\n```\n\nWe also have a generator for rails scaffold CSS. Just like the Sass gem, we simply parse the scaffold.css in the default rails generator and save it as a scaffolds.css.less file. This is done automatically during other scaffold generator actions.\n\n\n\n## Contributing\n\nThis gem is fully tested from Rails 5.0 to Rails 6.0. We run our tests on [Travis CI](http://travis-ci.org/metaskills/less-rails) for officialy supported Rubies If you detect a problem, open up a github issue or fork the repo and help out. After you fork or clone the repository, the following commands will get you up and running on the test suite. \n\n```shell\n$ bundle\n$ bundle exec appraisal install\n$ bundle exec appraisal rake\n```\n\nWe use the [appraisal](https://github.com/thoughtbot/appraisal) gem from Thoughtbot to help us generate the individual gemfiles for each Rails version and to run the tests locally against each generated Gemfile. The `rake appraisal test` command actually runs our test suite against all Rails versions in our `Appraisal` file. If you want to run the tests for a specific Rails version, use `rake -T` for a list. For example, the following command will run the tests for Rails 5.0 only.\n\n```shell\n$ bundle exec rake appraisal:rails50 test\n```\n\nOur current build status is:\n[![Build Status](https://secure.travis-ci.org/metaskills/minitest-spec-rails.png)](http://travis-ci.org/metaskills/less-rails)\n\n\n## License\n\nLess::Rails is Copyright (c) 2011-2013 Ken Collins, \u003cken@metaskills.net\u003e and is distributed under the MIT license.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmetaskills%2Fless-rails","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmetaskills%2Fless-rails","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmetaskills%2Fless-rails/lists"}