LESS: generate different CSSs for different theme (color variation) - less

I would like to manage creation of different "theme" for my site, using LESS.
My idea is to generate different compiled .css files, using each time a specific variable.less that is imported by root file.
Here a simple example:
1) I have 2 different color scheme in 2 distinct files: variable1.less and variable2.less.
2) A file style.less should have an #import rule like "#import variableX.less" and obviously this 'X' should change assuming values '1' and '2'.
3) Compiler should then generate style1.css and style2.css, each based on relative variable1.less and variable2.less.
How to obtain this?

You need to flip your import directions.
The style.less file should not import any variables.
Instead, each variableN.less file should import style.less after defining all of its variables.
These files will then each compile to a full set of rules based on their variable values.

Related

Can I create Variable Names from Constants in Objective-C/Swift?

This question is related to Swift and Objective-C.
I want to create variables from Constant Strings. So, in future, when I change name of a variable though out app, I just need to change it at one place, it must be changed, wherever it is used.
Example:
I have user_id in 14 files, if I want to change user_id into userID I have to change in all 14 files, but I want to change at once place only.
One way to do this would be to use the Xcode build process and add a script (language can be of your choice, but the default is a BASH script)
Create string constant text file where you define all your variables you want to change in some format that expresses the change you want to make, for example:
"variable_one_name" = "new_variable_one_name"
Depending on how 'smart' you wanted your script to be you could also list all your variables and include some way of indicating when a variable is not to be replaced.
"variable_one_name" = "new_variable_one_name"
"variable_two_name" = "DO_NOT_CHANGE"
Run a pre build script on you project that reads in the string constant text file and then iterates through your source files and executes the desired replacement. Be careful to limit the directories you search to you OWN source files!
build project...
This would allow you to manage your constants from one place. However it clearly is only going to help you after you have created a project and written some code :)
BASH string replacement
Adding a run script to the Xcode build process

How can one include another LiveScript file in LiveScript?

