Generating a project in Padrino is not quite as simple as rails new_project. Since Padrino strives for agnosticism, you should provide it with a list of systems to use. For example, you want Haml for HTML generation and Sass for CSS generation. I say should because if you don't provide these parameters to the generator command, Padrino will select some defaults. However, those defaults are probably not what you want.
Before generating a project in Padrino, you must first install Padrino.
Generating anything in Padrino, including entire projects, is done with the padrino-gen command. The first argument to this command is what you want to generate. In this case, we want to generate a project. Following that, you'll need to provide a list of the gems you want to use for HTML generation, CSS generation, the database, testing and any client-side scripting. A list of these switches is below, as well as what will be used in this example. Also, each of these switches also has a short version, but the long versions are much easier to remember.
While it is more work to go through all these commands, it does give you exactly what you want. Unlike Rails (at least anything before Rails 3), you're not stuck with what Rails gives you, but this freedom comes at a small price. You really need to tell Padrino what you want, or it'll give you something you don't.
There's one final switch that needs mentioning, the -b, --run-bundle switch. This will run Bundler, which will look at the Gemfile generated by padrino-gen and install any dependencies you'll need. So, if you didn't have Haml installed, or any other gems your project will need, Bundler will install them.
Once we stitch together all these switches, the command will look something like the following. Note that if you put a backslash as the last character of a command in Bash, it will allow you to continue the command on the next line. If you're using another shell, or this isn't working for you, you can put all the switches on the same line. This is only done for the sake of readability.
You should see quite a lot of files being created, and if everything worked, you'll see a message that reads hello_world is ready for development! Ignore the directions to run bundle from the project directory, that was already done with the --run-bundle command line switch.
If any error messages were displayed, scroll up to the first error message in the chain. This should give you a clue as to what's wrong. For example, on my first attempt, activerecord failed to install because I needed to install the SQLite development files (headers and static libraries or source code). Once you fix the problem, you can try again by running bundle install from the project directory.
You're done! Your project is generated and ready to go. Take a look around in the new directory, and you'll see some very familiar things if you're familiar with other MVC frameworks.
Before generating a project in Padrino, you must first install Padrino.
Generating anything in Padrino, including entire projects, is done with the padrino-gen command. The first argument to this command is what you want to generate. In this case, we want to generate a project. Following that, you'll need to provide a list of the gems you want to use for HTML generation, CSS generation, the database, testing and any client-side scripting. A list of these switches is below, as well as what will be used in this example. Also, each of these switches also has a short version, but the long versions are much easier to remember.
- -d, --orm=ORM - Which database engine (or Object Relational Model) you wish to use. This could be some kind of NoSQL type database, or just ActiveRecord, which you should be familiar with if you've used Rails.
- -t, --test=TEST - Which TDD library to use. The default is rspec, but we don't want testing for this "Hello World" type application, so we'll use none.
- -m, --mock=MOCK - Which mockup library to use. This is only useful if you're using a TDD library, so we'll use none.
- -s, --script=SCRIPT - Which client-side scripting library to use. Though this project won't use any client-side Javascript scripting, we'll include jquery anyway.
- -e, --renderer=REND - Which HTML rendering engine to use. If you want Rails-like ERB templates, you can use ERB but we'll be using haml.
- -c, --stylesheet=STYLESHEET - Similar to the HTML renderer, you can choose the stylesheet renderer. We're not going to bother with a stylesheet renderer in this small project, so we'll choose none.
While it is more work to go through all these commands, it does give you exactly what you want. Unlike Rails (at least anything before Rails 3), you're not stuck with what Rails gives you, but this freedom comes at a small price. You really need to tell Padrino what you want, or it'll give you something you don't.
There's one final switch that needs mentioning, the -b, --run-bundle switch. This will run Bundler, which will look at the Gemfile generated by padrino-gen and install any dependencies you'll need. So, if you didn't have Haml installed, or any other gems your project will need, Bundler will install them.
Once we stitch together all these switches, the command will look something like the following. Note that if you put a backslash as the last character of a command in Bash, it will allow you to continue the command on the next line. If you're using another shell, or this isn't working for you, you can put all the switches on the same line. This is only done for the sake of readability.
$ padrino-gen project hello_world \
> --orm=activerecord \
> --test=none \
> --mock=none \
> --script=jquery \
> --renderer=haml \
> --stylesheet=none \
> --run-bundle
You should see quite a lot of files being created, and if everything worked, you'll see a message that reads hello_world is ready for development! Ignore the directions to run bundle from the project directory, that was already done with the --run-bundle command line switch.
If any error messages were displayed, scroll up to the first error message in the chain. This should give you a clue as to what's wrong. For example, on my first attempt, activerecord failed to install because I needed to install the SQLite development files (headers and static libraries or source code). Once you fix the problem, you can try again by running bundle install from the project directory.
You're done! Your project is generated and ready to go. Take a look around in the new directory, and you'll see some very familiar things if you're familiar with other MVC frameworks.
SHARE