initial commit
This commit is contained in:
commit
b60ffa8f58
5
Manifest
Normal file
5
Manifest
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
Manifest
|
||||||
|
Rakefile
|
||||||
|
bin/trivialize
|
||||||
|
dist/htaccess.dist
|
||||||
|
lib/trivial.php
|
18
Rakefile
Normal file
18
Rakefile
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
require 'rubygems'
|
||||||
|
require 'rake'
|
||||||
|
require 'echoe'
|
||||||
|
|
||||||
|
Echoe.new('trivial', '0.0.1') do |p|
|
||||||
|
p.summary = "Ultra-lightweight website framework for PHP"
|
||||||
|
p.description = <<-EOT
|
||||||
|
For those who are using PHP to build their sites and want a very simple framework
|
||||||
|
in which to organize their files, trivial is the solution. It's one PHP file
|
||||||
|
that can include a few other pre-determined PHP and HTML files based on the
|
||||||
|
request URI. This very simple division of content, actions (controllers), and
|
||||||
|
views allows for multiple people to easily work on a smaller project without
|
||||||
|
the overhead of a larger framework.
|
||||||
|
EOT
|
||||||
|
p.author = "John Bintz"
|
||||||
|
p.email = "john@coswelproductions.com"
|
||||||
|
p.url = "http://github.com/johnbintz/trivial"
|
||||||
|
end
|
24
bin/trivialize
Executable file
24
bin/trivialize
Executable file
@ -0,0 +1,24 @@
|
|||||||
|
#!/usr/bin/env ruby
|
||||||
|
require 'fileutils'
|
||||||
|
|
||||||
|
if !ARGV[0]
|
||||||
|
puts "Please specify the name of a new directory to create & trivialize"
|
||||||
|
exit 1
|
||||||
|
end
|
||||||
|
|
||||||
|
puts "Trivializing #{ARGV[0]}"
|
||||||
|
FileUtils.mkdir ARGV[0] if (!File.directory? ARGV[0])
|
||||||
|
%w{content actions views scripts styles lib}.each do |dir|
|
||||||
|
FileUtils.mkdir File.join(ARGV[0], dir) if (!File.directory? File.join(ARGV[0], dir))
|
||||||
|
end
|
||||||
|
|
||||||
|
FileUtils.cp(File.join(File.dirname(__FILE__), '..', 'lib', 'trivial.php'), File.join(ARGV[0], 'lib', 'trivial.php'))
|
||||||
|
FileUtils.cp(File.join(File.dirname(__FILE__), '..', 'dist', 'htaccess.dist'), File.join(ARGV[0], '.htaccess'))
|
||||||
|
|
||||||
|
if !File.exists? File.join(ARGV[0], 'content', 'index.html')
|
||||||
|
File.open File.join(ARGV[0], 'content', 'index.html'), "w" do |fh|
|
||||||
|
fh.puts %{Your Website construction work just became <a href="http://github.com/johnbintz/trivial/">trivial</a>!}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
puts "Done! Make sure you can use .htaccess files in your Webserver setup."
|
9
dist/htaccess.dist
vendored
Normal file
9
dist/htaccess.dist
vendored
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
RewriteEngine On
|
||||||
|
|
||||||
|
RewriteRule ^$ lib/trivial.php [L]
|
||||||
|
|
||||||
|
RewriteCond %{REQUEST_FILENAME} !-d
|
||||||
|
RewriteCond %{REQUEST_FILENAME} !-f
|
||||||
|
RewriteCond %{REQUEST_FILENAME} !.*\.inc$
|
||||||
|
RewriteRule /(.*) lib/trivial.php [L]
|
||||||
|
|
83
lib/trivial.php
Normal file
83
lib/trivial.php
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
// If you're using a different global default layout name, change it here
|
||||||
|
$layout = 'application';
|
||||||
|
|
||||||
|
// END OF USER-CONFIGURABLE SETTINGS
|
||||||
|
|
||||||
|
function fe_check($path) {
|
||||||
|
global $root_dir;
|
||||||
|
if (file_exists($full_path = ($root_dir . '/' . $path))) {
|
||||||
|
return $full_path;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function partial($name, $local = array()) {
|
||||||
|
$name = preg_replace('#/([^/]+)$', '/_\1', $name);
|
||||||
|
if (($path = fe_check('views/' . $name . '.inc')) !== false) {
|
||||||
|
extract($local);
|
||||||
|
ob_start();
|
||||||
|
include($path);
|
||||||
|
return ob_get_clean();
|
||||||
|
} else {
|
||||||
|
trigger_error("No partial named ${name} found!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$root_dir = realpath(dirname(__FILE__) . '/../');
|
||||||
|
|
||||||
|
$trim = str_replace(realpath($_SERVER['DOCUMENT_ROOT']), '', realpath($root_dir));
|
||||||
|
|
||||||
|
$requested = preg_replace('#/$#', '/index.html', $_SERVER['REDIRECT_URL']);
|
||||||
|
$requested = preg_replace("#${trim}/(.*)\.[^\.]+\$#", '\1', $requested);
|
||||||
|
|
||||||
|
function styles($additional = array()) {
|
||||||
|
return head_component($additional, 'styles/%s.css', '<link rel="stylesheet" href="%s" type="text/css" />');
|
||||||
|
}
|
||||||
|
|
||||||
|
function scripts($additional = array()) {
|
||||||
|
return head_component($additional, 'scripts/%s.js', '<script type="text/javascript" src="%s"></script>');
|
||||||
|
}
|
||||||
|
|
||||||
|
function head_component($additional, $search, $format) {
|
||||||
|
global $requested;
|
||||||
|
|
||||||
|
$output = array();
|
||||||
|
foreach (array_merge(array('application', $requested), $additional) as $file) {
|
||||||
|
if (fe_check(sprintf($search, $file)) !== false) {
|
||||||
|
$output[] = sprintf($format, $file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return implode("\n", $output);
|
||||||
|
}
|
||||||
|
|
||||||
|
$content = null;
|
||||||
|
if (($content_file = fe_check('content/' . $requested . '.html')) !== false) {
|
||||||
|
$content = file_get_contents($content_file);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (array('application', $requested) as $action) {
|
||||||
|
if (($action_file = fe_check('actions/' . $action . '.inc')) !== false) {
|
||||||
|
include($action_file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (($view_file = fe_check('views/' . $requested . '.inc')) !== false) {
|
||||||
|
ob_start();
|
||||||
|
include($view_file);
|
||||||
|
$content = ob_get_clean();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_null($content)) {
|
||||||
|
trigger_error("No content generated for ${requested}! Did you create a content, action, or view file for this request?");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (($layout_file = fe_check('views/' . $layout . '.inc')) !== false) {
|
||||||
|
ob_start();
|
||||||
|
include($layout_file);
|
||||||
|
$content = ob_get_clean();
|
||||||
|
}
|
||||||
|
|
||||||
|
echo $content;
|
38
trivial.gemspec
Normal file
38
trivial.gemspec
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
# -*- encoding: utf-8 -*-
|
||||||
|
|
||||||
|
Gem::Specification.new do |s|
|
||||||
|
s.name = %q{trivial}
|
||||||
|
s.version = "0.0.1"
|
||||||
|
|
||||||
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
||||||
|
s.authors = ["John Bintz"]
|
||||||
|
s.date = %q{2010-03-21}
|
||||||
|
s.default_executable = %q{trivialize}
|
||||||
|
s.description = %q{ For those who are using PHP to build their sites and want a very simple framework
|
||||||
|
in which to organize their files, trivial is the solution. It's one PHP file
|
||||||
|
that can include a few other pre-determined PHP and HTML files based on the
|
||||||
|
request URI. This very simple division of content, actions (controllers), and
|
||||||
|
views allows for multiple people to easily work on a smaller project without
|
||||||
|
the overhead of a larger framework.
|
||||||
|
}
|
||||||
|
s.email = %q{john@coswelproductions.com}
|
||||||
|
s.executables = ["trivialize"]
|
||||||
|
s.extra_rdoc_files = ["bin/trivialize", "lib/trivial.php"]
|
||||||
|
s.files = ["Manifest", "Rakefile", "bin/trivialize", "dist/htaccess.dist", "lib/trivial.php", "trivial.gemspec"]
|
||||||
|
s.homepage = %q{http://github.com/johnbintz/trivial}
|
||||||
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Trivial"]
|
||||||
|
s.require_paths = ["lib"]
|
||||||
|
s.rubyforge_project = %q{trivial}
|
||||||
|
s.rubygems_version = %q{1.3.6}
|
||||||
|
s.summary = %q{Ultra-lightweight website framework for PHP}
|
||||||
|
|
||||||
|
if s.respond_to? :specification_version then
|
||||||
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
||||||
|
s.specification_version = 3
|
||||||
|
|
||||||
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
||||||
|
else
|
||||||
|
end
|
||||||
|
else
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user