Parsing LESS options in a Sinatra app - sinatra

I'm having trouble changing the path that LESS uses to include imports. My routes file has
get "/css/main.css" do
less :main, :paths => ["public/css"]
end
However, if I include an external less file with #import in my stylesheet the LESS compiler cannot find the file. I've placed a copy in both the views path and public/css directories, but it still can't find it. It CAN however find plain .css files in public\css.

I hit this today, and was able to solve it like so:
require 'less'
require 'sinatra/base'
class App < Sinatra::Base
# Make LESS #import statements work
Less.paths << settings.views
# Use LESS for CSS
get '/stylesheets/:style.css' do
less(params[:style].to_sym)
end
end

You can use something like this here which I use to pick up all .css files whether scss or plain css (i.e. it looks in public first by default and then moves on to check in views):
get '/css/:file.css' do
halt 404 unless File.exist?("views/#{params[:file]}.scss")
time = File.stat("views/#{params[:file]}.scss").ctime
last_modified(time)
scss params[:file].intern
end
You'd have to replace scss with less to make it work.

Passing options to Less should be fixed in tilt by this commit 70465f9.
If you are using bundler, adding the following line to your Gemfile should fix the problem:
gem 'tilt', :git => 'git://github.com/rtomayko/tilt.git'

Related

How to check if a file is already included?

I have a procedure structure like this:
<someprocedure.p>
<randomCode>
<INCLUDE standardIncludeFile.i>
</someprocedure>
The standardIncludeFile.i-include file can be used with any procedure files. However, it requires other include files to work. F.ex. stantarderror.i and standardconstants.i.
If the someprocedure.p already has included these 2 files, they shouldn't be included in the standardIncludeFile.i. If they're not, they should be included in the standardIncludeFile.i.
Can I use DEFINED inside the standardIncludeFile.i to check if those .i-files are already included in the someprocedure.p?
If I use INCLUDE anyway without any conditions, the Eclipse Open-Edge editor gives me the setting to include once, but I'm not sure if that's a good way. The files are compiled on the server for production, anyway.
Currently stantarderror.i or standardconstants.i do not contain any GLOBAL-DEFINED constants, so I cannot check them that way with DEFINED.
Within your incldue file, do something like this
&IF DEFINED (stantarderror) EQ 0 &THEN
GLOBAL-DEFINE stantarderror stantarderror
// actual code here
&ENDIF

Learning to use a modular approach. Have to save multiple files to see result of css?

Ok, I am trying to learn to use a modular approach to my css for scalable and modular development. My file structure is similar to this.
File Structure
Now, I have a red border on every element that I toggle on and off it helps me visualize as I position elements. Its the first line of code in my _grid.sass file. I have a single file named main.sass with only
#import '_base.sass'
#import '_grid.sass'
#import '_colors.sass'
inside of it. Then, I use atom editor's auto compile to convert main.sass into main.min.css which is linked to the html file. So if I turn off the border property in _grid.sass. I have to save that file, then save main.sass, then save _grid.sass again. I have to be doing something wrong, because if I want to develop an entire site like this, I will have to save 3 times for each individual change, and that will add up to about 5 million redundant saves a minute. Can someone give me some information on this?
I'm assuming you are using the sass-autocompile package. While this is great for single file projects, it doesn't work so well for larger projects.
Instead I would advise using a build system like gulp or grunt. I am more familiar with gulp, so here is a modified version of my build system to work with your project structure.
In order to use this you will need to install gulp and the other packages imported.
var gulp = require('gulp');
var sass = require('gulp-sass');
var rename = require('gulp-rename');
gulp.task('default', function() {
return gulp.src('stylesheets/main.scss')
.pipe(
sass({
outputStyle: 'compressed',
includePaths: ['stylesheets/modules', 'stylesheets/partials', 'stylesheets/vendor']
}).on('error', sass.logError)
)
.pipe(rename('compiled.css'))
.pipe(gulp.dest('stylesheets'));
});
Also, you don't need to (and shouldn't) include the underscore and extension in your partial names, so use #import 'base'; instead of #import '_base.scss';