How can one use code in a LiveScript file from another LS file? For example:
# In script-one.ls
foo = 5
# In script-two.ls
bar = -> foo + 3
Simply including both files in the HTML via script tags does not seem to work. Changing the first script to export foo = 5 and using require! './script-one' (or variants) in the second script doesn't work either.
And what about circular dependencies?
LiveScript simply compiles to javascript. The module format is your decision just like in JS.
The export keyword simply compiles to a commonjs exports.foo = right now and will not work in browsers without using something like browserify (http://browserify.org/) to bundle your modules (ES6 compat is planned in the future).

Best way to concatenate JavaScript files with dependencies and to output them as a module?

I know this question came up in similar variations often, but no solution seems to fully fit my needs. I have the following problem:
In development I use multiple JS files (a single file every "object"). These JS files have several dependencies within each other - some rely on others and I need to load them first. Currently I use RequireJS to load each JS file in the right order, so I define a module for each file. Fine and dandy.
But now I want to concatenate all my JS files into one big JS file which should be a module itself. I use the RequireJS optimizer r.js to do that. My problem: Every JS file is concatenated to a big JS file, but the module definition for each object is included to. I don't have one big module in one big file, but many modules in one big file.
After that I tried grunt for concatenating which works fine, but ignores dependencies of files. It just concatenates every file in alphabetical order or I have to hardcode the order in my gruntfile.
How can I solve this?
Just as an illustration to my problem:
I have following files (pseudo code):
FileA
- define FileA module
- depends on FileB
- FileA Logic
FileB
- define FileB module
- FileB Logic
And I want this output:
LibFile
- define LibFile module
- FileB Logic, FileA Logic
But I get this with r.js (module definition from FileA and FileB is copied):
LibFile
- define FileB module
- FileB Logic
- define FileA module
- depends on FileB
- FileA Logic
And I get this with grunt (wrong order):
LibFile
- FileA Logic
- FileB Logic
Maybe that questions is a little bit stupid, but I just can't solve this with the tools everybody seems to use...
I tried the grunt-requirejs plugin, too. But it throws several erros which I couldn't resolve.
Thank you,
Pipo
I am going to move it into an answer. Just so the code is a bit clearer.
I am doing these by memory (since I can't test it right now) so some little things may be not entirely accurate.
It depends of course on how you package your modules, but one way is to register all your smaller modules in a bigger module:
File A.js
define([], function() {
// do something
return A;
});
File B.js
define(['path/to/A'], function(A){
// do something with A and more
return B;
});
Then, you package them together:
File mylib.js
define(['path/to/A', 'path/to/B'], function(A, B){
return {
A : A,
B : B
}
}
you then can point your build profile to mylib.js and it will be combined into
one big file. It won't be one all-encapsulating module, but it will have an entry
module that references everything else. You then can use it like so:
require.config({
paths : {
'path/to/mylib' : 'real/path/to/mylib/on/server'
}
});
require(['path/to/mylib'], function(Lib) {
// do something using Lib.A or Lib.B
}
the one thing to pay attention to is the ID of your big module file. By default
RequireJS build gives ID that matches physical path (from appDir IIRC) and you
have to match that when you load your dependency. Simply put, if your resulting
mylib.js file has a main module that received the name 'path/to/mylib', you will
have to match it and load it by the same ID (using require.config.paths) or play with
maps and such (some of which requires RequireJS 2.0).
The following is the reason I asked you why would you want to do the "big module" thing
Other thing of note is that all your inner smaller modules also receive IDs matching their
physical path and you can use these IDs when you use the big package module (so that you can access them not only through Lib.A) if mylib.js has been loaded:
require(['path/to/A'], function(A) {
// do something using A
}

Difference between #import header file with <filename> and "filename" [duplicate]

I'm wondering what decides whether you're allowed to use <Header.h> or "Header.h" when you're importing files in Objective-C. So far my observation has been that you use the quote marks "" for files in your project that you've got the implementation source to, and angle brackets <> when you're referencing a library or framework.
But how exactly does that work? What would I have to do to get my own classes to use the brackets? Right now Xcode will not allow me to do that for my own headers.
Also, by looking in some frameworks headers, I see that the headers reference each other with <frameworkname/file.h>. How does that work? It looks a lot like packages in Java, but as far as I know, there is no such thing as a package in Objective-C.
Objective-C has this in common with C/C++; the quoted form is for "local" includes of files (you need to specify the relative path from the current file, e.g. #include "headers/my_header.h"), while the angle-bracket form is for "global" includes -- those found somewhere on the include path passed to the compiler (e.g. #include <math.h>).
So to have your own headers use < > not " " you need to pass either the relative or the absolute path for your header directory to the compiler. See "How to add a global include path for Xcode" for info on how to do that in Xcode.
See this MSDN page for more info.
In C, the convention is that header files in <> bracket are searched in 'system' directories and "" in user or local directories.
The definition of system and local is a bit vague, I guess. I believe it looks in system directories in include path or in CPPFLAGS for <header.h>, and local directory or directory specified with -I to compiler are searched for "header.h" files.
I assume it works similarly for Objective-C.
To import your own classes using "< >" you have to put the header files (*.h) in the lib folder of compiler or set a SYSTEM VARIABLES ponting to your lib folder.
#import <> vs ""
<Name.h> - Angle brackets tells to preprocessor to search in a special pre-designated system's directories. For example you import systems headers like <UIKit/UIKit.h> or added frameworks
"Name.h" - Quotation marks tells to preprocessor to search in a current directory. If a header was not found the preprocessor try to use <Name.h>. Usually you should use it with your project's files
Just stumbled upon the same problem, there are 2 types of search paths is Xcode:
User Header Search Paths
Header Search Paths
If you add your own include folders into Header Search Paths, you can use angled brackets without any problem.
Or set Always Search User Path to YES so you can use angle brackets.
With angle brackets e.g. <Foundation/Foundation.h> you import system files.
You use double quotes "Person.h" to import local files (files that you created) and to tell the compiler where to look for them.
If this is an Xcode project and you want to include it in a framework, have the header file you want to included open. Then, open Xcode's rightmost tab and under "Target Membership", click on the framework you want your file to available from.
e.g. If your framework is AlphaTools and your header, AceHeader, then you'll select AlphaTools on Target Membership so you can access < AlphaTools/AceHeader.h
WHAT IS HEADER FILE ?
Header files contain definitions of functions and variables which can be incorporated into any C program by using the pre-processor #include statement. Standard header files are provided with each compiler, and cover a range of areas, string handling, mathematical, data conversion, printing and reading of variables.
Ex- #include it contain the information about input like scanf(),and out put like printf() function and etc in a compiler.
INCLUDE
1) #INCLUDE:-
It is a pre-processor that process before process of main function.
The main work of pre-processor is to initialize the environment of program i.e that is the program with the header file.
2).h:-
(Header file) A header file is a file with extension .h which contains C function declarations and macro definitions and to be shared between several source files.
Q) There are two types of header files: the files that the programmer writes and the files that come with your compiler ?
A)In a angular brackets
Angular-bracket form is for "global" includes -- those found somewhere on the include path passed to the compiler (e.g. #include)
It is used for using of library function which is all ready define in compiler.
In C the convention is that header files in <> bracket are searched in 'system' directories 
B) Quote marks:- “header.h”
quoted form is for "local" includes of files (you need to specify the relative path from the current file, e.g. #include "headers/my_header.h")
In C the convention is that header files in " " are searched in user or local directories.
In it one file to be included in another .(FILE INCLUSION).
It can be used in two cases:
Case 1: If we have a very large program, the code is best divided int several different files,each containing a set of related functions.
Case 2: There are some functions and micros definitions that we need at most in all programs that we write.
Ex

#import using angle brackets < > and quote marks " "

I'm wondering what decides whether you're allowed to use <Header.h> or "Header.h" when you're importing files in Objective-C. So far my observation has been that you use the quote marks "" for files in your project that you've got the implementation source to, and angle brackets <> when you're referencing a library or framework.
But how exactly does that work? What would I have to do to get my own classes to use the brackets? Right now Xcode will not allow me to do that for my own headers.
Also, by looking in some frameworks headers, I see that the headers reference each other with <frameworkname/file.h>. How does that work? It looks a lot like packages in Java, but as far as I know, there is no such thing as a package in Objective-C.
Objective-C has this in common with C/C++; the quoted form is for "local" includes of files (you need to specify the relative path from the current file, e.g. #include "headers/my_header.h"), while the angle-bracket form is for "global" includes -- those found somewhere on the include path passed to the compiler (e.g. #include <math.h>).
So to have your own headers use < > not " " you need to pass either the relative or the absolute path for your header directory to the compiler. See "How to add a global include path for Xcode" for info on how to do that in Xcode.
See this MSDN page for more info.
In C, the convention is that header files in <> bracket are searched in 'system' directories and "" in user or local directories.
The definition of system and local is a bit vague, I guess. I believe it looks in system directories in include path or in CPPFLAGS for <header.h>, and local directory or directory specified with -I to compiler are searched for "header.h" files.
I assume it works similarly for Objective-C.
To import your own classes using "< >" you have to put the header files (*.h) in the lib folder of compiler or set a SYSTEM VARIABLES ponting to your lib folder.
#import <> vs ""
<Name.h> - Angle brackets tells to preprocessor to search in a special pre-designated system's directories. For example you import systems headers like <UIKit/UIKit.h> or added frameworks
"Name.h" - Quotation marks tells to preprocessor to search in a current directory. If a header was not found the preprocessor try to use <Name.h>. Usually you should use it with your project's files
Just stumbled upon the same problem, there are 2 types of search paths is Xcode:
User Header Search Paths
Header Search Paths
If you add your own include folders into Header Search Paths, you can use angled brackets without any problem.
Or set Always Search User Path to YES so you can use angle brackets.
With angle brackets e.g. <Foundation/Foundation.h> you import system files.
You use double quotes "Person.h" to import local files (files that you created) and to tell the compiler where to look for them.
If this is an Xcode project and you want to include it in a framework, have the header file you want to included open. Then, open Xcode's rightmost tab and under "Target Membership", click on the framework you want your file to available from.
e.g. If your framework is AlphaTools and your header, AceHeader, then you'll select AlphaTools on Target Membership so you can access < AlphaTools/AceHeader.h
WHAT IS HEADER FILE ?
Header files contain definitions of functions and variables which can be incorporated into any C program by using the pre-processor #include statement. Standard header files are provided with each compiler, and cover a range of areas, string handling, mathematical, data conversion, printing and reading of variables.
Ex- #include it contain the information about input like scanf(),and out put like printf() function and etc in a compiler.
INCLUDE
1) #INCLUDE:-
It is a pre-processor that process before process of main function.
The main work of pre-processor is to initialize the environment of program i.e that is the program with the header file.
2).h:-
(Header file) A header file is a file with extension .h which contains C function declarations and macro definitions and to be shared between several source files.
Q) There are two types of header files: the files that the programmer writes and the files that come with your compiler ?
A)In a angular brackets
Angular-bracket form is for "global" includes -- those found somewhere on the include path passed to the compiler (e.g. #include)
It is used for using of library function which is all ready define in compiler.
In C the convention is that header files in <> bracket are searched in 'system' directories 
B) Quote marks:- “header.h”
quoted form is for "local" includes of files (you need to specify the relative path from the current file, e.g. #include "headers/my_header.h")
In C the convention is that header files in " " are searched in user or local directories.
In it one file to be included in another .(FILE INCLUSION).
It can be used in two cases:
Case 1: If we have a very large program, the code is best divided int several different files,each containing a set of related functions.
Case 2: There are some functions and micros definitions that we need at most in all programs that we write.
Ex