What would be the closest thing to having Ruby in HTML like for PHP with <?php ?> tags?
Can it be done without the need of frameworks that impose website structure or without the need to run Ruby servers, ecc... ?
Is there a way?
rack-server-pages
Rack middleware and application for serving dynamic pages in very
simple way. There are no controllers or models, just only views like a
jsp, asp and php!
https://github.com/migrs/rack-server-pages
https://stackoverflow.com/a/32938202/988591
You can run it with "rackup" or any app server supporting rack. For example with passenger you just need to go to the folder where config.ru is and run "passenger start".
You're looking for erb files.
Open a test.erb file and write this down:
<h1><%= "hello" %></h1>
then run it with:
ruby -rerb -e 'puts ERB.new(File.read("test.erb")).result'
To run erb within a webser you need to wrap it somehow.
Here is a gem that does the job:
Serve - A Rapid Prototyping Framework for Web Applications
gem install serve
And then run it on the directory where your scripts are:
serve
The standard address is localhost:4000
You can cram as much logic in a template as you wish, but you still need an application server. PHP has this as mod_php or through FastCGI, etc. Ruby offers many options. Consider serve or create a bare bones sinatra app.
Consider what ends you are trying to achieve. This is generally poor practice and many people moved from the old style PHP to more modern frameworks which avoid this pitfall. This may be why only 2 people use it and you can't find any tutorials.
Related
I am a new learner to node. I am getting some issues with node. Like if it is really required to use any framework/module like 'Express' etc with node?
Cant we just simply create a web application similar to PHP or asp etc. In PHP we can simply create files & we know where to put our files & rest of the things handled by server itself.
PHP Frameworks : CodeIgniter, CakePHP (Tell us where to put code, means MVC etc)
Node Frameworks : Express , Fab.js (Tell us without using these we cant proceed easily)
For example i want to create a simple Profile edit form for a student. In php i can simply create a form in HTML, display already filled values by user in fields & can add some validations on it. But with node,how we can do it?
Where actually should i place my server side files?
Do i really require any framework(express) to do that in node?
Can i write a mixture of html & Node.js together as we usually do in PHP using < ?php ?>
Like if it is really required to use any framework/module like 'Express' etc with node?
No. As with any framework, it just makes life easier for you by doing some common things for you.
In PHP we can simply create files & we know where to put our files & rest of the things handled by server itself.
Typical Node apps have the server built in and have to do URL routing themselves (this is what Express does).
Typical (small) PHP apps use a separate server and let it handle their routing for them.
You can do that with Node, but you need to have some way to link the server to the specific JavaScript program you want to run. You could write all your JavaScript programs to conform with the CGI specification, but CGI isn't very efficient and (my impression is that) most people choosing to use Node do so for performance reasons.
Where actually should i place my server side files?
This is up to you. There are lots of approaches you can take to organise your code.
Can i write a mixture of html & Node.js together as we usually do in PHP using < ?php ?>
PHP makes it easy to mix your business logic with your display logic. This makes it very easy to knock out trivial programs. It also makes it very easy to make non-trivial programs a maintenance nightmare.
As far as I know, Node doesn't come with a templating language but plenty are available through NPM. I'm not aware of any that let you splurge raw JavaScript into the middle of templates, but that isn't a feature I'd consider desirable.
you can put your node files anywhere, it's common to have the main entry point to your app at root level of your project. Then libraries generally are out in a subdirectory, 3rd party modules are managed through npm and install to node_modules by default. node_modules is on node path by default so they can be referenced without paths ie require('async'), assuming you have installed npm async
you don't need any framework, node provides all the tools necessary to create a server in its standard library
node has a couple of templating libraries, I'm pretty sure most of them allow you to mix html and a couple of expressions that evaluate to js, like loops and conditionals. Some might allow arbitrary js, but I don't have any experience with them
I'm trying to make sense on the best way to do automatize a series of things in a row in order to deploy a web-app and haven't yet came up with a suitable solution. I would like to:
use google's compiler.jar to minify my JS
use yahoo's yui-compressor.jar to minify my CSS
access a file and change a string so that header files like "global.css?v=21" get served the correct version
deploy the app (sftp, mercurial or rsync?) omitting certain directories like "/userfiles"
Can you guys put me on the right track to solve this?
Thank you!
you may want to check out phing http://phing.info/ (they are in the process of moving servers so may be down this weekend), but it can do all of what you are wanting and is written in php.
A quick google search should bring up plenty of tutorials to get you started.
You can run php from the command line to do all sorts of fun things.
$ php script_name.php arg1 arg2
See: command line, argv, argc, exec
Running PHP from the command line is very fast. I've been doing this a lot lately for various automation tasks.
I generally run Python projects so this may or may not be an option for you: but apart from writing your own scripts you could look into the following:
Fabric
Buildout
maven
I am using Sinatra to design a web interface for some research we are doing. However, I also want to be able to use phpMyAdmin for database administration. Is there any way to get Sinatra to serve up php? I know that it can be done with some tweaks to Apache, but since I do not control our setup, I was hoping to be able to do it from within Sinatra.
The server I'll be working on is Windows (don't know what version), has Ruby 1.9.2, PHP 5.3.5, and Apache 2.2, and there are no other web facing or database related projects on it.
My goal is to be be able to access it like this:
researchserveraddress/app/admin/index.php
where
researchserveraddress/app/ would be the main page of our app (served by Sinatra).
I'm sorry if I'm unclear, I do not have very much experience with servers and deploying an app, so far, everything I have done has been locally.
You could use rack-legacy, which allows Sinatra to serve PHP files. It simply uses php-cgi to run the scripts. For example, put phpMyAdmin under directory admin and put something along these lines to config.ru:
require 'app'
map "/admin" do
use Rack::Legacy::Php, 'admin'
use Rack::Static, :urls => ['/'], :root => 'admin'
run lambda{|env| [200, {'Content-type' => 'text/plain'}, 'OK']}
end
map "/" do
run Sinatra::Application
end
(If you're not familiar with using config.ru with your Sinatra app, see this part of Sinatra docs).
I'd suggest to configure Apache instead if possible. It strikes me as a cleaner solution and it would be also more efficient, but that's probably not a problem if you're only using it for phpMyAdmin.
Sinatra can't interpret the PHP files so any embedded variables will be left unprocessed.
You COULD use Sinatra to redirect the requests to the appropriate PHP page, which is then handled in the normal fashion by the PHP processor.
I'm trying to make sense on the best way to do automatize a series of things in a row in order to deploy a web-app and haven't yet came up with a suitable solution. I would like to:
use google's compiler.jar to minify my JS
use yahoo's yui-compressor.jar to minify my CSS
access a file and change a string so that header files like "global.css?v=21" get served the correct version
deploy the app (sftp, mercurial or rsync?) omitting certain directories like "/userfiles"
Can you guys put me on the right track to solve this?
Thank you!
you may want to check out phing http://phing.info/ (they are in the process of moving servers so may be down this weekend), but it can do all of what you are wanting and is written in php.
A quick google search should bring up plenty of tutorials to get you started.
You can run php from the command line to do all sorts of fun things.
$ php script_name.php arg1 arg2
See: command line, argv, argc, exec
Running PHP from the command line is very fast. I've been doing this a lot lately for various automation tasks.
I generally run Python projects so this may or may not be an option for you: but apart from writing your own scripts you could look into the following:
Fabric
Buildout
maven
I was just wondering how I use Ant to build my web applications that I have written in PHP? I've googled around a bit and I have seen that it is possible but there are not any examples of the basic idea or any advanced use for them. Can any of you help me out?
Thanks!
This is definitely possible. If you are looking for a pure php solution phing might be what you want. Also note that there's usually no reasons to build PHP scripts. They should 'just work'.
While Ant itself is written in java, you can use it to build any kind of applications you want. Here's a basic tutorial and a full manual. Beyond that, you need to clarify what is it you want to do to get a more precise answer here.
Update (based on question clarifications):
Copying / moving files / folders is easy via Ant. Look through the "Hello World" tutorial I've linked above and Familiarize yourself with FileSet concept and Copy, Mkdir and Move tasks to get started. Here's another tutorial that shows how to set up a basic build (ignore java-specific stuff like javac/war).
Making changes to the database is an entirely different subject. If you have 'alter' scripts ready, you can use Ant's Exec task to invoke your DB's command-line client to run those scripts (though I probably wouldn't do it in production). If you want to use Ant to track those changes, then you're looking at the wrong tool. Liquibase can be used to do that and it seems to be getting a lot of traction lately. It's quite like Ant in the sense that it's written in Java but can be used in any environment. I'm no PHP expert so I wouldn't know if there's something more PHP-geared available.
We use ant to 'build' php apps. At it's most basic, the ant script just copies the file into the folder on the testing webserver (localhost in my case).
Why do this? well there's not a great deal of point to it, but it is a handy way to avoid putting .svn files into the webserver. If you want to change the location of the webserver you can just build to the new location. You can also do different things according to whether you're on Linux or Windows for example, but I've never used that side of it.
Having tried Phing, Ant and Gradle, I would strongly recommend gradle. Here is a bit of description Choosing tools for PHP application automation