Is it possible to use virtual paths / subfolders registering scripts in Orchard Themes? - orchardcms

I'm trying to build a new Orchard theme, and to keep things structures I'd like to put script includes in separate folders (this particular script include needs quite a bit of files so to put all of them in the root of the scripts folder doesn't seem so great).
Basicly I can't wrap my head around this:
Script.Require("~/ThemesFolderEtc/Scripts/libs/shadowbox/shadowbox.js");
it seems only possible to do something like this:
Script.Require("shadowbox.js");
Does anyone have any pointers on what virtual path to use, and if it's supported to use virtual paths?

I believe Script.Require is key/value dictionary of registered scripts. Try Script.Include("path"). This is what I do with my css file. I point it to a file on in public dropbox folder which makes changing the css super easy and no ftp!

Related

How do I serve MathJax from a local Happstack server?

I'm not a developer/programmer. I'm just someone trying to use Gitit to take notes. I've got it to the point where it runs on Windows, but the math looks best using MathJax. I don't want to rely on a remote CDN to get the MathJax working (power cuts and internet disconnections are very frequent here). The author of the app mentions it can be setup in "4 lines of code" in Happstack:
mathjax-script: https://d3eoax9i5htok0.cloudfront.net/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML
# specifies the path to MathJax rendering script.
# You might want to use your own MathJax script to render formulas without
# Internet connection or if you want to use some special LaTeX packages.
# Note: path specified there cannot be an absolute path to a script on your hdd,
# instead you should run your (local if you wish) HTTP server which will
# serve the MathJax.js script. You can easily (in four lines of code) serve
# MathJax.js using http://happstack.com/docs/crashcourse/FileServing.html
# Do not forget the "http://" prefix (e.g. http://localhost:1234/MathJax.js)
The link to the tutorial is broken, so I'd be grateful for some assistance. Is there is any MathJax configuration I need to change, or simply extracting the files will do? I'll be writing lots of math in gitit. I'd prefer not to set up Apache etc. to serve MathJax. Gitit already uses Happstack, I'd prefer using that. Thanks!
EDIT: Just to be clear I'm not sure how to assign the port 1234 to serve this script
Ok I got MathJax working using portable Apache and the MathJax archive downloaded from docs.mathjax.org. The URL needs to be of the form (assuming you extracted the files into apache2/htdocs/MathJax):
http://localhost/MathJax/MathJax.js?config=TeX-AMS-MML_HTMLorMML
I wanted to keep this lightweight by reusing the same instance of Happstack as Gitit, but that seems beyond my skills/available time right now.
EDIT: Just found out that ghc will pack everything into one exe when building. So I doubt it is even possible to use the same Happstack instance, as the root directory of the server doesn't exist?
From the documentation, the static directory should work just fine:
On receiving a request, gitit always looks first in the static
directory (or in whatever directory is specified for static-dir in the
configuration file). If a file corresponding to the request is found
there, it is served immediately. If the file is not found in static,
gitit next looks in the static subdirectory of gitit's data file
($CABALDIR/share/gitit-x.y.z/data). This is where default css, images,
and javascripts are stored. If the file is not found there either,
gitit treats the request as a request for a wiki page or wiki command.
So, you can throw anything you want to be served statically (for
example, a robots.txt file or favicon.ico) in the static directory.
You can override any of gitit's default css, javascript, or image
files by putting a file with the same relative path in static. Note
that gitit has a default robots.txt file that excludes all URLs
beginning with /_.
(source: https://github.com/jgm/gitit)
Download the MathJax.js file from e.g. cdn.mathjax.org and place it in data/static/js/MathJax.js. Then change the config you quote to:
mathjax-script: http://localhost:5001/js/MathJax.js

How to use .htaccess to reformat a directory listing while including the directory name?

For directory listings, I've created a common .htaccess file as well as a common header ("HeaderName /header.html).
Everything works fine, except one thing: while I don't want the derpy h1 version of "Index of /blah", I'd like to display a customized (and normal-sized) version of that, e.g., "CurDir = /blah". By default, specifying the HeaderName replaces all of that with some static text.
I tried embedding a bit of PHP (getcwd()) but that just returned the root directory where the header.html lives, no matter what subtree was being displayed. Surely there's some way to access the CWD without having to sprinkle control files like this in each subfolder?
I stumbled upon what may be a suitable environment variable while looking at the phpinfo() output... but is there a better (more common) way people handle this, perhaps without even using PHP?
<?php
$dir = getenv("REQUEST_URI");
?>

Best practice for white-labeling a static web site?

I have a directory structure with files under directory 'web', which represents a white-label web site (html files, images, js etc.).
I also have some twenty different 'brands' let's call them 'web-1', 'web-2' etc. each containing specific files that should override the files in 'web' for a specific brand.
Apache is configured to find the files for each virtual site i in document root 'website-i'.
In order for each 'website-i' to contain content like 'web' with the overrides for brand 'web-i', my build script first copies all of 'web' to 'website-i' and then overrides it with the source files from 'web-i'.
There several problems with this approach:
It takes time to copy the files.
It takes a lot of disk space
Adding a new brand requires adding to the script.
Is there a best practice for doing this in a way that does not require duplicating files?
(with Apache and Linux)
Well, the best solution is with pretty simple server-side code but I'm going to assume you've already rejected that, maybe because you haven't permission to run code on the server (although if your hacking the config then you probably do).
A solution just in config could be to make it serve from the default root but rewrite the url if the file exists in the proper dir ...
RewriteCond /web-1/a_file -f
RewriteRule ^(.*)$ /web/$1
But you'd have to do this for every file in every brand. You might be able to be more clever about it if the files are stored in a dir that's the same as the hostname but that's getting too complex for me.
Seriously, server-side code is the way to go on this...
Strangely enough, a work colleague was in pretty much exactly the same situation a couple of weeks ago and he eventually rewrote it as PHP. Each site is a row in a database, one page which pulls out the changed text and urls for images, etc. and falls back to a default if there's nothing there.
Having said all that. Using links, as you say above, solves problem 2, probably much of 1 and I don't think there's a way around 3 any way.

XUL accessing resources and application structure

So I'm new to XUL.
As a language it seems easy enough and I'm already pretty handy at javascript, but the thing I can't wrap my mind around is the way you access resources from manifest files or from xul files. So I did the 'Getting started with XULRunner' tutorial... https://developer.mozilla.org/en/getting_started_with_xulrunner
and I'm more confused than ever... so I'm hoping someone can set me straight.
Here is why... (you may want to open the tutorial for this).
The manifest file, the prefs.js and the xul file all refer to a package called 'myapp', that if everything I've read thus far on MDN can be trusted means that inside the chrome directory there must be either a jar file or directory called myapp, but there is neither. The root directory of the whole app is called myapp, but I called mine something completely different and it still worked.
When I placed the content folder, inside another folder called 'foo', and changed all references to 'myapp' to 'foo', thus I thought creating a 'foo' package, a popup informed me that it couldn't find 'chrome://foo/content/main.xul', though that's exactly where it was.
Also in the xul file it links to a stylesheet inside 'chrome://global/skin/' which doesn't exist. Yet something is overriding any inline styling I try to do to the button. And when I create a css file and point the url to it, the program doesn't even run.
Can someone please explain what strange magic is going on here... I'm very confused.
When you register a content folder in a chrome.manifest you must use the following format:
content packagename uri/to/files/ [flags]
The uri/to/files/ may be absolute or relative to the location of the manifest. That is, it doesn't matter what the name of the containing folder is relative to your package name; the point is to tell chrome how to resolve URIs of the following form:
chrome://packagename/content/...
The packagename simply creates a mapping to the location of the files on disk (wherever that may be).
The chrome protocol defines a logical package structure, it simply maps one URL to another. The structure on disk might be entirely different and the files might not even be located on disk. When the protocol handler encounters an address like chrome://foo/content/main.xul it checks: "Do we have a manifest entry somewhere that defines the content mapping for package foo?" And if it then finds content foobar file:///something/ - it doesn't care whether that URL refers to a file, it simply resolves main.xul relatively to file:///something/ which results in file:///something/main.xul. So file:///something/browser.xul will be the URL from which the data will be read in the end - but you could also map a chrome package to another chrome URL, a jar URL or something else (theoretically you could even use http but that is forbidden for security reasons).
If you look into the Firefox/XULRunner directory you will see another chrome.manifest there (in Firefox 4/5 it is located inside omni.jar file). That's where the mappings for global package are defined for example.

where should I store CSS files in a sharepoint install?

I have some css files that are deployed in a feature scoped to "site"
They contains some calls to images (also deployed by the solution) and so the paths are things like
background: #ffcc00 url( '/sites/portal/Style Library/CSS/PersonalCenter.gif' ) repeat-x;
However I would quite like to be able to deploy to other "sites/XXXX" without having to change the url in all the css files!
I cannot just place them in the top level URL as it has its own styles etc and it would be confusing to mash styles from subs-sites into it.
Is there somewhere else I should be storing things like this?
Thanks!
How about placing them (the images) in _layouts, then you could use
url( '/_layouts/images/PersonalCenter.gif' )
There are two major options for this:
1. Store your images in the Style Library.
Browse to /sites/portal/Style Library/Images and create a folder there to store your images. This appears to be similar to what is already being done in the CSS file. Use a relative path in the CSS file to avoid the /sites/portal part of the URL.
Advantages: Version control, no need to worry about deployment across multiple servers.
2. Store your images on the file system.
Create a folder for the images specific to your solution, e.g. at
C:\Program Files\Common
Files\Microsoft Shared\web server
extensions\12\TEMPLATE\IMAGES\siteXXX
This maps to the folder that Johan mentions where you would use
/_layouts/images/siteXXX/image.gif
to reference your images.
Advantages: Performance (maybe) depending on how the server is configured.
Recommendation: Use the Style Library if possible. Version control alone is a huge benefit.
Thanks for your answers... In the end I have remembered about relative paths and
background: #ffcc00 url( '../CSS/PersonalCenter.gif' ) repeat-x;
works just fine.
The images/css files remain in the Style Library which has been useful to check CSS changes before committing them to the main feature and doing a 'proper' release of the solution
Now why did I not just do that from the start !?

Resources