Giter VIP home page Giter VIP logo

less4clj's Introduction

Less4clj

Clojars Project Build Status AppVeyor

Clojure wrapper for Less4j Java implementation of Less compiler. This repository also contains Boot and Leiningen tasks.

For parallel Sass library check sass4clj

ATTENTION: less4j is not maintained and only targets Less ~1.3-1.4. Consider using Less.js if you do not need to read LESS files from the Java classpath.

Features

  • Load imports directly from Java classpath (e.g. Webjars)
    • Add dependency [org.webjars.bower/bootstrap "3.3.6"] to use Bootstrap

Boot Clojars Project

  • Provides the less task (deraen.boot-less/less)
  • Select main files using inputs option
  • or, for each .main.less file in the fileset creates equivalent .css file.
  • Check boot less --help for task options.

Leiningen Clojars Project

  • Provides the less4clj task
  • Select main files using inputs option
  • or, for each .main.less file in source-dirs creates equivalent .css file.
  • Check lein help less4clj for options.

Clj

Test in the repository:

clj -m less4clj.main --source-paths test-resources

Check clj -m less4clj.main --help for options.

Import load order

Loading order for @import "{name}"; on file at {path}

  1. Local file at {path}/{name}.less
  2. Classpath resource (io/resource "{name}.less")
  3. Classpath resource (io/resource "{path}/{name}.less")
  4. Webjar asset
    • Resource META-INF/resources/webjars/{package}/{version}/{path} can be referred using {package}/{path}
    • For example @import "bootstrap/less/bootstrap.less"; will import META-INF/resources/webjars/bootstrap/3.3.6/less/bootstrap.less

FAQ

Shadow-cljs integration

Check the example from sass4clj, it should work with less4clj also.

Semantic-UI theme.config

Semantic-UI needs theme.config file in your project. Add this file to your classpath under path META-INF/resources/webjars/semantic-ui/2.2.10/src/theme.config, e.g under resources/ folder.

Log configuration

If you don't have any slf4j implementations, you will see a warning:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

To disable this, add a no operation logger to your project. As this is only required on the build phase, you can use :scope "test" so that the dependency is not transitive and is not included in Uberjar. Alternatively, you can add this dependency to your Leiningen dev profile.

[org.slf4j/slf4j-nop "1.7.13" :scope "test"]

License

Copyright © 2014-2021 Juho Teperi

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

less4clj's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

less4clj's Issues

Less files cannot be imported from other directories that are configured in :source-paths

We used older version, 0.3.2, in our project, and had two different directories configured in our project.clj under :source-paths (basically like this {:less {:source-paths ["src/less" "less"]}}). In these directories it was possible to import files from the other source path and vice versa with no problems. After updating to the newest version this no longer works, error given is "The file file.less does not exist." This can be fixed by using a relative path to the file in the import statement but then it seems it does not matter if the other directory even is configured in source-paths.

So is it a bug with the newest version that the directories configured as source-paths do not see files in the other directories in source-paths or was the old functionality we relied on with the old version not meant to be?

Import font in semantic-ui results in incorrect css

So, semantic-ui is working!

But I keep getting a warning:
WARN: Compilation resulted in incorrect CSS. The IMPORT ended up inside a body of rule set located at 17:1 at line 51

It seems to be caused by this line:

/*******************************
             Page
*******************************/

.loadFonts();

Which triggers this mixin:

.loadFonts() when (@importGoogleFonts) {
  @import url('@{googleProtocol}fonts.googleapis.com/css?family=@{googleFontRequest}');
}

And then results in the following css:

 {
  /*******************************
             Page
*******************************/
  @import url('https://fonts.googleapis.com/css?family=Roboto:400,700,400italic,700italic&subset=latin');
}

The {} around the import statement shouldn't be there I think

Clojure 1.9 beta15 spec failure

When building using lein less4j once the following output error is displayed (due to Clojure 1.9beta15 having hardened syntactical requirements)

leiningen.less4j/compile-less fails spec: :clojure.core.specs/arg-list at: [:args :bs :arity-1 :args] predicate: vector?
leiningen.less4j/compile-less fails spec: :clojure.core.specs/args+body at: [:args :bs :arity-n] predicate: (cat :args :clojure.core.specs/arg-list :body (alt :prepost+body (cat :prepost map? :body (+ any?)) :body (* any?)))

This prevents the task from being fulfilled.

less4clj fails when there are spaces in the directory (uri)

It seems to fail with less4clj.core/join-url with the java.net.URI constructor, not accepting whitespace.