Issue with a topjson object in a Meteor app built with coffeescript

Apologies for the lack of precision in the question, but I'm not completely sure which of possibly many things I'm doing wrong here.
I'm relatively new to Coffeescript and also geo applications in general, but here goes:
I've got a working (simple) Meteor (.7.0.1) application utilizing coffeescript in both client and server. The issue I'm having occurs when attempting to utilize TopoJSON encoded files to create a layer of US congressional districts. (the purpose of the app is to help highlight voter suppression in the US)
So, a few things: Typically in a non-Meteor app, I would just load the topoJSON file like so:
$.getJSON('./data/us-congress-113.json', function (data) {
var congress_geojson = topojson.feature(data, data.objects.districts);
congress_layer.addData(congress_geojson);
});
Now of course this won't work in Meteor because its not asynchronous.
One of the things that was recommended here on SO was to not worry about reading the file, and to instead change the json file to .js, and then set the contents (which are of course just an object) equal to a variable.
Here's what I did:
First, I changed the .json file to a .js file in the server directory, and added the "congress =" to the beginning of the file. It's a huge file so forgive me for omitting the whole object.
congress = {"type":"Topology",
"objects":
{"districts":
{"type":"GeometryCollection","geometries":[{"type":"Polygon"
Now here's where everything starts to give me issues:
In the server.coffee, I've created a variable like so to reference the congress object:
#congress_geojson = topojson.feature(congress, congress.objects.districts)
Notice how I'm putting the # symbol there? I've been told this allows a variable in Coffeescript to be globally scoped? I tried to also use a Meteor feature called "share" where I declare the variable as "share.congress_geojson". That led to the same issues which I will describe below.
Now in the client.coffee file, I'm trying to call this variable to load into a Leaflet map.
congress_layer = L.geoJson(null,
style:
color: "#DE0404"
weight: 2
opacity: 0.4
fillOpacity: 0.1
)
congress_layer.addData(#congress_geojson)
This isn't working, and specifically (despite attempts to find other ways, the errors I'm getting in the console are:
Exception from Deps afterFlush function: TypeError: Cannot read property 'features' of undefined
at o.GeoJSON.o.FeatureGroup.extend.addData (http://localhost:3000/packages/leaflet.js?ad7b569067d1f68c7403ea1c89a172b4cfd68d85:39:16471)
at Object.Template.map.rendered (http://localhost:3000/client/client.coffee.js?37b1cdc5945f3407f2726a5719e1459f44d1db2d:213:18)
I have no doubt that I'm missing something stupidly obvious here. Any suggestions or tips for what I'm doing completely wrong would be appreciated. Is it a case where an object globally declared in a .js file isn't available to code in a .coffee file? Maybe I'm doing something wrong on the Meteor side?
Thanks!
Edit:
So I was able to get things working by putting the .js file containing the congress object in a root /lib folder, causing the object to load first, and then calling the congress object from the client. However, I'm still wanting to know how I could simply share this object from the server? What is the "Meteor way" here?
If you are looking for the Meteor way to order the loading of files, use the Meteor.startup function and put the initialization code there. That function is the $.ready of the Meteor world, i.e., it will execute only after all your files have been successfully loaded on the client.
So in your case:
Meter.startup ->
congress_layer.addData(#congress_geojson)

How to resolve Unable to find file.cpp in path(s) in Marmalade?

I'm just trying to begin develop a game in Marmalade (6.3). But when I have made my new sources (.cpp, and .h) and added them to the mkb, and then trying to run my program, then I got an error which says that Unable to find file.cpp in path(s). It's for all of my files except the files (game.h, game.cpp, main.cpp) which were made by Marmalade when I have chosen the new 2D game project. Should I add my .cpp and .h files to anywhere else?
Thanks
It is difficult to give a categorical answer without more info. However my guess is that you've copied and pasted from an example and not understood about the syntax of the files section. Basically:
files
{
(foo)
humbug.cpp
)
The "(foo)" might look very innocent, but it actually says that humbug.cpp is actually in directory foo - relative to the mkb file. It is common practice to actually use "(source)" and put all the source files in a directory of that name - making the source layout a bit neater.
Naturally if you have (source) and don't put the files actually in directory source, they won't be found. My guess is that is what you are seeing.
Just to clarify previous answer, The format of files directive is like this -
files
{
(<Path relative to MKB>,<Alternate Path>)
["Name of the parent Group in VS/XCode project","Name of the subparent group"]
fileName.cpp
fileName.h
}
for example I have two files SoundManager.h and SoundManager.cpp in System folder of Source, while MainMenu.h and MainMenu.cpp in Source/UI. Now the files directive would be -
files
{
(Source/System)
["Source","System"] #This part is not required, it's just to arrange your files in IDE project
SoundManager.h
SoundManager.cpp
(Source/UI)
("Source","UI")
MainMenu.h
ManinMenu.cpp
}

Joomla template parameters and params.ini - file becomes unwritable after save

I am using wamp on Win XP SP3 and creating a Joomla template with changeable parameters.
initially the message is
The parameter file \templates\ssc_2010\params.ini is
writable!
once I make changes everything works as expected, except now i get the message:
The parameter file \templates\ssc_2010\params.ini is
unwritable!
One solution is to brows to the directory, right click the file, select properties, and uncheck read-only. Again the file is writable but once I modify the parameters again it becomes read only again. I'm quite lazy and would like to prevent this from happening again, I've notice this happening in past projects, but now I have to work a lot with parameters so it becomes quite boring doing manual labor like that :P
There is a bug in Joomla 1.5 that causes the message to be displayed.
A security feature was added that makes the template files unwritable until just before save, where they are made writable, saved, then made unwritable again.
Try to make a change, then go back and check the preview. You will see that the change was actually made.
If you want to fix the annoying unwritable message, add the following code to
administrator/components/controller.php around line 179, just after setting the FTP credentials:
$file = $client->path.DS.'templates'.DS.$template.DS.'params.ini';
// Try to make the params file writeable
if (!$ftp['enabled'] && JPath::isOwner($file) && !JPath::setPermissions($file, '0755')) {
JError::raiseNotice('SOME_ERROR_CODE', JText::_('Could not make the template parameter file writable'));
}
This will make the file writable during the edit load process, and before the file's status is posted in the template.
Then for security, in case the edit screen is closed without saving, search for the following lines:
require_once (JPATH_COMPONENT.DS.'admin.templates.html.php');
TemplatesView::editTemplate($row, $lists, $params, $option, $client, $ftp, $template);
and paste the following code just AFTER these lines but before the closing brace:
// Try to make the params file unwriteable
if (!$ftp['enabled'] && JPath::isOwner($file) && !JPath::setPermissions($file, '0555')) {
JError::raiseNotice('SOME_ERROR_CODE', JText::_('Could not make the template parameter file unwritable'));
}
That will make the file unwritable again.
This is the same code that is used in the saveTemplate() function. We are just doing it again before we display the status of the file on the edit screen. If the process fails because of your web server's configuration, you will get warning messages, BEFORE you've made a bunch of changes to your template. :)
P.S. Remember to save a copy of this file separately, so that you can redo the changes when you upgrade Joomla! (if they haven't fixed this themselves yet.)
This sounds like a user rights problem within Windows - have a look a the security permissions for the directory in which the file you are editing is located, and check that the user "IUSR_xxx" (where xxx is the name of your computer) has full control.
If this doesn't work, then can you tell us what version of Windows you are running as this may help...
Matt