Simple "static" Ruby sites? - ruby

For early development, I typically build out a static version of the site. Previously I'd use PHP and have something like...
images
javascripts
stylesheets
templates
-- header.php
-- footer.php
index.php
users.php
And the index.php and users.php would have some basic PHP include code for those header and footer files.
I also got the added benefit of being able to use a few PHP functions.
But I haven't used PHP for anything in ages and use Ruby almost exclusively...so I'm wondering, is there a way to pull off something really basic like this in Ruby?
Primarily looking for something that allows me to:
Do basic file includes (so I can create simple templates)
Run Ruby inside the files
Ideally I could also use LiveReload with it.
Additional details: I'm running this locally on OS X and I typically use Pow as a server.

Peter is right to recommend Sinatra. There are typically two types of Sinatra applications. Modular and classical. For your example, I'll create a classical application. It isn't much work to convert it to a modular if you find that style would better fit your needs.
You'll want to install the gem with gem install sinatra. Create a new directory for your project and two new files as follows:
# app.rb
require 'sinatra'
get '/' do
erb :index
end
# config.ru
require './app'
run Sinatra::Application
Create another directory called views and add this file:
# index.erb
Hello World!
Then type ruby app.rb and viola, you now have a working project on localhost:4567/.
To serve static files like css and js, just create a public directory. From there, any file will be able to accessed after the root url. So if you created a css folder, its respective url would be: yourdomain.com/css/styles.css.
So the entire directory would be as folllows:
app/
app.rb
config.ru
public/
css/
js/
images/
views/
index.erb
Between the Sinatra Book and the read me, you should be able to find all the info you need.
To accomplish the templates, you'll need something called Sinatra Partial.
I'm not too familiar LiveReload but it seems like Compass accomplishes the same thing and has great integration with Sinatra. So long as pow is a rack based, you should have no problem using it.
Here is a Sinatra Bootstrap I use for all my projects. It has Compass and Sinatra Partial preconfigured and makes it really easy to deploy with Heroku. It also uses Slim, Coffeescript, Thin (as the server), Twitter Bootstrap and Sass but it shouldn't be too much work to sub that with your respective favorites or remove them all together.

I gifted my girlfriend a website with her domain name, I chose Jekyll for the job which uses RubyGems for the purpose.
It was easy and fun. Moreover you have lots of themes available which you can configure with .YML files just changing there will work for hole site. Although Linux or Mac OS is suggested by official Jekyll website but i did it in windows which was not much of a problem. They have steps defined for working on windows on their website.
http://jekyllrb.com/
The best part was that i could host the website via the git hub pages only. I didn't have to buy anything. Git hub allows you to host one repo. (funFact : Jekyll was developed by github inventor)
That's the one i used and made the website in 20 hours with no prior knowledge of Ruby and Jekyll.
So i will suggest you check it out!

Perhaps Jekyll will fit the bill?
Its description:
Jekyll is a simple, blog aware, static site generator. It takes a
template directory (representing the raw form of a website), runs it
through Textile or Markdown and Liquid converters, and spits out a
complete, static website suitable for serving with Apache or your
favorite web server. This is also the engine behind GitHub Pages,
which you can use to host your project’s page or blog right here from
GitHub

Yes, i use Sinatra for this, see https://github.com/sinatra/sinatra/ for some samples.
Running ruby inside the files isn't very static but in Sinatra you can do both.

Jekyll won't leave you run Ruby code "inside" the files. Jekyll is a parsing engine bundled as a ruby gem. You basically code templates using HTML and Liquid and write content using markdown that gets embebed generating plain HTML files that you can upload to any web server.

Related

Basic HTTP Authentication for a Middleman app

