How to get FitNesse root or page folder in FitSharp - path

Recently I encountered this problem and have searched a lot but no solution by now.
Does somebody know how I can get the root directory or the page folder of FitNesse in FitSharp fixture codes?
One of the troubles is that we have a lot of existing pages arranged in different suites and I want to add some new features to all these pages requiring an absolute path of FitNesse folder. Using a fixture together with the environmental parameter in pages could require a lot of effort. I was even trying to use hard configuration in app.config for example!
Big thanks in advance! Looking forward to your kind answer.

The root path is available as a FitNesse predefined variable. Pass that into a fixture that can expose it as a property. This could go in a setup page.
|rootpath|
|load|${FITNESSE_ROOTPATH}|
public class RootPath {
public static string Path;
public void Load(string value) { Path = value;}
}

Related

Access to Resources resx file failing. (MVC & ErrorMessageResourceType)

Been troubling me for hours this! As a newbie to MVC, have followed various ways of trying to access a resource file in the App_GlobalRecources folder.
The RESX file properties are Embedded Resource as build action, and custom tool is set to PublicResXFileCodeGenerator.
I also have this in the web.config (system.web):
<globalization enableClientBasedCulture="true" culture="auto" uiCulture="auto" />
In a view model, (although have tried accessing from functions with the same problem), I have the following:
Public Class ExternalLoginConfirmationViewModel
<Required(ErrorMessageResourceType:=TypeOf (Resource1), ErrorMessageResourceName:="Test")>
<Display(Name:="Email")>
Public Property Email As String
End Class
The problem is that I get the following error:
'Resource1' is a class type and cannot be used as an expression.
I cannot figure out why as have tried numerous suggestions from numerous websites, and get the same error.
OK - so seemed to have solved it.
Every website I have found advises the VB below (or the C# equivalent):
<Required(ErrorMessageResourceType:=TypeOf (Resource1), ErrorMessageResourceName:="Test")>
Not one website has suggested this which seems to have solved the problem, although I don't know why:
<Required(ErrorMessageResourceType:=GetType(Resource1), ErrorMessageResourceName:="Test")>
Anyway, hope this helps if someone else has the same issue.

How to get the public path in Perl Dancer

Probably a silly question, but how do I get the path to the /public folder in Dancer?
I want to store/read csv files under the public folder, but don't know if Dancer offers any convenience methods to get the base path to the public folder.
The error I get when trying to create a file by saying:
open(FILE, ">>", "myapp/public/file.csv") or die "$!";
is:
No such file or directory in /ur/share/perl5/Dancer/Handler.pm l. 98
I'm not sure why it's going to Handler.pm?
My first answer is, don't do it that way...for two reasons:
You're potentially opening up a security issue. What if somehow a hacker figures out a way to write to your environment files, change your passwords, etc.?
You really want your /public files to be static, for version control, portability, etc.
That being said, if you really still want to do this, the public dir lives in config->{public}:
print "Public dir:".config->{public}."\n";
Source:
http://search.cpan.org/~xsawyerx/Dancer-1.3110/lib/Dancer/Config.pm#public_%28directory%29

Deploy ZF2 site to shared host

When you deploy a Zend Framework website to a shared host, you usually cannot change the DocumentRoot to point at the public/ folder of the website. As a result the URL to the website is now http://www.example.com/public/. This doesn't look very professional, so I'd like to remove it. Up to now I have used ZF1 and Rob Allen kindly provides a method for doing this on his blog http://akrabat.com/zend-framework/zend-framework-on-a-shared-host/ . I have tried to modify this for ZF2. He proposes placing an index.php file in the root with the line:
include 'public/index.php';
After doing this, http://www.example.com opens the index page OK but the CSS links are broken. Rob adds a controller plugin to reset the baseUrl to /public to deal with public facing CSS and image files etc. To do this in ZF2 I found an item from Matthew Weier O' Phinney http://zend-framework-community.634137.n4.nabble.com/Setting-the-base-url-in-ZF2-MVC-td3946284.html where he describes how to set the baseUrl. Based on his code I added this to modules/Application/Module.php
class Module {
public function onBootstrap(MvcEvent $e) {
$config = $e->getApplication()->getServiceManager()->get('config');
$router = $e->getApplication()->getServiceManager()->get('router');
$router->setBaseUrl($config['base_url']);
}
}
The base_url key is set in modules/Application/configs/module.config.php:
'base_url' => '/public'
I was able to dump the router object and confirm that the base_url was being set correctly at this stage. Unfortunately, now http://www.example.com no longer opens the index page and gives a 404 routing error.
Is anyone able to tell me what I am doing wrong or point me in the right direction for running a ZF2 site in a shared hosted environment?
Are you using the skeleton app?
that seems a little over the top, surely it's lot simpler than that.
move everything from public to the root
change index.php
<?php
/**
* This makes our life easier when dealing with paths. Everything is relative
* to the application root now.
*/
//chdir(dirname(__DIR__));
chdir(__DIR__);
// Setup autoloading
require 'init_autoloader.php';
// Run the application!
Zend\Mvc\Application::init(require 'config/application.config.php')->run();
Simples.
If you are running an application like this you may want to block direct access to some of the Zend Framework folders using htaccess etc

Changing file references during the Publishing of the website

I have a master file which has references to the JS and the CSS file used for my website. These references are pointing to the non-crunched version of the files. Now, when I hit the Publish button through Visual Studio for my project I want to change the references in my master file to point to the crunched version of the JS and CSS.
Eg: During development if it was pointing to http://www.example.com/main.js, during publish it should change the reference to http://www.example.com/main_min.js. Is there a way to do this?
Also, before changing the reference I need to run my current js file(main.js) through the tool which outputs the crunched js file(main_min.js).
Any help on this is appreciated!
Thanks.
You could go to the project's properties and in the Build Events tab enter the following into the "Post-build event command line":
$(SolutionDir)..\YourJsCruncher.exe $(ProjectDir)\content\js\debug\ $(ProjectDir)\content\js\release\
and then have a custom HTML helper:
public static MvcHtmlString IncludeJs(this UrlHelper helper, string javascriptFile)
{
#if DEBUG
var subfolder = "debug";
#else
var subfolder = "release";
#endif
var path = helper.Content("~/Content/js/{1}/{2}.js", subfolder, javascriptFile);
return MvcHtmlString.Create(string.Format("<script type=\"text/javascript\" src=\"{0}\"></script>", path));
}
and then in your view:
<%= Url.IncludeJs("foo.js") %>
This question has most of the answers you need:
Concatenate and minify JavaScript on the fly OR at build time - ASP.NET MVC
Customizing the publich process for one click publish is a little trickier. The best I could answer is linking to this blog: http://vishaljoshi.blogspot.com/ When I was working with one-click-publish customization this is the place I found the most answers. If I remember correctly this wasn't trivial and its better to integrate this into your build process like the answers in the first question I link explain.

Read a file form web-app

Inside a grails application, I need to upload a file under web-app/js, add a prefix, and put it in S3. I'm having trouble figuring out how to read the js file in a way that will work in development (/web-app/js) and production (/js). I'm doing this from inside a domain object.
In your controllers, you can call :
def jsFolder = grailsAttributes.getApplicationContext().getResource("js/").getFile()
and then proceed with jsFolder.
To determine the base directory of a running Grails application, use
String dir = applicationContent.getResource("/").getFile()
Getting the js path from a service is a little bit tricky:
You need to implement the ApplicationContextAware interface like this :
class MyService implements ApplicationContextAware {
ApplicationContext applicationContext
However, calling this code from a domain class is not a good idea (see this thread for some explanations) and I am not even sure if it's possible except from getting paths from manual configurations
Hope it helps.

Resources