Is there something like a root_to method in middleman? - middleman

I would like to move source/index.html.erb into a directory to sit nicely alongside the partials I'm using in index.html.erb.
Is there an existing way to move the source/index.html.erb into a directory?
Something like
# config.rb
root_to 'root#index'
So that I can do
source/
root/
|- _hero_box.html.erb
|- index.html.erb

You have two options here. Neither involve moving index.html.erb out of the root of your source directory.
The first one is to provide the path to the partial in your source. It would look like:
<%= partial 'root/hero_box' %>
The alternative is to configure middleman to look for your partials in a specific directory:
# config.rb
set :partials_dir, 'root'
You would not need to prefix the partial with the path in this case.

Related

How to Serving static files with express if it is inside a subdirectory

I am having trouble with serving a html file which is inside a subdirectory inside public folder.
My directory structure looks like:
public/
HTML/
index.html
index.js
I want to serve the index.html for the root route.
This doesn't work:
app.use('/',express.static(path.join(__dirname,'public')));
According to the docs, this should be enough:
app.use(express.static('public'))
It also gives you such example
http://localhost:3000/images/kitten.jpg
http://localhost:3000/css/style.css
http://localhost:3000/js/app.js
http://localhost:3000/images/bg.png
http://localhost:3000/hello.html
It doesn't go much further other than explaining how you can set up multiple public directories. Anyway, it has worked for me in my projects.
Perhaps you need to state directly app.use(express.static('html')) or app.use(express.static('public/html')). Let me know what works for you.

Deploy on Shared Web Host

I have a simple question but I just can't find a straightforward answer anywhere.
I'm not very familiar with apache .htaccess and now I should deploy a ZF2 app on a web host that doesn't allow me to change the website root folder.
I have a standard project structure so my index.php file is located inside the /public folder, like this:
www.mydomain.com
root/ <--- I can't set root to /public folder
/config
...
/module
...
/public
.htaccess
index.php
...
/vendor
...
...
This is from the ZF2 skeleton app.
Please I need a workaround, I'm sure this is a pretty common problem that many ZF2 developers already tackled. I think I should add a .htaccess file to /root but I don't know how to write one that would work in this case.
As always any help is much appreciated,
Dan
In order to make this work you have to take everything from the /public folder and put it inside your web root. The file index.php from the skeleton app must be edited to take account of its new position.
First remove the line:
chdir(dirname(__DIR__));
Because its purpose is to set the current directory to the web root which we are already inside.
Second you have to either:
Replace the line require 'init_autoloader.php' with require 'vendor/autoload.php' (if using composer).
OR
Inside your .htaccess set the ZF2_PATH env variable to where zf2 is installed on your server:
#First line of your .htaccess
SetEnv ZF2_PATH path/to/zf2
Now it should be working.
Make it better
With the above setup you'll have to put all your public folders inside the web root. If you, like me, don't like that just continue reading.
You can put your public folders (e.g., /js, /css) inside /public (index.php and .htaccess still need to be in the root) by simply telling zf2 your new base_path. This is what is used by the basePath() view helper inside your view scripts. You simply need to add the following to your config:
'view_manager' => array(
'base_path' => './public',
),
And the basePath() view helper will output the correct urls.
Make it even better
The last problem with this setup is that your app files are accessible from the web. To fix this I put everything I want to hide inside the /private folder. You end up with a project structure similar to this:
/root
/private
/config
/data
/module
/vendor
.htaccess <-- You have to create this one
composer.json
composer.lock <-- Created by composer after install
composer.phar
/public
/css
/js
.htaccess
index.php
Inside the /private folder you have to create a new .htaccess file and put this line inside it:
Deny from all
This makes everything inside the folder not accessible from the web.
With this change you have broken your app. Infact inside /private/config/application.config.php you have to adjust the module_paths config:
'module_listener_options' => array(
'module_paths' => array(
'./module',
'./vendor',
),
),
You have to prepend /private to the paths:
'module_listener_options' => array(
'module_paths' => array(
'./private/module',
'./private/vendor',
),
),
This will make your app run once again. Now you can deploy your ZF2 apps to shared web hosts and retain a clean project structure.

How to change the rails asset location of the javascripts template folder?

Currently to require a javascript template file, I put the file in app/assets/javascripts/templates, and include a line like this in a javascript file:
// = require templates/cool_thing.jst
And then I access the template in my javascript like this:
JST['templates/cool_thing']
This works fine, of course, but it requires having my templates put in a subdirectory of the assets/javascript folder. Templates are a large part of my project and I'd really like them to have their own space.
Ideally, I'd love to have my rails 3 assets folder organized like this:
- Assets
- javascripts
- templates
- stylesheets
And then require the templates like thus:
// = require templates/cool_thing.jst
And access them in javascript like this:
JST['cool_thing']
Is this possible, and if so how is it done?
Add this to your application.rb config:
config.assets.paths &lt&lt File.join(Rails.root, 'app', 'assets', 'templates')

Works only in root folder

My application written with YII framework works only if placed in root folder like: Localhost/
if I place it somewhere like: localhost/test, then it does not work(Links does not work, CSS is not attaching)
Where should I change it? thanks!
You should work around your basePath variable in protected/config/main.php.
In almost all cases it looks like
'basePath' => dirname(__FILE__).'/..'
But if this won't help you i think you should check your web-server config.

Rails engine 'require' prefix

If i have a gem 'foo' (Which is engine-based), how can i say that all files included in it will need the 'foo/' prefix when 'require'ing them?
For instance, if in my 'foo' gem i have a 'bar.rb' file, i'd like to be able to force that the inclusion of this file are done like this:
require 'foo/bar'
instead of the usual
require 'bar'
i want this behavior to apply whatever the inclusion context is (From an APP, from another gem, etc)...
i know it's doable since most of rails files are included through the 'rails' prefix:
require 'rails/something'
You can't do that programatically other than manually specifying the prefix manually when the files are required. There's no way for Ruby to know other than if you tell it.
How about this:
Dir["/path/to/directory/*.rb"].each {|file| require file }
Just make sure you have your foo in the root directory and the rest of the files in the subdirectory (otherwise it'll include itself)