Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
patcoll committed Apr 6, 2010
1 parent 21ec561 commit f3b284b
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitmodules
@@ -0,0 +1,6 @@
[submodule "vendors/Twig"]
path = vendors/Twig
url = git://github.com/fabpot/Twig.git
[submodule "vendors/yaml"]
path = vendors/yaml
url = git://github.com/fabpot/yaml.git
32 changes: 32 additions & 0 deletions Rakefile
@@ -0,0 +1,32 @@
include FileUtils

BASE_FOLDER = File.expand_path(File.dirname(__FILE__))
BUILD = File.join(BASE_FOLDER, "build")
PUBLIC = File.join(BASE_FOLDER, "public")
TEMPLATES = File.join(BASE_FOLDER, "templates")

task :build do
cd BASE_FOLDER
rm_rf BUILD
mkdir_p BUILD

# copy assets
cd PUBLIC
cp_r "static", BUILD

# get list of templates to process
cd TEMPLATES
templates = Dir["**/*"].delete_if { |p| not p =~ /\.html$/ }

cd BUILD
mkdirs = templates.map { |t| File.dirname(t) }.uniq
mkdir_p(mkdirs)

cd BASE_FOLDER
templates.each do |path|
sh "php #{PUBLIC}/index.php #{path} > #{BUILD}/#{path}"
end
end

task :default => :build

Empty file added data/.gitignore
Empty file.
7 changes: 7 additions & 0 deletions public/.htaccess
@@ -0,0 +1,7 @@
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>
56 changes: 56 additions & 0 deletions public/index.php
@@ -0,0 +1,56 @@
<?php
error_reporting(E_ALL);
ini_set('display_errors', true);

define('BASE_FOLDER', dirname(dirname(__FILE__)) . '/');
define('DATA', BASE_FOLDER . 'data/');
define('PUBLIC', BASE_FOLDER . 'public/');
define('TEMPLATES', BASE_FOLDER . 'templates/');
define('VENDORS', BASE_FOLDER . 'vendors/');

set_include_path(implode(PATH_SEPARATOR, array_merge(glob(VENDORS . '*/lib'), array(get_include_path()))));

require 'sfYaml.php';
require 'Twig/Autoloader.php';

Twig_Autoloader::register();

if (isset($argv) and count($argv) == 2) {
$url = $argv[1];
}
else if (isset($_GET['url'])) {
$url = $_GET['url'];
}
else {
$url = '';
}

if (empty($url)) {
$url = 'index';
}

$url = trim($url, '/');

if (is_dir(TEMPLATES . $url)) {
$url .= '/index';
}
$url = str_replace('.html', '', $url);
$url .= '.html';

$loader = new Twig_Loader_Filesystem(TEMPLATES);
$twig = new Twig_Environment($loader, array(
'debug' => true,
));

$data = array();

foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator(DATA), RecursiveIteratorIterator::LEAVES_ONLY) as $file) {
if (preg_match('/\.ya?ml$/', $file)) {
if ($loaded = sfYaml::load($file->getRealPath())) {
$data = array_merge($data, $loaded);
}
}
}

$template = $twig->loadTemplate($url);
$template->display($data);
Empty file added public/static/.gitignore
Empty file.
Empty file added templates/.gitignore
Empty file.
1 change: 1 addition & 0 deletions vendors/Twig
Submodule Twig added at 0593d7
1 change: 1 addition & 0 deletions vendors/yaml
Submodule yaml added at 9e767c

0 comments on commit f3b284b

Please sign in to comment.