Using Compass generated sprites in Middleman, how to leave out sprite source files from the build? - middleman

Using Middleman 2.0.14, I use the Compass features to generate some sprites in my CSS file with:
#import "companies/*.png";
#include all-companies-sprites;
This takes all the files from source/images/companies/*.png and generates a single sprite file source/images/companies-s45e421528f.png. So far, so good.
When I do a middleman build, it dutifully copies over the generated image file, but also includes the companies/*.png files.
Its not a big deal to have a deployment script remove these extra files, but I wonder if there is an option I'm missing somewhere? (Or maybe the 'almost ready to release MM 3.x' has a solution?) Perhaps I should put the companies/*.png files somewhere else in the source tree?

I suggest cleaning them up with a script (or an after_build hook). This is the default behavior of Compass, to generate images in development mode, and it would require some monkey patching to alter (for now, the Compass beta have direct access to these options).
In 3.0, you could try:
configure :build do
ignore "source/images/companies/*.png"
end
But I'm not sure Compass wouldn't choke on that.

Using ignore slowed down the build significantly for me so I preferred putting the sprite assets outside of source/.
This way, sprites are generated under source/sprites/, build/sprites and the sources are excluded without ignoreing it.
Here is how to set this up:
# config.rb
compass_config do |config|
# tell Compass to load sprites from `project_root/sprites`
config.sprite_load_path =
config.sprite_load_path
.to_a
.push(File.join root, 'sprites')
end
# style.css.scss
#import "..sprites/companies/*.png";
#include all-companies-sprites;

Related

Replace Glyphicons with Font Awesome in CSS using LESS and Grunt

Short version: I would like to use a font set to REPLACE Glyphicons without also including Glyphicons CSS, and without modifying the source bootstrap.less file.
Long version:
Using Bootstrap's own Grunt file and source files as a base, by default a build process will include Glyphicons in the compiled CSS file.
Since I do not plan to use Glyphicons at all, the "lowest hanging fruit" for me is to go ahead and compile this way, but also include the font I will be using (for example, Font Awesome).
However, the more "elegant" way will be to only include the replacement font.
I can modify bootstrap.less, which includes this line:
#import "glyphicons.less";
such that the Font Awesome less file is used instead. However, the problem with this is that I am using Bootstrap as an "untouchable library" not as a modifiable source file. I want to be able to drop in new versions of Bootstrap at a moment's notice without the need to remember to change this modified line.
Does Grunt have the concept of "replace string A with string B in memory before the compile runs"? Or is there another way to accomplish my goal? Or should I just not worry about it and include both sets of compiled CSS?
I think you can use grunt-string-replace
https://github.com/erickrdch/grunt-string-replace

Monogame and .fx files?

I'm currently following this tutorial but using MonoGame :
http://www.riemers.net/eng/Tutorials/XNA/Csharp/Series1/Terrain_from_file.php
As said in the tutorial, my main goal is to render a terrain from an image file.
There is a .fx provided with the tutorial which I included in my project.
I had some issues using MonoGame to load the bmp file for example and now I managed to load it. The problem comes now from the fx file. MonoDevelop tells this : The MGX File is Corrupt !
Here is the original code from the writer of the article :
effect = Content.Load<Effect> ("effects");
And here is how I used it with MonoGame :
effect = Content.Load<Effect> ("effects.fx");
I am really lost about the usage of the effects file in MonoGame. Is there any good tutorial about this ? Anyway I'm really lost with MonoGame. How come there is no clear tutorials for MonoGame has it is widely used ?
You need to convert your shader .fx to appropriate file format for monogame using 2MGFX tool. You can find the tool inside installed monogame directory C:\Program Files (x86)\MSBuild\MonoGame\v3.0
How to use:
Create a .bat file and write code as shown below:
2MGFX.exe effects.fx effects.mgfxo
pause
Execute the .bat file
Note that the shader file, .bat file and 2MGFX.exe must be in same directory.
Here is how to use compiled .mgfxo file as effect:
Put the effects.mgfxo into Assets\Content folder of your project
Load a file as shown below
Stream s = Assembly.GetExecutingAssembly().GetManifestResourceStream("ProjectNameSpace.Assets.Content.effects.mgfxo");
BinaryReader Reader = new BinaryReader(s);
Effect effect = new Effect(graphics, Reader.ReadBytes((int)Reader.BaseStream.Length));
If you have problems converting a shader .fx to .mgfxo please leave comments.
I've been trying to follow Riemers tutorial myself, like you, I struggled with the effects.
I had to make a couple changes to the original effects file before I successfully managed to compile and use it without any exceptions.
Renamed the following:
vs_2_0 to vs_4_0
ps_2_0 to ps_4_0
POSITION to SV_POSITION
Once these changes were made I used the compile tool like following:
2MGFX.exe effects.fx effects.mgfxo /Profile:DirectX_11
Once compiled I moved the mgfxo file into my contents folder and assigned following parameters:
Build action: Embedded resource
Copy to output directory: Copy always
It took me a couple of attempts until I managed to use the shader without MonoGame throwing any exceptions at me.
byte[] bytes = File.ReadAllBytes("Content/effects.mgfxo");
effect = new Effect(GraphicsDevice, bytes);
Using the 2MGFX tool is optional, you can either use the tool or the Content pipeline, personally I prefer the Content pipeline because it will automatically process the shader file everytime I (re)build the Content project.
How to do this?
First: add a MonoGame Content project,
Then add the .FX file in this project
Set the Content processor to: "MonoGame effect content processor" in properties
Then, in your game project Add a Reference to this Content project.
And use the shader like so:
var myEffect = Content.Load<Effect>("shaderFileNameWithoutExtension");
or if you have folders in your content project:
var myEffect = Content.Load<Effect>("FolderName\\shaderFileNameWithoutExtension");
I'm seeing you're working on Linux. Compiling shaders on Linux is a little difficult. In my own projects, I find the following resource especially helpful.
http://www.infinitespace-studios.co.uk/general/monogame-building-fx-shaders-on-a-mac-and-linux/
Following this, you're able to build shaders using the MonoGame Pipeline as normal (provided you have added the pipeline reference).
Hope this helps!

XCode warning - duplicate CMakeLists.txt while trying to change project name

I tried to change the name of my xcode project, (which uses the cocos2d framework), but for some reason my main files folder (the one that contains all the .h and .mm files) wouldn't change the name. so then i manually clicked under "MyProj TARGETS -> Build Settings" and manually changed the fields:
Info.plist File
Header Search Paths
User Header Search Paths
Prefix Header
to be using "MyProj/" instead of "PrevName/" (the previous name i had named the project) but now i'm getting these two strange warnings:
Warning: Multiple build commands for output file /Users/me/Library/Developer/Xcode/DerivedData/MyProj-fzlkaghtvjzkgkenbpejhzwvxsft/Build/Products/Debug-iphonesimulator/MyProj.app/CMakeLists.txt
Warning: The Copy Bundle Resources build phase contains this target's Info.plist file 'MyProj/Resources/Info.plist'.
you'll see that this is also mentioned under: http://www.cocos2d-iphone.org/forum/topic/33245 but no one has answered this part
and i tried to look under Xcode warning: "Multiple build commands for output file" to see under "Build Phases -> Copy Bundle Resource"... and indeed, there were 2 CMakeLists.txt files. one is:
MyProj/libs/Box2D
and the other is:
MyProj/libs/kazmath/src
which one do i need? or do i need both, since i think xcode used to be compiling with both??
i should mention that my project seems to be running okay right now if i leave the warnings in. but i don't like warnings that i don't understand, and i know that i could just swap my source/assets to a new project to get rid of the warning, but i'd like to know for future reference how to properly rename everything in a xcode project.
Thanks
Oh wow... I had no idea the traffic on stackoverflow is so low these days...(or at least for xcode & iOS dev) sighs
Anyways, I think I figured out a fix.
I read apple developer guilde for the second Warning
For the first Warning, I looked at another file that I had created, and I compared my project's settings to the other project's settings. (such a simple solution, duh, why didn't I think of this >_<) and it turns out, under Copy Bundle Resources, you're only supposed to have:
Your .png files and other resources used in code (but NOT your plist file, for the very reason given in the link above)
iTunesArtwork
ChangeLog
Actually, i'm not sure if you even need #2 or #3. I'll give an upvote to whoever experiments with it. So.... the solution is to simply remove all those other CMakeLists and cmakes and all that junk, including plist :)

Precompiled Header with Constants issue

I have a few constants files "Constants.h" in my project that I am including in the Prefix.pch file to be available to all the classes in my project. They just contain a bunch of #define statements.
My classes don't recognize these constants (no autocomplete) and Xcode gives me "Undeclared Identifier" errors every time I use them. However when I run the project everything works fine (set to ignore errors).
Is there any way I can get rid of these warnings? #pragma ignore them in the prefix file or something? I've tried many options, including setting "precompile prefix header" to NO in build settings.
Any ideas?
EDIT:
I have tried deleting derived data and cleaning / deleting build folder to no avail.
It might be worth noting that I have 3 targets in my project, and another project within this project.
Also, some of the #imports import normal classes. Like a category extension on UIFont and an Analytics class. Could this affect it?
To fix this, I had to change the 'Precompile Prefix Header' flag to NO in my target's Build Settings. By doing this you'll lose any build performance achieved by having a cached compiled header file, but in my case, my Prefix Header is pretty small so I wont see a hit in the time it takes to build.
Try deleting the project derived data. Xcode sometimes needs to re-index your project to remove "errors" such as this.
Organizer > Projects > Your Project
Click on the "Delete" button to the right of the Derived Data row.
Immediately quit Xcode, and then reopen.
I had the PCH file importing .h file with a lot of macros (specifically, I use the MJGAvailability header that warns when I use features that are newer than my deployment target).
Replacing:
#import "MJGAvailability.h"
with
#include "MJGAvailability.h"
solved this issue for me.
I had a preprocessor macro in one of my targets that I moved from 'preprocessor macros' to 'preprocessor macros not used in precompiled headers' and that solved the problem.

Multiple build commands warning while building - Objective C

When I build my iPhone Project in XCode, I'm getting the following warning.
[WARN]Warning: Multiple build commands for output file /Users/SilentCoder/Library/Developer/Xcode/DerivedData/myProject-csfqcpziyuvhbiatwwjtkkmwbxwv/Build/Products/Debug-iphonesimulator/myProject.app/car.png
I don't understand what does that mean. I have made targets for both iPhone and iPad for my project.
It's likely that you have specified the resource to be copied to your bundle/resources twice.
(check your copy resource build phases)
Works for me.
Check the list of resources in Project - Target - Build Phases - Copy Bundle Resources Section and remove the resources references.
I create my own first framework following [http://www.raywenderlich.com/65964/create-a-framework-for-ios] (How to Create a Framework for iOS), appearing the same warning.
And I have no extra resources but two source code files (.h and .m).
Lastly, I found that the .h file appears in two place, one is Copy Files, the other is Copy Header, and I delete latter one, the warning disappeared
NB: you get the exact same error message in a slightly different situation: if a header file appears twice in Xcode's internal list of header-files to export.
If the affected file has a .h suffix, then ... instead of removing from the "Copy Bundle Resources" phase, you need to remove from the "Copy Headers" phase.
(NB: this ought to be impossible, and XCode SHOULD NOT allow it to happen, but Xcode's handling of header files is terrible (and doesn't adhere to the standards :( ), so it's quite easy to end up with this "duplicated commands for the same header file" problem)