I wonder whether there's an easy way to add Basic HTTP Authentication to a Middleman deployed website? I found some Heroku specific gists, but nothing else.
The Heroku specific gists all seem to need a config.ru file, but do Middleman projects even have such a file? Mine don't.
config.ru is not specific to Middleman or Heroku, but is a convention for serving a rack-based app (see https://devcenter.heroku.com/articles/rack). If you want to have basic auth on a static site that you have built using middleman and then deployed, you will need to set it up in a way that's appropriate to that hosting. Where are you hosting the site?

jekyll plugin not work on github

I want to change the order of pages in navitation bar by using jekyll-plugins / weighted_pages.rb from here.
This plugin work very well on my localhost but github.
I find the navitation bar is empty on github host, which seems this plugin does not work.
How can I solve this problem?
I copy weighted_pages.rb code below:
# Generates a copy of site.pages as site.weighted_pages
# with pages sorted by weight attribute. Pages with no
# weight specified are placed after the pages with specified weight.
module Jekyll
class WeightedPagesGenerator < Generator
safe true
def generate(site)
site.config['weighted_pages'] = site.pages.sort_by { |a|
a.data['weight'] ? a.data['weight'] : site.pages.length }
end
end
end
Add weight attribute to the front matter of your pages (like weight: 1) and use site.weighted_pages instead of site.pages in your loops.
Github pages does not support plugins. From jekyll's documentation:
GitHub Pages is powered by Jekyll, however all Pages sites are generated using the --safe option to disable custom plugins for security reasons. Unfortunately, this means your plugins won’t work if you’re deploying to GitHub Pages.
The same documentation page also gives you a workaround:
You can still use GitHub Pages to publish your site, but you’ll need to convert the site locally and push the generated static files to your GitHub repository instead of the Jekyll source files.
Currently, Github pages does not support some custom plugins.
If you want to make Jekyll site run as if it were local, such as let the custom plugins work properly, here is a way really convenient to build and deploy the Jekyll site to Github Pages.
jekyll-deploy-action - 🪂 A Github Action to deploy the Jekyll site conveniently for GitHub Pages.
https://github.com/jeffreytse/jekyll-deploy-action
With this action, I think your issues can be settled perfectly.

symfony2 how to access app/Resources/img from browser?

I've got some project specific images that I don't want to include in any bundle. I'd like to have them accessible from twig layer. The question is: how can I publish them (I can see neither symlinks in web directory nor assetic config in my project). Any hint will be appreciated.
edit:
When I run
php app/console assets:install help
I get Installing assets for XxxBundle into web/bundles/xxx, but nothing happens for the app/Resources directory.
If you really don't want to put them in a bundle you can just place them directly in the web directory. E.g. image.jpg placed in web/appImages/ can be displayed in a template using img src="/appImages/image.jpg" />.
Nevertheless "the Symfony way" encourages you to keep everything within bundles. If you don't want to have the Resources in one specific bundle where your code lives you can have a separate bundle specifically for the application-wide resources.
You can publish items in the app/Resources/img by doing:
php app/console assetic:dump --env=prod --no-debug
from the root of the project.
That is where you place system wide libraries.

How do I create alias for Jekyll static site on Heroku?

I have a Jekyll site running on Heroku.
After site generation, I have a file created public/photos.html. How do I set up Jekyll/Heroku to allow me to access the page as domain.com/photos instead of domain.com/photos.html?
And I'd prefer NOT to have to use rack-rewrite which stands up rack middleware. Seems a bit much for this.
Thanks!
Simplest way is to just name the file photos/index.html instead of photos.html. If that doesn't work for you, you can use the variable permalink in the Front Matter.
You can do route matching in Sinatra and serve whatever pages you like, see: http://www.sinatrarb.com/intro.html

code igniter framework guidance for beginners

I am just a beginner in code igniter. I have just downloaded the code igniter framework. But i don't know that where should i keep my html, php files and stylesheets, images etc. Is there any procedure to do the things? Please guide me.
CodeIgniter has an awesome user guide that will come with the install you can read through (or read it online at - http://codeigniter.com/user_guide/ ), or you can watch some of the videos on their site - http://codeigniter.com/tutorials/
In comparison to most other frameworks you're going to find they have maybe the smallest learning curve and great documentation. I would also recommend learning basic PHP and getting familiar with your web environment maybe before beginning.
I used these tutorials to help get me started with the framework haven't look back since! http://net.tutsplus.com/sessions/codeigniter-from-scratch/
hi I am a weekend coder and picked up CI about a year ago.
It helped me a lot.
The best tutorial I found was on the IBM's developer site. It runs through putting together a simple application. Admittedly, there's nothing in it about directory and file placement but it helps cement ideas about how models, views and controllers (MVC), and why MVC is so helpful. Because the basic idea is quite simple, it's worth running through a simple CI tutorial again and again till you 'feel' or intuit the basic helpfulness of the setup.
Things like JS, CSS files can be kept in their own folders at the first level of your website folder e.g /js or /css or /images. You ask about PHP files as well. PHP files which you, the coder, write, are either 'views', 'models' or 'controllers'. These go in the folders with those names in the /application folder e.g /application/views/yourview.php or /application/controllers/yourcontroller.php. The CI install comes with a default view file and a default controller, which you are probably already aware of.
The files inside /application/config are important as well. Read the user-guide about tweaking these files. The most obvious tweaks are to database.php to connect to your db, autoload to give automatic use of CI helpers/libraries which you can choose, and to config.php to give CI the name of your website e.g the name you give to '/'.
The file 'index.php' comes with the CI installation (/index.php). You don't need to fiddle with it at all really except to determine the level of error reporting you want ('environment') and that's not a priority at all. But it's important to remember this about index.php - that CI uses it as the essential reference for defining paths to useful folders like CSS or images. So even if your view file is in /application/views, if it refers to an image like a logo.gif in /images for example, the path to it is just /images/logo.gif. It is not anything more complicated like ../../images/logo.gif.
I hope that helps.
Tom
Offline version of CodeIgniter user guide is available with CodeIgniter which already downloaded by you.
just extract your CodeIgniter zip file in your localhost server root directory,
Then http://localhost/www/CodeIgniter_2.1.2/user_guide/ open this url with browser ,here you can access offline version of CodeIgniter user guide.
Here I am using wamp server so I used this url, If you are using xampp server then please use http://localhost/CodeIgniter_2.1.2/user_guide/
Okay this is what I would usually do for code igniter
here is my directory structure.
CI App Path (e.g "c:\xampp\htdocs\ci_app_name" )
-application
-system
-assets
--css (new folder , where css files will be included)
--js (javascript and jquery libraries location)
Basic HTML and PHP files should be location
CI_app_pah
-application
--views (this is where to put HTML and PHP files)
For other things such as Controller , Models and Views , you can't put any where but put in their related area.
That will be
CI app
-application
--controllers
--models
--views

Resources