java.net.URISyntaxException: Illegal character in path at index 66: /home/jenkins/.boot/cache/tmp/opt/jenkins/.jenkins/workspace/Kikka - Develop/fab/-reftg1/css/

lein less4j fails with clojure alpha 14

Exception in thread "main" java.lang.IllegalArgumentException: Call to clojure.core/fn did not conform to spec:
In: [0] val: leiningen.less4j/compile-less fails spec: :clojure.core.specs/arg-list at: [:args :bs :arity-1 :args] predicate: vector?
In: [0] val: leiningen.less4j/compile-less fails spec: :clojure.core.specs/args+body at: [:args :bs :arity-n] predicate: (cat :args :clojure.core.specs/arg-list :prepost (? map?) :body (* any?))
:clojure.spec/args  (leiningen.less4j/compile-less [& _] (clojure.core/doseq [[path__5687__auto__ relative-path__5688__auto__] [["resources/public/css/app.main.less" "app.main.less"] ["resources/public/css/vendor.main.less" "vendor.main.less"]]] (clojure.core/println (clojure.core/format "Compiling {less}... %s" relative-path__5688__auto__)) (clojure.core/let [result__5689__auto__ (try (less4clj.core/less-compile-to-file path__5687__auto__ "resources/public/css" relative-path__5688__auto__ {}) (catch java.lang.Exception e__5690__auto__ (if false (clojure.core/println (.getMessage e__5690__auto__)) (throw e__5690__auto__))))] (clojure.core/doseq [warning__5691__auto__ (:warnings result__5689__auto__)] (clojure.core/println (clojure.core/format "WARN: %s %s\n" (:message warning__5691__auto__) (clojure.core/str (if (:uri (:source warning__5691__auto__)) (clojure.core/str "on file " (:uri (:source warning__5691__auto__)) (if (:line warning__5691__auto__) (clojure.core/str " at line " (:line warning__5691__auto__) " character " (:char warning__5691__auto__))))))))))))

I'm using [deraen/lein-less4j "0.6.1"]

Enable silent compilation

:verbosity is either 1 or 2. Maybe it could be 0 too, to disable all printing. This would be usefull when using from likes of Integrant, Mount and Component.

(defmethod ig/init-key :adapter.less/watch [_ opts]
  (less4clj.api/start opts))

(defmethod ig/halt-key! :adapter.less/watch [_ this]
  (less4clj.api/stop this))

Provide functions for repl and CLI main use

Less4clj should be usable from REPL similar to how figwheel (start-figwheel) works. This should also allow use with Component/Integrant.

Similar main function should be usable with Clojure CLI.

slj4j-nop causes errors if project is also using some slf4j impl.

                 [org.webjars/webjars-locator "0.19"]
                 [org.slf4j/slf4j-nop "1.7.7"]

It might be possible to remove other slf4j implementations from project config before doing the eval-in-project (on lein-less4j / boot-less). But I think a better solution would be to just implement what webjars-locator is doing in Clojure, shouldn't be too complex.

Webjars ring handler

Even though this doesn't directly relate to Less, using webjars locator implementation it would be easy to provide a ring handler to find files in webjars.

(resources "/fonts" {:root "META-INF/resources/webjars/bootstrap/3.3.2/fonts"})
; ->
(webjars "/fonts" {:name "bootstrap" :prefix "fonts"})

Note: https://github.com/weavejester/ring-webjars exists already, but it's using java Webjars library.

Using "&" parent selector + Double-hyphens in a class name causes the compiler to fail

I noticed weird behaviour when naming my CSS classes with BEM-naming convention, using & and double hyphens. When naming my classes in a following way

.foo { &__bar { &--baz { } } }

the error occurs

ERROR file:/** 260:8 mismatched character 'b' expecting '>' 259: &__bar { 260: &--baz { 261:

When using the double hyphens without the "&" parent selector, it seems to be working fine.

To add: it also works with .foo__bar--baz so the problem isn't the double hyphens, but the combination of &-selector and double hyphens.

source-map name and "file" parameter are incorrect if multiple less files are compiled

I have a number of .less files, all imported in site.main.less file.
lein less4j once properly creates site.css and map file named site.main.css.map (not site.css.map).
It works (because same file name is specified in site.css), but doesn't feel quite right and some tools fails to associate them properly.

Real bug is there's target file specified inside site.main.css.map:

"file":"devcards.main.css",

There's no such file, of course.

I am not sure if it is a Less4j or less4clj issue, but I believe "file" should point to site.css and it would be nice that name of the map file was matching css file (i.e. site.css.map, not site.main.css.map).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.